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

internal: add conditionals evaluation API #9749

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
91 changes: 91 additions & 0 deletions include/fluent-bit/flb_conditionals.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */

/* Fluent Bit
* ==========
* Copyright (C) 2015-2024 The Fluent Bit Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef FLB_CONDITIONS_H
#define FLB_CONDITIONS_H

#include <fluent-bit/flb_info.h>
#include <fluent-bit/flb_sds.h>
#include <fluent-bit/flb_regex.h>
#include <fluent-bit/flb_mp.h>
#include <fluent-bit/flb_cfl_record_accessor.h>
#include <monkey/mk_core.h>
#include <fluent-bit/flb_mp_chunk.h>

/* Context types enum */
enum record_context_type {
RECORD_CONTEXT_BODY = 0,
RECORD_CONTEXT_METADATA = 1
};

struct flb_condition;

enum flb_condition_operator {
FLB_COND_OP_AND,
FLB_COND_OP_OR
};

enum flb_rule_operator {
FLB_RULE_OP_EQ,
FLB_RULE_OP_NEQ,
FLB_RULE_OP_GT,
FLB_RULE_OP_LT,
FLB_RULE_OP_REGEX,
FLB_RULE_OP_IN,
FLB_RULE_OP_NOT_IN
};

struct flb_condition_rule {
struct flb_cfl_record_accessor *ra; /* Record accessor for the field */
enum record_context_type context; /* Whether rule applies to body or metadata */
enum flb_rule_operator op;
union {
flb_sds_t str_val;
double num_val;
struct {
flb_sds_t *values;
int count;
} array;
} value;
struct flb_regex *regex;
struct mk_list _head;
};

struct flb_condition {
enum flb_condition_operator op;
struct mk_list rules;
};

/* Core condition functions */
struct flb_condition *flb_condition_create(enum flb_condition_operator op);

int flb_condition_add_rule(struct flb_condition *cond,
const char *field,
enum flb_rule_operator op,
void *value,
int value_count,
enum record_context_type context);

void flb_condition_destroy(struct flb_condition *cond);

/* Evaluation function */
int flb_condition_evaluate(struct flb_condition *cond,
struct flb_mp_chunk_record *record);

#endif /* FLB_CONDITIONS_H */
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ set(src
flb_lock.c
flb_cfl_ra_key.c
flb_cfl_record_accessor.c
flb_conditionals.c
)

# Config format
Expand Down
Loading
Loading