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/OpenSearch] OpenSearch exporter setup #23819

Merged
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
31742d8
Added space
MitchellGale Jun 25, 2023
cb37238
Added MitchellGale to CODEOWNERS
MitchellGale Jun 25, 2023
89dca47
Added OpenSearchExporter builder-config.yaml.
MitchellGale Jun 26, 2023
1928c8f
Added OpenSearchExporter go.mod otel contrib col.
MitchellGale Jun 26, 2023
4a1672b
Added MakeFile for OpenSearchExporter.
MitchellGale Jun 26, 2023
aa474de
Added OpenSearchExporter for versions.yaml
MitchellGale Jun 26, 2023
8758cba
Added OpenSearchExporter for .golangci.yml, bug_report.yaml, feature_…
MitchellGale Jun 26, 2023
e355bd2
Reverted changes in go.mod
MitchellGale Jun 26, 2023
969fc59
Reverted MakeFile space.
MitchellGale Jun 26, 2023
b4aedd5
Reverted go.mod manual change.
MitchellGale Jun 26, 2023
b2ae742
added OS config.go
MitchellGale Jun 26, 2023
3d99174
added link for OS config.go
MitchellGale Jun 26, 2023
f9dd5cd
Added go mod
MitchellGale Jun 26, 2023
d1a6c93
Renamed Makefile
MitchellGale Jun 26, 2023
29076e6
Switched go mod go version from 1.20 to 1.19
MitchellGale Jun 26, 2023
4a35bea
Ran `make genotelcontribcol`
MitchellGale Jun 26, 2023
62dd060
Made with go mod changes and adding factory.go, and adding config to …
MitchellGale Jun 27, 2023
e286d18
Fixed issues in config and factor go.
MitchellGale Jun 27, 2023
8a51d24
go sum
MitchellGale Jun 27, 2023
85d206f
Added YangDB and Max Ksyunz to code owners for OpenSearch exporter.
MitchellGale Jun 28, 2023
fdc9b14
Merge pull request #20 from Bit-Quill/mainCopy
MitchellGale Jun 28, 2023
a078ad6
Removed commented out code. Added @Aneurysm9 as code owner.
MitchellGale Jun 28, 2023
ee759b6
Removed opensearch from builder-config.yaml
MitchellGale Jun 30, 2023
22fcf52
Merge remote-tracking branch 'upstream/main' into Integ/OpenSearchExp…
MitchellGale Jul 5, 2023
581ac14
Updated README.md
MitchellGale Jul 5, 2023
d4db8ab
Updated go mod and go sum
MitchellGale Jul 5, 2023
bb9972f
Added change log for opensearch.
MitchellGale Jul 5, 2023
993ce1a
Updated dependabot.yml
MitchellGale Jul 5, 2023
244fc29
Reverted changes in otelcontrib.
MitchellGale Jul 5, 2023
9fce291
Reverted changes in versions.
MitchellGale Jul 5, 2023
d57a6af
Added new line at end of new component
MitchellGale Jul 5, 2023
c778313
Reverted file to golangci.yml
MitchellGale Jul 5, 2023
c6eaf01
Added Opensearch exporter to excluded modules in versions.yaml.
MitchellGale Jul 5, 2023
50db30a
Adding defaults for Namespace and Dataset in factory.go as outlined i…
MitchellGale Jul 7, 2023
e240c46
swapped defaults for Namespace and Dataset in factory.go as outlined …
MitchellGale Jul 7, 2023
e383557
Merge remote-tracking branch 'upstream/main' into Integ/OpenSearchExp…
MitchellGale Jul 7, 2023
fc8d591
Update dependabot.
MitchellGale Jul 7, 2023
9575754
Update README.md with details on default num_workers
MitchellGale Jul 10, 2023
4d7d124
Address review feedback.
MaxKsyunz Jul 19, 2023
a2ed3e8
Re-run fmt, mod tidy
MaxKsyunz Jul 20, 2023
232e82d
Merge branch 'main' into integ/OpenSearchExporter-setup
MaxKsyunz Jul 21, 2023
0f53242
Re-run gendependabot
MaxKsyunz Jul 21, 2023
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
9 changes: 9 additions & 0 deletions .chloggen/opensearch-exporter.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
change_type: new_component

component: opensearchexporter

