Skip to content
Open
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
26 changes: 16 additions & 10 deletions plugins/filter_kubernetes/kube_conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ struct flb_kube *flb_kube_conf_create(struct flb_filter_instance *ins,
{
int off;
int ret;
int cache_size = FLB_HASH_TABLE_SIZE;
const char *url;
const char *tmp;
const char *p;
Expand Down Expand Up @@ -125,30 +126,35 @@ struct flb_kube *flb_kube_conf_create(struct flb_filter_instance *ins,
}
}

/* Check if a custom cache size has been defined */
if (ctx->kube_meta_cache_size > 0) {
cache_size = ctx->kube_meta_cache_size;
}

if (ctx->kube_meta_cache_ttl > 0) {
ctx->hash_table = flb_hash_table_create_with_ttl(ctx->kube_meta_cache_ttl,
FLB_HASH_TABLE_EVICT_OLDER,
FLB_HASH_TABLE_SIZE,
FLB_HASH_TABLE_SIZE);
cache_size,
cache_size);
}
else {
ctx->hash_table = flb_hash_table_create(FLB_HASH_TABLE_EVICT_RANDOM,
FLB_HASH_TABLE_SIZE,
FLB_HASH_TABLE_SIZE);
cache_size,
cache_size);
}

if (ctx->kube_meta_namespace_cache_ttl > 0) {
ctx->namespace_hash_table = flb_hash_table_create_with_ttl(
ctx->kube_meta_namespace_cache_ttl,
FLB_HASH_TABLE_EVICT_OLDER,
FLB_HASH_TABLE_SIZE,
FLB_HASH_TABLE_SIZE);
cache_size,
cache_size);
}
else {
ctx->namespace_hash_table = flb_hash_table_create(
FLB_HASH_TABLE_EVICT_RANDOM,
FLB_HASH_TABLE_SIZE,
FLB_HASH_TABLE_SIZE);
cache_size,
cache_size);
}


Expand Down Expand Up @@ -192,8 +198,8 @@ struct flb_kube *flb_kube_conf_create(struct flb_filter_instance *ins,

ctx->aws_pod_service_hash_table = flb_hash_table_create_with_ttl(ctx->aws_pod_service_map_ttl,
FLB_HASH_TABLE_EVICT_OLDER,
FLB_HASH_TABLE_SIZE,
FLB_HASH_TABLE_SIZE);
cache_size,
cache_size);
if (!ctx->aws_pod_service_hash_table) {
flb_kube_conf_destroy(ctx);
return NULL;
Expand Down
1 change: 1 addition & 0 deletions plugins/filter_kubernetes/kube_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ struct flb_kube {
int kubelet_port;

int kube_meta_cache_ttl;
int kube_meta_cache_size;
int kube_meta_namespace_cache_ttl;

/* Configuration used for enabling pod to service name mapping*/
Expand Down
24 changes: 22 additions & 2 deletions plugins/filter_kubernetes/kube_meta.c
Original file line number Diff line number Diff line change
Expand Up @@ -2296,7 +2296,7 @@ static inline int flb_kube_pod_meta_get(struct flb_kube *ctx,
{
int id;
int ret;
const char *hash_meta_buf;
const char *hash_meta_buf = NULL;
char *tmp_hash_meta_buf;
size_t off = 0;
size_t hash_meta_size;
Expand Down Expand Up @@ -2335,6 +2335,16 @@ static inline int flb_kube_pod_meta_get(struct flb_kube *ctx,
flb_hash_table_get_by_id(ctx->hash_table, id, meta->cache_key,
&hash_meta_buf, &hash_meta_size);
}
else {
flb_plg_error(ctx->ins, "could not add metadata to the cache: %s",
meta->cache_key);
flb_free(tmp_hash_meta_buf);
return -1;
}
}

if (!hash_meta_buf) {
return -1;
}

/*
Expand Down Expand Up @@ -2375,7 +2385,7 @@ static inline int flb_kube_namespace_meta_get(struct flb_kube *ctx,
{
int id;
int ret;
const char *hash_meta_buf;
const char *hash_meta_buf = NULL;
char *tmp_hash_meta_buf;
size_t off = 0;
size_t hash_meta_size;
Expand Down Expand Up @@ -2414,6 +2424,16 @@ static inline int flb_kube_namespace_meta_get(struct flb_kube *ctx,
flb_hash_table_get_by_id(ctx->namespace_hash_table, id, meta->cache_key,
&hash_meta_buf, &hash_meta_size);
}
else {
flb_plg_error(ctx->ins, "could not add namespace metadata to the cache: %s",
meta->cache_key);
flb_free(tmp_hash_meta_buf);
return -1;
}
}

if (!hash_meta_buf) {
return -1;
}

/*
Expand Down
16 changes: 11 additions & 5 deletions plugins/filter_kubernetes/kubernetes.c
Original file line number Diff line number Diff line change
Expand Up @@ -1114,13 +1114,19 @@ static struct flb_config_map config_map[] = {
{
FLB_CONFIG_MAP_TIME, "kube_meta_cache_ttl", "0",
0, FLB_TRUE, offsetof(struct flb_kube, kube_meta_cache_ttl),
"configurable TTL for K8s cached metadata. "
"By default, it is set to 0 which means TTL for cache entries is disabled and "
"cache entries are evicted at random when capacity is reached. "
"In order to enable this option, you should set the number to a time interval. "
"For example, set this value to 60 or 60s and cache entries "
"configurable TTL for K8s cached metadata. "
"By default, it is set to 0 which means TTL for cache entries is disabled and "
"cache entries are evicted at random when capacity is reached. "
"In order to enable this option, you should set the number to a time interval. "
"For example, set this value to 60 or 60s and cache entries "
"which have been created more than 60s will be evicted"
},
{
FLB_CONFIG_MAP_INT, "kube_meta_cache_size", "0",
0, FLB_TRUE, offsetof(struct flb_kube, kube_meta_cache_size),
"configurable size for K8s cached metadata hash table. "
"By default, it is set to 0 which means the default size (256) is used."
},
{
FLB_CONFIG_MAP_TIME, "kube_meta_namespace_cache_ttl", "15m",
0, FLB_TRUE, offsetof(struct flb_kube, kube_meta_namespace_cache_ttl),
Expand Down
Loading