Skip to content

Commit 350c9b5

Browse files
committed
# This is a combination of 4 commits.
# This is the 1st commit message: processor: input_metric: Prevent dangling pointer if cmt context is recreated Signed-off-by: Hiroshi Hatake <hiroshi@chronosphere.io> # This is the commit message #2: processor_labels: Follow change of the signature of metrics callback Signed-off-by: Hiroshi Hatake <hiroshi@chronosphere.io> # This is the commit message #3: processor_selector: Implement selector processor for metrics For future extensibility, we use "selector" as a name for this processor. Signed-off-by: Hiroshi Hatake <hiroshi@chronosphere.io> # This is the commit message #4: lib: Support setter for processor Signed-off-by: Hiroshi Hatake <hiroshi@chronosphere.io>
1 parent 9a173d0 commit 350c9b5

File tree

11 files changed

+680
-10
lines changed

11 files changed

+680
-10
lines changed

CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,8 @@ option(FLB_FILTER_WASM "Enable WASM filter"
285285
option(FLB_PROCESSOR_LABELS "Enable metrics label manipulation processor" Yes)
286286
option(FLB_PROCESSOR_ATTRIBUTES "Enable atributes manipulation processor" Yes)
287287
option(FLB_PROCESSOR_CONTENT_MODIFIER "Enable content modifier processor" Yes)
288+
option(FLB_PROCESSOR_SELECTOR "Enable selector processor" Yes)
289+
288290

289291
if(DEFINED FLB_NIGHTLY_BUILD AND NOT "${FLB_NIGHTLY_BUILD}" STREQUAL "")
290292
FLB_DEFINITION_VAL(FLB_NIGHTLY_BUILD ${FLB_NIGHTLY_BUILD})

include/fluent-bit/flb_lib.h

+4
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,15 @@ struct flb_lib_out_cb {
4646
/* For Fluent Bit library callers, we only export the following symbols */
4747
typedef struct flb_lib_ctx flb_ctx_t;
4848

49+
struct flb_processor;
50+
4951
FLB_EXPORT void flb_init_env();
5052
FLB_EXPORT flb_ctx_t *flb_create();
5153
FLB_EXPORT void flb_destroy(flb_ctx_t *ctx);
5254
FLB_EXPORT int flb_input(flb_ctx_t *ctx, const char *input, void *data);
55+
FLB_EXPORT int flb_input_set_processor(flb_ctx_t *ctx, int ffd, struct flb_processor *proc);
5356
FLB_EXPORT int flb_output(flb_ctx_t *ctx, const char *output, struct flb_lib_out_cb *cb);
57+
FLB_EXPORT int flb_output_set_processor(flb_ctx_t *ctx, int ffd, struct flb_processor *proc);
5458
FLB_EXPORT int flb_filter(flb_ctx_t *ctx, const char *filter, void *data);
5559
FLB_EXPORT int flb_input_set(flb_ctx_t *ctx, int ffd, ...);
5660
FLB_EXPORT int flb_input_property_check(flb_ctx_t *ctx, int ffd, char *key, char *val);

include/fluent-bit/flb_processor.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@ struct flb_processor_plugin {
143143
int);
144144

145145
int (*cb_process_metrics) (struct flb_processor_instance *,
146-
struct cmt *,
146+
struct cmt *, /* in */
147+
struct cmt **, /* out */
147148
const char *,
148149
int);
149150

plugins/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ REGISTER_IN_PLUGIN("in_random")
283283
# ==========
284284
REGISTER_PROCESSOR_PLUGIN("processor_labels")
285285
REGISTER_PROCESSOR_PLUGIN("processor_content_modifier")
286+
REGISTER_PROCESSOR_PLUGIN("processor_selector")
286287

287288
# OUTPUTS
288289
# =======

plugins/processor_labels/labels.c

+19
Original file line numberDiff line numberDiff line change
@@ -1696,15 +1696,23 @@ static int hash_labels(struct cmt *metrics_context,
16961696

16971697
static int cb_process_metrics(struct flb_processor_instance *processor_instance,
16981698
struct cmt *metrics_context,
1699+
struct cmt **out_context,
16991700
const char *tag,
17001701
int tag_len)
17011702
{
1703+
struct cmt *out_cmt;
17021704
struct internal_processor_context *processor_context;
17031705
int result;
17041706

17051707
processor_context =
17061708
(struct internal_processor_context *) processor_instance->context;
17071709

1710+
out_cmt = cmt_create();
1711+
if (out_cmt == NULL) {
1712+
flb_plg_error(processor_instance, "could not create out_cmt context");
1713+
return FLB_PROCESSOR_FAILURE;
1714+
}
1715+
17081716
result = delete_labels(metrics_context,
17091717
&processor_context->delete_labels);
17101718

@@ -1728,6 +1736,17 @@ static int cb_process_metrics(struct flb_processor_instance *processor_instance,
17281736
&processor_context->hash_labels);
17291737
}
17301738

1739+
if (result == FLB_PROCESSOR_SUCCESS) {
1740+
result = cmt_cat(out_cmt, metrics_context);
1741+
if (result != 0) {
1742+
cmt_destroy(out_cmt);
1743+
1744+
return FLB_PROCESSOR_FAILURE;
1745+
}
1746+
1747+
*out_context = out_cmt;
1748+
}
1749+
17311750
if (result != FLB_PROCESSOR_SUCCESS) {
17321751
return FLB_PROCESSOR_FAILURE;
17331752
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
set(src
2+
selector.c)
3+
4+
FLB_PLUGIN(processor_selector "${src}" "")

0 commit comments

Comments
 (0)