Coverage Report

Created: 2026-08-09 07:14

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/fluent-bit/plugins/in_elasticsearch/in_elasticsearch_config.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
#include <fluent-bit/flb_input_plugin.h>
21
22
#include "in_elasticsearch.h"
23
#include "in_elasticsearch_config.h"
24
struct flb_in_elasticsearch *in_elasticsearch_config_create(struct flb_input_instance *ins)
25
0
{
26
0
    int ret;
27
0
    char port[8];
28
0
    struct flb_in_elasticsearch *ctx;
29
30
0
    ctx = flb_calloc(1, sizeof(struct flb_in_elasticsearch));
31
0
    if (!ctx) {
32
0
        flb_errno();
33
0
        return NULL;
34
0
    }
35
0
    ctx->ins = ins;
36
37
    /* Load the config map */
38
0
    ret = flb_input_config_map_set(ins, (void *) ctx);
39
0
    if (ret == -1) {
40
0
        flb_free(ctx);
41
0
        return NULL;
42
0
    }
43
44
    /* Listen interface (if not set, defaults to 0.0.0.0:9200) */
45
0
    flb_input_net_default_listener("0.0.0.0", 9200, ins);
46
47
0
    ctx->listen = flb_sds_create(ins->host.listen);
48
0
    snprintf(port, sizeof(port) - 1, "%d", ins->host.port);
49
0
    ctx->tcp_port = flb_sds_create(port);
50
51
0
    ctx->log_encoder = flb_log_event_encoder_create(FLB_LOG_EVENT_FORMAT_DEFAULT);
52
0
    if (ctx->log_encoder == NULL) {
53
0
        flb_plg_error(ctx->ins, "event encoder initialization error");
54
0
        in_elasticsearch_config_destroy(ctx);
55
56
0
        return NULL;
57
0
    }
58
59
    /* Create record accessor for tag_key if specified */
60
0
    if (ctx->tag_key) {
61
0
        ctx->ra_tag_key = flb_ra_create(ctx->tag_key, FLB_TRUE);
62
0
        if (!ctx->ra_tag_key) {
63
0
            flb_plg_error(ctx->ins, "invalid record accessor pattern for tag_key: %s", ctx->tag_key);
64
0
            in_elasticsearch_config_destroy(ctx);
65
0
            return NULL;
66
0
        }
67
0
    }
68
69
0
    return ctx;
70
0
}
71
72
int in_elasticsearch_config_destroy(struct flb_in_elasticsearch *ctx)
73
0
{
74
0
    if (ctx->ra_tag_key) {
75
0
        flb_ra_destroy(ctx->ra_tag_key);
76
0
    }
77
78
0
    flb_log_event_encoder_destroy(ctx->log_encoder);
79
80
0
    flb_http_server_destroy(&ctx->http_server);
81
82
0
    flb_sds_destroy(ctx->listen);
83
0
    flb_sds_destroy(ctx->tcp_port);
84
85
0
    flb_free(ctx);
86
87
0
    return 0;
88
0
}