Skip to content

Commit

Permalink
change tag
Browse files Browse the repository at this point in the history
  • Loading branch information
NameHaibinZhang committed Nov 14, 2024
1 parent 569f691 commit c7f1e04
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 69 deletions.
28 changes: 14 additions & 14 deletions core/metadata/K8sMetadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(DEFAULT_TRACE_TAG_IMAGES) || !json.isMember(DEFAULT_TRACE_TAG_LABELS) || !json.isMember(DEFAULT_TRACE_TAG_NAMESPACE)
|| !json.isMember(DEFAULT_TRACE_TAG_WORKLOAD_KIND) || !json.isMember(DEFAULT_TRACE_TAG_WORKLOAD_NAME)) {
if (!json.isMember("images") || !json.isMember("labels") || !json.isMember("namespace")
|| !json.isMember("workloadKind") || !json.isMember("workloadName")) {
return false;
}

for (const auto& key : json[DEFAULT_TRACE_TAG_IMAGES].getMemberNames()) {
if (json[DEFAULT_TRACE_TAG_IMAGES].isMember(key)) {
info.images[key] = json[DEFAULT_TRACE_TAG_IMAGES][key].asString();
for (const auto& key : json["images"].getMemberNames()) {
if (json["images"].isMember(key)) {
info.images[key] = json["images"][key].asString();
}
}
for (const auto& key : json[DEFAULT_TRACE_TAG_LABELS].getMemberNames()) {
if (json[DEFAULT_TRACE_TAG_LABELS].isMember(key)) {
info.labels[key] = json[DEFAULT_TRACE_TAG_LABELS][key].asString();
for (const auto& key : json["lables"].getMemberNames()) {
if (json["lables"].isMember(key)) {
info.labels[key] = json["lables"][key].asString();

if (key == DEFAULT_TRACE_TAG_APPID) {
info.appId = json[DEFAULT_TRACE_TAG_LABELS][key].asString();
info.appId = json["lables"][key].asString();
}
}
}

info.k8sNamespace = json[DEFAULT_TRACE_TAG_NAMESPACE].asString();
if (json.isMember(DEFAULT_TRACE_TAG_SERVICENAME)) {
info.serviceName = json[DEFAULT_TRACE_TAG_SERVICENAME].asString();
info.k8sNamespace = json["namespace"].asString();
if (json.isMember("serviceName")) {
info.serviceName = json["serviceName"].asString();
}
info.workloadKind = json[DEFAULT_TRACE_TAG_WORKLOAD_KIND].asString();
info.workloadName = json[DEFAULT_TRACE_TAG_WORKLOAD_NAME].asString();
info.workloadKind = json["workloadKind"].asString();
info.workloadName = json["workloadName"].asString();
info.timestamp = std::time(0);
return true;
}
Expand Down
110 changes: 55 additions & 55 deletions core/unittest/metadata/K8sMetadataUnittest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class k8sMetadataUnittest : public ::testing::Test {
public:
void TestGetByContainerIds() {
LOG_INFO(sLogger, ("TestGetByContainerIds() begin", time(NULL)));
const std::string jsonData = R"({"containerd://286effd2650c0689b779018e42e9ec7aa3d2cb843005e038204e85fc3d4f9144":{"k8s.namespace.name":"default","workload.name":"oneagent-demo-658648895b","workload.kind":"replicaset","service.name":"","k8s.pod.label":{"app":"oneagent-demo","pod-template-hash":"658648895b"},"envs":{},"container.image.name":{"oneagent-demo":"sls-opensource-registry.cn-shanghai.cr.aliyuncs.com/ilogtail-community-edition/centos7-cve-fix:1.0.0"}}})";
const std::string jsonData = R"({"containerd://286effd2650c0689b779018e42e9ec7aa3d2cb843005e038204e85fc3d4f9144":{"namespace":"default","workloadName":"oneagent-demo-658648895b","workloadKind":"replicaset","serviceName":"","labels":{"app":"oneagent-demo","pod-template-hash":"658648895b"},"envs":{},""images"":{"oneagent-demo":"sls-opensource-registry.cn-shanghai.cr.aliyuncs.com/ilogtail-community-edition/centos7-cve-fix:1.0.0"}}})";

Json::Value root;
Json::CharReaderBuilder readerBuilder;
Expand All @@ -63,28 +63,28 @@ class k8sMetadataUnittest : public ::testing::Test {
// Sample JSON data
const std::string jsonData = R"({
"10.41.0.2": {
"k8s.namespace.name": "kube-system",
"workload.name": "coredns-7b669cbb96",
"workload.kind": "replicaset",
"service.name": "",
"k8s.pod.label": {
"namespace": "kube-system",
"workloadName": "coredns-7b669cbb96",
"workloadKind": "replicaset",
"serviceName": "",
"labels": {
"k8s-app": "kube-dns",
"pod-template-hash": "7b669cbb96"
},
"envs": {
"COREDNS_NAMESPACE": "",
"COREDNS_POD_NAME": ""
},
"container.image.name": {
""images"": {
"coredns": "registry-cn-chengdu-vpc.ack.aliyuncs.com/acs/coredns:v1.9.3.10-7dfca203-aliyun"
}
},
"10.41.0.3": {
"k8s.namespace.name": "kube-system",
"workload.name": "csi-provisioner-8bd988c55",
"workload.kind": "replicaset",
"service.name": "",
"k8s.pod.label": {
"namespace": "kube-system",
"workloadName": "csi-provisioner-8bd988c55",
"workloadKind": "replicaset",
"serviceName": "",
"labels": {
"app": "csi-provisioner",
"pod-template-hash": "8bd988c55"
},
Expand All @@ -94,7 +94,7 @@ class k8sMetadataUnittest : public ::testing::Test {
"KUBE_NODE_NAME": "",
"SERVICE_TYPE": "provisioner"
},
"container.image.name": {
""images"": {
"csi-provisioner": "registry-cn-chengdu-vpc.ack.aliyuncs.com/acs/csi-plugin:v1.30.3-921e63a-aliyun",
"external-csi-snapshotter": "registry-cn-chengdu-vpc.ack.aliyuncs.com/acs/csi-snapshotter:v4.0.0-a230d5b-aliyun",
"external-disk-attacher": "registry-cn-chengdu-vpc.ack.aliyuncs.com/acs/csi-attacher:v4.5.0-4a01fda6-aliyun",
Expand All @@ -107,19 +107,19 @@ class k8sMetadataUnittest : public ::testing::Test {
}
},
"172.16.20.108": {
"k8s.namespace.name": "kube-system",
"workload.name": "kube-proxy-worker",
"workload.kind": "daemonset",
"service.name": "",
"k8s.pod.label": {
"namespace": "kube-system",
"workloadName": "kube-proxy-worker",
"workloadKind": "daemonset",
"serviceName": "",
"labels": {
"controller-revision-hash": "756748b889",
"k8s-app": "kube-proxy-worker",
"pod-template-generation": "1"
},
"envs": {
"NODE_NAME": ""
},
"container.image.name": {
""images"": {
"kube-proxy-worker": "registry-cn-chengdu-vpc.ack.aliyuncs.com/acs/kube-proxy:v1.30.1-aliyun.1"
}
}
Expand Down Expand Up @@ -183,28 +183,28 @@ class k8sMetadataUnittest : public ::testing::Test {
// Sample JSON data
const std::string jsonData = R"({
"10.41.0.2": {
"k8s.namespace.name": "kube-system",
"workload.name": "coredns-7b669cbb96",
"workload.kind": "replicaset",
"service.name": "",
"k8s.pod.label": {
"namespace": "kube-system",
"workloadName": "coredns-7b669cbb96",
"workloadKind": "replicaset",
"serviceName": "",
"labels": {
"k8s-app": "kube-dns",
"pod-template-hash": "7b669cbb96"
},
"envs": {
"COREDNS_NAMESPACE": "",
"COREDNS_POD_NAME": ""
},
"container.image.name": {
""images"": {
"coredns": "registry-cn-chengdu-vpc.ack.aliyuncs.com/acs/coredns:v1.9.3.10-7dfca203-aliyun"
}
},
"10.41.0.3": {
"k8s.namespace.name": "kube-system",
"workload.name": "csi-provisioner-8bd988c55",
"workload.kind": "replicaset",
"service.name": "",
"k8s.pod.label": {
"namespace": "kube-system",
"workloadName": "csi-provisioner-8bd988c55",
"workloadKind": "replicaset",
"serviceName": "",
"labels": {
"app": "csi-provisioner",
"pod-template-hash": "8bd988c55"
},
Expand All @@ -214,7 +214,7 @@ class k8sMetadataUnittest : public ::testing::Test {
"KUBE_NODE_NAME": "",
"SERVICE_TYPE": "provisioner"
},
"container.image.name": {
""images"": {
"csi-provisioner": "registry-cn-chengdu-vpc.ack.aliyuncs.com/acs/csi-plugin:v1.30.3-921e63a-aliyun",
"external-csi-snapshotter": "registry-cn-chengdu-vpc.ack.aliyuncs.com/acs/csi-snapshotter:v4.0.0-a230d5b-aliyun",
"external-disk-attacher": "registry-cn-chengdu-vpc.ack.aliyuncs.com/acs/csi-attacher:v4.5.0-4a01fda6-aliyun",
Expand All @@ -227,19 +227,19 @@ class k8sMetadataUnittest : public ::testing::Test {
}
},
"172.16.20.108": {
"k8s.namespace.name": "kube-system",
"workload.name": "kube-proxy-worker",
"workload.kind": "daemonset",
"service.name": "",
"k8s.pod.label": {
"namespace": "kube-system",
"workloadName": "kube-proxy-worker",
"workloadKind": "daemonset",
"serviceName": "",
"labels": {
"controller-revision-hash": "756748b889",
"k8s-app": "kube-proxy-worker",
"pod-template-generation": "1"
},
"envs": {
"NODE_NAME": ""
},
"container.image.name": {
""images"": {
"kube-proxy-worker": "registry-cn-chengdu-vpc.ack.aliyuncs.com/acs/kube-proxy:v1.30.1-aliyun.1"
}
}
Expand Down Expand Up @@ -297,28 +297,28 @@ class k8sMetadataUnittest : public ::testing::Test {
// Sample JSON data
const std::string jsonData = R"({
"10.41.0.2": {
"k8s.namespace.name": "kube-system",
"workload.name": "coredns-7b669cbb96",
"workload.kind": "replicaset",
"service.name": "",
"k8s.pod.label": {
"namespace": "kube-system",
"workloadName": "coredns-7b669cbb96",
"workloadKind": "replicaset",
"serviceName": "",
"labels": {
"k8s-app": "kube-dns",
"pod-template-hash": "7b669cbb96"
},
"envs": {
"COREDNS_NAMESPACE": "",
"COREDNS_POD_NAME": ""
},
"container.image.name": {
""images"": {
"coredns": "registry-cn-chengdu-vpc.ack.aliyuncs.com/acs/coredns:v1.9.3.10-7dfca203-aliyun"
}
},
"10.41.0.3": {
"k8s.namespace.name": "kube-system",
"workload.name": "csi-provisioner-8bd988c55",
"workload.kind": "replicaset",
"service.name": "",
"k8s.pod.label": {
"namespace": "kube-system",
"workloadName": "csi-provisioner-8bd988c55",
"workloadKind": "replicaset",
"serviceName": "",
"labels": {
"app": "csi-provisioner",
"pod-template-hash": "8bd988c55"
},
Expand All @@ -328,7 +328,7 @@ class k8sMetadataUnittest : public ::testing::Test {
"KUBE_NODE_NAME": "",
"SERVICE_TYPE": "provisioner"
},
"container.image.name": {
""images"": {
"csi-provisioner": "registry-cn-chengdu-vpc.ack.aliyuncs.com/acs/csi-plugin:v1.30.3-921e63a-aliyun",
"external-csi-snapshotter": "registry-cn-chengdu-vpc.ack.aliyuncs.com/acs/csi-snapshotter:v4.0.0-a230d5b-aliyun",
"external-disk-attacher": "registry-cn-chengdu-vpc.ack.aliyuncs.com/acs/csi-attacher:v4.5.0-4a01fda6-aliyun",
Expand All @@ -341,19 +341,19 @@ class k8sMetadataUnittest : public ::testing::Test {
}
},
"172.16.20.108": {
"k8s.namespace.name": "kube-system",
"workload.name": "kube-proxy-worker",
"workload.kind": "daemonset",
"service.name": "",
"k8s.pod.label": {
"namespace": "kube-system",
"workloadName": "kube-proxy-worker",
"workloadKind": "daemonset",
"serviceName": "",
"labels": {
"controller-revision-hash": "756748b889",
"k8s-app": "kube-proxy-worker",
"pod-template-generation": "1"
},
"envs": {
"NODE_NAME": ""
},
"container.image.name": {
""images"": {
"kube-proxy-worker": "registry-cn-chengdu-vpc.ack.aliyuncs.com/acs/kube-proxy:v1.30.1-aliyun.1"
}
}
Expand Down

0 comments on commit c7f1e04

Please sign in to comment.