Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[exporter/elasticsearch] support sending otlp tracing to Elasticsearch #10180

Merged
merged 46 commits into from
Sep 8, 2022
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
b828971
fix conflicts
JaredTan95 Jun 17, 2022
eb34cf6
update README.md
JaredTan95 May 20, 2022
9ed6b03
fix fmt
JaredTan95 May 20, 2022
db3fc26
fix lint
JaredTan95 May 20, 2022
14e9b87
fix make goporto
JaredTan95 May 20, 2022
c01468c
fix ut.
JaredTan95 May 20, 2022
193ce99
fix conf
JaredTan95 Jun 17, 2022
394af91
Merge branch 'main' into es_exporter_otlp_tracing
JaredTan95 Jun 28, 2022
e00f8db
update logical
JaredTan95 Jun 29, 2022
2aeb8d6
Merge branch 'es_exporter_otlp_tracing' of https://github.com/JaredTa…
JaredTan95 Jun 29, 2022
abe09b2
Merge branch 'main' into es_exporter_otlp_tracing
JaredTan95 Jun 29, 2022
81840cc
polish
JaredTan95 Jun 29, 2022
8e3094b
Merge branch 'main' into es_exporter_otlp_tracing
JaredTan95 Jun 29, 2022
1f6d56d
Merge branch 'es_exporter_otlp_tracing' of https://github.com/JaredTa…
JaredTan95 Jun 29, 2022
0f748f0
remove unused errmsg
JaredTan95 Jun 29, 2022
7b4f9de
fix ut
JaredTan95 Jun 29, 2022
17479fc
fix docs.
JaredTan95 Jun 29, 2022
ce1a363
Update exporter/elasticsearchexporter/testdata/config-use-deprecated-…
JaredTan95 Jun 29, 2022
b5f957e
add waring msg
JaredTan95 Jun 29, 2022
c1b2534
Merge branch 'es_exporter_otlp_tracing' of https://github.com/JaredTa…
JaredTan95 Jun 29, 2022
a22497d
fix conflicts
JaredTan95 Jul 4, 2022
d27c35f
revert
JaredTan95 Jul 4, 2022
be8438d
revert
JaredTan95 Jul 4, 2022
c75417d
polish
JaredTan95 Jul 5, 2022
f1eac6c
add issue.
JaredTan95 Jul 5, 2022
bb45708
udpate
JaredTan95 Jul 11, 2022
d75d759
Merge remote-tracking branch 'upstream/main' into es_exporter_otlp_tr…
JaredTan95 Jul 22, 2022
ca90fb4
add stability info
JaredTan95 Jul 22, 2022
8c855a9
fix fmt
JaredTan95 Jul 22, 2022
1e1aaf3
Merge branch 'main' into es_exporter_otlp_tracing
JaredTan95 Aug 9, 2022
d0eee98
Merge branch 'main' into es_exporter_otlp_tracing
JaredTan95 Aug 11, 2022
574b557
fix funcs usage
JaredTan95 Aug 12, 2022
ff86297
Merge branch 'main' into es_exporter_otlp_tracing
JaredTan95 Aug 12, 2022
3b41811
Merge branch 'es_exporter_otlp_tracing' of https://github.com/JaredTa…
JaredTan95 Aug 12, 2022
6cbb6a1
fix and add ut
JaredTan95 Aug 12, 2022
97ff73a
Merge branch 'main' into es_exporter_otlp_tracing
JaredTan95 Aug 12, 2022
a4abcb3
Update exporter/elasticsearchexporter/logs_exporter.go
JaredTan95 Aug 15, 2022
b7bde8a
Merge branch 'main' into es_exporter_otlp_tracing
JaredTan95 Aug 15, 2022
dc456a0
update deprecated
JaredTan95 Aug 15, 2022
bab7f8e
Merge branch 'main' into es_exporter_otlp_tracing
JaredTan95 Aug 15, 2022
7ae794e
Merge branch 'main' into es_exporter_otlp_tracing
JaredTan95 Aug 16, 2022
5be9500
Merge branch 'main' into es_exporter_otlp_tracing
JaredTan95 Aug 22, 2022
4f4d629
Merge branch 'main' into es_exporter_otlp_tracing
JaredTan95 Aug 24, 2022
7241245
Merge branch 'main' into es_exporter_otlp_tracing
JaredTan95 Aug 26, 2022
1fbea43
Merge branch 'main' into es_exporter_otlp_tracing
JaredTan95 Aug 27, 2022
c47978a
fix lint
JaredTan95 Sep 3, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 31 additions & 9 deletions exporter/elasticsearchexporter/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Elasticsearch Exporter

