Skip to content

Commit 93a60a1

Browse files
KayzzzZyyuuttaaoo
andauthored
feat: support report agent info for sae scenario (alibaba#2379)
* add agentinfo content * add ut * add dest id --------- Co-authored-by: Tom Yu <yyuuttaaoo@gmail.com>
1 parent 195229d commit 93a60a1

3 files changed

Lines changed: 23 additions & 5 deletions

File tree

core/ebpf/plugin/network_observer/Connection.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ void Connection::TryAttachPeerMeta(int family, uint32_t ip) {
281281
}
282282
if (!K8sMetadata::GetInstance().Enable()) {
283283
// k8smetadata not enable, mark attached ...
284+
updatePeerPodMetaForExternal();
284285
MarkPeerMetaAttached();
285286
return;
286287
}

core/ebpf/plugin/network_observer/NetworkObserverManager.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "rapidjson/stringbuffer.h"
2121
#include "rapidjson/writer.h"
2222

23+
#include "application/Application.h"
2324
#include "collection_pipeline/queue/ProcessQueueItem.h"
2425
#include "collection_pipeline/queue/ProcessQueueManager.h"
2526
#include "common/HashUtil.h"
@@ -51,6 +52,7 @@ extern "C" {
5152
DEFINE_FLAG_INT32(ebpf_networkobserver_max_connections, "maximum connections", 5000);
5253
DEFINE_FLAG_STRING(ebpf_networkobserver_enable_protocols, "enable application protocols, split by comma", "HTTP");
5354
DEFINE_FLAG_DOUBLE(ebpf_networkobserver_default_sample_rate, "ebpf network observer default sample rate", 1.0);
55+
DEFINE_FLAG_STRING(ebpf_networkobserver_agent_env, "deploy env: ACSK8S,Serverless,ECS_AUTO", "ACSK8S");
5456

5557
namespace logtail::ebpf {
5658

@@ -1680,9 +1682,6 @@ const static std::string kAgentInfoServiceIdKey = "acs_arms_service_id";
16801682
const static std::string kAgentInfoWorkspaceKey = "acs_cms_workspace";
16811683
const static std::string kAgentInfoPropertiesKey = "properties";
16821684

1683-
const static std::string kAgentInfoAgentEnvACKVal = "ACSK8S";
1684-
const static std::string kAgentInfoAgentEnvECSAutoVal = "ECS_AUTO";
1685-
const static std::string kAgentInfoAgentEnvDefaultVal = "DEFAULT";
16861685
const static std::string kAgentInfoPropertiesKeyClusterId = "k8s.cluster.uid";
16871686
const static std::string kAgentInfoPropertiesKeyClusterName = "k8s.cluster.name";
16881687
const static std::string kAgentInfoPropertiesKeyNamespace = "k8s.namespace.name";
@@ -1740,18 +1739,26 @@ bool NetworkObserverManager::reportAgentInfo(const time_t& now,
17401739
event->SetContent(kAgentInfoAppIdKey, appConfig->mAppId);
17411740
event->SetContent(kAgentInfoAppnameKey, appConfig->mAppName);
17421741
event->SetContent(kAgentInfoAgentVersionKey, ILOGTAIL_VERSION);
1743-
event->SetContentNoCopy(kAgentInfoAgentEnvKey, kAgentInfoAgentEnvACKVal);
1742+
event->SetContentNoCopy(kAgentInfoAgentEnvKey, STRING_FLAG(ebpf_networkobserver_agent_env));
1743+
event->SetContent(kAgentInfoAppIdKey, appConfig->mAppId);
1744+
event->SetContent(kAgentInfoServiceIdKey, appConfig->mServiceId);
1745+
event->SetContent(kAgentInfoWorkspaceKey, appConfig->mWorkspace);
17441746
if (Connection::gSelfPodIp.empty()) {
17451747
event->SetContent(kAgentInfoIpKey, GetHostIp());
17461748
} else {
17471749
event->SetContentNoCopy(kAgentInfoIpKey, Connection::gSelfPodIp);
17481750
}
1749-
17501751
if (Connection::gSelfPodName.empty()) {
17511752
event->SetContent(kAgentInfoHostnameKey, GetHostName());
17521753
} else {
17531754
event->SetContentNoCopy(kAgentInfoHostnameKey, Connection::gSelfPodName);
17541755
}
1756+
event->SetContent(kAgentInfoAppnameKey, appConfig->mAppName);
1757+
event->SetContent(kAgentInfoLanguageKey, appConfig->mLanguage);
1758+
event->SetContentNoCopy(kAgentInfoAgentVersionKey, ILOGTAIL_VERSION);
1759+
static auto sStartTime = ToString(Application::GetInstance()->GetStartTime()) + "000";
1760+
event->SetContent(kAgentInfoStartTsKey, sStartTime); // ms
1761+
event->SetContent(kAgentInfoTimestampKey, ToString(now * 1000));
17551762
event->SetTimestamp(now, 0);
17561763
} else {
17571764
if (!K8sMetadata::GetInstance().Enable()) {
@@ -1769,6 +1776,7 @@ bool NetworkObserverManager::reportAgentInfo(const time_t& now,
17691776
LOG_DEBUG(sLogger, ("[AgentInfo] generate for cid", containerId)("podName", podMeta->mPodName));
17701777

17711778
auto* event = eventGroup.AddLogEvent(true, mEventPool);
1779+
event->SetContentNoCopy(kAgentInfoAgentEnvKey, STRING_FLAG(ebpf_networkobserver_agent_env));
17721780
event->SetContent(kAgentInfoAppIdKey, appConfig->mAppId);
17731781
event->SetContent(kAgentInfoServiceIdKey, appConfig->mServiceId);
17741782
event->SetContent(kAgentInfoWorkspaceKey, appConfig->mWorkspace);

core/unittest/ebpf/NetworkObserverUnittest.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,15 @@ void NetworkObserverManagerUnittest::TestReportAgentInfo() {
792792
mManager->ReportAgentInfo();
793793
APSARA_TEST_EQUAL(mManager->mAgentInfoEventGroups.size(), 1UL);
794794
APSARA_TEST_EQUAL(mManager->mAgentInfoEventGroups[0].GetEvents().size(), 1UL);
795+
APSARA_TEST_TRUE(mManager->mAgentInfoEventGroups[0].GetEvents()[0].Is<LogEvent>());
796+
auto* logEvent = mManager->mAgentInfoEventGroups[0].GetEvents()[0].Get<LogEvent>();
797+
APSARA_TEST_EQUAL(logEvent->GetContent("pid"), "test-app-id");
798+
APSARA_TEST_EQUAL(logEvent->GetContent("acs_cms_workspace"), "test-workspace");
799+
APSARA_TEST_EQUAL(logEvent->GetContent("acs_arms_service_id"), "test-service-id");
800+
APSARA_TEST_EQUAL(logEvent->GetContent("appName"), "test-app");
801+
APSARA_TEST_EQUAL(logEvent->GetContent("agentEnv"), "ACSK8S");
802+
APSARA_TEST_TRUE(logEvent->GetContent("timestamp") != "");
803+
APSARA_TEST_TRUE(logEvent->GetContent("startTimestamp") != "");
795804

796805
// 测试有 workload 配置和 container 时调用 ReportAgentInfo
797806
options.mSelectors = {{"test-workload", "deployment", "test-namespace"}};

0 commit comments

Comments
 (0)