Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

in_kubernetes_events: make timestamp from incoming record configurable #8289

Merged
merged 2 commits into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 $lastTimestamp."
},

#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
2 changes: 1 addition & 1 deletion plugins/in_kubernetes_events/kubernetes_events_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading