diff --git a/plugins/filter_kubernetes/kube_meta.c b/plugins/filter_kubernetes/kube_meta.c index 42390268d73..1b0579661c0 100644 --- a/plugins/filter_kubernetes/kube_meta.c +++ b/plugins/filter_kubernetes/kube_meta.c @@ -1123,6 +1123,7 @@ static int merge_pod_meta(struct flb_kube_meta *meta, struct flb_kube *ctx, int have_labels = -1; int have_annotations = -1; int have_nodename = -1; + int have_podip = -1; size_t off = 0; msgpack_sbuffer mp_sbuf; msgpack_packer mp_pck; @@ -1254,6 +1255,19 @@ static int merge_pod_meta(struct flb_kube_meta *meta, struct flb_kube *ctx, } } + /* Process status map value for podIP */ + if (status_found == FLB_TRUE) { + for (i = 0; i < status_val.via.map.size; i++) { + k = status_val.via.map.ptr[i].key; + if (k.via.str.size == 5 && + strncmp(k.via.str.ptr, "podIP", 5) == 0) { + have_podip = i; + map_size++; + break; + } + } + } + if ((!meta->container_hash || !meta->docker_id || !meta->container_image) && status_found) { extract_container_hash(meta, status_val); } @@ -1311,6 +1325,14 @@ static int merge_pod_meta(struct flb_kube_meta *meta, struct flb_kube *ctx, msgpack_pack_object(&mp_pck, v); } + if (have_podip >= 0) { + v = status_val.via.map.ptr[have_podip].val; + + msgpack_pack_str(&mp_pck, 6); + msgpack_pack_str_body(&mp_pck, "pod_ip", 6); + msgpack_pack_object(&mp_pck, v); + } + if (meta->container_name != NULL) { msgpack_pack_str(&mp_pck, 14); msgpack_pack_str_body(&mp_pck, "container_name", 14); diff --git a/tests/runtime/data/kubernetes/out/core/core_base_fluent-bit.out b/tests/runtime/data/kubernetes/out/core/core_base_fluent-bit.out index 6a1a3ac5c2f..e9de515f7af 100644 --- a/tests/runtime/data/kubernetes/out/core/core_base_fluent-bit.out +++ b/tests/runtime/data/kubernetes/out/core/core_base_fluent-bit.out @@ -1 +1 @@ -[1554141513.598656,{"log":"Fluent Bit is logging\n","stream":"stdout","kubernetes":{"pod_name":"base","namespace_name":"core","pod_id":"e9f2963f-55f2-11e9-84c5-02e422b8a84a","labels":{"app.kubernetes.io/name":"fluent-bit"},"annotations":{"prometheus.io/path":"/api/v1/metrics/prometheus","prometheus.io/port":"2020","prometheus.io/scrape":"true"},"host":"ip-10-49-18-80.eu-west-1.compute.internal","container_name":"fluent-bit","docker_id":"c9898099f6d235126d564ed38a020007ea7a6fac6e25e718de683c9dd0076c16","container_hash":"fluent/fluent-bit@sha256:7ac0fd3569af866e9a6a22eb592744200d2dbe098cf066162453f8d0b06c531f","container_image":"fluent/fluent-bit:latest"}}] +[1554141513.598656,{"log":"Fluent Bit is logging\n","stream":"stdout","kubernetes":{"pod_name":"base","namespace_name":"core","pod_id":"e9f2963f-55f2-11e9-84c5-02e422b8a84a","labels":{"app.kubernetes.io/name":"fluent-bit"},"annotations":{"prometheus.io/path":"/api/v1/metrics/prometheus","prometheus.io/port":"2020","prometheus.io/scrape":"true"},"host":"ip-10-49-18-80.eu-west-1.compute.internal","pod_ip":"100.116.192.42","container_name":"fluent-bit","docker_id":"c9898099f6d235126d564ed38a020007ea7a6fac6e25e718de683c9dd0076c16","container_hash":"fluent/fluent-bit@sha256:7ac0fd3569af866e9a6a22eb592744200d2dbe098cf066162453f8d0b06c531f","container_image":"fluent/fluent-bit:latest"}}] diff --git a/tests/runtime/data/kubernetes/out/kairosdb-914055854-b63vq.out b/tests/runtime/data/kubernetes/out/kairosdb-914055854-b63vq.out index efaaf0d8be1..cec200b8d54 100644 --- a/tests/runtime/data/kubernetes/out/kairosdb-914055854-b63vq.out +++ b/tests/runtime/data/kubernetes/out/kairosdb-914055854-b63vq.out @@ -1 +1 @@ -[1541358747.464754,{"_UID":"1000","_GID":"1000","_CAP_EFFECTIVE":"0","_SELINUX_CONTEXT":"unconfined\n","_AUDIT_LOGINUID":"1000","_SYSTEMD_OWNER_UID":"1000","_SYSTEMD_SLICE":"user-1000.slice","_SYSTEMD_USER_SLICE":"-.slice","_BOOT_ID":"e3abb4093a904a169e2ac21af241392f","_MACHINE_ID":"28d81df105e641e9b7d85e9d41433662","_HOSTNAME":"cube","PRIORITY":"6","CODE_FILE":"filter_kubernetes.c","CODE_LINE":"456","CODE_FUNC":"flb_test_systemd_logs","CONTAINER_NAME":"k8s_kairosdb_kairosdb-914055854-b63vq_default_d6c53deb-05a4-11e8-a8c4-080027435fb7_23","CONTAINER_TAG":"","CONTAINER_ID":"56e257661383","CONTAINER_ID_FULL":"56e257661383836fac4cd90a23ee8a7a02ee1538c8f35657d1a90f3de1065a22","MESSAGE":"08:58:45.839 [qtp151442075-47] DEBUG [HttpParser.java:281] - filled 157/157","KUBE_TEST":"2018","SYSLOG_IDENTIFIER":"flb-rt-filter_kubernetes","_TRANSPORT":"journal","_PID":"32318","_COMM":"flb-rt-filter_k","_EXE":"build/bin/flb-rt-filter_kubernetes","_CMDLINE":"bin/flb-rt-filter_kubernetes","_AUDIT_SESSION":"7417","_SYSTEMD_CGROUP":"/user.slice/user-1000.slice/session-7417.scope","_SYSTEMD_SESSION":"7417","_SYSTEMD_UNIT":"session-7417.scope","_SYSTEMD_INVOCATION_ID":"899c0f7241ae4db0af3cb4088dca76b0","_SOURCE_REALTIME_TIMESTAMP":"1541358747464738","kubernetes":{"pod_name":"kairosdb-914055854-b63vq","namespace_name":"default","pod_id":"d6c53deb-05a4-11e8-a8c4-080027435fb7","labels":{"name":"kairosdb","pod-template-hash":"914055854"},"annotations":{"kubernetes.io/created-by":"{\"kind\":\"SerializedReference\",\"apiVersion\":\"v1\",\"reference\":{\"kind\":\"ReplicaSet\",\"namespace\":\"default\",\"name\":\"kairosdb-914055854\",\"uid\":\"d6c2f841-05a4-11e8-a8c4-080027435fb7\",\"apiVersion\":\"extensions\",\"resourceVersion\":\"1592\"}}\n"},"host":"192.168.10.169","container_name":"kairosdb","docker_id":"02d45318f220ad01109d13df31fbbb0668b87fdd06ef6607abfdecf5eba4b311","container_hash":"davradocker/docker-kairosdb@sha256:2ee07e3f3ba61b96597c78ab0aa7b837d771b375888b020da7a7316bb524b6e8","container_image":"davradocker/docker-kairosdb:1.1.1_9"}}] +[1541358747.464754,{"_UID":"1000","_GID":"1000","_CAP_EFFECTIVE":"0","_SELINUX_CONTEXT":"unconfined\n","_AUDIT_LOGINUID":"1000","_SYSTEMD_OWNER_UID":"1000","_SYSTEMD_SLICE":"user-1000.slice","_SYSTEMD_USER_SLICE":"-.slice","_BOOT_ID":"e3abb4093a904a169e2ac21af241392f","_MACHINE_ID":"28d81df105e641e9b7d85e9d41433662","_HOSTNAME":"cube","PRIORITY":"6","CODE_FILE":"filter_kubernetes.c","CODE_LINE":"456","CODE_FUNC":"flb_test_systemd_logs","CONTAINER_NAME":"k8s_kairosdb_kairosdb-914055854-b63vq_default_d6c53deb-05a4-11e8-a8c4-080027435fb7_23","CONTAINER_TAG":"","CONTAINER_ID":"56e257661383","CONTAINER_ID_FULL":"56e257661383836fac4cd90a23ee8a7a02ee1538c8f35657d1a90f3de1065a22","MESSAGE":"08:58:45.839 [qtp151442075-47] DEBUG [HttpParser.java:281] - filled 157/157","KUBE_TEST":"2018","SYSLOG_IDENTIFIER":"flb-rt-filter_kubernetes","_TRANSPORT":"journal","_PID":"32318","_COMM":"flb-rt-filter_k","_EXE":"build/bin/flb-rt-filter_kubernetes","_CMDLINE":"bin/flb-rt-filter_kubernetes","_AUDIT_SESSION":"7417","_SYSTEMD_CGROUP":"/user.slice/user-1000.slice/session-7417.scope","_SYSTEMD_SESSION":"7417","_SYSTEMD_UNIT":"session-7417.scope","_SYSTEMD_INVOCATION_ID":"899c0f7241ae4db0af3cb4088dca76b0","_SOURCE_REALTIME_TIMESTAMP":"1541358747464738","kubernetes":{"pod_name":"kairosdb-914055854-b63vq","namespace_name":"default","pod_id":"d6c53deb-05a4-11e8-a8c4-080027435fb7","labels":{"name":"kairosdb","pod-template-hash":"914055854"},"annotations":{"kubernetes.io/created-by":"{\"kind\":\"SerializedReference\",\"apiVersion\":\"v1\",\"reference\":{\"kind\":\"ReplicaSet\",\"namespace\":\"default\",\"name\":\"kairosdb-914055854\",\"uid\":\"d6c2f841-05a4-11e8-a8c4-080027435fb7\",\"apiVersion\":\"extensions\",\"resourceVersion\":\"1592\"}}\n"},"host":"192.168.10.169","pod_ip":"10.2.39.12","container_name":"kairosdb","docker_id":"02d45318f220ad01109d13df31fbbb0668b87fdd06ef6607abfdecf5eba4b311","container_hash":"davradocker/docker-kairosdb@sha256:2ee07e3f3ba61b96597c78ab0aa7b837d771b375888b020da7a7316bb524b6e8","container_image":"davradocker/docker-kairosdb:1.1.1_9"}}]