forked from open-telemetry/opentelemetry-collector-contrib
-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.go
110 lines (85 loc) · 3.31 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package sapmexporter // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/sapmexporter"
import (
"errors"
"fmt"
"net/url"
sapmclient "github.com/signalfx/sapm-proto/client"
"go.opentelemetry.io/collector/config/configopaque"
"go.opentelemetry.io/collector/config/configretry"
"go.opentelemetry.io/collector/exporter/exporterhelper"
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/splunk"
)
const (
defaultEndpointScheme = "https"
)
// Config defines configuration for SAPM exporter.
type Config struct {
// Endpoint is the destination to where traces will be sent to in SAPM format.
// It must be a full URL and include the scheme, port and path e.g, https://ingest.signalfx.com/v2/trace
Endpoint string `mapstructure:"endpoint"`
// AccessToken is the authentication token provided by SignalFx.
AccessToken configopaque.String `mapstructure:"access_token"`
// NumWorkers is the number of workers that should be used to export traces.
// Exporter can make as many requests in parallel as the number of workers. Defaults to 8.
NumWorkers uint `mapstructure:"num_workers"`
// MaxConnections is used to set a limit to the maximum idle HTTP connection the exporter can keep open.
MaxConnections uint `mapstructure:"max_connections"`
// Disable compression. If set to true then Compression field is ignored.
DisableCompression bool `mapstructure:"disable_compression"`
// Compression method to use (gzip or zstd). Ignored if DisableCompression=true.
// If unspecified defaults to gzip.
Compression string `mapstructure:"compression"`
// Log detailed response from trace ingest.
LogDetailedResponse bool `mapstructure:"log_detailed_response"`
splunk.AccessTokenPassthroughConfig `mapstructure:",squash"`
TimeoutSettings exporterhelper.TimeoutConfig `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct.
QueueSettings exporterhelper.QueueConfig `mapstructure:"sending_queue"`
configretry.BackOffConfig `mapstructure:"retry_on_failure"`
}
func (c *Config) Validate() error {
if c.Endpoint == "" {
return errors.New("`endpoint` not specified")
}
_, err := url.Parse(c.Endpoint)
if err != nil {
return err
}
switch c.Compression {
// Valid compression methods.
case "", // no compression
string(sapmclient.CompressionMethodGzip),
string(sapmclient.CompressionMethodZstd):
default:
return fmt.Errorf("invalid compression %q", c.Compression)
}
return nil
}
func (c *Config) clientOptions() []sapmclient.Option {
e, _ := url.Parse(c.Endpoint)
endpoint := c.Endpoint
if e.Scheme == "" {
e.Scheme = defaultEndpointScheme
endpoint = e.String()
}
opts := []sapmclient.Option{
sapmclient.WithEndpoint(endpoint),
}
if c.NumWorkers > 0 {
opts = append(opts, sapmclient.WithWorkers(c.NumWorkers))
}
if c.MaxConnections > 0 {
opts = append(opts, sapmclient.WithMaxConnections(c.MaxConnections))
}
if c.AccessToken != "" {
opts = append(opts, sapmclient.WithAccessToken(string(c.AccessToken)))
}
if c.DisableCompression {
opts = append(opts, sapmclient.WithDisabledCompression())
}
if c.Compression != "" {
opts = append(opts, sapmclient.WithCompressionMethod(sapmclient.CompressionMethod(c.Compression)))
}
return opts
}