Skip to content

Commit fa23086

Browse files
committed
pipeline: outputs: es: support overriding the most plugin parameters with Upstream node configuration
For Elastic cloud authentication these parameters are always taken from plugin configuration and never from Upstream node configuration: cloud_id. For AWS authentication these parameters are always taken from plugin configuration and never from Upstream node configuration: http_proxy, no_proxy, tls*. Signed-off-by: Marat Abrarov <[email protected]>
1 parent 3dd5288 commit fa23086

File tree

6 files changed

+715
-136
lines changed

6 files changed

+715
-136
lines changed

plugins/out_es/es.c

Lines changed: 38 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838

3939
#include "es.h"
4040
#include "es_conf.h"
41+
#include "es_conf_prop.h"
4142
#include "es_bulk.h"
4243
#include "murmur3.h"
4344

@@ -1138,91 +1139,91 @@ static int cb_es_exit(void *data, struct flb_config *config)
11381139
/* Configuration properties map */
11391140
static struct flb_config_map config_map[] = {
11401141
{
1141-
FLB_CONFIG_MAP_STR, "index", FLB_ES_DEFAULT_INDEX,
1142+
FLB_CONFIG_MAP_STR, FLB_ES_CONFIG_PROPERTY_INDEX, FLB_ES_DEFAULT_INDEX,
11421143
0, FLB_TRUE, offsetof(struct flb_elasticsearch_config, index),
11431144
"Set an index name"
11441145
},
11451146
{
1146-
FLB_CONFIG_MAP_STR, "type", FLB_ES_DEFAULT_TYPE,
1147+
FLB_CONFIG_MAP_STR, FLB_ES_CONFIG_PROPERTY_TYPE, FLB_ES_DEFAULT_TYPE,
11471148
0, FLB_TRUE, offsetof(struct flb_elasticsearch_config, type),
11481149
"Set the document type property"
11491150
},
11501151
{
1151-
FLB_CONFIG_MAP_BOOL, "suppress_type_name", "false",
1152+
FLB_CONFIG_MAP_BOOL, FLB_ES_CONFIG_PROPERTY_SUPPRESS_TYPE_NAME, "false",
11521153
0, FLB_TRUE, offsetof(struct flb_elasticsearch_config, suppress_type_name),
11531154
"If true, mapping types is removed. (for v7.0.0 or later)"
11541155
},
11551156

11561157
/* HTTP Authentication */
11571158
{
1158-
FLB_CONFIG_MAP_STR, "http_user", NULL,
1159+
FLB_CONFIG_MAP_STR, FLB_ES_CONFIG_PROPERTY_HTTP_USER, NULL,
11591160
0, FLB_TRUE, offsetof(struct flb_elasticsearch_config, http_user),
11601161
"Optional username credential for Elastic X-Pack access"
11611162
},
11621163
{
1163-
FLB_CONFIG_MAP_STR, "http_passwd", "",
1164+
FLB_CONFIG_MAP_STR, FLB_ES_CONFIG_PROPERTY_HTTP_PASSWD, "",
11641165
0, FLB_TRUE, offsetof(struct flb_elasticsearch_config, http_passwd),
11651166
"Password for user defined in HTTP_User"
11661167
},
11671168
{
1168-
FLB_CONFIG_MAP_STR, "http_api_key", NULL,
1169+
FLB_CONFIG_MAP_STR, FLB_ES_CONFIG_PROPERTY_HTTP_API_KEY, NULL,
11691170
0, FLB_TRUE, offsetof(struct flb_elasticsearch_config, http_api_key),
11701171
"Base-64 encoded API key credential for Elasticsearch"
11711172
},
11721173

11731174
/* HTTP Compression */
11741175
{
1175-
FLB_CONFIG_MAP_STR, "compress", NULL,
1176+
FLB_CONFIG_MAP_STR, FLB_ES_CONFIG_PROPERTY_COMPRESS, NULL,
11761177
0, FLB_FALSE, 0,
11771178
"Set payload compression mechanism. Option available is 'gzip'"
11781179
},
11791180

11801181
/* Cloud Authentication */
11811182
{
1182-
FLB_CONFIG_MAP_STR, "cloud_id", NULL,
1183+
FLB_CONFIG_MAP_STR, FLB_ES_CONFIG_PROPERTY_CLOUD_ID, NULL,
11831184
0, FLB_FALSE, 0,
11841185
"Elastic cloud ID of the cluster to connect to"
11851186
},
11861187
{
1187-
FLB_CONFIG_MAP_STR, "cloud_auth", NULL,
1188+
FLB_CONFIG_MAP_STR, FLB_ES_CONFIG_PROPERTY_CLOUD_AUTH, NULL,
11881189
0, FLB_FALSE, 0,
11891190
"Elastic cloud authentication credentials"
11901191
},
11911192

11921193
/* AWS Authentication */
11931194
#ifdef FLB_HAVE_AWS
11941195
{
1195-
FLB_CONFIG_MAP_BOOL, "aws_auth", "false",
1196+
FLB_CONFIG_MAP_BOOL, FLB_ES_CONFIG_PROPERTY_AWS_AUTH, "false",
11961197
0, FLB_TRUE, offsetof(struct flb_elasticsearch_config, has_aws_auth),
11971198
"Enable AWS Sigv4 Authentication"
11981199
},
11991200
{
1200-
FLB_CONFIG_MAP_STR, "aws_region", NULL,
1201+
FLB_CONFIG_MAP_STR, FLB_ES_CONFIG_PROPERTY_AWS_REGION, NULL,
12011202
0, FLB_TRUE, offsetof(struct flb_elasticsearch_config, aws_region),
12021203
"AWS Region of your Amazon OpenSearch Service cluster"
12031204
},
12041205
{
1205-
FLB_CONFIG_MAP_STR, "aws_sts_endpoint", NULL,
1206+
FLB_CONFIG_MAP_STR, FLB_ES_CONFIG_PROPERTY_AWS_STS_ENDPOINT, NULL,
12061207
0, FLB_TRUE, offsetof(struct flb_elasticsearch_config, aws_sts_endpoint),
12071208
"Custom endpoint for the AWS STS API, used with the AWS_Role_ARN option"
12081209
},
12091210
{
1210-
FLB_CONFIG_MAP_STR, "aws_role_arn", NULL,
1211+
FLB_CONFIG_MAP_STR, FLB_ES_CONFIG_PROPERTY_AWS_ROLE_ARN, NULL,
12111212
0, FLB_FALSE, 0,
12121213
"AWS IAM Role to assume to put records to your Amazon OpenSearch cluster"
12131214
},
12141215
{
1215-
FLB_CONFIG_MAP_STR, "aws_external_id", NULL,
1216+
FLB_CONFIG_MAP_STR, FLB_ES_CONFIG_PROPERTY_AWS_EXTERNAL_ID, NULL,
12161217
0, FLB_FALSE, 0,
12171218
"External ID for the AWS IAM Role specified with `aws_role_arn`"
12181219
},
12191220
{
1220-
FLB_CONFIG_MAP_STR, "aws_service_name", "es",
1221+
FLB_CONFIG_MAP_STR, FLB_ES_CONFIG_PROPERTY_AWS_SERVICE_NAME, "es",
12211222
0, FLB_TRUE, offsetof(struct flb_elasticsearch_config, aws_service_name),
12221223
"AWS Service Name"
12231224
},
12241225
{
1225-
FLB_CONFIG_MAP_STR, "aws_profile", NULL,
1226+
FLB_CONFIG_MAP_STR, FLB_ES_CONFIG_PROPERTY_AWS_PROFILE, NULL,
12261227
0, FLB_TRUE, offsetof(struct flb_elasticsearch_config, aws_profile),
12271228
"AWS Profile name. AWS Profiles can be configured with AWS CLI and are usually stored in "
12281229
"$HOME/.aws/ directory."
@@ -1231,68 +1232,68 @@ static struct flb_config_map config_map[] = {
12311232

12321233
/* Logstash compatibility */
12331234
{
1234-
FLB_CONFIG_MAP_BOOL, "logstash_format", "false",
1235+
FLB_CONFIG_MAP_BOOL, FLB_ES_CONFIG_PROPERTY_LOGSTASH_FORMAT, "false",
12351236
0, FLB_TRUE, offsetof(struct flb_elasticsearch_config, logstash_format),
12361237
"Enable Logstash format compatibility"
12371238
},
12381239
{
1239-
FLB_CONFIG_MAP_STR, "logstash_prefix", FLB_ES_DEFAULT_PREFIX,
1240+
FLB_CONFIG_MAP_STR, FLB_ES_CONFIG_PROPERTY_LOGSTASH_PREFIX, FLB_ES_DEFAULT_PREFIX,
12401241
0, FLB_TRUE, offsetof(struct flb_elasticsearch_config, logstash_prefix),
12411242
"When Logstash_Format is enabled, the Index name is composed using a prefix "
12421243
"and the date, e.g: If Logstash_Prefix is equals to 'mydata' your index will "
12431244
"become 'mydata-YYYY.MM.DD'. The last string appended belongs to the date "
12441245
"when the data is being generated"
12451246
},
12461247
{
1247-
FLB_CONFIG_MAP_STR, "logstash_prefix_separator", "-",
1248+
FLB_CONFIG_MAP_STR, FLB_ES_CONFIG_PROPERTY_LOGSTASH_PREFIX_SEPARATOR, "-",
12481249
0, FLB_TRUE, offsetof(struct flb_elasticsearch_config, logstash_prefix_separator),
12491250
"Set a separator between logstash_prefix and date."
12501251
},
12511252
{
1252-
FLB_CONFIG_MAP_STR, "logstash_prefix_key", NULL,
1253+
FLB_CONFIG_MAP_STR, FLB_ES_CONFIG_PROPERTY_LOGSTASH_PREFIX_KEY, NULL,
12531254
0, FLB_TRUE, offsetof(struct flb_elasticsearch_config, logstash_prefix_key),
12541255
"When included: the value in the record that belongs to the key will be looked "
12551256
"up and over-write the Logstash_Prefix for index generation. If the key/value "
12561257
"is not found in the record then the Logstash_Prefix option will act as a "
12571258
"fallback. Nested keys are supported through record accessor pattern"
12581259
},
12591260
{
1260-
FLB_CONFIG_MAP_STR, "logstash_dateformat", FLB_ES_DEFAULT_TIME_FMT,
1261+
FLB_CONFIG_MAP_STR, FLB_ES_CONFIG_PROPERTY_LOGSTASH_DATEFORMAT, FLB_ES_DEFAULT_TIME_FMT,
12611262
0, FLB_TRUE, offsetof(struct flb_elasticsearch_config, logstash_dateformat),
12621263
"Time format (based on strftime) to generate the second part of the Index name"
12631264
},
12641265

12651266
/* Custom Time and Tag keys */
12661267
{
1267-
FLB_CONFIG_MAP_STR, "time_key", FLB_ES_DEFAULT_TIME_KEY,
1268+
FLB_CONFIG_MAP_STR, FLB_ES_CONFIG_PROPERTY_TIME_KEY, FLB_ES_DEFAULT_TIME_KEY,
12681269
0, FLB_TRUE, offsetof(struct flb_elasticsearch_config, time_key),
12691270
"When Logstash_Format is enabled, each record will get a new timestamp field. "
12701271
"The Time_Key property defines the name of that field"
12711272
},
12721273
{
1273-
FLB_CONFIG_MAP_STR, "time_key_format", FLB_ES_DEFAULT_TIME_KEYF,
1274+
FLB_CONFIG_MAP_STR, FLB_ES_CONFIG_PROPERTY_TIME_KEY_FORMAT, FLB_ES_DEFAULT_TIME_KEYF,
12741275
0, FLB_TRUE, offsetof(struct flb_elasticsearch_config, time_key_format),
12751276
"When Logstash_Format is enabled, this property defines the format of the "
12761277
"timestamp"
12771278
},
12781279
{
1279-
FLB_CONFIG_MAP_BOOL, "time_key_nanos", "false",
1280+
FLB_CONFIG_MAP_BOOL, FLB_ES_CONFIG_PROPERTY_TIME_KEY_NANOS, "false",
12801281
0, FLB_TRUE, offsetof(struct flb_elasticsearch_config, time_key_nanos),
12811282
"When Logstash_Format is enabled, enabling this property sends nanosecond "
12821283
"precision timestamps"
12831284
},
12841285
{
1285-
FLB_CONFIG_MAP_BOOL, "include_tag_key", "false",
1286+
FLB_CONFIG_MAP_BOOL, FLB_ES_CONFIG_PROPERTY_INCLUDE_TAG_KEY, "false",
12861287
0, FLB_TRUE, offsetof(struct flb_elasticsearch_config, include_tag_key),
12871288
"When enabled, it append the Tag name to the record"
12881289
},
12891290
{
1290-
FLB_CONFIG_MAP_STR, "tag_key", FLB_ES_DEFAULT_TAG_KEY,
1291+
FLB_CONFIG_MAP_STR, FLB_ES_CONFIG_PROPERTY_TAG_KEY, FLB_ES_DEFAULT_TAG_KEY,
12911292
0, FLB_TRUE, offsetof(struct flb_elasticsearch_config, tag_key),
12921293
"When Include_Tag_Key is enabled, this property defines the key name for the tag"
12931294
},
12941295
{
1295-
FLB_CONFIG_MAP_SIZE, "buffer_size", FLB_ES_DEFAULT_HTTP_MAX,
1296+
FLB_CONFIG_MAP_SIZE, FLB_ES_CONFIG_PROPERTY_BUFFER_SIZE, FLB_ES_DEFAULT_HTTP_MAX,
12961297
0, FLB_TRUE, offsetof(struct flb_elasticsearch_config, buffer_size),
12971298
"Specify the buffer size used to read the response from the Elasticsearch HTTP "
12981299
"service. This option is useful for debugging purposes where is required to read "
@@ -1303,64 +1304,64 @@ static struct flb_config_map config_map[] = {
13031304

13041305
/* Elasticsearch specifics */
13051306
{
1306-
FLB_CONFIG_MAP_STR, "path", NULL,
1307+
FLB_CONFIG_MAP_STR, FLB_ES_CONFIG_PROPERTY_PATH, NULL,
13071308
0, FLB_FALSE, 0,
13081309
"Elasticsearch accepts new data on HTTP query path '/_bulk'. But it is also "
13091310
"possible to serve Elasticsearch behind a reverse proxy on a subpath. This "
13101311
"option defines such path on the fluent-bit side. It simply adds a path "
13111312
"prefix in the indexing HTTP POST URI"
13121313
},
13131314
{
1314-
FLB_CONFIG_MAP_STR, "pipeline", NULL,
1315+
FLB_CONFIG_MAP_STR, FLB_ES_CONFIG_PROPERTY_PIPELINE, NULL,
13151316
0, FLB_FALSE, 0,
13161317
"Newer versions of Elasticsearch allows to setup filters called pipelines. "
13171318
"This option allows to define which pipeline the database should use. For "
13181319
"performance reasons is strongly suggested to do parsing and filtering on "
13191320
"Fluent Bit side, avoid pipelines"
13201321
},
13211322
{
1322-
FLB_CONFIG_MAP_BOOL, "generate_id", "false",
1323+
FLB_CONFIG_MAP_BOOL, FLB_ES_CONFIG_PROPERTY_GENERATE_ID, "false",
13231324
0, FLB_TRUE, offsetof(struct flb_elasticsearch_config, generate_id),
13241325
"When enabled, generate _id for outgoing records. This prevents duplicate "
13251326
"records when retrying ES"
13261327
},
13271328
{
1328-
FLB_CONFIG_MAP_STR, "write_operation", "create",
1329+
FLB_CONFIG_MAP_STR, FLB_ES_CONFIG_PROPERTY_WRITE_OPERATION, "create",
13291330
0, FLB_TRUE, offsetof(struct flb_elasticsearch_config, write_operation),
13301331
"Operation to use to write in bulk requests"
13311332
},
13321333
{
1333-
FLB_CONFIG_MAP_STR, "id_key", NULL,
1334+
FLB_CONFIG_MAP_STR, FLB_ES_CONFIG_PROPERTY_ID_KEY, NULL,
13341335
0, FLB_TRUE, offsetof(struct flb_elasticsearch_config, id_key),
13351336
"If set, _id will be the value of the key from incoming record."
13361337
},
13371338
{
1338-
FLB_CONFIG_MAP_BOOL, "replace_dots", "false",
1339+
FLB_CONFIG_MAP_BOOL, FLB_ES_CONFIG_PROPERTY_REPLACE_DOTS, "false",
13391340
0, FLB_TRUE, offsetof(struct flb_elasticsearch_config, replace_dots),
13401341
"When enabled, replace field name dots with underscore, required by Elasticsearch "
13411342
"2.0-2.3."
13421343
},
13431344

13441345
{
1345-
FLB_CONFIG_MAP_BOOL, "current_time_index", "false",
1346+
FLB_CONFIG_MAP_BOOL, FLB_ES_CONFIG_PROPERTY_CURRENT_TIME_INDEX, "false",
13461347
0, FLB_TRUE, offsetof(struct flb_elasticsearch_config, current_time_index),
13471348
"Use current time for index generation instead of message record"
13481349
},
13491350

13501351
/* Trace */
13511352
{
1352-
FLB_CONFIG_MAP_BOOL, "trace_output", "false",
1353+
FLB_CONFIG_MAP_BOOL, FLB_ES_CONFIG_PROPERTY_TRACE_OUTPUT, "false",
13531354
0, FLB_TRUE, offsetof(struct flb_elasticsearch_config, trace_output),
13541355
"When enabled print the Elasticsearch API calls to stdout (for diag only)"
13551356
},
13561357
{
1357-
FLB_CONFIG_MAP_BOOL, "trace_error", "false",
1358+
FLB_CONFIG_MAP_BOOL, FLB_ES_CONFIG_PROPERTY_TRACE_ERROR, "false",
13581359
0, FLB_TRUE, offsetof(struct flb_elasticsearch_config, trace_error),
13591360
"When enabled print the Elasticsearch exception to stderr (for diag only)"
13601361
},
13611362

13621363
{
1363-
FLB_CONFIG_MAP_STR, "upstream", NULL,
1364+
FLB_CONFIG_MAP_STR, FLB_ES_CONFIG_PROPERTY_UPSTREAM, NULL,
13641365
0, FLB_FALSE, 0,
13651366
"Path to 'upstream' configuration file (define multiple nodes)"
13661367
},

plugins/out_es/es.h

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@
3434
#define FLB_ES_DEFAULT_TAG_KEY "flb-key"
3535
#define FLB_ES_DEFAULT_HTTP_MAX "512k"
3636
#define FLB_ES_DEFAULT_HTTPS_PORT 443
37-
#define FLB_ES_WRITE_OP_INDEX "index"
38-
#define FLB_ES_WRITE_OP_CREATE "create"
39-
#define FLB_ES_WRITE_OP_UPDATE "update"
40-
#define FLB_ES_WRITE_OP_UPSERT "upsert"
4137

4238
#define FLB_ES_STATUS_SUCCESS (1 << 0)
4339
#define FLB_ES_STATUS_IMCOMPLETE (1 << 1)
@@ -63,7 +59,9 @@ struct flb_elasticsearch_config {
6359

6460
/* Elastic Cloud Auth */
6561
char *cloud_user;
62+
int own_cloud_user;
6663
char *cloud_passwd;
64+
int own_cloud_passwd;
6765

6866
/* AWS Auth */
6967
#ifdef FLB_HAVE_AWS
@@ -72,12 +70,17 @@ struct flb_elasticsearch_config {
7270
char *aws_sts_endpoint;
7371
char *aws_profile;
7472
struct flb_aws_provider *aws_provider;
73+
int own_aws_provider;
7574
struct flb_aws_provider *base_aws_provider;
75+
int own_base_aws_provider;
7676
/* tls instances can't be re-used; aws provider requires a separate one */
7777
struct flb_tls *aws_tls;
78+
int own_aws_tls;
7879
struct flb_tls *aws_sts_tls;
80+
int own_aws_sts_tls;
7981
char *aws_service_name;
8082
struct mk_list *aws_unsigned_headers;
83+
int own_aws_unsigned_headers;
8184
#endif
8285

8386
/* HTTP Client Setup */
@@ -104,40 +107,51 @@ struct flb_elasticsearch_config {
104107

105108
/* prefix */
106109
flb_sds_t logstash_prefix;
110+
int own_logstash_prefix;
107111
flb_sds_t logstash_prefix_separator;
112+
int own_logstash_prefix_separator;
108113

109114
/* prefix key */
110115
flb_sds_t logstash_prefix_key;
116+
int own_logstash_prefix_key;
111117

112118
/* date format */
113119
flb_sds_t logstash_dateformat;
120+
int own_logstash_dateformat;
114121

115122
/* time key */
116123
flb_sds_t time_key;
124+
int own_time_key;
117125

118126
/* time key format */
119127
flb_sds_t time_key_format;
128+
int own_time_key_format;
120129

121130
/* time key nanoseconds */
122131
int time_key_nanos;
123132

124133
/* write operation */
125134
flb_sds_t write_operation;
135+
int own_write_operation;
126136
/* write operation elasticsearch operation */
127-
flb_sds_t es_action;
137+
const char *es_action;
128138

129139
/* id_key */
130140
flb_sds_t id_key;
141+
int own_id_key;
131142
struct flb_record_accessor *ra_id_key;
143+
int own_ra_id_key;
132144

133145
/* include_tag_key */
134146
int include_tag_key;
135147
flb_sds_t tag_key;
148+
int own_tag_key;
136149

137150
/* Elasticsearch HTTP API */
138151
char uri[256];
139152

140153
struct flb_record_accessor *ra_prefix_key;
154+
int own_ra_prefix_key;
141155

142156
/* Compression mode (gzip) */
143157
int compress_gzip;

0 commit comments

Comments
 (0)