fluent-plugin-input-opensearch 1.1.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +7 -0
  2. data/.coveralls.yml +1 -0
  3. data/.editorconfig +9 -0
  4. data/.github/ISSUE_TEMPLATE/bug_report.md +29 -0
  5. data/.github/ISSUE_TEMPLATE/feature_request.md +24 -0
  6. data/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md +9 -0
  7. data/.github/workflows/coverage.yaml +22 -0
  8. data/.github/workflows/issue-auto-closer.yml +12 -0
  9. data/.github/workflows/linux.yml +26 -0
  10. data/.github/workflows/macos.yml +26 -0
  11. data/.github/workflows/windows.yml +26 -0
  12. data/.gitignore +18 -0
  13. data/CONTRIBUTING.md +24 -0
  14. data/Gemfile +10 -0
  15. data/History.md +67 -0
  16. data/LICENSE.txt +201 -0
  17. data/README.OpenSearchGenID.md +116 -0
  18. data/README.OpenSearchInput.md +314 -0
  19. data/README.Troubleshooting.md +482 -0
  20. data/README.md +1622 -0
  21. data/Rakefile +37 -0
  22. data/fluent-plugin-opensearch.gemspec +39 -0
  23. data/gemfiles/Gemfile.elasticsearch.v6 +12 -0
  24. data/lib/fluent/log-ext.rb +64 -0
  25. data/lib/fluent/plugin/filter_opensearch_genid.rb +103 -0
  26. data/lib/fluent/plugin/in_opensearch.rb +410 -0
  27. data/lib/fluent/plugin/oj_serializer.rb +48 -0
  28. data/lib/fluent/plugin/opensearch_constants.rb +39 -0
  29. data/lib/fluent/plugin/opensearch_error.rb +31 -0
  30. data/lib/fluent/plugin/opensearch_error_handler.rb +182 -0
  31. data/lib/fluent/plugin/opensearch_fallback_selector.rb +36 -0
  32. data/lib/fluent/plugin/opensearch_index_template.rb +155 -0
  33. data/lib/fluent/plugin/opensearch_simple_sniffer.rb +36 -0
  34. data/lib/fluent/plugin/opensearch_tls.rb +96 -0
  35. data/lib/fluent/plugin/out_opensearch.rb +1158 -0
  36. data/lib/fluent/plugin/out_opensearch_data_stream.rb +229 -0
  37. data/test/helper.rb +60 -0
  38. data/test/plugin/datastream_template.json +4 -0
  39. data/test/plugin/test_alias_template.json +9 -0
  40. data/test/plugin/test_filter_opensearch_genid.rb +241 -0
  41. data/test/plugin/test_in_opensearch.rb +500 -0
  42. data/test/plugin/test_index_alias_template.json +11 -0
  43. data/test/plugin/test_index_template.json +25 -0
  44. data/test/plugin/test_oj_serializer.rb +45 -0
  45. data/test/plugin/test_opensearch_error_handler.rb +770 -0
  46. data/test/plugin/test_opensearch_fallback_selector.rb +100 -0
  47. data/test/plugin/test_opensearch_tls.rb +171 -0
  48. data/test/plugin/test_out_opensearch.rb +3980 -0
  49. data/test/plugin/test_out_opensearch_data_stream.rb +746 -0
  50. data/test/plugin/test_template.json +23 -0
  51. data/test/test_log-ext.rb +61 -0
  52. metadata +291 -0
