Skip to content

Commit 41826ad

Browse files
committed
support redis protocol
Signed-off-by: Shuyi Cheng <chengshuyi@linux.alibaba.com>
1 parent b0e356a commit 41826ad

File tree

9 files changed

+741
-39
lines changed

9 files changed

+741
-39
lines changed

core/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ if (LINUX)
158158
if (ENABLE_ENTERPRISE)
159159
set(SUB_DIRECTORIES_LIST ${SUB_DIRECTORIES_LIST} shennong shennong/sdk apm/forward)
160160
endif()
161-
set(SUB_DIRECTORIES_LIST ${SUB_DIRECTORIES_LIST} ebpf ebpf/type ebpf/type/table ebpf/util ebpf/util/sampler ebpf/protocol/http ebpf/protocol/mysql ebpf/protocol ebpf/plugin/file_security ebpf/plugin/network_observer ebpf/plugin/process_security ebpf/plugin/network_security ebpf/plugin ebpf/observer ebpf/security
161+
set(SUB_DIRECTORIES_LIST ${SUB_DIRECTORIES_LIST} ebpf ebpf/type ebpf/type/table ebpf/util ebpf/util/sampler ebpf/protocol/http ebpf/protocol/mysql ebpf/protocol/redis ebpf/protocol ebpf/plugin/file_security ebpf/plugin/network_observer ebpf/plugin/process_security ebpf/plugin/network_security ebpf/plugin ebpf/observer ebpf/security
162162
prometheus prometheus/labels prometheus/schedulers prometheus/async prometheus/component
163163
host_monitor host_monitor/collector host_monitor/common forward forward/loongsuite
164164
)

core/ebpf/plugin/network_observer/Connection.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,12 @@ static constexpr StringView kExternalStr = "external";
3535
static constexpr StringView kLocalhostStr = "localhost";
3636
static constexpr StringView kHttpStr = "http";
3737
static constexpr StringView kMysqlStr = "mysql";
38+
static constexpr StringView kRedisStr = "redis";
3839
static constexpr StringView kSqlStr = "sql";
40+
static constexpr StringView kNoSqlStr = "nosql";
3941
static constexpr StringView kRpc25Str = "25";
4042
static constexpr StringView kRpc60Str = "60";
43+
static constexpr StringView kRpc105Str = "105";
4144
static constexpr StringView kRpc0Str = "0";
4245
static constexpr StringView kHttpClientStr = "http_client";
4346
static constexpr StringView kUnknownStr = "unknown";
@@ -132,6 +135,11 @@ void Connection::TryAttachL7Meta(support_role_e role, support_proto_e protocol)
132135
mTags.SetNoCopy<kCallKind>(kSqlStr);
133136
mTags.SetNoCopy<kCallType>(kMysqlStr);
134137
MarkL7MetaAttached();
138+
} else if (mProtocol == support_proto_e::ProtoRedis) {
139+
mTags.SetNoCopy<kRpcType>(kRpc105Str);
140+
mTags.SetNoCopy<kCallKind>(kNoSqlStr);
141+
mTags.SetNoCopy<kCallType>(kRedisStr);
142+
MarkL7MetaAttached();
135143
}
136144
}
137145

core/ebpf/plugin/network_observer/NetworkObserverManager.cpp

Lines changed: 4 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -574,23 +574,8 @@ bool NetworkObserverManager::ConsumeLogAggregateTree() { // handler
574574
logEvent->SetContent(kLatencyNS.LogKey(), std::to_string(record->GetLatencyNs()));
575575
auto timeSpec = ConvertKernelTimeToUnixTime(record->GetStartTimeStamp());
576576
logEvent->SetTimestamp(timeSpec.tv_sec, timeSpec.tv_nsec);
577-
auto protocol = record->GetConnection()->GetProtocol();
578-
if (protocol == support_proto_e::ProtoHTTP) {
579-
auto* httpRecord = static_cast<HttpRecord*>(record);
580-
logEvent->SetContent(kHTTPMethod.LogKey(), httpRecord->GetMethod());
581-
logEvent->SetContent(kHTTPPath.LogKey(),
582-
httpRecord->GetRealPath().size() ? httpRecord->GetRealPath()
583-
: httpRecord->GetPath());
584-
logEvent->SetContent(kHTTPVersion.LogKey(), httpRecord->GetProtocolVersion());
585-
logEvent->SetContent(kStatusCode.LogKey(), std::to_string(httpRecord->GetStatusCode()));
586-
logEvent->SetContent(kHTTPReqBody.LogKey(), httpRecord->GetReqBody());
587-
logEvent->SetContent(kHTTPRespBody.LogKey(), httpRecord->GetRespBody());
588-
} else if (protocol == support_proto_e::ProtoMySQL) {
589-
auto* mysqlRecord = static_cast<MysqlRecord*>(record);
590-
logEvent->SetContent(kDBSystemName.LogKey(), "mysql");
591-
logEvent->SetContent(kDBResponseStatusCode.LogKey(), std::to_string(mysqlRecord->GetStatusCode()));
592-
logEvent->SetContent(kDBStatement.LogKey(), mysqlRecord->GetSql());
593-
}
577+
// Fill protocol-specific log fields using polymorphism
578+
record->FillProtocolSpecificLogFields(logEvent);
594579
LOG_DEBUG(sLogger, ("add one log, log timestamp", timeSpec.tv_sec)("nano", timeSpec.tv_nsec));
595580
needPush = true;
596581
}
@@ -1080,26 +1065,8 @@ bool NetworkObserverManager::ConsumeSpanAggregateTree() { // handler
10801065
}
10811066

