-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
Copy pathfactory.go
193 lines (169 loc) · 5.73 KB
/
factory.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package signalfxexporter // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/signalfxexporter"
import (
"context"
"errors"
"fmt"
"time"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/confighttp"
"go.opentelemetry.io/collector/config/configretry"
"go.opentelemetry.io/collector/exporter"
"go.opentelemetry.io/collector/exporter/exporterhelper"
"go.uber.org/zap"
"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/signalfxexporter/internal/correlation"
"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/signalfxexporter/internal/metadata"
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/splunk"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/batchperresourceattr"
)
const (
defaultHTTPTimeout = time.Second * 10
defaultHTTP2ReadIdleTimeout = time.Second * 10
defaultHTTP2PingTimeout = time.Second * 10
defaultMaxConns = 100
defaultDimMaxBuffered = 10000
defaultDimSendDelay = 10 * time.Second
defaultDimMaxConnsPerHost = 20
defaultDimMaxIdleConns = 20
defaultDimMaxIdleConnsPerHost = 20
)
// NewFactory creates a factory for SignalFx exporter.
func NewFactory() exporter.Factory {
return exporter.NewFactory(
metadata.Type,
createDefaultConfig,
exporter.WithMetrics(createMetricsExporter, metadata.MetricsStability),
exporter.WithLogs(createLogsExporter, metadata.LogsStability),
exporter.WithTraces(createTracesExporter, metadata.TracesStability),
)
}
func createDefaultConfig() component.Config {
maxConnCount := defaultMaxConns
idleConnTimeout := 30 * time.Second
timeout := 10 * time.Second
return &Config{
BackOffConfig: configretry.NewDefaultBackOffConfig(),
QueueSettings: exporterhelper.NewDefaultQueueSettings(),
ClientConfig: confighttp.ClientConfig{
Timeout: defaultHTTPTimeout,
MaxIdleConns: &maxConnCount,
MaxIdleConnsPerHost: &maxConnCount,
IdleConnTimeout: &idleConnTimeout,
HTTP2ReadIdleTimeout: defaultHTTP2ReadIdleTimeout,
HTTP2PingTimeout: defaultHTTP2PingTimeout,
},
AccessTokenPassthroughConfig: splunk.AccessTokenPassthroughConfig{
AccessTokenPassthrough: true,
},
DeltaTranslationTTL: 3600,
Correlation: correlation.DefaultConfig(),
NonAlphanumericDimensionChars: "_-.",
DimensionClient: DimensionClientConfig{
SendDelay: defaultDimSendDelay,
MaxBuffered: defaultDimMaxBuffered,
MaxConnsPerHost: defaultDimMaxConnsPerHost,
MaxIdleConns: defaultDimMaxIdleConns,
MaxIdleConnsPerHost: defaultDimMaxIdleConnsPerHost,
IdleConnTimeout: idleConnTimeout,
Timeout: timeout,
},
}
}
func createTracesExporter(
ctx context.Context,
set exporter.Settings,
eCfg component.Config,
) (exporter.Traces, error) {
cfg := eCfg.(*Config)
corrCfg := cfg.Correlation
if corrCfg.ClientConfig.Endpoint == "" {
apiURL, err := cfg.getAPIURL()
if err != nil {
return nil, fmt.Errorf("unable to create API URL: %w", err)
}
corrCfg.ClientConfig.Endpoint = apiURL.String()
}
if cfg.AccessToken == "" {
return nil, errors.New("access_token is required")
}
set.Logger.Info("Correlation tracking enabled", zap.String("endpoint", corrCfg.ClientConfig.Endpoint))
tracker := correlation.NewTracker(corrCfg, cfg.AccessToken, set)
return exporterhelper.NewTracesExporter(
ctx,
set,
cfg,
tracker.ProcessTraces,
exporterhelper.WithStart(tracker.Start),
exporterhelper.WithShutdown(tracker.Shutdown))
}
func createMetricsExporter(
ctx context.Context,
set exporter.Settings,
config component.Config,
) (exporter.Metrics, error) {
cfg := config.(*Config)
exp, err := newSignalFxExporter(cfg, set)
if err != nil {
return nil, err
}
me, err := exporterhelper.NewMetricsExporter(
ctx,
set,
cfg,
exp.pushMetrics,
// explicitly disable since we rely on http.Client timeout logic.
exporterhelper.WithTimeout(exporterhelper.TimeoutSettings{Timeout: 0}),
exporterhelper.WithRetry(cfg.BackOffConfig),
exporterhelper.WithQueue(cfg.QueueSettings),
exporterhelper.WithStart(exp.start),
exporterhelper.WithShutdown(exp.shutdown))
if err != nil {
return nil, err
}
// If AccessTokenPassthrough enabled, split the incoming Metrics data by splunk.SFxAccessTokenLabel,
// this ensures that we get batches of data for the same token when pushing to the backend.
if cfg.AccessTokenPassthrough {
me = &baseMetricsExporter{
Component: me,
Metrics: batchperresourceattr.NewBatchPerResourceMetrics(splunk.SFxAccessTokenLabel, me),
}
}
return &signalfMetadataExporter{
Metrics: me,
exporter: exp,
}, nil
}
func createLogsExporter(
ctx context.Context,
set exporter.Settings,
cfg component.Config,
) (exporter.Logs, error) {
expCfg := cfg.(*Config)
exp, err := newEventExporter(expCfg, set)
if err != nil {
return nil, err
}
le, err := exporterhelper.NewLogsExporter(
ctx,
set,
cfg,
exp.pushLogs,
// explicitly disable since we rely on http.Client timeout logic.
exporterhelper.WithTimeout(exporterhelper.TimeoutSettings{Timeout: 0}),
exporterhelper.WithRetry(expCfg.BackOffConfig),
exporterhelper.WithQueue(expCfg.QueueSettings),
exporterhelper.WithStart(exp.startLogs))
if err != nil {
return nil, err
}
// If AccessTokenPassthrough enabled, split the incoming Metrics data by splunk.SFxAccessTokenLabel,
// this ensures that we get batches of data for the same token when pushing to the backend.
if expCfg.AccessTokenPassthrough {
le = &baseLogsExporter{
Component: le,
Logs: batchperresourceattr.NewBatchPerResourceLogs(splunk.SFxAccessTokenLabel, le),
}
}
return le, nil
}