data/README.md ADDED
@@ -0,0 +1,1622 @@
1
+ # Fluent::Plugin::OpenSearch, a plugin for [Fluentd](http://fluentd.org)
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/fluent-plugin-opensearch.png)](http://badge.fury.io/rb/fluent-plugin-opensearch)
4
+ ![Testing on Windows](https://github.com/fluent/fluent-plugin-opensearch/workflows/Testing%20on%20Windows/badge.svg?branch=main)
5
+ ![Testing on macOS](https://github.com/fluent/fluent-plugin-opensearch/workflows/Testing%20on%20macOS/badge.svg?branch=main)
6
+ ![Testing on Ubuntu](https://github.com/fluent/fluent-plugin-opensearch/workflows/Testing%20on%20Ubuntu/badge.svg?branch=main)
7
+ [![Coverage Status](https://coveralls.io/repos/github/fluent/fluent-plugin-opensearch/badge.svg?branch=upload-coverage-into-coveralls)](https://coveralls.io/github/fluent/fluent-plugin-opensearch?branch=main)
8
+
9
+ Send your logs to OpenSearch (and search them with OpenSearch Dashboards maybe?)
10
+
11
+ * [Installation](#installation)
12
+ * [Usage](#usage)
13
+ + [Index templates](#index-templates)
14
+ * [Configuration](#configuration)
15
+ + [host](#host)
16
+ + [port](#port)
17
+ + [emit_error_for_missing_id](#emit_error_for_missing_id)
18
+ + [hosts](#hosts)
19
+ + [user, password, path, scheme, ssl_verify](#user-password-path-scheme-ssl_verify)
20
+ + [logstash_format](#logstash_format)
21
+ + [logstash_prefix](#logstash_prefix)
22
+ + [logstash_prefix_separator](#logstash_prefix_separator)
23
+ + [logstash_dateformat](#logstash_dateformat)
24
+ + [pipeline](#pipeline)
25
+ + [time_key_format](#time_key_format)
26
+ + [time_precision](#time_precision)
27
+ + [time_key](#time_key)
28
+ + [time_key_exclude_timestamp](#time_key_exclude_timestamp)
29
+ + [include_timestamp](#include_timestamp)
30
+ + [utc_index](#utc_index)
31
+ + [suppress_type_name](#suppress_type_name)
32
+ + [target_index_key](#target_index_key)
33
+ + [target_type_key](#target_type_key)
34
+ + [target_index_affinity](#target_index_affinity)
35
+ + [template_name](#template_name)
36
+ + [template_file](#template_file)
37
+ + [template_overwrite](#template_overwrite)
38
+ + [customize_template](#customize_template)
39
+ + [index_date_pattern](#index_date_pattern)
40
+ + [application_name](#application_name)
41
+ + [index_prefix](#index_prefix)
42
+ + [templates](#templates)
43
+ + [max_retry_putting_template](#max_retry_putting_template)
44
+ + [fail_on_putting_template_retry_exceed](#fail_on_putting_template_retry_exceed)
45
+ + [fail_on_detecting_os_version_retry_exceed](#fail_on_detecting_os_version_retry_exceed)
46
+ + [max_retry_get_os_version](#max_retry_get_os_version)
47
+ + [request_timeout](#request_timeout)
48
+ + [reload_connections](#reload_connections)
49
+ + [reload_on_failure](#reload_on_failure)
50
+ + [resurrect_after](#resurrect_after)
51
+ + [include_tag_key, tag_key](#include_tag_key-tag_key)
52
+ + [id_key](#id_key)
53
+ + [parent_key](#parent_key)
54
+ + [routing_key](#routing_key)
55
+ + [remove_keys](#remove_keys)
56
+ + [remove_keys_on_update](#remove_keys_on_update)
57
+ + [remove_keys_on_update_key](#remove_keys_on_update_key)
58
+ + [retry_tag](#retry_tag)
59
+ + [write_operation](#write_operation)
60
+ + [time_parse_error_tag](#time_parse_error_tag)
61
+ + [reconnect_on_error](#reconnect_on_error)
62
+ + [with_transporter_log](#with_transporter_log)
63
+ + [content_type](#content_type)
64
+ + [include_index_in_url](#include_index_in_url)
65
+ + [http_backend](#http_backend)
66
+ + [http_backend_excon_nonblock](#http_backend_excon_nonblock)
67
+ + [prefer_oj_serializer](#prefer_oj_serializer)
68
+ + [compression_level](#compression_level)
69
+ + [Client/host certificate options](#clienthost-certificate-options)
70
+ + [Proxy Support](#proxy-support)
71
+ + [Buffer options](#buffer-options)
72
+ + [Hash flattening](#hash-flattening)
73
+ + [Generate Hash ID](#generate-hash-id)
74
+ + [sniffer_class_name](#sniffer-class-name)
75
+ + [selector_class_name](#selector-class-name)
76
+ + [reload_after](#reload-after)
77
+ + [validate_client_version](#validate-client-version)
78
+ + [unrecoverable_error_types](#unrecoverable-error-types)
79
+ + [unrecoverable_record_types](#unrecoverable-record-types)
80
+ + [emit_error_label_event](#emit-error-label-event)
81
+ + [verify os version at startup](#verify_os_version_at_startup)
82
+ + [default_opensearch_version](#default_opensearch_version)
83
+ + [custom_headers](#custom_headers)
84
+ + [api_key](#api_key)
85
+ + [Not seeing a config you need?](#not-seeing-a-config-you-need)
86
+ + [Dynamic configuration](#dynamic-configuration)
87
+ + [Placeholders](#placeholders)
88
+ + [Multi workers](#multi-workers)
89
+ + [log_os_400_reason](#log_os_400_reason)
90
+ + [suppress_doc_wrap](#suppress_doc_wrap)
91
+ + [ignore_exceptions](#ignore_exceptions)
92
+ + [exception_backup](#exception_backup)
93
+ + [bulk_message_request_threshold](#bulk_message_request_threshold)
94
+ + [truncate_caches_interval](#truncate_caches_interval)
95
+ + [use_legacy_template](#use_legacy_template)
96
+ + [metadata section](#metadata-section)
97
+ + [include_chunk_id](#include_chunk_id)
98
+ + [chunk_id_key](#chunk_id_key)
99
+ * [Configuration - OpenSearch Input](#configuration---opensearch-input)
100
+ * [Configuration - OpenSearch Filter GenID](#configuration---opensearch-filter-genid)
101
+ * [Configuration - OpenSearch Output Data Stream](#configuration---opensearch-output-data-stream)
102
+ * [Configuration - AWS OpenSearch Service](#configuration---aws-opensearch-service)
103
+ * [Troubleshooting](#troubleshooting)
104
+ * [Contact](#contact)
105
+ * [Contributing](#contributing)
106
+ * [Running tests](#running-tests)
107
+
108
+ ## Requirements
109
+
110
+ | fluent-plugin-opensearch | fluentd | ruby |
111
+ |:----------------------------:|:-----------:|:------:|
112
+ | >= 1.0.0 | >= v1.x | >= 2.4 |
113
+
114
+ NOTE: Since fluent-plugin-opensearch 1.1.0, it requires faraday 2.0 or later.
115
+
116
+ NOTE: This documentation is for fluent-plugin-opensearch 1.x or later.
117
+
118
+ ## Installation
119
+
120
+ ```sh
121
+ $ gem install fluent-plugin-opensearch
122
+ ```
123
+
124
+ ## Usage
125
+
126
+ In your Fluentd configuration, use `@type opensearch`. Additional configuration is optional, default values would look like this:
127
+
128
+ ```
129
+ <match my.logs>
130
+ @type opensearch
131
+ host localhost
132
+ port 9200
133
+ index_name fluentd
134
+ </match>
135
+ ```
136
+
137
+ NOTE: `type_name` parameter is fixed value and cannot change and configure from `_doc` value for OpenSearch 1.
138
+
139
+ ### Index templates
140
+
141
+ This plugin creates OpenSearch indices by merely writing to them. Consider using [Index Templates](https://opensearch.org/docs/latest/opensearch/index-templates/) to gain control of what get indexed and how.
142
+
143
+ ## Configuration
144
+
145
+ ### host
146
+
147
+ ```
148
+ host user-custom-host.domain # default localhost
149
+ ```
150
+
151
+ You can specify OpenSearch host by this parameter.
152
+
153
+ To use IPv6 address on `host` parameter, you can use the following styles:
154
+
155
+ #### string style
156
+
157
+ To use string style, you must quote IPv6 address due to prevent to be interpreted as JSON:
158
+
159
+ ```
160
+ host "[2404:7a80:d440:3000:192a:a292:bd7f:ca10]"
161
+ ```
162
+
163
+ #### raw style
164
+
165
+ You can also specify raw IPv6 address. This will be handled as `[specified IPv6 address]`:
166
+
167
+ ```
168
+ host 2404:7a80:d440:3000:192a:a292:bd7f:ca10
169
+ ```
170
+
171
+ ### port
172
+
173
+ ```
174
+ port 9201 # defaults to 9200
175
+ ```
176
+
177
+ You can specify OpenSearch port by this parameter.
178
+
179
+ ### emit_error_for_missing_id
180
+
181
+ ```
182
+ emit_error_for_missing_id true
183
+ ```
184
+ When `write_operation` is configured to anything other then `index`, setting this value to `true` will
185
+ cause the plugin to `emit_error_event` of any records which do not include an `_id` field. The default (`false`)
186
+ behavior is to silently drop the records.
187
+
188
+ ### hosts
189
+
190
+ ```
191
+ hosts host1:port1,host2:port2,host3:port3
192
+ ```
193
+
194
+ You can specify multiple OpenSearch hosts with separator ",".
195
+
196
+ If you specify multiple hosts, this plugin will load balance updates to OpenSearch. This is an [opensearch-ruby](https://github.com/opensearch-project/opensearch-ruby) feature, the default strategy is round-robin.
197
+
198
+ If you specify `hosts` option, `host` and `port` options are ignored.
199
+
200
+ ```
201
+ host user-custom-host.domain # ignored
202
+ port 9200 # ignored
203
+ hosts host1:port1,host2:port2,host3:port3
204
+ ```
205
+
206
+ If you specify `hosts` option without port, `port` option is used.
207
+
208
+ ```
209
+ port 9200
210
+ hosts host1:port1,host2:port2,host3 # port3 is 9200
211
+ ```
212
+
213
+ **Note:** If you will use scheme https, do not include "https://" in your hosts ie. host "https://domain", this will cause ES cluster to be unreachable and you will receive an error "Can not reach OpenSearch cluster"
214
+
215
+ **Note:** Embedded the username/password in the URL syntax is not recommended to use because it was found to cause serious connection problems. Please do not use its style on your settings and use the `user` and `password` field (described below) instead.
216
+
217
+ #### IPv6 addresses
218
+
219
+ When you want to specify IPv6 addresses, you must specify schema together:
220
+
221
+ ```
222
+ hosts http://[2404:7a80:d440:3000:de:7311:6329:2e6c]:port1,http://[2404:7a80:d440:3000:de:7311:6329:1e6c]:port2,http://[2404:7a80:d440:3000:de:6311:6329:2e6c]:port3
223
+ ```
224
+
225
+ If you don't specify hosts with schema together, OpenSearch plugin complains Invalid URI for them.
226
+
227
+ ### user, password, path, scheme, ssl_verify
228
+
229
+ ```
230
+ user demo
231
+ password secret
232
+ path /elastic_search/
233
+ scheme https
234
+ ```
235
+
236
+ You can specify user and password for HTTP Basic authentication.
237
+
238
+ And this plugin will escape required URL encoded characters within `%{}` placeholders.
239
+
240
+ ```
241
+ user %{demo+}
242
+ password %{@secret}
243
+ ```
244
+
245
+ Specify `ssl_verify false` to skip ssl verification (defaults to true)
246
+
247
+ ### logstash_format
248
+
249
+ ```
250
+ logstash_format true # defaults to false
251
+ ```
252
+
253
+ This is meant to make writing data into OpenSearch indices compatible to what [Logstash](https://www.elastic.co/products/logstash) calls them. By doing this, one could take advantage of [Kibana](https://www.elastic.co/products/kibana). See logstash\_prefix and logstash\_dateformat to customize this index name pattern. The index name will be `#{logstash_prefix}-#{formatted_date}`
254
+
255
+ :warning: Setting this option to `true` will ignore the `index_name` setting. The default index name prefix is `logstash-`.
256
+
257
+ ### include_timestamp
258
+
259
+ ```
260
+ include_timestamp true # defaults to false
261
+ ```
262
+
263
+ Adds a `@timestamp` field to the log, following all settings `logstash_format` does, except without the restrictions on `index_name`. This allows one to log to an alias in OpenSearch and utilize the rollover API.
264
+
265
+ ### logstash_prefix
266
+
267
+ ```
268
+ logstash_prefix mylogs # defaults to "logstash"
269
+ ```
270
+
271
+ ### logstash_prefix_separator
272
+
273
+ ```
274
+ logstash_prefix_separator _ # defaults to "-"
275
+ ```
276
+
277
+ ### logstash_dateformat
278
+
279
+ The strftime format to generate index target index name when `logstash_format` is set to true. By default, the records are inserted into index `logstash-YYYY.MM.DD`. This option, alongwith `logstash_prefix` lets us insert into specified index like `mylogs-YYYYMM` for a monthly index.
280
+
281
+ ```
282
+ logstash_dateformat %Y.%m. # defaults to "%Y.%m.%d"
283
+ ```
284
+
285
+ ### pipeline
286
+
287
+ This param is to set a pipeline id of your opensearch to be added into the request, you can configure ingest node.
288
+
289
+ ```
290
+ pipeline pipeline_id
291
+ ```
292
+
293
+ ### time_key_format
294
+
295
+ The format of the time stamp field (`@timestamp` or what you specify with [time_key](#time_key)). This parameter only has an effect when [logstash_format](#logstash_format) is true as it only affects the name of the index we write to. Please see [Time#strftime](http://ruby-doc.org/core-1.9.3/Time.html#method-i-strftime) for information about the value of this format.
296
+
297
+ Setting this to a known format can vastly improve your log ingestion speed if all most of your logs are in the same format. If there is an error parsing this format the timestamp will default to the ingestion time. You can get a further performance improvement by installing the "strptime" gem: `fluent-gem install strptime`.
298
+
299
+ For example to parse ISO8601 times with sub-second precision:
300
+
301
+ ```
302
+ time_key_format %Y-%m-%dT%H:%M:%S.%N%z
303
+ ```
304
+
305
+ ### time_precision
306
+
307
+ Should the record not include a `time_key`, define the degree of sub-second time precision to preserve from the `time` portion of the routed event.
308
+
309
+ For example, should your input plugin not include a `time_key` in the record but it able to pass a `time` to the router when emitting the event (AWS CloudWatch events are an example of this), then this setting will allow you to preserve the sub-second time resolution of those events. This is the case for: [fluent-plugin-cloudwatch-ingest](https://github.com/sampointer/fluent-plugin-cloudwatch-ingest).
310
+
311
+ ### time_key
312
+
313
+ By default, when inserting records in [Logstash](https://www.elastic.co/products/logstash) format, `@timestamp` is dynamically created with the time at log ingestion. If you'd like to use a custom time, include an `@timestamp` with your record.
314
+
315
+ ```
316
+ {"@timestamp": "2014-04-07T000:00:00-00:00"}
317
+ ```
318
+
319
+ You can specify an option `time_key` (like the option described in [tail Input Plugin](http://docs.fluentd.org/articles/in_tail)) to replace `@timestamp` key.
320
+
321
+ Suppose you have settings
322
+
323
+ ```
324
+ logstash_format true
325
+ time_key vtm
326
+ ```
327
+
328
+ Your input is:
329
+ ```
330
+ {
331
+ "title": "developer",
332
+ "vtm": "2014-12-19T08:01:03Z"
333
+ }
334
+ ```
335
+
336
+ The output will be
337
+ ```
338
+ {
339
+ "title": "developer",
340
+ "@timestamp": "2014-12-19T08:01:03Z",
341
+ "vtm": "2014-12-19T08:01:03Z"
342
+ }
343
+ ```
344
+
345
+ See `time_key_exclude_timestamp` to avoid adding `@timestamp`.
346
+
347
+ ### time_key_exclude_timestamp
348
+
349
+ ```
350
+ time_key_exclude_timestamp false
351
+ ```
352
+
353
+ By default, setting `time_key` will copy the value to an additional field `@timestamp`. When setting `time_key_exclude_timestamp true`, no additional field will be added.
354
+
355
+ ### utc_index
356
+
357
+ ```
358
+ utc_index true
359
+ ```
360
+
361
+ By default, the records inserted into index `logstash-YYMMDD` with UTC (Coordinated Universal Time). This option allows to use local time if you describe utc_index to false.
362
+
363
+
364
+ ### suppress_type_name
365
+
366
+ If OpenSearch cluster complains types removal warnings, this can be suppressed with:
367
+
368
+ ```
369
+ suppress_type_name true
370
+ ```
371
+
372
+ ### target_index_key
373
+
374
+ Tell this plugin to find the index name to write to in the record under this key in preference to other mechanisms. Key can be specified as path to nested record using dot ('.') as a separator.
375
+
376
+ If it is present in the record (and the value is non falsy) the value will be used as the index name to write to and then removed from the record before output; if it is not found then it will use logstash_format or index_name settings as configured.
377
+
378
+ Suppose you have the following settings
379
+
380
+ ```
381
+ target_index_key @target_index
382
+ index_name fallback
383
+ ```
384
+
385
+ If your input is:
386
+ ```
387
+ {
388
+ "title": "developer",
389
+ "@timestamp": "2014-12-19T08:01:03Z",
390
+ "@target_index": "logstash-2014.12.19"
391
+ }
392
+ ```
393
+
394
+ The output would be
395
+
396
+ ```
397
+ {
398
+ "title": "developer",
399
+ "@timestamp": "2014-12-19T08:01:03Z",
400
+ }
401
+ ```
402
+
403
+ and this record will be written to the specified index (`logstash-2014.12.19`) rather than `fallback`.
404
+
405
+ ### target_type_key
406
+
407
+ Similar to `target_index_key` config, find the type name to write to in the record under this key (or nested record). If key not found in record - fallback to `type_name` (default "fluentd").
408
+
409
+ ### target_index_affinity
410
+
411
+ Enable plugin to dynamically select logstash time based target index in update/upsert operations based on already indexed data rather than current time of indexing.
412
+
413
+ ```
414
+ target_index_affinity true # defaults to false
415
+ ```
416
+
417
+ By default plugin writes data of logstash format index based on current time. For example daily based index after mignight data is written to newly created index. This is normally ok when data is coming from single source and not updated after indexing.
418
+
419
+ But if you have a use case where data is also updated after indexing and `id_key` is used to identify the document uniquely for updating. Logstash format is wanted to be used for easy data managing and retention. Updates are done right after indexing to complete the data (all data not available from single source) and no updates are done anymore later point on time. In this case problem happends at index rotation time where write to 2 indexes with same id_key value may happen.
420
+
421
+ This setting will search existing data by using elastic search's [id query](https://www.elastic.co/guide/en/opensearch/reference/current/query-dsl-ids-query.html) using `id_key` value (with logstash_prefix and logstash_prefix_separator index pattarn e.g. `logstash-*`). The index of found data is used for update/upsert. When no data is found, data is written to current logstash index as normally.
422
+
423
+ This setting requires following other settings:
424
+ ```
425
+ logstash_format true
426
+ id_key myId # Some field on your data to identify the data uniquely
427
+ write_operation upsert # upsert or update
428
+ ```
429
+
430
+ Suppose you have the following situation where you have 2 different match to consume data from 2 different Kafka topics independently but close in time with each other (order not known).
431
+
432
+ ```
433
+ <match data1>
434
+ @type opensearch
435
+ ...
436
+ id_key myId
437
+ write_operation upsert
438
+ logstash_format true
439
+ logstash_dateformat %Y.%m.%d
440
+ logstash_prefix myindexprefix
441
+ target_index_affinity true
442
+ ...
443
+
444
+ <match data2>
445
+ @type opensearch
446
+ ...
447
+ id_key myId
448
+ write_operation upsert
449
+ logstash_format true
450
+ logstash_dateformat %Y.%m.%d
451
+ logstash_prefix myindexprefix
452
+ target_index_affinity true
453
+ ...
454
+ ```
455
+
456
+ If your first (data1) input is:
457
+ ```
458
+ {
459
+ "myId": "myuniqueId1",
460
+ "datafield1": "some value",
461
+ }
462
+ ```
463
+
464
+ and your second (data2) input is:
465
+ ```
466
+ {
467
+ "myId": "myuniqueId1",
468
+ "datafield99": "some important data from other source tightly related to id myuniqueId1 and wanted to be in same document.",
469
+ }
470
+ ```
471
+
472
+ Date today is 10.05.2021 so data is written to index `myindexprefix-2021.05.10` when both data1 and data2 is consumed during today.
473
+ But when we are close to index rotation and data1 is consumed and indexed at `2021-05-10T23:59:55.59707672Z` and data2
474
+ is consumed a bit later at `2021-05-11T00:00:58.222079Z` i.e. logstash index has been rotated and normally data2 would have been written
475
+ to index `myindexprefix-2021.05.11`. But with target_index_affinity setting as value true, data2 is now written to index `myindexprefix-2021.05.10`
476
+ into same document with data1 as wanted and duplicated document is avoided.
477
+
478
+ ### template_name
479
+
480
+ The name of the template to define. If a template by the name given is already present, it will be left unchanged, unless [template_overwrite](#template_overwrite) is set, in which case the template will be updated.
481
+
482
+ This parameter along with template_file allow the plugin to behave similarly to Logstash (it installs a template at creation time) so that raw records are available. See [https://github.com/uken/fluent-plugin-elasticsearch/issues/33](https://github.com/uken/fluent-plugin-elasticsearch/issues/33).
483
+
484
+ [template_file](#template_file) must also be specified.
485
+
486
+ ### template_file
487
+
488
+ The path to the file containing the template to install.
489
+
490
+ [template_name](#template_name) must also be specified.
491
+
492
+ ### templates
493
+
494
+ Specify index templates in form of hash. Can contain multiple templates.
495
+
496
+ ```
497
+ templates { "template_name_1": "path_to_template_1_file", "template_name_2": "path_to_template_2_file"}
498
+ ```
499
+
500
+ **Note:** Before ES plugin v4.1.2, if `template_file` and `template_name` are set, then this parameter will be ignored. In 4.1.3 or later, `template_file` and `template_name` can work with `templates`.
501
+
502
+ ### customize_template
503
+
504
+ Specify the string and its value to be replaced in form of hash. Can contain multiple key value pair that would be replaced in the specified template_file.
505
+
506
+ ```
507
+ customize_template {"string_1": "subs_value_1", "string_2": "subs_value_2"}
508
+ ```
509
+
510
+ If [template_file](#template_file) and [template_name](#template_name) are set, then this parameter will be in effect otherwise ignored.
511
+
512
+ ### index_date_pattern
513
+
514
+ Specify this to override the index date pattern for creating a rollover index. The default is to use "now/d",
515
+ for example: <logstash-default-{now/d}-000001>. Overriding this changes the rollover time period. Setting
516
+ "now/w{xxxx.ww}" would create weekly rollover indexes instead of daily.
517
+
518
+ ```
519
+ index_date_pattern "now/w{xxxx.ww}" # defaults to "now/d"
520
+ ```
521
+
522
+ If empty string(`""`) is specified in `index_date_pattern`, index date pattern is not used.
523
+ OpenSearch plugin just creates <`target_index`-`application_name`-000001> rollover index instead of <`target_index`-`application_name`-`{index_date_pattern}`-000001>.
524
+
525
+ If [customize_template](#customize_template) is set, then this parameter will be in effect otherwise ignored.
526
+
527
+ ### index_prefix
528
+
529
+ This parameter is marked as obsoleted.
530
+
531
+ ### application_name
532
+
533
+ Specify the application name for the rollover index to be created.
534
+ ```
535
+ application_name default # defaults to "default"
536
+ ```
537
+
538
+ ### template_overwrite
539
+
540
+ Always update the template, even if it already exists.
541
+
542
+ ```
543
+ template_overwrite true # defaults to false
544
+ ```
545
+
546
+ One of [template_file](#template_file) or [templates](#templates) must also be specified if this is set.
547
+
548
+ ### max_retry_putting_template
549
+
550
+ You can specify times of retry putting template.
551
+
552
+ This is useful when OpenSearch plugin cannot connect OpenSearch to put template.
553
+ Usually, booting up clustered OpenSearch containers are much slower than launching Fluentd container.
554
+
555
+ ```
556
+ max_retry_putting_template 15 # defaults to 10
557
+ ```
558
+
559
+ ### fail_on_putting_template_retry_exceed
560
+
561
+ Indicates whether to fail when `max_retry_putting_template` is exceeded.
562
+ If you have multiple output plugin, you could use this property to do not fail on fluentd statup.
563
+
564
+ ```
565
+ fail_on_putting_template_retry_exceed false # defaults to true
566
+ ```
567
+
568
+ ### fail_on_detecting_os_version_retry_exceed
569
+
570
+ Indicates whether to fail when `max_retry_get_os_version` is exceeded.
571
+ If you want to use fallback mechanism for obtaining OpenSearch version, you could use this property to do not fail on fluentd statup.
572
+
573
+ ```
574
+ fail_on_detecting_os_version_retry_exceed false
575
+ ```
576
+
577
+ And the following parameters should be working with:
578
+
579
+ ```
580
+ verify_os_version_at_startup true
581
+ max_retry_get_os_version 2 # greater than 0.
582
+ default_opensearch_version 1 # This version is used when occurring fallback.
583
+ ```
584
+
585
+ ### max_retry_get_os_version
586
+
587
+ You can specify times of retry obtaining OpenSearch version.
588
+
589
+ This is useful when OpenSearch plugin cannot connect OpenSearch to obtain OpenSearch version.
590
+ Usually, booting up clustered OpenSearch containers are much slower than launching Fluentd container.
591
+
592
+ ```
593
+ max_retry_get_os_version 17 # defaults to 15
594
+ ```
595
+
596
+ ### request_timeout
597
+
598
+ You can specify HTTP request timeout.
599
+
600
+ This is useful when OpenSearch cannot return response for bulk request within the default of 5 seconds.
601
+
602
+ ```
603
+ request_timeout 15s # defaults to 5s
604
+ ```
605
+
606
+ ### reload_connections
607
+
608
+ You can tune how the opensearch-transport host reloading feature works. By default it will reload the host list from the server every 10,000th request to spread the load. This can be an issue if your OpenSearch cluster is behind a Reverse Proxy, as Fluentd process may not have direct network access to the OpenSearch nodes.
609
+
610
+ ```
611
+ reload_connections false # defaults to true
612
+ ```
613
+
614
+ ### reload_on_failure
615
+
616
+ Indicates that the opensearch-transport will try to reload the nodes addresses if there is a failure while making the
617
+ request, this can be useful to quickly remove a dead node from the list of addresses.
618
+
619
+ ```
620
+ reload_on_failure true # defaults to false
621
+ ```
622
+
623
+ ### resurrect_after
624
+
625
+ You can set in the opensearch-transport how often dead connections from the opensearch-transport's pool will be resurrected.
626
+
627
+ ```
628
+ resurrect_after 5s # defaults to 60s
629
+ ```
630
+
631
+ ### include_tag_key, tag_key
632
+
633
+ ```
634
+ include_tag_key true # defaults to false
635
+ tag_key tag # defaults to tag
636
+ ```
637
+
638
+ This will add the Fluentd tag in the JSON record. For instance, if you have a config like this:
639
+
640
+ ```
641
+ <match my.logs>
642
+ @type opensearch
643
+ include_tag_key true
644
+ tag_key _key
645
+ </match>
646
+ ```
647
+
648
+ The record inserted into OpenSearch would be
649
+
650
+ ```
651
+ {"_key": "my.logs", "name": "Johnny Doeie"}
652
+ ```
653
+
654
+ ### id_key
655
+
656
+ ```
657
+ id_key request_id # use "request_id" field as a record id in ES
658
+ ```
659
+
660
+ By default, all records inserted into OpenSearch get a random _id. This option allows to use a field in the record as an identifier.
661
+
662
+ This following record `{"name": "Johnny", "request_id": "87d89af7daffad6"}` will trigger the following OpenSearch command
663
+
664
+ ```
665
+ { "index" : { "_index": "logstash-2013.01.01", "_type": "fluentd", "_id": "87d89af7daffad6" } }
666
+ { "name": "Johnny", "request_id": "87d89af7daffad6" }
667
+ ```
668
+
669
+ Fluentd re-emits events that failed to be indexed/ingested in OpenSearch with a new and unique `_id` value, this means that congested OpenSearch clusters that reject events (due to command queue overflow, for example) will cause Fluentd to re-emit the event with a new `_id`, however OpenSearch may actually process both (or more) attempts (with some delay) and create duplicate events in the index (since each have a unique `_id` value), one possible workaround is to use the [fluent-plugin-genhashvalue](https://github.com/mtakemi/fluent-plugin-genhashvalue) plugin to generate a unique `_hash` key in the record of each event, this `_hash` record can be used as the `id_key` to prevent OpenSearch from creating duplicate events.
670
+
671
+ ```
672
+ id_key _hash
673
+ ```
674
+
675
+ Example configuration for [fluent-plugin-genhashvalue](https://github.com/mtakemi/fluent-plugin-genhashvalue) (review the documentation of the plugin for more details)
676
+ ```
677
+ <filter logs.**>
678
+ @type genhashvalue
679
+ keys session_id,request_id
680
+ hash_type md5 # md5/sha1/sha256/sha512
681
+ base64_enc true
682
+ base91_enc false
683
+ set_key _hash
684
+ separator _
685
+ inc_time_as_key true
686
+ inc_tag_as_key true
687
+ </filter>
688
+ ```
689
+
690
+ :warning: In order to avoid hash-collisions and loosing data careful consideration is required when choosing the keys in the event record that should be used to calculate the hash
691
+
692
+ #### Using nested key
693
+
694
+ Nested key specifying syntax is also supported.
695
+
696
+ With the following configuration
697
+
698
+ ```aconf
699
+ id_key $.nested.request_id
700
+ ```
701
+
702
+ and the following nested record
703
+
704
+ ```json
705
+ {"nested":{"name": "Johnny", "request_id": "87d89af7daffad6"}}
706
+ ```
707
+
708
+ will trigger the following OpenSearch command
709
+
710
+ ```
711
+ {"index":{"_index":"fluentd","_type":"fluentd","_id":"87d89af7daffad6"}}
712
+ {"nested":{"name":"Johnny","request_id":"87d89af7daffad6"}}
713
+ ```
714
+
715
+ :warning: Note that [Hash flattening](#hash-flattening) may be conflict nested record feature.
716
+
717
+ ### parent_key
718
+
719
+ ```
720
+ parent_key a_parent # use "a_parent" field value to set _parent in opensearch command
721
+ ```
722
+
723
+ If your input is
724
+ ```
725
+ { "name": "Johnny", "a_parent": "my_parent" }
726
+ ```
727
+
728
+ OpenSearch command would be
729
+
730
+ ```
731
+ { "index" : { "_index": "****", "_type": "****", "_id": "****", "_parent": "my_parent" } }
732
+ { "name": "Johnny", "a_parent": "my_parent" }
733
+ ```
734
+
735
+ if `parent_key` is not configed or the `parent_key` is absent in input record, nothing will happen.
736
+
737
+ #### Using nested key
738
+
739
+ Nested key specifying syntax is also supported.
740
+
741
+ With the following configuration
742
+
743
+ ```aconf
744
+ parent_key $.nested.a_parent
745
+ ```
746
+
747
+ and the following nested record
748
+
749
+ ```json
750
+ {"nested":{ "name": "Johnny", "a_parent": "my_parent" }}
751
+ ```
752
+
753
+ will trigger the following OpenSearch command
754
+
755
+ ```
756
+ {"index":{"_index":"fluentd","_type":"fluentd","_parent":"my_parent"}}
757
+ {"nested":{"name":"Johnny","a_parent":"my_parent"}}
758
+ ```
759
+
760
+ :warning: Note that [Hash flattening](#hash-flattening) may be conflict nested record feature.
761
+
762
+ ### routing_key
763
+
764
+ Similar to `parent_key` config, will add `_routing` into opensearch command if `routing_key` is set and the field does exist in input event.
765
+
766
+ ### remove_keys
767
+
768
+ ```
769
+ parent_key a_parent
770
+ routing_key a_routing
771
+ remove_keys a_parent, a_routing # a_parent and a_routing fields won't be sent to opensearch
772
+ ```
773
+
774
+ ### remove_keys_on_update
775
+
776
+ Remove keys on update will not update the configured keys in opensearch when a record is being updated.
777
+ This setting only has any effect if the write operation is update or upsert.
778
+
779
+ If the write setting is upsert then these keys are only removed if the record is being
780
+ updated, if the record does not exist (by id) then all of the keys are indexed.
781
+
782
+ ```
783
+ remove_keys_on_update foo,bar
784
+ ```
785
+
786
+ ### remove_keys_on_update_key
787
+
788
+ This setting allows `remove_keys_on_update` to be configured with a key in each record, in much the same way as `target_index_key` works.
789
+ The configured key is removed before indexing in opensearch. If both `remove_keys_on_update` and `remove_keys_on_update_key` is
790
+ present in the record then the keys in record are used, if the `remove_keys_on_update_key` is not present then the value of
791
+ `remove_keys_on_update` is used as a fallback.
792
+
793
+ ```
794
+ remove_keys_on_update_key keys_to_skip
795
+ ```
796
+
797
+ ### retry_tag
798
+
799
+ This setting allows custom routing of messages in response to bulk request failures. The default behavior is to emit
800
+ failed records using the same tag that was provided. When set to a value other then `nil`, failed messages are emitted
801
+ with the specified tag:
802
+
803
+ ```
804
+ retry_tag 'retry_es'
805
+ ```
806
+ **NOTE:** `retry_tag` is optional. If you would rather use labels to reroute retries, add a label (e.g '@label @SOMELABEL') to your fluent
807
+ opensearch plugin configuration. Retry records are, by default, submitted for retry to the ROOT label, which means
808
+ records will flow through your fluentd pipeline from the beginning. This may nor may not be a problem if the pipeline
809
+ is idempotent - that is - you can process a record again with no changes. Use tagging or labeling to ensure your retry
810
+ records are not processed again by your fluentd processing pipeline.
811
+
812
+ ### write_operation
813
+
814
+ The write_operation can be any of:
815
+
816
+ | Operation | Description |
817
+ | ------------- | ----------- |
818
+ | index (default) | new data is added while existing data (based on its id) is replaced (reindexed).|
819
+ | create | adds new data - if the data already exists (based on its id), the op is skipped.|
820
+ | update | updates existing data (based on its id). If no data is found, the op is skipped.|
821
+ | upsert | known as merge or insert if the data does not exist, updates if the data exists (based on its id).|
822
+
823
+ **Please note, id is required in create, update, and upsert scenario. Without id, the message will be dropped.**
824
+
825
+ ### time_parse_error_tag
826
+
827
+ With `logstash_format true`, opensearch plugin parses timestamp field for generating index name. If the record has invalid timestamp value, this plugin emits an error event to `@ERROR` label with `time_parse_error_tag` configured tag.
828
+
829
+ Default value is `opensearch_plugin.output.time.error`. Note that this default values is quite different from Elasticsearch plugin.
830
+
831
+ ### reconnect_on_error
832
+ Indicates that the plugin should reset connection on any error (reconnect on next send).
833
+ By default it will reconnect only on "host unreachable exceptions".
834
+ We recommended to set this true in the presence of opensearch shield.
835
+ ```
836
+ reconnect_on_error true # defaults to false
837
+ ```
838
+
839
+ ### with_transporter_log
840
+
841
+ This is debugging purpose option to enable to obtain transporter layer log.
842
+ Default value is `false` for backward compatibility.
843
+
844
+ We recommend to set this true if you start to debug this plugin.
845
+
846
+ ```
847
+ with_transporter_log true
848
+ ```
849
+
850
+ ### content_type
851
+
852
+ With `content_type application/x-ndjson`, opensearch plugin adds `application/x-ndjson` as `Content-Type` in payload.
853
+
854
+ Default value is `application/json` which is default Content-Type of OpenSearch requests.
855
+ If you will not use template, it recommends to set `content_type application/x-ndjson`.
856
+
857
+ ```
858
+ content_type application/x-ndjson
859
+ ```
860
+
861
+ ### include_index_in_url
862
+
863
+ With this option set to true, Fluentd manifests the index name in the request URL (rather than in the request body).
864
+ You can use this option to enforce an URL-based access control.
865
+
866
+ ```
867
+ include_index_in_url true
868
+ ```
869
+
870
+ ### http_backend
871
+
872
+ With `http_backend typhoeus`, opensearch plugin uses typhoeus faraday http backend.
873
+ Typhoeus can handle HTTP keepalive.
874
+
875
+ Default value is `excon` which is default http_backend of opensearch plugin.
876
+
877
+ ```
878
+ http_backend typhoeus
879
+ ```
880
+
881
+ ### http_backend_excon_nonblock
882
+
883
+ With `http_backend_excon_nonblock false`, opensearch plugin use excon with nonblock=false.
884
+ If you use opensearch plugin with jRuby for https, you may need to consider to set `false` to avoid follwoing problems.
885
+ - https://github.com/geemus/excon/issues/106
886
+ - https://github.com/jruby/jruby-ossl/issues/19
887
+
888
+ But for all other case, it strongly reccomend to set `true` to avoid process hangin problem reported in https://github.com/uken/fluent-plugin-elasticsearch/issues/732
889
+
890
+ Default value is `true`.
891
+
892
+ ```
893
+ http_backend_excon_nonblock false
894
+ ```
895
+
896
+ ### compression_level
897
+ You can add gzip compression of output data. In this case `default_compression`, `best_compression` or `best speed` option should be chosen.
898
+ By default there is no compression, default value for this option is `no_compression`
899
+ ```
900
+ compression_level best_compression
901
+ ```
902
+
903
+ ### prefer_oj_serializer
904
+
905
+ With default behavior, OpenSearch client uses `Yajl` as JSON encoder/decoder.
906
+ `Oj` is the alternative high performance JSON encoder/decoder.
907
+ When this parameter sets as `true`, OpenSearch client uses `Oj` as JSON encoder/decoder.
908
+
909
+ Default value is `false`.
910
+
911
+ ```
912
+ prefer_oj_serializer true
913
+ ```
914
+
915
+ ### Client/host certificate options
916
+
917
+ Need to verify OpenSearch's certificate? You can use the following parameter to specify a CA instead of using an environment variable.
918
+ ```
919
+ ca_file /path/to/your/ca/cert
920
+ ```
921
+
922
+ Does your OpenSearch cluster want to verify client connections? You can specify the following parameters to use your client certificate, key, and key password for your connection.
923
+ ```
924
+ client_cert /path/to/your/client/cert
925
+ client_key /path/to/your/private/key
926
+ client_key_pass password
927
+ ```
928
+
929
+ If you want to configure SSL/TLS version, you can specify ssl\_version parameter.
930
+ ```
931
+ ssl_version TLSv1_2 # or [SSLv23, TLSv1, TLSv1_1]
932
+ ```
933
+
934
+ :warning: If SSL/TLS enabled, it might have to be required to set ssl\_version.
935
+
936
+ In OpenSearch plugin v4.0.2 with Ruby 2.5 or later combination, OpenSearch plugin also support `ssl_max_version` and `ssl_min_version`.
937
+
938
+ ```
939
+ ssl_max_version TLSv1_3
940
+ ssl_min_version TLSv1_2
941
+ ```
942
+
943
+ OpenSearch plugin will use TLSv1.2 as minimum ssl version and TLSv1.3 as maximum ssl version on transportation with TLS. Note that when they are used in Elastissearch plugin configuration, *`ssl_version` is not used* to set up TLS version.
944
+
945
+ If they are *not* specified in the OpenSearch plugin configuration, `ssl_max_version` and `ssl_min_version` is set up with:
946
+
947
+ In OpenSearch plugin v1.0.0 or later with Ruby 2.5 or later environment, `ssl_max_version` should be `TLSv1_3` and `ssl_min_version` should be `TLSv1_2`.
948
+
949
+ ### Proxy Support
950
+
951
+ Starting with version 0.8.0, this gem uses excon, which supports proxy with environment variables - https://github.com/excon/excon#proxy-support
952
+
953
+ ### Buffer options
954
+
955
+ `fluentd-plugin-opensearch` extends [Fluentd's builtin Output plugin](https://docs.fluentd.org/output#overview) and use `compat_parameters` plugin helper. It adds the following options:
956
+
957
+ ```
958
+ buffer_type memory
959
+ flush_interval 60s
960
+ retry_limit 17
961
+ retry_wait 1.0
962
+ num_threads 1
963
+ ```
964
+
965
+ The value for option `buffer_chunk_limit` should not exceed value `http.max_content_length` in your OpenSearch setup (by default it is 100mb).
966
+
967
+ **Note**: If you use or evaluate Fluentd v0.14, you can use `<buffer>` directive to specify buffer configuration, too. In more detail, please refer to the [buffer configuration options for v0.14](https://docs.fluentd.org/v0.14/articles/buffer-plugin-overview#configuration-parameters)
968
+
969
+ **Note**: If you use `disable_retry_limit` in v0.12 or `retry_forever` in v0.14 or later, please be careful to consume memory inexhaustibly.
970
+
971
+ ### Hash flattening
972
+
973
+ OpenSearch will complain if you send object and concrete values to the same field. For example, you might have logs that look this, from different places:
974
+
975
+ {"people" => 100}
976
+ {"people" => {"some" => "thing"}}
977
+
978
+ The second log line will be rejected by the OpenSearch parser because objects and concrete values can't live in the same field. To combat this, you can enable hash flattening.
979
+
980
+ ```
981
+ flatten_hashes true
982
+ flatten_hashes_separator _
983
+ ```
984
+
985
+ This will produce opensearch output that looks like this:
986
+ {"people_some" => "thing"}
987
+
988
+ Note that the flattener does not deal with arrays at this time.
989
+
990
+ ### Generate Hash ID
991
+
992
+ By default, the fluentd opensearch plugin does not emit records with a \_id field, leaving it to OpenSearch to generate a unique \_id as the record is indexed. When an OpenSearch cluster is congested and begins to take longer to respond than the configured request_timeout, the fluentd opensearch plugin will re-send the same bulk request. Since OpenSearch can't tell its actually the same request, all documents in the request are indexed again resulting in duplicate data. In certain scenarios, this can result in essentially and infinite loop generating multiple copies of the same data.
993
+
994
+ The bundled opensearch\_genid filter can generate a unique \_hash key for each record, this key may be passed to the id_key parameter in the opensearch plugin to communicate to OpenSearch the uniqueness of the requests so that duplicates will be rejected or simply replace the existing records.
995
+ Here is a sample config:
996
+
997
+ ```
998
+ <filter **>
999
+ @type opensearch_genid
1000
+ hash_id_key _hash # storing generated hash id key (default is _hash)
1001
+ </filter>
1002
+ <match **>
1003
+ @type opensearch
1004
+ id_key _hash # specify same key name which is specified in hash_id_key
1005
+ remove_keys _hash # OpenSearch doesn't like keys that start with _
1006
+ # other settings are omitted.
1007
+ </match>
1008
+ ```
1009
+
1010
+ ### Sniffer Class Name
1011
+
1012
+ The default Sniffer used by the `OpenSearch::Transport` class works well when Fluentd has a direct connection
1013
+ to all of the OpenSearch servers and can make effective use of the `_nodes` API. This doesn't work well
1014
+ when Fluentd must connect through a load balancer or proxy. The parameter `sniffer_class_name` gives you the
1015
+ ability to provide your own Sniffer class to implement whatever connection reload logic you require. In addition,
1016
+ there is a new `Fluent::Plugin::OpenSearchSimpleSniffer` class which reuses the hosts given in the configuration, which
1017
+ is typically the hostname of the load balancer or proxy. For example, a configuration like this would cause
1018
+ connections to `logging-os` to reload every 100 operations:
1019
+
1020
+ ```
1021
+ host logging-os
1022
+ port 9200
1023
+ reload_connections true
1024
+ sniffer_class_name Fluent::Plugin::OpenSearchSimpleSniffer
1025
+ reload_after 100
1026
+ ```
1027
+
1028
+ #### Tips
1029
+
1030
+ The included sniffer class is not required `out_opensearch`.
1031
+ You should tell Fluentd where the sniffer class exists.
1032
+
1033
+ If you use td-agent, you must put the following lines into `TD_AGENT_DEFAULT` file:
1034
+
1035
+ ```
1036
+ sniffer=$(td-agent-gem contents fluent-plugin-opensearch|grep opensearch_simple_sniffer.rb)
1037
+ TD_AGENT_OPTIONS="--use-v1-config -r $sniffer"
1038
+ ```
1039
+
1040
+ If you use Fluentd directly, you must pass the following lines as Fluentd command line option:
1041
+
1042
+ ```
1043
+ sniffer=$(td-agent-gem contents fluent-plugin-opensearch|grep opensearch_simple_sniffer.rb)
1044
+ $ fluentd -r $sniffer [AND YOUR OTHER OPTIONS]
1045
+ ```
1046
+
1047
+ ### Selector Class Name
1048
+
1049
+ The default selector used by the `OpenSearch::Transport` class works well when Fluentd should behave round robin and random selector cases. This doesn't work well when Fluentd should behave fallbacking from exhausted ES cluster to normal ES cluster.
1050
+ The parameter `selector_class_name` gives you the ability to provide your own Selector class to implement whatever selection nodes logic you require.
1051
+
1052
+ The below configuration is using plugin built-in `OpenSearchFallbackSelector`:
1053
+
1054
+ ```
1055
+ hosts exhausted-host:9201,normal-host:9200
1056
+ selector_class_name "Fluent::Plugin::OpenSeartchFallbackSelector"
1057
+ ```
1058
+
1059
+ #### Tips
1060
+
1061
+ The included selector class is required in `out_opensearch` by default.
1062
+ But, your custom selector class is not required in `out_opensearch`.
1063
+ You should tell Fluentd where the selector class exists.
1064
+
1065
+ If you use td-agent, you must put the following lines into `TD_AGENT_DEFAULT` file:
1066
+
1067
+ ```
1068
+ selector=/path/to/your_awesome_selector.rb
1069
+ TD_AGENT_OPTIONS="--use-v1-config -r $selector"
1070
+ ```
1071
+
1072
+ If you use Fluentd directly, you must pass the following lines as Fluentd command line option:
1073
+
1074
+ ```
1075
+ selector=/path/to/your_awesome_selector.rb
1076
+ $ fluentd -r $selector [AND YOUR OTHER OPTIONS]
1077
+ ```
1078
+
1079
+ ### Reload After
1080
+
1081
+ When `reload_connections true`, this is the integer number of operations after which the plugin will
1082
+ reload the connections. The default value is 10000.
1083
+
1084
+ ### Validate Client Version
1085
+
1086
+ When you use mismatched OpenSearch server and client libraries, fluent-plugin-opensearch cannot send data into OpenSearch. The default value is `false`.
1087
+
1088
+ ```
1089
+ validate_client_version true
1090
+ ```
1091
+
1092
+ ### Unrecoverable Error Types
1093
+
1094
+ Default `unrecoverable_error_types` parameter is set up strictly.
1095
+ Because `rejected_execution_exception` is caused by exceeding OpenSearch's thread pool capacity.
1096
+ Advanced users can increase its capacity, but normal users should follow default behavior.
1097
+
1098
+ If you want to increase it and forcibly retrying bulk request, please consider to change `unrecoverable_error_types` parameter from default value.
1099
+
1100
+ Change default value of `thread_pool.bulk.queue_size` in opensearch.yml:
1101
+ e.g.)
1102
+
1103
+ ```yaml
1104
+ thread_pool.bulk.queue_size: 1000
1105
+ ```
1106
+
1107
+ Then, remove `rejected_execution_exception` from `unrecoverable_error_types` parameter:
1108
+
1109
+ ```
1110
+ unrecoverable_error_types ["out_of_memory_error"]
1111
+ ```
1112
+
1113
+
1114
+ ### Unrecoverable Record Types
1115
+
1116
+ Default `unrecoverable_record_types` parameter is set up loosely.
1117
+ Because `json_parse_exception` is caused by invalid JSON record.
1118
+ Another possible unrecoverable record error should be included within this paramater.
1119
+
1120
+ If you want to handle `security_exception` as _unrecoverable exceptions_, please consider to change `unrecoverable_record_types` parameter from default value:
1121
+
1122
+ ```
1123
+ unrecoverable_record_types ["json_parse_exception", "security_exception"]
1124
+ ```
1125
+
1126
+ If this error type is included in OpenSearch response, an invalid record should be sent in `@ERROR` data pipeline.
1127
+
1128
+ ### emit_error_label_event
1129
+
1130
+ Default `emit_error_label_event` value is `true`.
1131
+
1132
+ Emitting error label events is default behavior.
1133
+
1134
+ When using the followin configuration, OpenSearch plugin will cut error events on error handler:
1135
+
1136
+ ```aconf
1137
+ emit_error_label_event false
1138
+ ```
1139
+
1140
+ ### verify_os_version_at_startup
1141
+
1142
+ Because OpenSearch plugin will ought to change behavior each of OpenSearch major versions.
1143
+
1144
+ For example, OpenSearch 1 requests to handle only `_doc` type_name in index.
1145
+
1146
+ If you want to disable to verify OpenSearch version at start up, set it as `false`.
1147
+
1148
+ When using the following configuration, OpenSearch plugin intends to communicate into OpenSearch 1.
1149
+
1150
+ ```
1151
+ verify_os_version_at_startup false
1152
+ default_opensearch_version 1
1153
+ ```
1154
+
1155
+ The default value is `true`.
1156
+
1157
+ ### default_opensearch_version
1158
+
1159
+ This parameter changes that OpenSearch plugin assumes the default OpenSearch version. The default value is `1`.
1160
+
1161
+ ### custom_headers
1162
+
1163
+ This parameter adds additional headers to request. The default value is `{}`.
1164
+
1165
+ ```
1166
+ custom_headers {"token":"secret"}
1167
+ ```
1168
+
1169
+ ### Not seeing a config you need?
1170
+
1171
+ We try to keep the scope of this plugin small and not add too many configuration options. If you think an option would be useful to others, feel free to open an issue or contribute a Pull Request.
1172
+
1173
+ Alternatively, consider using [fluent-plugin-forest](https://github.com/tagomoris/fluent-plugin-forest). For example, to configure multiple tags to be sent to different OpenSearch indices:
1174
+
1175
+ ```
1176
+ <match my.logs.*>
1177
+ @type forest
1178
+ subtype opensearch
1179
+ remove_prefix my.logs
1180
+ <template>
1181
+ logstash_prefix ${tag}
1182
+ # ...
1183
+ </template>
1184
+ </match>
1185
+ ```
1186
+
1187
+ And yet another option is described in Dynamic Configuration section.
1188
+
1189
+ **Note**: If you use or evaluate Fluentd v0.14, you can use builtin placeholders. In more detail, please refer to [Placeholders](#placeholders) section.
1190
+
1191
+ ### Placeholders
1192
+
1193
+ v0.14 placeholders can handle `${tag}` for tag, `%Y%m%d` like strftime format, and custom record keys like as `record["mykey"]`.
1194
+
1195
+ Note that custom chunk key is different notations for `record_reformer` and `record_modifier`.
1196
+ They uses `record["some_key"]` to specify placeholders, but this feature uses `${key1}`, `${key2}` notation. And tag, time, and some arbitrary keys must be included in buffer directive attributes.
1197
+
1198
+ They are used as below:
1199
+
1200
+ #### tag
1201
+
1202
+ ```aconf
1203
+ <match my.logs>
1204
+ @type opensearch
1205
+ index_name elastic.${tag} #=> replaced with each event's tag. e.g.) elastic.test.tag
1206
+ <buffer tag>
1207
+ @type memory
1208
+ </buffer>
1209
+ # <snip>
1210
+ </match>
1211
+ ```
1212
+
1213
+ #### time
1214
+
1215
+ ```aconf
1216
+ <match my.logs>
1217
+ @type opensearch
1218
+ index_name elastic.%Y%m%d #=> e.g.) elastic.20170811
1219
+ <buffer tag, time>
1220
+ @type memory
1221
+ timekey 3600
1222
+ </buffer>
1223
+ # <snip>
1224
+ </match>
1225
+ ```
1226
+
1227
+ #### custom key
1228
+
1229
+ ```log
1230
+ records = {key1: "value1", key2: "value2"}
1231
+ ```
1232
+
1233
+ ```aconf
1234
+ <match my.logs>
1235
+ @type opensearch
1236
+ index_name elastic.${key1}.${key2} # => e.g.) elastic.value1.value2
1237
+ <buffer tag, key1, key2>
1238
+ @type memory
1239
+ </buffer>
1240
+ # <snip>
1241
+ </match>
1242
+ ```
1243
+
1244
+ ## Multi workers
1245
+
1246
+ Since Fluentd v0.14, multi workers feature had been implemented to increase throughput with multiple processes. This feature allows Fluentd processes to use one or more CPUs. This feature will be enabled by the following system configuration:
1247
+
1248
+ ```
1249
+ <system>
1250
+ workers N # where N is a natural number (N >= 1).
1251
+ </system>
1252
+ ```
1253
+
1254
+ ## log_os_400_reason
1255
+
1256
+ By default, the error logger won't record the reason for a 400 error from the OpenSearch API unless you set log_level to debug. However, this results in a lot of log spam, which isn't desirable if all you want is the 400 error reasons. You can set this `true` to capture the 400 error reasons without all the other debug logs.
1257
+
1258
+ Default value is `false`.
1259
+
1260
+ ## suppress_doc_wrap
1261
+
1262
+ By default, record body is wrapped by 'doc'. This behavior can not handle update script requests. You can set this to suppress doc wrapping and allow record body to be untouched.
1263
+
1264
+ Default value is `false`.
1265
+
1266
+ ## ignore_exceptions
1267
+
1268
+ A list of exception that will be ignored - when the exception occurs the chunk will be discarded and the buffer retry mechanism won't be called. It is possible also to specify classes at higher level in the hierarchy. For example
1269
+
1270
+ ```
1271
+ ignore_exceptions ["OpenSearch::Transport::Transport::ServerError"]
1272
+ ```
1273
+
1274
+ will match all subclasses of `ServerError` - `OpenSearch::Transport::Transport::Errors::BadRequest`, `OpenSearch::Transport::Transport::Errors::ServiceUnavailable`, etc.
1275
+
1276
+ Default value is empty list (no exception is ignored).
1277
+
1278
+ ## exception_backup
1279
+
1280
+ Indicates whether to backup chunk when ignore exception occurs.
1281
+
1282
+ Default value is `true`.
1283
+
1284
+ ## bulk_message_request_threshold
1285
+
1286
+ Configure `bulk_message` request splitting threshold size.
1287
+
1288
+ Default value is `-1`(unlimited).
1289
+
1290
+ If you specify this size as negative number, `bulk_message` request splitting feature will be disabled.
1291
+
1292
+ ## truncate_caches_interval
1293
+
1294
+ Specify truncating caches interval.
1295
+
1296
+ If it is set, timer for clearing `alias_indexes` and `template_names` caches will be launched and executed.
1297
+
1298
+ Default value is `nil`.
1299
+
1300
+ ## use_legacy_template
1301
+
1302
+ Use legacy template or not.
1303
+
1304
+ Composable template documentation is [Put Index Template API | OpenSearch Reference](https://opensearch.org/docs/latest/opensearch/index-templates/). OpenSearch still supports legacy template but we recommend to migrate to use Composable template.
1305
+
1306
+ Please confirm that whether the using OpenSearch cluster(s) support the composable template feature or not when turn on the brand new feature with this parameter.
1307
+
1308
+ ## <metadata\> section
1309
+
1310
+ Users can specify whether including `chunk_id` information into records or not:
1311
+
1312
+ ```aconf
1313
+ <match your.awesome.routing.tag>
1314
+ @type opensearch
1315
+ # Other configurations.
1316
+ <metadata>
1317
+ include_chunk_id true
1318
+ # chunk_id_key chunk_id # Default value is "chunk_id".
1319
+ </metadata>
1320
+ </match>
1321
+ ```
1322
+
1323
+ ### include_chunk_id
1324
+
1325
+ Whether including `chunk_id` for not. Default value is `false`.
1326
+
1327
+ ```aconf
1328
+ <match your.awesome.routing.tag>
1329
+ @type opensearch
1330
+ # Other configurations.
1331
+ <metadata>
1332
+ include_chunk_id true
1333
+ </metadata>
1334
+ </match>
1335
+ ```
1336
+
1337
+
1338
+ ### chunk_id_key
1339
+
1340
+ Specify `chunk_id_key` to store `chunk_id` information into records. Default value is `chunk_id`.
1341
+
1342
+ ```aconf
1343
+ <match your.awesome.routing.tag>
1344
+ @type opensearch
1345
+ # Other configurations.
1346
+ <metadata>
1347
+ include_chunk_id
1348
+ chunk_id_key chunk_hex
1349
+ </metadata>
1350
+ </match>
1351
+ ```
1352
+
1353
+ ## Configuration - OpenSearch Input
1354
+
1355
+ See [OpenSearch Input plugin document](README.OpenSearchInput.md)
1356
+
1357
+ ## Configuration - OpenSearch Filter GenID
1358
+
1359
+ See [OpenSearch Filter GenID document](README.OpenSearchGenID.md)
1360
+
1361
+ ## Configuration - OpenSearch Output Data Stream
1362
+
1363
+ Since Elasticsearch 7.9 that is predessor software of OpenSearch, Data Streams was introduced.
1364
+
1365
+ **NOTE:** This feature is slated to official support. Currently, this fetaure is beta.
1366
+
1367
+ You can enable this feature by specifying `@type opensearch_data_stream`.
1368
+
1369
+ ```
1370
+ @type opensearch_data_stream
1371
+ data_stream_name test
1372
+ ```
1373
+
1374
+ The matching index template will be also created automatically.
1375
+
1376
+ ### data_stream_name
1377
+
1378
+ You can specify OpenSearch data stream name by this parameter.
1379
+ This parameter is mandatory for `opensearch_data_stream`.
1380
+
1381
+ ### data_stream_template_name
1382
+
1383
+ You can specify an existing matching index template for the data stream. If not present, it creates a new matching index template.
1384
+
1385
+ Default value is `data_stream_name`.
1386
+
1387
+ ## Configuration - AWS OpenSearch Service
1388
+
1389
+ This settings are effective for AWS OpenSearch Service that is successor of AWS Elasticsearch service.
1390
+
1391
+
1392
+ ### \<endpoint\> section
1393
+
1394
+ AWS OpenSearch Service related settings are placed in `<endpoint>` directive.
1395
+ This is because `elasticsearch-ruby` does not work with OpenSearch and `opensearch-ruby` does not work with Elasticsearch.
1396
+
1397
+ Configuration example is below:
1398
+
1399
+ ```aconf
1400
+ <match es.**>
1401
+ type opensearch
1402
+ logstash_format true
1403
+ include_tag_key true
1404
+ flush_interval 1s
1405
+
1406
+ <endpoint>
1407
+ url https://CLUSTER_ENDPOINT_URL
1408
+ region YOUR_AWS_REGION
1409
+ # access_key_id "secret"
1410
+ # secret_access_key "foo_secret"
1411
+ </endpoint>
1412
+ </match>
1413
+ ```
1414
+
1415
+ #### region
1416
+
1417
+ Specify AWS region.
1418
+
1419
+ ```aconf
1420
+ <endpoint>
1421
+ region us-east-2 # e.g.) AWS Ohio region
1422
+ # other stuffs.
1423
+ </endpoint>
1424
+ ```
1425
+
1426
+ #### url
1427
+
1428
+ Specify AWS OpenSearch Service endpoint.
1429
+
1430
+ ```aconf
1431
+ <endpoint>
1432
+ url https://CLUSTER_ENDPOINT_URL
1433
+ # other stuffs.
1434
+ </endpoint>
1435
+ ```
1436
+
1437
+ **NOTE:** This plugin will remove trailing slashes automatically. You don't need to pay attention to the trailing slash characters.
1438
+
1439
+ #### access_key_id
1440
+
1441
+ Specify AWS access key.
1442
+
1443
+ ```aconf
1444
+ <endpoint>
1445
+ access_key_id YOUR_AWS_ACCESS_KEY
1446
+ # other stuffs.
1447
+ </endpoint>
1448
+ ```
1449
+
1450
+ #### secret_access_key
1451
+
1452
+ Specify AWS secret access key.
1453
+
1454
+ ```aconf
1455
+ <endpoint>
1456
+ secret_access_key YOUR_AWS_SECRET_ACCESS_KEY
1457
+ # other stuffs.
1458
+ </endpoint>
1459
+ ```
1460
+
1461
+ ### IAM
1462
+
1463
+ If you don't want to use `access_key_id` and `secret_access_key` on your endpoint configuration, you should use IAM policies instead.
1464
+
1465
+ #### Assign an IAM instance role
1466
+
1467
+ The first step needs to assign an IAM instance role (ROLE) to your EC2 instances. You should change its name appropriately.
1468
+ The attaching role should not contain no policy: We're using the role as the authenticating factor and placing the policy into the OpenSearch cluster.
1469
+
1470
+ Then, you should configure a policy for the OpenSearch cluster policy with substitution s for the capitalized terms:
1471
+
1472
+ ```json
1473
+ {
1474
+ "Version": "2012-10-17",
1475
+ "Statement": [
1476
+ {
1477
+ "Effect": "Allow",
1478
+ "Principal": {
1479
+ "AWS": "arn:aws:iam::ACCOUNT:role/ROLE"
1480
+ },
1481
+ "Action": "es:*",
1482
+ "Resource": "arn:aws:es:AWS_REGION:ACCOUNT:domain/OPENSEARCH_DOMAIN/*"
1483
+ },
1484
+ {
1485
+ "Effect": "Allow",
1486
+ "Principal": {
1487
+ "AWS": "*"
1488
+ },
1489
+ "Action": "es:*",
1490
+ "Resource": "arn:aws:es:AWS_REGION:ACCOUNT:domain/OPENSEARCH_DOMAIN/*",
1491
+ "Condition": {
1492
+ "IpAddress": {
1493
+ "aws:SourceIp": [
1494
+ "1.2.3.4/32",
1495
+ "5.6.7.8/32"
1496
+ ]
1497
+ }
1498
+ }
1499
+ }
1500
+ ]
1501
+ }
1502
+ ```
1503
+
1504
+ The above policy will allow your Fluentd hosts and any traffic coming from the specified IP addresses (you querying OpenSearch Dashboard) to access the various endpoints. While not ideally secure it should allow you to get up and ingesting logs without anything
1505
+
1506
+ #### Use STS assumed role as the authenticating factor
1507
+
1508
+ Additionally, you can use a STS assumed role as the authenticating factor and instruct the plugin to assume this role.
1509
+ This is useful for cross-account access and when assigning a standard role is not possible. In this case, the endpoint configuration looks like:
1510
+
1511
+ ```aconf
1512
+ <endpoint>
1513
+ url https://CLUSTER_ENDPOINT_URL
1514
+ region YOUR_AWS_REGION
1515
+ assume_role_arn arn:aws:sts::ACCOUNT:role/ROLE
1516
+ assume_role_session_name SESSION_ID # Defaults to fluentd if omitted
1517
+ sts_credentials_region YOUR_AWS_STS_REGION # Defaults to region if omitted
1518
+ </endpoint>
1519
+ ```
1520
+
1521
+ The policy attached into your OpenSearch cluster becomes something like:
1522
+
1523
+ ```json
1524
+ {
1525
+ "Version": "2012-10-17",
1526
+ "Statement": [
1527
+ {
1528
+ "Effect": "Allow",
1529
+ "Principal": {
1530
+ "AWS": "arn:aws:sts::ACCOUNT:assumed-role/ROLE/SESSION_ID"
1531
+ },
1532
+ "Action": "es:*",
1533
+ "Resource": "arn:aws:es:AWS_REGION:ACCOUNT:domain/ES_DOMAIN/*"
1534
+ }
1535
+ ]
1536
+ }
1537
+ ```
1538
+
1539
+ #### Ensure the environment to assume roles
1540
+
1541
+ You'll need to ensure that the environment where the Fluentd plugin runs to have the capability to assume this role, by attaching a policy something like this to the instance profile:
1542
+
1543
+ ```json
1544
+ {
1545
+ "Version": "2012-10-17",
1546
+ "Statement": {
1547
+ "Effect": "Allow",
1548
+ "Action": "sts:AssumeRole",
1549
+ "Resource": "arn:aws:iam::ACCOUNT:role/ROLE"
1550
+ }
1551
+ }
1552
+ ```
1553
+
1554
+ ### EKS
1555
+
1556
+ If you want to use IAM roles for service accounts on your Amazon EKS clusters, please refer to the official documentation and specify a Service Account for your fluentd Pod.
1557
+
1558
+ In this case, the endpoint configuration looks like:
1559
+
1560
+ ```aconf
1561
+ <endpoint>
1562
+ url https://CLUSTER_ENDPOINT_URL
1563
+ region eu-west-1
1564
+ assume_role_arn "#{ENV['AWS_ROLE_ARN']}"
1565
+ assume_role_web_identity_token_file "#{ENV['AWS_WEB_IDENTITY_TOKEN_FILE']}"
1566
+ </endpoint>
1567
+ ```
1568
+
1569
+ ### Expiring AWS credentials
1570
+
1571
+ If you want to expire AWS credentials in certain interval, you should specify `refresh_credentials_interval` parameter under `endpoint` section:
1572
+
1573
+ ```aconf
1574
+ <endpoint>
1575
+ url https://CLUSTER_ENDPOINT_URL
1576
+ region eu-west-1
1577
+ # ...
1578
+ refresh_credentials_interval 3h # default is 5h (five hours).
1579
+ </endpoint>
1580
+ ```
1581
+
1582
+ ### Use OpenSearch Serverless
1583
+
1584
+ If you want to use Serverless version of OpenSearch service, you have to specify `aoss` in `aws_service_name` under `endpoint` section:
1585
+
1586
+ ```aconf
1587
+ <endpoint>
1588
+ url https://CLUSTER_ENDPOINT_URL
1589
+ region us-east-2
1590
+ # ...
1591
+ aws_service_name aoss # default is es that is for AWS OpenSearch Service not Serverless.
1592
+ </endpoint>
1593
+ ```
1594
+
1595
+ ## Troubleshooting
1596
+
1597
+ See [Troubleshooting document](README.Troubleshooting.md)
1598
+
1599
+ ## Contact
1600
+
1601
+ If you have a question, [open an Issue](https://github.com/fluent/fluent-plugin-opensearch/issues).
1602
+
1603
+ ## Contributing
1604
+
1605
+ There are usually a few feature requests, tagged [Easy](https://github.com/fluent/fluent-plugin-opensearch/issues?q=is%3Aissue+is%3Aopen+label%3Alevel%3AEasy), [Normal](https://github.com/fluent/fluent-plugin-opensearch/issues?q=is%3Aissue+is%3Aopen+label%3Alevel%3ANormal) and [Hard](https://github.com/fluent/fluent-plugin-opensearch/issues?q=is%3Aissue+is%3Aopen+label%3Alevel%3AHard). Feel free to work on any one of them.
1606
+
1607
+ Pull Requests are welcomed.
1608
+
1609
+ Before sending a pull request or reporting an issue, please read [the contribution guideline](CONTRIBUTING.md).
1610
+
1611
+ ## Running tests
1612
+
1613
+ Install dev dependencies:
1614
+
1615
+ ```sh
1616
+ $ gem install bundler
1617
+ $ bundle install
1618
+ $ bundle exec rake test
1619
+ # To just run the test you are working on:
1620
+ $ bundle exec rake test TEST=test/plugin/test_out_opensearch.rb TESTOPTS='--verbose --name=test_bulk_error_retags_with_error_when_configured_and_fullfilled_buffer'
1621
+
1622
+ ```