From 047ca27caba75babd7f8be116581d39913043af5 Mon Sep 17 00:00:00 2001 From: ryanohnemus Date: Fri, 15 Dec 2023 15:11:25 -0600 Subject: [PATCH 1/2] in_kubernetes_events: make timestamp from incoming record configurable Signed-off-by: ryanohnemus --- plugins/in_kubernetes_events/kubernetes_events.c | 5 +++++ plugins/in_kubernetes_events/kubernetes_events.h | 3 +++ plugins/in_kubernetes_events/kubernetes_events_conf.c | 9 +++++++-- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/plugins/in_kubernetes_events/kubernetes_events.c b/plugins/in_kubernetes_events/kubernetes_events.c index 97719fba6e0..2be73a68aed 100644 --- a/plugins/in_kubernetes_events/kubernetes_events.c +++ b/plugins/in_kubernetes_events/kubernetes_events.c @@ -889,6 +889,11 @@ static struct flb_config_map config_map[] = { 0, FLB_TRUE, offsetof(struct k8s_events, namespace), "kubernetes namespace to get events from, gets event from all namespaces by default." }, + { + FLB_CONFIG_MAP_STR, "timestamp_key", K8S_EVENTS_RA_TIMESTAMP, + 0, FLB_TRUE, offsetof(struct k8s_events, timestamp_key), + "Record accessor for the timestamp from the event. Default is $metadata['creationTimestamp']." + }, #ifdef FLB_HAVE_SQLDB { diff --git a/plugins/in_kubernetes_events/kubernetes_events.h b/plugins/in_kubernetes_events/kubernetes_events.h index 3afd48570fa..cb1e7233775 100644 --- a/plugins/in_kubernetes_events/kubernetes_events.h +++ b/plugins/in_kubernetes_events/kubernetes_events.h @@ -74,6 +74,9 @@ struct k8s_events { struct flb_log_event_encoder *encoder; + /* timestamp key */ + flb_sds_t timestamp_key; + /* record accessor */ struct flb_record_accessor *ra_timestamp; struct flb_record_accessor *ra_resource_version; diff --git a/plugins/in_kubernetes_events/kubernetes_events_conf.c b/plugins/in_kubernetes_events/kubernetes_events_conf.c index 4f67d8cfcee..2d4ed6f17cb 100644 --- a/plugins/in_kubernetes_events/kubernetes_events_conf.c +++ b/plugins/in_kubernetes_events/kubernetes_events_conf.c @@ -135,6 +135,7 @@ struct k8s_events *k8s_events_conf_create(struct flb_input_instance *ins) int ret; const char *p; const char *url; + const char *timestampKey; const char *tmp; struct k8s_events *ctx = NULL; pthread_mutexattr_t attr; @@ -165,10 +166,14 @@ struct k8s_events *k8s_events_conf_create(struct flb_input_instance *ins) } /* Record accessor pattern */ - ctx->ra_timestamp = flb_ra_create(K8S_EVENTS_RA_TIMESTAMP, FLB_TRUE); + timestampKey = flb_input_get_property("timestamp_key", ins); + if (!timestampKey ) { + timestampKey = K8S_EVENTS_RA_TIMESTAMP; + } + ctx->ra_timestamp = flb_ra_create(timestampKey, FLB_TRUE); if (!ctx->ra_timestamp) { flb_plg_error(ctx->ins, - "could not create record accessor for metadata items"); + "could not create record accessor for record timestamp"); k8s_events_conf_destroy(ctx); return NULL; } From 765141b4b18ff2e420f05d44660416a7e97f30cd Mon Sep 17 00:00:00 2001 From: ryanohnemus Date: Thu, 21 Dec 2023 17:00:14 -0600 Subject: [PATCH 2/2] in_kubernetes_events: set default timestamp_key to $lastTimestamp Signed-off-by: ryanohnemus --- plugins/in_kubernetes_events/kubernetes_events.c | 2 +- plugins/in_kubernetes_events/kubernetes_events_conf.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/in_kubernetes_events/kubernetes_events.c b/plugins/in_kubernetes_events/kubernetes_events.c index 2be73a68aed..b5f90a15015 100644 --- a/plugins/in_kubernetes_events/kubernetes_events.c +++ b/plugins/in_kubernetes_events/kubernetes_events.c @@ -892,7 +892,7 @@ static struct flb_config_map config_map[] = { { FLB_CONFIG_MAP_STR, "timestamp_key", K8S_EVENTS_RA_TIMESTAMP, 0, FLB_TRUE, offsetof(struct k8s_events, timestamp_key), - "Record accessor for the timestamp from the event. Default is $metadata['creationTimestamp']." + "Record accessor for the timestamp from the event. Default is $lastTimestamp." }, #ifdef FLB_HAVE_SQLDB diff --git a/plugins/in_kubernetes_events/kubernetes_events_conf.h b/plugins/in_kubernetes_events/kubernetes_events_conf.h index 9d6b54197f1..73b48c323f3 100644 --- a/plugins/in_kubernetes_events/kubernetes_events_conf.h +++ b/plugins/in_kubernetes_events/kubernetes_events_conf.h @@ -38,7 +38,7 @@ #define K8S_EVENTS_KUBE_TOKEN "/var/run/secrets/kubernetes.io/serviceaccount/token" #define K8S_EVENTS_KUBE_CA "/var/run/secrets/kubernetes.io/serviceaccount/ca.crt" -#define K8S_EVENTS_RA_TIMESTAMP "$metadata['creationTimestamp']" +#define K8S_EVENTS_RA_TIMESTAMP "$lastTimestamp" #define K8S_EVENTS_RA_RESOURCE_VERSION "$metadata['resourceVersion']" struct k8s_events *k8s_events_conf_create(struct flb_input_instance *ins);