note: exports OpenTelemetry signals to [OpenSearch](https://opensearch.org/).

issues: [23611]

subtext:
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ exporter/logzioexporter/ @open-telemetry/collect
exporter/lokiexporter/ @open-telemetry/collector-contrib-approvers @gramidt @gouthamve @jpkrohling @kovrus @mar4uk
exporter/mezmoexporter/ @open-telemetry/collector-contrib-approvers @dashpole @billmeyer @gjanco
exporter/opencensusexporter/ @open-telemetry/collector-contrib-approvers @open-telemetry/collector-approvers
exporter/opensearchexporter/ @open-telemetry/collector-contrib-approvers @Aneurysm9 @MitchellGale @MaxKsyunz @YANG-DB
exporter/parquetexporter/ @open-telemetry/collector-contrib-approvers @atoulme
exporter/prometheusexporter/ @open-telemetry/collector-contrib-approvers @Aneurysm9
exporter/prometheusremotewriteexporter/ @open-telemetry/collector-contrib-approvers @Aneurysm9 @rapphil
Expand Down
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/bug_report.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ body:
- exporter/loki
- exporter/mezmo
- exporter/opencensus
- exporter/opensearch
- exporter/parquet
- exporter/prometheus
- exporter/prometheusremotewrite
Expand Down
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/feature_request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ body:
- exporter/loki
- exporter/mezmo
- exporter/opencensus
- exporter/opensearch
- exporter/parquet
- exporter/prometheus
- exporter/prometheusremotewrite
Expand Down
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/other.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ body:
- exporter/loki
- exporter/mezmo
- exporter/opencensus
- exporter/opensearch
- exporter/parquet
- exporter/prometheus
- exporter/prometheusremotewrite
Expand Down
10 changes: 5 additions & 5 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,11 @@ updates:
schedule:
interval: "weekly"
day: "wednesday"
- package-ecosystem: "gomod"
directory: "/exporter/opensearchexporter"
schedule:
interval: "weekly"
day: "wednesday"
- package-ecosystem: "gomod"
directory: "/exporter/parquetexporter"
schedule:
Expand Down Expand Up @@ -1097,8 +1102,3 @@ updates:
schedule:
interval: "weekly"
day: "wednesday"
- package-ecosystem: "gomod"
directory: "/receiver/syslogreceiver"
Aneurysm9 marked this conversation as resolved.
Show resolved Hide resolved
schedule:
interval: "weekly"
day: "wednesday"
1 change: 1 addition & 0 deletions exporter/opensearchexporter/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../../Makefile.Common
66 changes: 66 additions & 0 deletions exporter/opensearchexporter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# OpenSearch Exporter

| Status | |
| ------------------------ |-----------|
| Stability | [devel] |
| Supported pipeline types | traces |
| Distributions | [contrib] |

This exporter supports sending OpenTelemetry signals as documents to [OpenSearch](https://www.opensearch.org).

The documents are sent using [observability catalog](https://github.com/opensearch-project/opensearch-catalog/tree/main/schema/observability) schema.

## Configuration options

- `endpoints`: List of OpenSearch URLs. If endpoints is missing, the
OPENSEARCH_URL environment variable will be used.
Aneurysm9 marked this conversation as resolved.
Show resolved Hide resolved
- `num_workers` (optional): Number of workers publishing bulk requests concurrently.
Aneurysm9 marked this conversation as resolved.
Show resolved Hide resolved
- `dataset` (default=`default`) a user-provided label. It is used to construct the name of the destination index or data stream.
- `namespace` (default=`namespace`)a user-provided label. It is used to construct the name of the destination index or data stream.
Aneurysm9 marked this conversation as resolved.
Show resolved Hide resolved
- `flush`: Event bulk buffer flush settings
- `bytes` (default=5242880): Write buffer flush limit.
- `interval` (default=30s): Write buffer time limit.
Aneurysm9 marked this conversation as resolved.
Show resolved Hide resolved
- `retry`: Event retry settings
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably use the exporterhelper.RetrySettings type to provide consistency of configuration across exporters.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These values are used to create a backoff function for the OpenSearch client.
We'll check if exporterhelper.RetrySettings can be used here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The config struct can be changed to use exporterhelper.RetrySettings but the implied behaviour may be different.

exporterhelper.WithRetry retries a batch of trace records, right? OpenSearch supports retrying one failed document from a bulk indexing request.

Would it be more appropriate to log documents that OpenSearch failed to index and move on? Currently they are added back to the bulk indexer queue to be tried later.

Copy link
Member

@Aneurysm9 Aneurysm9 Jul 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use the consumererror.Traces type to return an error containing the spans that failed to export. The exporterhelper error handler will unwrap the error, extract the spans, and replace the request with one containing just the failed spans.

- `enabled` (default=true): Enable/Disable event retry on error. Retry
support is enabled by default.
- `max_requests` (default=3): Number of HTTP request retries.
- `initial_interval` (default=100ms): Initial waiting time if a HTTP request failed.
- `max_interval` (default=1m): Max waiting time if a HTTP request failed.

### HTTP settings
Aneurysm9 marked this conversation as resolved.
Show resolved Hide resolved

- `read_buffer_size` (default=0): Read buffer size.
- `write_buffer_size` (default=0): Write buffer size used when.
- `timeout` (default=90s): HTTP request time limit.
- `headers` (optional): Headers to be send with each HTTP request.

### Security and Authentication settings
Aneurysm9 marked this conversation as resolved.
Show resolved Hide resolved

- `user` (optional): Username used for HTTP Basic Authentication.
- `password` (optional): Password used for HTTP Basic Authentication.

### TLS settings
- `ca_file` (optional): Root Certificate Authority (CA) certificate, for
verifying the server's identity, if TLS is enabled.
- `cert_file` (optional): Client TLS certificate.
- `key_file` (optional): Client TLS key.
- `insecure` (optional): In gRPC when set to true, this is used to disable the client transport security. In HTTP, this disables verifying the server's certificate chain and host name.
- `insecure_skip_verify` (optional): Will enable TLS but not verify the certificate.
is enabled.

## Example

```yaml
exporters:
opensearch/trace:
endpoints: [https://opensearch.example.com:9200]
# ······
service:
pipelines:
traces:
receivers: [otlp]
exporters: [opensearch/trace]
processors: [batch]
```
[devel]:https://github.com/open-telemetry/opentelemetry-collector#development
[contrib]:https://github.com/open-telemetry/opentelemetry-collector-releases/tree/main/distributions/otelcol-contrib
122 changes: 122 additions & 0 deletions exporter/opensearchexporter/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package opensearchexporter // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/opensearchexporter"

import (
"errors"
"os"
"time"

"go.opentelemetry.io/collector/config/configopaque"
"go.opentelemetry.io/collector/config/configtls"
)

const (
defaultOpenSearchEnvName = "OPENSEARCH_URL"
)

// Config defines configuration for OpenSearch exporter.
type Config struct {
Aneurysm9 marked this conversation as resolved.
Show resolved Hide resolved

// Endpoints holds the OpenSearch URLs the exporter should send events to.
//
// OPENSEARCH_URL environment variable is not set.
Endpoints []string `mapstructure:"endpoints"`

// NumWorkers configures the number of workers publishing bulk requests.
NumWorkers int `mapstructure:"num_workers"`

HTTPClientSettings `mapstructure:",squash"`
Retry RetrySettings `mapstructure:"retry"`
Flush FlushSettings `mapstructure:"flush"`
Namespace string `mapstructure:"namespace"`
Dataset string `mapstructure:"dataset"`
}

type HTTPClientSettings struct {
Authentication AuthenticationSettings `mapstructure:",squash"`

// ReadBufferSize for HTTP client. See http.Transport.ReadBufferSize.
ReadBufferSize int `mapstructure:"read_buffer_size"`

// WriteBufferSize for HTTP client. See http.Transport.WriteBufferSize.
WriteBufferSize int `mapstructure:"write_buffer_size"`

// Timeout configures the HTTP request timeout.
Timeout time.Duration `mapstructure:"timeout"`

// Headers allows users to configure optional HTTP headers that
// will be sent with each HTTP request.
Headers map[string]string `mapstructure:"headers,omitempty"`

configtls.TLSClientSetting `mapstructure:"tls,omitempty"`
}

// AuthenticationSettings defines user authentication related settings.
type AuthenticationSettings struct {
// User is used to configure HTTP Basic Authentication.
User string `mapstructure:"user"`

// Password is used to configure HTTP Basic Authentication.
Password configopaque.String `mapstructure:"password"`
}

// FlushSettings defines settings for configuring the write buffer flushing
// policy in the OpenSearch exporter. The exporter sends a bulk request with
// all events already serialized into the send-buffer.
type FlushSettings struct {
// Bytes sets the send buffer flushing limit.
Bytes int `mapstructure:"bytes"`

// Interval configures the max age of a document in the send buffer.
Interval time.Duration `mapstructure:"interval"`
}

// RetrySettings defines settings for the HTTP request retries in the OpenSearch exporter.
// Failed sends are retried with exponential backoff.
type RetrySettings struct {
// Enabled allows users to disable retry without having to comment out all settings.
Enabled bool `mapstructure:"enabled"`

// MaxRequests configures how often an HTTP request is retried before it is assumed to be failed.
MaxRequests int `mapstructure:"max_requests"`

// InitialInterval configures the initial waiting time if a request failed.
InitialInterval time.Duration `mapstructure:"initial_interval"`

// MaxInterval configures the max waiting time if consecutive requests failed.
MaxInterval time.Duration `mapstructure:"max_interval"`
}

type MappingsSettings struct {
// Mode configures the field mappings.
Mode string `mapstructure:"mode"`

// Try to find and remove duplicate fields
Dedup bool `mapstructure:"dedup"`

Dedot bool `mapstructure:"dedot"`
}

var (
errConfigNoEndpoint = errors.New("endpoints must be specified")
errConfigEmptyEndpoint = errors.New("endpoints must not include empty entries")
)

// Validate validates the opensearch server configuration.
func (cfg *Config) Validate() error {
if len(cfg.Endpoints) == 0 {
if os.Getenv(defaultOpenSearchEnvName) == "" {
return errConfigNoEndpoint
}
}

for _, endpoint := range cfg.Endpoints {
if endpoint == "" {
return errConfigEmptyEndpoint
}
}

return nil
}
58 changes: 58 additions & 0 deletions exporter/opensearchexporter/factory.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package opensearchexporter // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/opensearchexporter"

import (
"context"
"time"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/exporter"
"go.opentelemetry.io/collector/exporter/exporterhelper"
"go.opentelemetry.io/collector/pdata/ptrace"
)

const (
// The value of "type" key in configuration.
typeStr = "opensearch"
// The stability level of the exporter.
stability = component.StabilityLevelDevelopment
)

// NewFactory creates a factory for OpenSearch exporter.
func NewFactory() exporter.Factory {
return exporter.NewFactory(
typeStr,
createDefaultConfig,
exporter.WithTraces(createTracesExporter, stability),
)
}

func createDefaultConfig() component.Config {
return &Config{
HTTPClientSettings: HTTPClientSettings{
Timeout: 90 * time.Second,
},
Namespace: "",
Dataset: "",
Aneurysm9 marked this conversation as resolved.
Show resolved Hide resolved
Retry: RetrySettings{
Enabled: true,
MaxRequests: 3,
InitialInterval: 100 * time.Millisecond,
MaxInterval: 1 * time.Minute,
},
}
}

func createTracesExporter(ctx context.Context,
set exporter.CreateSettings,
cfg component.Config) (exporter.Traces, error) {

return exporterhelper.NewTracesExporter(ctx, set, cfg, func(ctx context.Context, ld ptrace.Traces) error {
return nil
},
exporterhelper.WithShutdown(func(ctx context.Context) error {
return nil
}))
}
47 changes: 47 additions & 0 deletions exporter/opensearchexporter/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
module github.com/open-telemetry/opentelemetry-collector-contrib/exporter/opensearchexporter

go 1.19

require (
go.opentelemetry.io/collector/component v0.81.0
go.opentelemetry.io/collector/config/configopaque v0.81.0
go.opentelemetry.io/collector/config/configtls v0.81.0
go.opentelemetry.io/collector/exporter v0.81.0
go.opentelemetry.io/collector/pdata v1.0.0-rcv0013
)

require (
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/knadh/koanf v1.5.0 // indirect
github.com/knadh/koanf/v2 v2.0.1 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/mapstructure v1.5.1-0.20220423185008-bf980b35cac4 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/collector v0.81.0 // indirect
go.opentelemetry.io/collector/config/configtelemetry v0.81.0 // indirect
go.opentelemetry.io/collector/confmap v0.81.0 // indirect
go.opentelemetry.io/collector/consumer v0.81.0 // indirect
go.opentelemetry.io/collector/extension v0.81.0 // indirect
go.opentelemetry.io/collector/featuregate v1.0.0-rcv0013 // indirect
go.opentelemetry.io/collector/processor v0.81.0 // indirect
go.opentelemetry.io/collector/receiver v0.81.0 // indirect
go.opentelemetry.io/otel v1.16.0 // indirect
go.opentelemetry.io/otel/metric v1.16.0 // indirect
go.opentelemetry.io/otel/trace v1.16.0 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.24.0 // indirect
golang.org/x/net v0.11.0 // indirect
golang.org/x/sys v0.9.0 // indirect
golang.org/x/text v0.10.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230530153820-e85fd2cbaebc // indirect
google.golang.org/grpc v1.56.1 // indirect
google.golang.org/protobuf v1.31.0 // indirect
)
Loading