From 68dbf53b15c98a227c1dc3f0b03f4349debaa8a3 Mon Sep 17 00:00:00 2001 From: zhb192729 Date: Thu, 14 Nov 2024 15:07:32 +0800 Subject: [PATCH] change tag --- core/metadata/K8sMetadata.cpp | 28 ++++++++++++++-------------- core/metadata/K8sMetadata.h | 8 ++++++++ 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/core/metadata/K8sMetadata.cpp b/core/metadata/K8sMetadata.cpp index 47177d8c19..75a7d8dd69 100644 --- a/core/metadata/K8sMetadata.cpp +++ b/core/metadata/K8sMetadata.cpp @@ -33,32 +33,32 @@ size_t WriteCallback(void* contents, size_t size, size_t nmemb, void* userp) { } bool K8sMetadata::FromInfoJson(const Json::Value& json, k8sContainerInfo& info) { - if (!json.isMember("images") || !json.isMember("labels") || !json.isMember("namespace") - || !json.isMember("workloadKind") || !json.isMember("workloadName")) { + if (!json.isMember(TAG_IMAGES) || !json.isMember("labels") || !json.isMember(TAG_NAMESPACE) + || !json.isMember(TAG_WORKLOADKIND) || !json.isMember(TAG_WORKLOADNAME)) { return false; } - for (const auto& key : json["images"].getMemberNames()) { - if (json["images"].isMember(key)) { - info.images[key] = json["images"][key].asString(); + for (const auto& key : json[TAG_IMAGES].getMemberNames()) { + if (json[TAG_IMAGES].isMember(key)) { + info.images[key] = json[TAG_IMAGES][key].asString(); } } - for (const auto& key : json["lables"].getMemberNames()) { - if (json["lables"].isMember(key)) { - info.labels[key] = json["lables"][key].asString(); + for (const auto& key : json[TAG_LABELS].getMemberNames()) { + if (json[TAG_LABELS].isMember(key)) { + info.labels[key] = json[TAG_LABELS][key].asString(); if (key == DEFAULT_TRACE_TAG_APPID) { - info.appId = json["lables"][key].asString(); + info.appId = json[TAG_LABELS][key].asString(); } } } - info.k8sNamespace = json["namespace"].asString(); - if (json.isMember("serviceName")) { - info.serviceName = json["serviceName"].asString(); + info.k8sNamespace = json[TAG_NAMESPACE].asString(); + if (json.isMember(TAG_SERVICENAME)) { + info.serviceName = json[TAG_SERVICENAME].asString(); } - info.workloadKind = json["workloadKind"].asString(); - info.workloadName = json["workloadName"].asString(); + info.workloadKind = json[TAG_WORKLOADKIND].asString(); + info.workloadName = json[TAG_WORKLOADNAME].asString(); info.timestamp = std::time(0); return true; } diff --git a/core/metadata/K8sMetadata.h b/core/metadata/K8sMetadata.h index bcaac4ae20..6d0c65dcbf 100644 --- a/core/metadata/K8sMetadata.h +++ b/core/metadata/K8sMetadata.h @@ -24,6 +24,14 @@ DECLARE_FLAG_STRING(loong_collector_operator_service); DECLARE_FLAG_INT32(loong_collector_k8s_meta_service_port); namespace logtail { + + const std::string TAG_NAMESPACE = "namespace"; + const std::string TAG_IMAGES = "images"; + const std::string TAG_WORKLOADNAME = "workloadName"; + const std::string TAG_WORKLOADKIND = "workloadKind"; + const std::string TAG_SERVICENAME = "serviceName" + const std::string TAG_LABELS = "labels"; + struct k8sContainerInfo { std::unordered_map images; std::unordered_map labels;