Skip to content

Commit ff160ac

Browse files
ryanohnemusedsiper
authored andcommitted
in_kubernetes_events: make timestamp from incoming record configurable
Signed-off-by: ryanohnemus <[email protected]>
1 parent 8738546 commit ff160ac

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

plugins/in_kubernetes_events/kubernetes_events.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -889,6 +889,11 @@ static struct flb_config_map config_map[] = {
889889
0, FLB_TRUE, offsetof(struct k8s_events, namespace),
890890
"kubernetes namespace to get events from, gets event from all namespaces by default."
891891
},
892+
{
893+
FLB_CONFIG_MAP_STR, "timestamp_key", K8S_EVENTS_RA_TIMESTAMP,
894+
0, FLB_TRUE, offsetof(struct k8s_events, timestamp_key),
895+
"Record accessor for the timestamp from the event. Default is $metadata['creationTimestamp']."
896+
},
892897

893898
#ifdef FLB_HAVE_SQLDB
894899
{

plugins/in_kubernetes_events/kubernetes_events.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ struct k8s_events {
7474

7575
struct flb_log_event_encoder *encoder;
7676

77+
/* timestamp key */
78+
flb_sds_t timestamp_key;
79+
7780
/* record accessor */
7881
struct flb_record_accessor *ra_timestamp;
7982
struct flb_record_accessor *ra_resource_version;

plugins/in_kubernetes_events/kubernetes_events_conf.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ struct k8s_events *k8s_events_conf_create(struct flb_input_instance *ins)
135135
int ret;
136136
const char *p;
137137
const char *url;
138+
const char *timestampKey;
138139
const char *tmp;
139140
struct k8s_events *ctx = NULL;
140141
pthread_mutexattr_t attr;
@@ -165,10 +166,14 @@ struct k8s_events *k8s_events_conf_create(struct flb_input_instance *ins)
165166
}
166167

167168
/* Record accessor pattern */
168-
ctx->ra_timestamp = flb_ra_create(K8S_EVENTS_RA_TIMESTAMP, FLB_TRUE);
169+
timestampKey = flb_input_get_property("timestamp_key", ins);
170+
if (!timestampKey ) {
171+
timestampKey = K8S_EVENTS_RA_TIMESTAMP;
172+
}
173+
ctx->ra_timestamp = flb_ra_create(timestampKey, FLB_TRUE);
169174
if (!ctx->ra_timestamp) {
170175
flb_plg_error(ctx->ins,
171-
"could not create record accessor for metadata items");
176+
"could not create record accessor for record timestamp");
172177
k8s_events_conf_destroy(ctx);
173178
return NULL;
174179
}

0 commit comments

Comments
 (0)