Coverage Report

Created: 2026-03-22 07:09

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/fluent-bit/plugins/processor_content_modifier/cm.c
Line
Count
Source
1
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3
/*  Fluent Bit
4
 *  ==========
5
 *  Copyright (C) 2015-2026 The Fluent Bit Authors
6
 *
7
 *  Licensed under the Apache License, Version 2.0 (the "License");
8
 *  you may not use this file except in compliance with the License.
9
 *  You may obtain a copy of the License at
10
 *
11
 *      http://www.apache.org/licenses/LICENSE-2.0
12
 *
13
 *  Unless required by applicable law or agreed to in writing, software
14
 *  distributed under the License is distributed on an "AS IS" BASIS,
15
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
 *  See the License for the specific language governing permissions and
17
 *  limitations under the License.
18
 */
19
20
21
#include <fluent-bit/flb_processor_plugin.h>
22
#include <fluent-bit/flb_utils.h>
23
#include <fluent-bit/flb_time.h>
24
#include <fluent-bit/flb_hash.h>
25
#include <fluent-bit/flb_pack.h>
26
#include <fluent-bit/flb_processor.h>
27
#include <fluent-bit/flb_log_event_decoder.h>
28
#include <fluent-bit/flb_log_event_encoder.h>
29
30
#include "cm.h"
31
#include "cm_config.h"
32
33
static int cb_init(struct flb_processor_instance *ins, void *source_plugin_instance,
34
                   int source_plugin_type, struct flb_config *config)
35
0
{
36
0
    struct content_modifier_ctx *ctx;
37
38
0
    ctx = cm_config_create(ins, config);
39
0
    if (!ctx) {
40
0
        return -1;
41
0
    }
42
43
0
    flb_processor_instance_set_context(ins, ctx);
44
45
0
    return FLB_PROCESSOR_SUCCESS;
46
0
}
47
48
static int cb_exit(struct flb_processor_instance *ins, void *data)
49
0
{
50
0
    struct content_modifier_ctx *ctx;
51
52
0
    if (!ins) {
53
0
        return FLB_PROCESSOR_SUCCESS;
54
0
    }
55
56
0
    ctx = data;
57
0
    if (ctx) {
58
0
        cm_config_destroy(ctx);
59
0
    }
60
61
0
    return FLB_PROCESSOR_SUCCESS;
62
0
}
63
64
static int cb_process_logs(struct flb_processor_instance *ins,
65
                           void *chunk_data,
66
                           const char *tag,
67
                           int tag_len)
68
0
{
69
0
    int ret;
70
0
    struct content_modifier_ctx *ctx;
71
0
    struct flb_mp_chunk_cobj *chunk_cobj = (struct flb_mp_chunk_cobj *) chunk_data;
72
73
0
    if (!ins->context) {
74
0
        return FLB_PROCESSOR_FAILURE;
75
0
    }
76
0
    ctx = ins->context;
77
78
0
    ret = cm_logs_process(ins, ctx, chunk_cobj, tag, tag_len);
79
0
    return ret;
80
81
0
}
82
83
static int cb_process_traces(struct flb_processor_instance *ins,
84
                             struct ctrace *in_ctr,
85
                             struct ctrace **out_ctr,
86
                             const char *tag,
87
                             int tag_len)
88
0
{
89
0
    int ret;
90
0
    struct content_modifier_ctx *ctx;
91
92
0
    if (!ins->context) {
93
0
        return FLB_PROCESSOR_FAILURE;
94
0
    }
95
0
    ctx = ins->context;
96
97
0
    ret = cm_traces_process(ins, ctx, in_ctr, out_ctr, tag, tag_len);
98
0
    return ret;
99
100
0
}
101
102
static int cb_process_metrics(struct flb_processor_instance *ins,
103
                              struct cmt *in_cmt,
104
                              struct cmt **out_cmt,
105
                              const char *tag,
106
                              int tag_len)
107
0
{
108
0
    int ret;
109
0
    struct content_modifier_ctx *ctx;
110
111
0
    if (!ins->context) {
112
0
        return FLB_PROCESSOR_FAILURE;
113
0
    }
114
0
    ctx = ins->context;
115
116
0
    ret = cm_metrics_process(ins, ctx, in_cmt, out_cmt, tag, tag_len);
117
0
    return ret;
118
0
}
119
120
static struct flb_config_map config_map[] = {
121
    {
122
        FLB_CONFIG_MAP_STR, "context", NULL,
123
        0, FLB_TRUE, offsetof(struct content_modifier_ctx, context_str),
124
        "Context where the action will be applied."
125
    },
126
127
    {
128
        FLB_CONFIG_MAP_STR, "action", NULL,
129
        0, FLB_TRUE, offsetof(struct content_modifier_ctx, action_str),
130
        "Action to perform over the content: insert, upsert, delete, rename or hash."
131
    },
132
133
    {
134
        FLB_CONFIG_MAP_STR, "key", NULL,
135
        0, FLB_TRUE, offsetof(struct content_modifier_ctx, key),
136
        "Key to apply the action."
137
    },
138
139
    {
140
        FLB_CONFIG_MAP_STR, "value", NULL,
141
        0, FLB_TRUE, offsetof(struct content_modifier_ctx, value),
142
        "Value to apply the action."
143
    },
144
145
    {
146
        FLB_CONFIG_MAP_STR, "pattern", NULL,
147
        0, FLB_TRUE, offsetof(struct content_modifier_ctx, pattern),
148
        "Pattern used to create a regular expression."
149
    },
150
151
    {
152
        FLB_CONFIG_MAP_STR, "converted_type", NULL,
153
        0, FLB_TRUE, offsetof(struct content_modifier_ctx, converted_type_str),
154
        "Specify the data type to convert to, allowed values are: int, double or string."
155
    },
156
157
    /* EOF */
158
    {0}
159
};
160
161
struct flb_processor_plugin processor_content_modifier_plugin = {
162
    .name               = "content_modifier",
163
    .description        = "Modify the content of Logs, Metrics and Traces",
164
    .cb_init            = cb_init,
165
    .cb_process_logs    = cb_process_logs,
166
    .cb_process_metrics = cb_process_metrics,
167
    .cb_process_traces  = cb_process_traces,
168
    .cb_exit            = cb_exit,
169
    .config_map         = config_map,
170
    .flags              = 0
171
};