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

cfl_record_accessor: cfl_ra_key: Implement generic CFL based record accessor #9566

Open
wants to merge 3 commits 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
74 changes: 74 additions & 0 deletions include/fluent-bit/flb_cfl_ra_key.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/* -*- 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_CFL_RA_KEY_H
#define FLB_CFL_RA_KEY_H

#include <fluent-bit/flb_info.h>
#include <fluent-bit/flb_sds.h>
#include <fluent-bit/flb_regex.h>
#include <fluent-bit/record_accessor/flb_ra_parser.h>
#include <monkey/mk_core.h>
#include <cfl/cfl.h>

#include <stdbool.h>

enum cfl_ra_types {
FLB_CFL_RA_BOOL = 0,
FLB_CFL_RA_INT,
FLB_CFL_RA_FLOAT,
FLB_CFL_RA_STRING,
FLB_CFL_RA_NULL
};

/* condition value types */
typedef union {
bool boolean;
int64_t i64;
double f64;
flb_sds_t string;
} cfl_ra_val;

/* Represent any value object */
struct flb_cfl_ra_value {
int type;
struct cfl_variant v;
cfl_ra_val val;
};

struct flb_cfl_ra_value *flb_cfl_ra_key_to_value(flb_sds_t ckey,
struct cfl_variant vobj,
struct mk_list *subkeys);
void flb_cfl_ra_key_value_destroy(struct flb_cfl_ra_value *v);

int flb_cfl_ra_key_value_get(flb_sds_t ckey, struct cfl_variant vobj,
struct mk_list *subkeys,
cfl_sds_t *start_key,
cfl_sds_t *out_key, struct cfl_variant **out_val);

int flb_cfl_ra_key_strcmp(flb_sds_t ckey, struct cfl_variant vobj,
struct mk_list *subkeys, char *str, int len);
int flb_cfl_ra_key_regex_match(flb_sds_t ckey, struct cfl_variant vobj,
struct mk_list *subkeys, struct flb_regex *regex,
struct flb_regex_search *result);
int flb_cfl_ra_key_value_append(struct flb_ra_parser *rp, struct cfl_variant *vobj,
struct cfl_variant *in_val);
int flb_cfl_ra_key_value_update(struct flb_ra_parser *rp, struct cfl_variant *vobj,
cfl_sds_t in_key, struct cfl_variant *in_val);
#endif
64 changes: 64 additions & 0 deletions include/fluent-bit/flb_cfl_record_accessor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/* -*- 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_CFL_RECORD_ACCESSOR_H
#define FLB_CFL_RECORD_ACCESSOR_H

#include <fluent-bit/flb_info.h>
#include <fluent-bit/flb_regex.h>
#include <fluent-bit/flb_sds.h>
#include <fluent-bit/flb_sds_list.h>
#include <monkey/mk_core.h>
#include <cfl/cfl.h>

struct flb_cfl_record_accessor {
size_t size_hint;
flb_sds_t pattern;
struct mk_list list; /* List of parsed strings */
struct mk_list _head; /* Head to custom list (only used by flb_mp.h) */
};
void flb_cfl_ra_destroy(struct flb_cfl_record_accessor *cra);
int flb_cfl_ra_subkey_count(struct flb_cfl_record_accessor *cra);
struct flb_cfl_record_accessor *flb_cfl_ra_create(char *str, int translate_env);
flb_sds_t flb_cfl_ra_create_str_from_list(struct flb_sds_list *str_list);
struct flb_cfl_record_accessor *flb_cfl_ra_create_from_list(struct flb_sds_list *str_list, int translate_env);
flb_sds_t flb_cfl_ra_translate(struct flb_cfl_record_accessor *cra,
char *tag, int tag_len,
struct cfl_variant var, struct flb_regex_search *result);
flb_sds_t flb_cfl_ra_translate_check(struct flb_cfl_record_accessor *cra,
char *tag, int tag_len,
struct cfl_variant var, struct flb_regex_search *result,
int check);
void flb_cfl_ra_dump(struct flb_cfl_record_accessor *cra);
int flb_cfl_ra_is_static(struct flb_cfl_record_accessor *cra);
int flb_cfl_ra_strcmp(struct flb_cfl_record_accessor *ra, struct cfl_variant var,
char *str, int len);
int flb_cfl_ra_regex_match(struct flb_cfl_record_accessor *cra, struct cfl_variant var,
struct flb_regex *regex, struct flb_regex_search *result);
int flb_cfl_ra_get_kv_pair(struct flb_cfl_record_accessor *ra,
struct cfl_variant var,
cfl_sds_t *start_key,
cfl_sds_t *out_key, struct cfl_variant **out_val);
struct flb_cfl_ra_value *flb_cfl_ra_get_value_object(struct flb_cfl_record_accessor *cra,
struct cfl_variant var);
int flb_cfl_ra_update_kv_pair(struct flb_cfl_record_accessor *cra, struct cfl_variant var,
cfl_sds_t in_key, struct cfl_variant *in_val);
int flb_cfl_ra_append_kv_pair(struct flb_cfl_record_accessor *cra, struct cfl_variant var,
struct cfl_variant *in_val);
#endif
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ set(src
flb_msgpack_append_message.c
flb_notification.c
flb_lock.c
flb_cfl_ra_key.c
flb_cfl_record_accessor.c
)

# Config format
Expand Down
Loading
Loading