summaryrefslogtreecommitdiffstats
path: root/fluent-bit/plugins/out_opensearch/opensearch.h
blob: a1087c1da3c74e52759a789f213b4c3d04af4c97 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */

/*  Fluent Bit
 *  ==========
 *  Copyright (C) 2015-2022 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_OUT_OPENSEARCH_H
#define FLB_OUT_OPENSEARCH_H

/* config defaults */
#define FLB_OS_DEFAULT_HOST       "127.0.0.1"
#define FLB_OS_DEFAULT_PORT       92000
#define FLB_OS_DEFAULT_INDEX      "fluent-bit"
#define FLB_OS_DEFAULT_TYPE       "_doc"
#define FLB_OS_DEFAULT_PREFIX     "logstash"
#define FLB_OS_DEFAULT_TIME_FMT   "%Y.%m.%d"
#define FLB_OS_DEFAULT_TIME_KEY   "@timestamp"
#define FLB_OS_DEFAULT_TIME_KEYF  "%Y-%m-%dT%H:%M:%S"
#define FLB_OS_DEFAULT_TAG_KEY    "flb-key"
#define FLB_OS_DEFAULT_HTTP_MAX   "512k"
#define FLB_OS_WRITE_OP_INDEX     "index"
#define FLB_OS_WRITE_OP_CREATE    "create"
#define FLB_OS_WRITE_OP_UPDATE    "update"
#define FLB_OS_WRITE_OP_UPSERT    "upsert"

/* macros */
#define FLB_OS_HEADER_SIZE        1024
#define OS_BULK_CHUNK      4096  /* Size of buffer chunks    */
#define OS_BULK_HEADER      165  /* Bulk API prefix line  */

/* Bulk formats */
#define OS_BULK_INDEX_FMT            "{\"%s\":{\"_index\":\"%s\",\"_type\":\"%s\"}}\n"
#define OS_BULK_INDEX_FMT_ID         "{\"%s\":{\"_index\":\"%s\",\"_type\":\"%s\",\"_id\":\"%s\"}}\n"
#define OS_BULK_INDEX_FMT_NO_TYPE    "{\"%s\":{\"_index\":\"%s\"}}\n"
#define OS_BULK_INDEX_FMT_ID_NO_TYPE "{\"%s\":{\"_index\":\"%s\",\"_id\":\"%s\"}}\n"

/* Bulk write-type operations */
#define OS_BULK_UPDATE_OP_BODY       "{\"doc\":"
#define OS_BULK_UPSERT_OP_BODY       "{\"doc_as_upsert\":true,\"doc\":"

/* Supported compression algorithms */
#define FLB_OS_COMPRESSION_NONE 0
#define FLB_OS_COMPRESSION_GZIP 1

struct flb_opensearch {
    /* OpenSearch index (database) and type (table) */
    flb_sds_t index;
    struct flb_record_accessor *ra_index;

    char *type;
    char suppress_type_name;

    /* HTTP Auth */
    char *http_user;
    char *http_passwd;

    /* AWS Auth */
#ifdef FLB_HAVE_AWS
    int has_aws_auth;
    char *aws_region;
    char *aws_sts_endpoint;
    char *aws_profile;
    struct flb_aws_provider *aws_provider;
    struct flb_aws_provider *base_aws_provider;
    /* tls instances can't be re-used; aws provider requires a separate one */
    struct flb_tls *aws_tls;
    /* one for the standard chain provider, one for sts assume role */
    struct flb_tls *aws_sts_tls;
    char *aws_session_name;
    char *aws_service_name;
    struct mk_list *aws_unsigned_headers;
#endif

    /* HTTP Client Setup */
    size_t buffer_size;

    /* If enabled, replace field name dots with underscore */
    int replace_dots;

    int trace_output;
    int trace_error;

    /*
     * Logstash compatibility options
     * ==============================
     */

    /* enabled/disabled */
    int logstash_format;
    int generate_id;
    int current_time_index;

    /* prefix */
    flb_sds_t logstash_prefix;
    flb_sds_t logstash_prefix_separator;

    /* prefix key */
    flb_sds_t logstash_prefix_key;

    /* date format */
    flb_sds_t logstash_dateformat;

    /* time key */
    flb_sds_t time_key;

    /* time key format */
    flb_sds_t time_key_format;

    /* time key nanoseconds */
    int time_key_nanos;

    /* write operation config value */
    flb_sds_t write_operation;

    /* write operation / action */
    char *action;

    /* id_key */
    flb_sds_t id_key;
    struct flb_record_accessor *ra_id_key;

    /* include_tag_key */
    int include_tag_key;
    flb_sds_t tag_key;

    /* HTTP API */
    char uri[1024];

    struct flb_record_accessor *ra_prefix_key;

    /* Upstream connection to the backend server */
    struct flb_upstream *u;

    /* Plugin output instance reference */
    struct flb_output_instance *ins;

    /* Compression algorithm */
    int compression;
    flb_sds_t compression_str;
};

#endif