Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cobj_record_accessor: Implement CFL based record accessor
Browse files Browse the repository at this point in the history
Signed-off-by: Hiroshi Hatake <hiroshi@chronosphere.io>
cosmo0920 committed Nov 8, 2024
1 parent f14e5dd commit 63fd0aa
Showing 4 changed files with 1,059 additions and 8 deletions.
64 changes: 64 additions & 0 deletions include/fluent-bit/flb_cobj_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_COBJ_RECORD_ACCESSOR_H
#define FLB_COBJ_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_cobj_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_cobj_ra_destroy(struct flb_cobj_record_accessor *cra);
int flb_cobj_ra_subkey_count(struct flb_cobj_record_accessor *cra);
struct flb_cobj_record_accessor *flb_cobj_ra_create(char *str, int translate_env);
flb_sds_t flb_cobj_ra_create_str_from_list(struct flb_sds_list *str_list);
struct flb_cobj_record_accessor *flb_cobj_ra_create_from_list(struct flb_sds_list *str_list, int translate_env);
flb_sds_t flb_cobj_ra_translate(struct flb_cobj_record_accessor *cra,
char *tag, int tag_len,
struct cfl_object cobj, struct flb_regex_search *result);
flb_sds_t flb_cobj_ra_translate_check(struct flb_cobj_record_accessor *cra,
char *tag, int tag_len,
struct cfl_object cobj, struct flb_regex_search *result,
int check);
void flb_cobj_ra_dump(struct flb_cobj_record_accessor *cra);
int flb_cobj_ra_is_static(struct flb_cobj_record_accessor *cra);
int flb_cobj_ra_strcmp(struct flb_cobj_record_accessor *ra, struct cfl_object cobj,
char *str, int len);
int flb_cobj_ra_regex_match(struct flb_cobj_record_accessor *cra, struct cfl_object cobj,
struct flb_regex *regex, struct flb_regex_search *result);
int flb_cobj_ra_get_kv_pair(struct flb_cobj_record_accessor *ra,
struct cfl_object cobj,
cfl_sds_t *start_key,
cfl_sds_t *out_key, struct cfl_variant **out_val);
struct flb_cobj_ra_value *flb_cobj_ra_get_value_object(struct flb_cobj_record_accessor *cra,
struct cfl_object cobj);
int flb_cobj_ra_update_kv_pair(struct flb_cobj_record_accessor *cra, struct cfl_object cobj,
cfl_sds_t in_key, struct cfl_variant *in_val);
int flb_cobj_ra_append_kv_pair(struct flb_cobj_record_accessor *cra, struct cfl_object cobj,
struct cfl_variant *in_val);
#endif
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -86,6 +86,7 @@ set(src
flb_notification.c
flb_lock.c
flb_cobj_ra_key.c
flb_cobj_record_accessor.c
)

# Config format
20 changes: 12 additions & 8 deletions src/flb_cobj_ra_key.c
Original file line number Diff line number Diff line change
@@ -510,6 +510,7 @@ static int update_subkey_kvlist(struct cfl_variant *vobj, struct mk_list *subkey
struct flb_ra_subentry *entry;
int ret;
flb_sds_t key = NULL;
flb_sds_t tmp = NULL;
struct cfl_kvlist *kvlist = NULL;
struct cfl_kvpair *kvpair = NULL;
struct cfl_kvpair *pair = NULL;
@@ -547,12 +548,11 @@ static int update_subkey_kvlist(struct cfl_variant *vobj, struct mk_list *subkey
*matched += 1;
if (levels == *matched) {
flb_trace("%s update key/val matched=%d", __FUNCTION__, *matched);
key = cfl_sds_create_len(pair->key, cfl_sds_len(pair->key));
if (key == NULL) {
return -1;
}
if (in_key != NULL && in_val != NULL) {
cfl_kvlist_insert(kvlist, in_key, in_val);
if (pair) {
cfl_kvpair_destroy(pair);
}
}
else if (in_key != NULL) {
tmp = kvpair->key;
@@ -564,11 +564,15 @@ static int update_subkey_kvlist(struct cfl_variant *vobj, struct mk_list *subkey
flb_sds_destroy(tmp);
}
else if (in_val != NULL) {
key = cfl_sds_create_len(pair->key, cfl_sds_len(pair->key));
if (key == NULL) {
return -1;
}
cfl_kvlist_insert(kvlist, key, in_val);
}
cfl_sds_destroy(key);
if (pair) {
cfl_kvpair_destroy(pair);
cfl_sds_destroy(key);
if (pair) {
cfl_kvpair_destroy(pair);
}
}
return 0;
}
982 changes: 982 additions & 0 deletions src/flb_cobj_record_accessor.c

Large diffs are not rendered by default.

0 comments on commit 63fd0aa

Please sign in to comment.