From 77d48a50e0b6f46dfea3159e8ea375abc5e3deb5 Mon Sep 17 00:00:00 2001 From: Pablo Baeyens Date: Tue, 23 Nov 2021 11:22:32 +0100 Subject: [PATCH] [exporter/datadogexporter] Rely on http.Client's timeout instead of in exporterhelper's --- exporter/datadogexporter/factory.go | 6 ++++-- exporter/datadogexporter/internal/metadata/metadata.go | 2 +- exporter/datadogexporter/internal/utils/http.go | 5 +++-- exporter/datadogexporter/metrics_exporter.go | 2 +- exporter/datadogexporter/trace_connection.go | 6 +++--- exporter/datadogexporter/traces_exporter.go | 2 +- 6 files changed, 13 insertions(+), 10 deletions(-) diff --git a/exporter/datadogexporter/factory.go b/exporter/datadogexporter/factory.go index 298cb3cd6ed9..4bc6bd67b3af 100644 --- a/exporter/datadogexporter/factory.go +++ b/exporter/datadogexporter/factory.go @@ -154,7 +154,8 @@ func createMetricsExporter( cfg, set, pushMetricsFn, - exporterhelper.WithTimeout(cfg.TimeoutSettings), + // explicitly disable since we rely on http.Client timeout logic. + exporterhelper.WithTimeout(exporterhelper.TimeoutSettings{Timeout: 0 * time.Second}), exporterhelper.WithRetry(cfg.RetrySettings), exporterhelper.WithQueue(cfg.QueueSettings), exporterhelper.WithShutdown(func(context.Context) error { @@ -207,7 +208,8 @@ func createTracesExporter( cfg, set, pushTracesFn, - exporterhelper.WithTimeout(cfg.TimeoutSettings), + // explicitly disable since we rely on http.Client timeout logic. + exporterhelper.WithTimeout(exporterhelper.TimeoutSettings{Timeout: 0 * time.Second}), exporterhelper.WithRetry(cfg.RetrySettings), exporterhelper.WithQueue(cfg.QueueSettings), exporterhelper.WithShutdown(func(context.Context) error { diff --git a/exporter/datadogexporter/internal/metadata/metadata.go b/exporter/datadogexporter/internal/metadata/metadata.go index 097ab18fbe63..69a843f3a50d 100644 --- a/exporter/datadogexporter/internal/metadata/metadata.go +++ b/exporter/datadogexporter/internal/metadata/metadata.go @@ -154,7 +154,7 @@ func pushMetadata(cfg *config.Config, buildInfo component.BuildInfo, metadata *H req, _ := http.NewRequest(http.MethodPost, path, bytes.NewBuffer(buf)) utils.SetDDHeaders(req.Header, buildInfo, cfg.API.Key) utils.SetExtraHeaders(req.Header, utils.JSONHeaders) - client := utils.NewHTTPClient(10 * time.Second) + client := utils.NewHTTPClient(cfg.TimeoutSettings) resp, err := client.Do(req) if err != nil { diff --git a/exporter/datadogexporter/internal/utils/http.go b/exporter/datadogexporter/internal/utils/http.go index 62e4446a391a..ac2848434ef1 100644 --- a/exporter/datadogexporter/internal/utils/http.go +++ b/exporter/datadogexporter/internal/utils/http.go @@ -22,6 +22,7 @@ import ( "time" "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/exporter/exporterhelper" ) var ( @@ -38,9 +39,9 @@ var ( ) // NewHTTPClient returns a http.Client configured with the Agent options. -func NewHTTPClient(timeout time.Duration) *http.Client { +func NewHTTPClient(settings exporterhelper.TimeoutSettings) *http.Client { return &http.Client{ - Timeout: timeout, + Timeout: settings.Timeout, Transport: &http.Transport{ Proxy: http.ProxyFromEnvironment, DialContext: (&net.Dialer{ diff --git a/exporter/datadogexporter/metrics_exporter.go b/exporter/datadogexporter/metrics_exporter.go index ddbcabaa3229..f37f022175d0 100644 --- a/exporter/datadogexporter/metrics_exporter.go +++ b/exporter/datadogexporter/metrics_exporter.go @@ -95,7 +95,7 @@ func translatorFromConfig(logger *zap.Logger, cfg *config.Config) (*translator.T func newMetricsExporter(ctx context.Context, params component.ExporterCreateSettings, cfg *config.Config) (*metricsExporter, error) { client := utils.CreateClient(cfg.API.Key, cfg.Metrics.TCPAddr.Endpoint) client.ExtraHeader["User-Agent"] = utils.UserAgent(params.BuildInfo) - client.HttpClient = utils.NewHTTPClient(10 * time.Second) + client.HttpClient = utils.NewHTTPClient(cfg.TimeoutSettings) utils.ValidateAPIKey(params.Logger, client) diff --git a/exporter/datadogexporter/trace_connection.go b/exporter/datadogexporter/trace_connection.go index c448a1975966..adfcfdfc8792 100644 --- a/exporter/datadogexporter/trace_connection.go +++ b/exporter/datadogexporter/trace_connection.go @@ -25,6 +25,7 @@ import ( "github.com/DataDog/datadog-agent/pkg/trace/exportable/stats" "github.com/gogo/protobuf/proto" "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/exporter/exporterhelper" "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/datadogexporter/internal/utils" ) @@ -45,19 +46,18 @@ type traceEdgeConnectionImpl struct { } const ( - traceEdgeTimeout time.Duration = 10 * time.Second traceEdgeRetryInterval time.Duration = 10 * time.Second ) // createTraceEdgeConnection returns a new traceEdgeConnection -func createTraceEdgeConnection(rootURL, apiKey string, buildInfo component.BuildInfo) traceEdgeConnection { +func createTraceEdgeConnection(rootURL, apiKey string, buildInfo component.BuildInfo, settings exporterhelper.TimeoutSettings) traceEdgeConnection { return &traceEdgeConnectionImpl{ traceURL: rootURL + "/api/v0.2/traces", statsURL: rootURL + "/api/v0.2/stats", buildInfo: buildInfo, apiKey: apiKey, - client: utils.NewHTTPClient(traceEdgeTimeout), + client: utils.NewHTTPClient(settings), } } diff --git a/exporter/datadogexporter/traces_exporter.go b/exporter/datadogexporter/traces_exporter.go index 490ff81d15ec..c769eb23051e 100644 --- a/exporter/datadogexporter/traces_exporter.go +++ b/exporter/datadogexporter/traces_exporter.go @@ -78,7 +78,7 @@ func newTracesExporter(ctx context.Context, params component.ExporterCreateSetti params: params, cfg: cfg, ctx: ctx, - edgeConnection: createTraceEdgeConnection(cfg.Traces.TCPAddr.Endpoint, cfg.API.Key, params.BuildInfo), + edgeConnection: createTraceEdgeConnection(cfg.Traces.TCPAddr.Endpoint, cfg.API.Key, params.BuildInfo, cfg.TimeoutSettings), obfuscator: obfuscator, client: client, denylister: denylister,