10821067
spanEvent->SetName(record->GetSpanName());
1083-
auto protocol = record->GetConnection()->GetProtocol();
1084-
if (protocol == support_proto_e::ProtoHTTP) {
1085-
auto* httpRecord = static_cast<HttpRecord*>(record);
1086-
spanEvent->SetTag(kRpc.SpanKey(), httpRecord->GetConvSpanName());
1087-
if (!ct->IsServer()) {
1088-
spanEvent->SetTag(kEndpoint.SpanKey(), httpRecord->GetConvSpanName());
1089-
}
1090-
spanEvent->SetTag(kHTTPReqBody.SpanKey(), httpRecord->GetReqBody());
1091-
spanEvent->SetTag(kHTTPRespBody.SpanKey(), httpRecord->GetRespBody());
1092-
spanEvent->SetTag(kHTTPReqBodySize.SpanKey(), std::to_string(httpRecord->GetReqBodySize()));
1093-
spanEvent->SetTag(kHTTPRespBodySize.SpanKey(), std::to_string(httpRecord->GetRespBodySize()));
1094-
spanEvent->SetTag(kHTTPVersion.SpanKey(), httpRecord->GetProtocolVersion());
1095-
// spanEvent->SetTag(kHTTPReqHeader.SpanKey(), httpRecord->GetReqHeaderMap());
1096-
// spanEvent->SetTag(kHTTPRespHeader.SpanKey(), httpRecord->GetRespHeaders());
1097-
} else if (protocol == support_proto_e::ProtoMySQL) {
1098-
auto* mysqlRecord = static_cast<MysqlRecord*>(record);
1099-
spanEvent->SetTag(kDBSystemName.SpanKey(), "mysql");
1100-
spanEvent->SetTag(kDBResponseStatusCode.SpanKey(), std::to_string(mysqlRecord->GetStatusCode()));
1101-
spanEvent->SetTag(kDBStatement.SpanKey(), mysqlRecord->GetSql());
1102-
}
1068+
// Fill protocol-specific span fields using polymorphism
1069+
record->FillProtocolSpecificSpanFields(spanEvent, ct->IsServer());
11031070

11041071
struct timespec startTime = ConvertKernelTimeToUnixTime(record->GetStartTimeStamp());
11051072
struct timespec endTime = ConvertKernelTimeToUnixTime(record->GetEndTimeStamp());

core/ebpf/protocol/ProtocolParser.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ extern "C" {
3131
namespace logtail::ebpf {
3232

3333
std::set<support_proto_e> ProtocolParserManager::AvaliableProtocolTypes() const {
34-
return {support_proto_e::ProtoHTTP, support_proto_e::ProtoMySQL};
34+
return {support_proto_e::ProtoHTTP, support_proto_e::ProtoMySQL, support_proto_e::ProtoRedis};
3535
}
3636

3737
support_proto_e ProtocolStringToEnum(std::string protocol) {
@@ -40,6 +40,8 @@ support_proto_e ProtocolStringToEnum(std::string protocol) {
4040
return support_proto_e::ProtoHTTP;
4141
} else if (protocol == "MYSQL") {
4242
return support_proto_e::ProtoMySQL;
43+
} else if (protocol == "REDIS") {
44+
return support_proto_e::ProtoRedis;
4345
}
4446

4547
return support_proto_e::ProtoUnknown;

0 commit comments

Comments
 (0)