diff --git a/plugins/in_kubernetes_events/kubernetes_events.c b/plugins/in_kubernetes_events/kubernetes_events.c index 97719fba6e0..b5f90a15015 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 $lastTimestamp." + }, #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; } 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);