From 33d820908019dde5c3625c2a349389df447003a5 Mon Sep 17 00:00:00 2001 From: Martin Chodur Date: Fri, 28 Jan 2022 02:56:55 +0100 Subject: [PATCH] feat: add elastic search ingester module Signed-off-by: Martin Chodur --- cmd/slo_exporter.go | 3 + docs/configuration.md | 1 + docs/modules/elasticsearch_ingester.md | 33 ++++ go.mod | 1 + go.sum | 13 +- pkg/elasticsearch_ingester/elastic_client.go | 25 +++ pkg/elasticsearch_ingester/elastic_tailer.go | 171 ++++++++++++++++ .../elasticsearch_ingester.go | 184 ++++++++++++++++++ pkg/elasticsearch_ingester/v7.go | 94 +++++++++ pkg/tailer/tailer.go | 6 +- pkg/tailer/tailer_test.go | 4 +- 11 files changed, 529 insertions(+), 6 deletions(-) create mode 100644 docs/modules/elasticsearch_ingester.md create mode 100644 pkg/elasticsearch_ingester/elastic_client.go create mode 100644 pkg/elasticsearch_ingester/elastic_tailer.go create mode 100644 pkg/elasticsearch_ingester/elasticsearch_ingester.go create mode 100644 pkg/elasticsearch_ingester/v7.go diff --git a/cmd/slo_exporter.go b/cmd/slo_exporter.go index 8925059..ed9200b 100644 --- a/cmd/slo_exporter.go +++ b/cmd/slo_exporter.go @@ -3,6 +3,7 @@ package main import ( "context" "fmt" + "github.com/seznam/slo-exporter/pkg/elasticsearch_ingester" "runtime" "github.com/gorilla/mux" @@ -71,6 +72,8 @@ func moduleFactory(moduleName string, logger logrus.FieldLogger, conf *viper.Vip return prometheus_ingester.NewFromViper(conf, logger) case "kafkaIngester": return kafka_ingester.NewFromViper(conf, logger) + case "elasticSearchIngester": + return elasticsearch_ingester.NewFromViper(conf, logger) case "envoyAccessLogServer": return envoy_access_log_server.NewFromViper(conf, logger) case "eventMetadataRenamer": diff --git a/docs/configuration.md b/docs/configuration.md index fe4f612..cc3816b 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -58,6 +58,7 @@ Only produces new events from the specified data source. - [`prometheusIngester`](modules/prometheus_ingester.md) - [`envoyAccessLogServer`](modules/envoy_access_log_server.md) - [`kafkaIngester`](modules/kafka_ingester.md) + - [`elasticSearchIngester`](modules/elasticsearch_ingester.md) ##### Processors: Reads input events, does some processing based in the module type and produces modified event. diff --git a/docs/modules/elasticsearch_ingester.md b/docs/modules/elasticsearch_ingester.md new file mode 100644 index 0000000..ffc4190 --- /dev/null +++ b/docs/modules/elasticsearch_ingester.md @@ -0,0 +1,33 @@ +# Elasticsearch ingester + +| | | +|----------------|-------------------------| +| `moduleName` | `elasticSearchIngester` | +| Module type | `producer` | +| Output event | `raw` | + +This module allows you to read events as a documents form Elastic search (assuming ELK stack). + +### Elastic search versions and support +Currently, only v7 is supported. + +### moduleConfig +```yaml +addresses: + - "https://foo.bar:4433" +index: "*:sklik-production-search" +clientCertFile: "./client.pem" +clientKeyFile: "./client-key.pem" +clientCaCertFile: "./ca.cert" +debug: true +insecureSkipVerify: false +maxBatchSize: 100 +interval: 5s +timeout: 5s +timestampField: "@timestamp" +timestampFormat: "2006-01-02T15:04:05Z07:00" # See # https://www.geeksforgeeks.org/time-formatting-in-golang/ for common examples +query: "app_name: nginx AND namespace: test" +rawLogField: "log" +rawLogParseRegexp: '^(?P[A-Fa-f0-9.:]{4,50}) \S+ \S+ \[(?P