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

wip - filter_ratelimit: Add record rate limiter #433

Closed
wants to merge 2 commits into from
Closed
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
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ option(FLB_FILTER_STDOUT "Enable stdout filter" Yes)
option(FLB_FILTER_PARSER "Enable parser filter" Yes)
option(FLB_FILTER_KUBERNETES "Enable kubernetes filter" Yes)
option(FLB_FILTER_RECORD_MODIFIER "Enable record_modifier filter" Yes)
option(FLB_FILTER_RATELIMIT "Enable ratelimit filter" Yes)

# Enable all features
if(FLB_ALL)
Expand Down
10 changes: 5 additions & 5 deletions include/fluent-bit/flb_hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
struct flb_hash_entry {
char *key;
size_t key_len;
char *val;
void *val;
size_t val_size;
struct mk_list _head;
};
Expand All @@ -48,11 +48,11 @@ struct flb_hash *flb_hash_create(size_t size);
void flb_hash_destroy(struct flb_hash *ht);

int flb_hash_add(struct flb_hash *ht, char *key, int key_len,
char *val, size_t val_size);
void *val, size_t val_size);
int flb_hash_get(struct flb_hash *ht, char *key, int key_len,
char **out_buf, size_t *out_size);
int flb_hash_get_by_id(struct flb_hash *ht, int id, char *key, char **out_buf,
size_t *out_size);
void **out, size_t *out_size);
int flb_hash_get_by_id(struct flb_hash *ht, int id, char *key, int key_len,
void **out, size_t *out_size);
int flb_hash_del(struct flb_hash *ht, char *key);

#endif
1 change: 1 addition & 0 deletions plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ if(FLB_REGEX)
REGISTER_FILTER_PLUGIN("filter_parser")
endif()
REGISTER_FILTER_PLUGIN("filter_record_modifier")
REGISTER_FILTER_PLUGIN("filter_ratelimit")

# Register external input and output plugins
if(EXT_IN_PLUGINS)
Expand Down
9 changes: 6 additions & 3 deletions plugins/filter_kubernetes/kube_meta.c
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,7 @@ int flb_kube_meta_get(struct flb_kube *ctx,
int id;
int ret;
char *hash_meta_buf;
void *out;
size_t hash_meta_size;

if (ctx->dummy_meta == FLB_TRUE) {
Expand All @@ -708,7 +709,8 @@ int flb_kube_meta_get(struct flb_kube *ctx,
/* Check if we have some data associated to the cache key */
ret = flb_hash_get(ctx->hash_table,
meta->cache_key, meta->cache_key_len,
&hash_meta_buf, &hash_meta_size);
&out, &hash_meta_size);
hash_meta_buf = out;
if (ret == -1) {
/* Retrieve API server meta and merge with local meta */
ret = get_and_merge_meta(ctx, meta,
Expand All @@ -727,8 +729,9 @@ int flb_kube_meta_get(struct flb_kube *ctx,
* the outgoing buffer and size.
*/
flb_free(hash_meta_buf);
flb_hash_get_by_id(ctx->hash_table, id, meta->cache_key,
&hash_meta_buf, &hash_meta_size);
flb_hash_get_by_id(ctx->hash_table, id, meta->cache_key, meta->cache_key_len,
&out, &hash_meta_size);
hash_meta_buf = out;
}
}

Expand Down
4 changes: 4 additions & 0 deletions plugins/filter_ratelimit/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
set(src
ratelimit.c)

FLB_PLUGIN(filter_ratelimit "${src}" "")
Loading