| Status | |
| ------------------------ |-----------|
| Stability | [beta] |
| Supported pipeline types | logs |
| Distributions | [contrib] |
| Status | |
| ------------------------ |-------------|
| Stability | [beta] |
| Supported pipeline types | logs,traces |
| Distributions | [contrib] |

This exporter supports sending OpenTelemetry logs to [Elasticsearch](https://www.elastic.co/elasticsearch).

Expand All @@ -20,7 +20,15 @@ This exporter supports sending OpenTelemetry logs to [Elasticsearch](https://www
- `index`: The
[index](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices.html)
or [datastream](https://www.elastic.co/guide/en/elasticsearch/reference/current/data-streams.html)
name to publish events to. The default value is `logs-generic-default`.
name to publish events to. The default value is `logs-generic-default`. Note: To better differentiate between log indexes and traces indexes, `index` option are deprecated and replaced with below `logs_index`
- `logs_index`: The
[index](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices.html)
or [datastream](https://www.elastic.co/guide/en/elasticsearch/reference/current/data-streams.html)
name to publish events to. The default value is `logs-generic-default`
- `traces_index`: The
[index](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices.html)
or [datastream](https://www.elastic.co/guide/en/elasticsearch/reference/current/data-streams.html)
name to publish traces to. The default value is `traces-generic-default`.
- `pipeline` (optional): Optional [Ingest Node](https://www.elastic.co/guide/en/elasticsearch/reference/current/ingest.html)
pipeline ID used for processing documents published by the exporter.
- `flush`: Event bulk buffer flush settings
Expand Down Expand Up @@ -85,9 +93,23 @@ nodes will automatically be used for load balancing.

```yaml
exporters:
elasticsearch:
endpoints:
- "https://localhost:9200"
elasticsearch/trace:
endpoints: [https://elastic.example.com:9200]
traces_index: trace_index
elasticsearch/log:
endpoints: [http://localhost:9200]
logs_index: my_log_index
······
service:
pipelines:
logs:
receivers: [otlp]
processors: [batch]
exporters: [elasticsearch/log]
traces:
receivers: [otlp]
exporters: [elasticsearch/trace]
processors: [batch]
```
[beta]:https://github.com/open-telemetry/opentelemetry-collector#beta
[contrib]:https://github.com/open-telemetry/opentelemetry-collector-releases/tree/main/distributions/otelcol-contrib
13 changes: 7 additions & 6 deletions exporter/elasticsearchexporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,15 @@ type Config struct {
// https://www.elastic.co/guide/en/elasticsearch/reference/current/indices.html
// https://www.elastic.co/guide/en/elasticsearch/reference/current/data-streams.html
//
// This setting is required.
// Deprecated: `index` is deprecated and replaced with `logs_index`.
Index string `mapstructure:"index"`
JaredTan95 marked this conversation as resolved.
Show resolved Hide resolved

// This setting is required when logging pipelines used.
LogsIndex string `mapstructure:"logs_index"`

// This setting is required when traces pipelines used.
TracesIndex string `mapstructure:"traces_index"`

// Pipeline configures the ingest node pipeline name that should be used to process the
// events.
//
Expand Down Expand Up @@ -171,7 +177,6 @@ const (
var (
errConfigNoEndpoint = errors.New("endpoints or cloudid must be specified")
errConfigEmptyEndpoint = errors.New("endpoints must not include empty entries")
errConfigNoIndex = errors.New("index must be specified")
)

func (m MappingMode) String() string {
Expand Down Expand Up @@ -217,10 +222,6 @@ func (cfg *Config) Validate() error {
}
}

if cfg.Index == "" {
return errConfigNoIndex
}

if _, ok := mappingModes[cfg.Mapping.Mode]; !ok {
return fmt.Errorf("unknown mapping mode %v", cfg.Mapping.Mode)
}
Expand Down
100 changes: 96 additions & 4 deletions exporter/elasticsearchexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,56 @@ import (
"go.opentelemetry.io/collector/service/servicetest"
)

func TestLoad_DeprecatedIndexConfigOption(t *testing.T) {
factories, err := componenttest.NopFactories()
require.NoError(t, err)

factory := NewFactory()
factories.Exporters[typeStr] = factory
cfg, err := servicetest.LoadConfigAndValidate(filepath.Join("testdata", "config-use-deprecated-index_option.yaml"), factories)
require.NoError(t, err)
require.NotNil(t, cfg)

r1 := cfg.Exporters[config.NewComponentIDWithName(typeStr, "log")].(*Config)
assert.Equal(t, r1, &Config{
ExporterSettings: config.NewExporterSettings(config.NewComponentIDWithName(typeStr, "log")),
Endpoints: []string{"http://localhost:9200"},
CloudID: "TRNMxjXlNJEt",
Index: "my_log_index",
LogsIndex: "logs-generic-default",
TracesIndex: "traces-generic-default",
Pipeline: "mypipeline",
HTTPClientSettings: HTTPClientSettings{
Authentication: AuthenticationSettings{
User: "elastic",
Password: "search",
APIKey: "AvFsEiPs==",
},
Timeout: 2 * time.Minute,
Headers: map[string]string{
"myheader": "test",
},
},
Discovery: DiscoverySettings{
OnStart: true,
},
Flush: FlushSettings{
Bytes: 10485760,
},
Retry: RetrySettings{
Enabled: true,
MaxRequests: 5,
InitialInterval: 100 * time.Millisecond,
MaxInterval: 1 * time.Minute,
},
Mapping: MappingsSettings{
Mode: "ecs",
Dedup: true,
Dedot: true,
},
})
}

func TestLoadConfig(t *testing.T) {
factories, err := componenttest.NopFactories()
require.NoError(t, err)
Expand All @@ -36,19 +86,21 @@ func TestLoadConfig(t *testing.T) {
require.NoError(t, err)
require.NotNil(t, cfg)

assert.Equal(t, len(cfg.Exporters), 2)
assert.Equal(t, len(cfg.Exporters), 3)

defaultCfg := factory.CreateDefaultConfig()
defaultCfg.(*Config).Endpoints = []string{"https://elastic.example.com:9200"}
r0 := cfg.Exporters[config.NewComponentID(typeStr)]
assert.Equal(t, r0, defaultCfg)

r1 := cfg.Exporters[config.NewComponentIDWithName(typeStr, "customname")].(*Config)
r1 := cfg.Exporters[config.NewComponentIDWithName(typeStr, "trace")].(*Config)
assert.Equal(t, r1, &Config{
ExporterSettings: config.NewExporterSettings(config.NewComponentIDWithName(typeStr, "customname")),
ExporterSettings: config.NewExporterSettings(config.NewComponentIDWithName(typeStr, "trace")),
Endpoints: []string{"https://elastic.example.com:9200"},
CloudID: "TRNMxjXlNJEt",
Index: "myindex",
Index: "",
LogsIndex: "logs-generic-default",
TracesIndex: "trace_index",
Pipeline: "mypipeline",
HTTPClientSettings: HTTPClientSettings{
Authentication: AuthenticationSettings{
Expand Down Expand Up @@ -79,6 +131,46 @@ func TestLoadConfig(t *testing.T) {
Dedot: true,
},
})

r2 := cfg.Exporters[config.NewComponentIDWithName(typeStr, "log")].(*Config)
assert.Equal(t, r2, &Config{
ExporterSettings: config.NewExporterSettings(config.NewComponentIDWithName(typeStr, "log")),
Endpoints: []string{"http://localhost:9200"},
CloudID: "TRNMxjXlNJEt",
Index: "",
LogsIndex: "my_log_index",
TracesIndex: "traces-generic-default",
Pipeline: "mypipeline",
HTTPClientSettings: HTTPClientSettings{
Authentication: AuthenticationSettings{
User: "elastic",
Password: "search",
APIKey: "AvFsEiPs==",
},
Timeout: 2 * time.Minute,
Headers: map[string]string{
"myheader": "test",
},
},
Discovery: DiscoverySettings{
OnStart: true,
},
Flush: FlushSettings{
Bytes: 10485760,
},
Retry: RetrySettings{
Enabled: true,
MaxRequests: 5,
InitialInterval: 100 * time.Millisecond,
MaxInterval: 1 * time.Minute,
},
Mapping: MappingsSettings{
Mode: "ecs",
Dedup: true,
Dedot: true,
},
})

}

func withDefaultConfig(fns ...func(*Config)) *Config {
Expand Down
Loading