Skip to content

Commit

Permalink
in_kubernetes_events: make timestamp from incoming record configurable
Browse files Browse the repository at this point in the history
Signed-off-by: ryanohnemus <[email protected]>
  • Loading branch information
ryanohnemus committed Dec 15, 2023
1 parent 1cb694e commit 047ca27
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
5 changes: 5 additions & 0 deletions plugins/in_kubernetes_events/kubernetes_events.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
3 changes: 3 additions & 0 deletions plugins/in_kubernetes_events/kubernetes_events.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 7 additions & 2 deletions plugins/in_kubernetes_events/kubernetes_events_conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 047ca27

Please sign in to comment.