Skip to content

fix: C++ source tag #2092

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions core/plugin/processor/inner/ProcessorTagNative.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,19 +95,15 @@ bool ProcessorTagNative::Init(const Json::Value& config) {
// should keep same with Go addAllConfigurableTags
void ProcessorTagNative::Process(PipelineEventGroup& logGroup) {
AddTag(logGroup, TagKey::HOST_NAME_TAG_KEY, LoongCollectorMonitor::GetInstance()->mHostname);
#ifdef __ENTERPRISE__
auto entity = InstanceIdentity::Instance()->GetEntity();
if (entity != nullptr) {
AddTag(logGroup, TagKey::HOST_ID_TAG_KEY, entity->GetHostID());
#ifdef __ENTERPRISE__
ECSMeta meta = entity->GetECSMeta();
const string cloudProvider
= meta.GetInstanceID().empty() ? DEFAULT_VALUE_DOMAIN_INFRA : DEFAULT_VALUE_DOMAIN_ACS;
#else
const string cloudProvider = DEFAULT_VALUE_DOMAIN_INFRA;
#endif
AddTag(logGroup, TagKey::CLOUD_PROVIDER_TAG_KEY, cloudProvider);
}
#ifdef __ENTERPRISE__
AddTag(logGroup, TagKey::AGENT_TAG_TAG_KEY, EnterpriseConfigProvider::GetInstance()->GetUserDefinedIdSet());
#else
AddTag(logGroup, TagKey::HOST_IP_TAG_KEY, LoongCollectorMonitor::GetInstance()->mIpAddr);
Expand Down Expand Up @@ -145,6 +141,7 @@ void ProcessorTagNative::Process(PipelineEventGroup& logGroup) {
// When flushing through Go pipeline, it will skip serializer, add a new unexpected tag
auto sb = logGroup.GetSourceBuffer()->CopyString(Application::GetInstance()->GetUUID());
logGroup.SetTagNoCopy(LOG_RESERVED_KEY_MACHINE_UUID, StringView(sb.data, sb.size));
logGroup.SetTagNoCopy(LOG_RESERVED_KEY_SOURCE, LoongCollectorMonitor::mIpAddr);
}

bool ProcessorTagNative::IsSupportedEvent(const PipelineEventPtr& /*e*/) const {
Expand Down
8 changes: 8 additions & 0 deletions core/unittest/processor/ProcessorTagNativeUnittest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ void ProcessorTagNativeUnittest::TestProcess() {
APSARA_TEST_EQUAL_FATAL(LoongCollectorMonitor::GetInstance()->mIpAddr,
eventGroup.GetTag(GetDefaultTagKeyString(TagKey::HOST_IP_TAG_KEY)));
#endif
APSARA_TEST_TRUE_FATAL(eventGroup.HasTag(LOG_RESERVED_KEY_SOURCE));
APSARA_TEST_TRUE_FATAL(eventGroup.HasTag(LOG_RESERVED_KEY_MACHINE_UUID));
}
{ // native branch default
Json::Value config;
Expand Down Expand Up @@ -161,6 +163,8 @@ void ProcessorTagNativeUnittest::TestProcess() {
APSARA_TEST_EQUAL_FATAL(LoongCollectorMonitor::GetInstance()->mIpAddr,
eventGroup.GetTag(GetDefaultTagKeyString(TagKey::HOST_IP_TAG_KEY)));
#endif
APSARA_TEST_TRUE_FATAL(eventGroup.HasTag(LOG_RESERVED_KEY_SOURCE));
APSARA_TEST_TRUE_FATAL(eventGroup.HasTag(LOG_RESERVED_KEY_MACHINE_UUID));
}
{ // native branch rename
Json::Value config;
Expand Down Expand Up @@ -217,6 +221,8 @@ void ProcessorTagNativeUnittest::TestProcess() {
APSARA_TEST_TRUE_FATAL(eventGroup.HasTag("test_host_ip"));
APSARA_TEST_EQUAL_FATAL(LoongCollectorMonitor::GetInstance()->mIpAddr, eventGroup.GetTag("test_host_ip"));
#endif
APSARA_TEST_TRUE_FATAL(eventGroup.HasTag(LOG_RESERVED_KEY_SOURCE));
APSARA_TEST_TRUE_FATAL(eventGroup.HasTag(LOG_RESERVED_KEY_MACHINE_UUID));
}
{ // native branch delete
Json::Value config;
Expand Down Expand Up @@ -266,6 +272,8 @@ void ProcessorTagNativeUnittest::TestProcess() {
#else
APSARA_TEST_FALSE_FATAL(eventGroup.HasTag(GetDefaultTagKeyString(TagKey::HOST_IP_TAG_KEY)));
#endif
APSARA_TEST_TRUE_FATAL(eventGroup.HasTag(LOG_RESERVED_KEY_SOURCE));
APSARA_TEST_TRUE_FATAL(eventGroup.HasTag(LOG_RESERVED_KEY_MACHINE_UUID));
}
}

Expand Down
Loading