Skip to content

Commit

Permalink
exporter/datadogexporter: add support for metrics as APM Stats (#16852)
Browse files Browse the repository at this point in the history
* exporter/datadogexporter: add support for metrics as APM Stats

This change adds the APM Stats consumer support into the Datadog
Exporter.

* Add changelog
  • Loading branch information
gbbr authored Dec 12, 2022
1 parent 9717194 commit 135f02c
Show file tree
Hide file tree
Showing 16 changed files with 397 additions and 102 deletions.
16 changes: 16 additions & 0 deletions .chloggen/gbbr_processor-1-exporter.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: datadogexporter

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Added support for consuming Datadog APM Stats as OTLP Metrics (usually generated by the datadogprocessor).

# One or more tracking issues related to the change
issues: [16853]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:
7 changes: 4 additions & 3 deletions cmd/configschema/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ require (
github.com/ClickHouse/clickhouse-go/v2 v2.4.3 // indirect
github.com/DataDog/agent-payload/v5 v5.0.43 // indirect
github.com/DataDog/datadog-agent/pkg/obfuscate v0.41.0-rc.3 // indirect
github.com/DataDog/datadog-agent/pkg/otlp/model v0.41.0-rc.3.0.20221114173638-98b8cd5ae742 // indirect
github.com/DataDog/datadog-agent/pkg/otlp/model v0.41.0-rc.3.0.20221207140548-a500ba1a95be // indirect
github.com/DataDog/datadog-agent/pkg/quantile v0.41.0-rc.3.0.20221114173638-98b8cd5ae742 // indirect
github.com/DataDog/datadog-agent/pkg/remoteconfig/state v0.41.0-rc.3 // indirect
github.com/DataDog/datadog-agent/pkg/trace v0.41.0-rc.3.0.20221114173638-98b8cd5ae742 // indirect
github.com/DataDog/datadog-agent/pkg/remoteconfig/state v0.41.0-rc.3.0.20221207140548-a500ba1a95be // indirect
github.com/DataDog/datadog-agent/pkg/trace v0.41.0-rc.3.0.20221207140548-a500ba1a95be // indirect
github.com/DataDog/datadog-agent/pkg/util/cgroups v0.41.0-rc.3 // indirect
github.com/DataDog/datadog-agent/pkg/util/log v0.41.0-rc.3 // indirect
github.com/DataDog/datadog-agent/pkg/util/scrubber v0.41.0-rc.3 // indirect
Expand Down Expand Up @@ -198,6 +198,7 @@ require (
github.com/golang-sql/sqlexp v0.1.0 // indirect
github.com/golang/glog v1.0.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/mock v1.6.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/cadvisor v0.46.0 // indirect
Expand Down
13 changes: 7 additions & 6 deletions cmd/configschema/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions cmd/otelcontribcol/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ require (
github.com/ClickHouse/clickhouse-go/v2 v2.4.3 // indirect
github.com/DataDog/agent-payload/v5 v5.0.43 // indirect
github.com/DataDog/datadog-agent/pkg/obfuscate v0.41.0-rc.3 // indirect
github.com/DataDog/datadog-agent/pkg/otlp/model v0.41.0-rc.3.0.20221114173638-98b8cd5ae742 // indirect
github.com/DataDog/datadog-agent/pkg/otlp/model v0.41.0-rc.3.0.20221207140548-a500ba1a95be // indirect
github.com/DataDog/datadog-agent/pkg/quantile v0.41.0-rc.3.0.20221114173638-98b8cd5ae742 // indirect
github.com/DataDog/datadog-agent/pkg/remoteconfig/state v0.41.0-rc.3 // indirect
github.com/DataDog/datadog-agent/pkg/trace v0.41.0-rc.3.0.20221114173638-98b8cd5ae742 // indirect
github.com/DataDog/datadog-agent/pkg/remoteconfig/state v0.41.0-rc.3.0.20221207140548-a500ba1a95be // indirect
github.com/DataDog/datadog-agent/pkg/trace v0.41.0-rc.3.0.20221207140548-a500ba1a95be // indirect
github.com/DataDog/datadog-agent/pkg/util/cgroups v0.41.0-rc.3 // indirect
github.com/DataDog/datadog-agent/pkg/util/log v0.41.0-rc.3 // indirect
github.com/DataDog/datadog-agent/pkg/util/scrubber v0.41.0-rc.3 // indirect
Expand Down Expand Up @@ -187,6 +187,7 @@ require (
github.com/golang-sql/sqlexp v0.1.0 // indirect
github.com/golang/glog v1.0.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/mock v1.6.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/cadvisor v0.46.0 // indirect
Expand Down
13 changes: 7 additions & 6 deletions cmd/otelcontribcol/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 41 additions & 7 deletions exporter/datadogexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"time"

"github.com/DataDog/datadog-agent/pkg/otlp/model/source"
"github.com/DataDog/datadog-agent/pkg/trace/agent"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/config/confignet"
Expand Down Expand Up @@ -49,6 +50,11 @@ type factory struct {
sourceProvider source.Provider
providerErr error

onceAgent sync.Once // ensures agent only gets instantiated once
wg sync.WaitGroup // waits for agent to exit
agent *agent.Agent // agent processes incoming traces and stats
agentErr error // specifies any error occurred while instantiating agent

registry *featuregate.Registry
}

Expand All @@ -59,6 +65,23 @@ func (f *factory) SourceProvider(set component.TelemetrySettings, configHostname
return f.sourceProvider, f.providerErr
}

func (f *factory) TraceAgent(ctx context.Context, params exporter.CreateSettings, cfg *Config, sourceProvider source.Provider) (*agent.Agent, error) {
f.onceAgent.Do(func() {
agnt, err := newTraceAgent(ctx, params, cfg, sourceProvider)
if err != nil {
f.agentErr = err
return
}
f.wg.Add(1)
go func() {
defer f.wg.Done()
agnt.Run()
}()
f.agent = agnt
})
return f.agent, f.agentErr
}

func newFactoryWithRegistry(registry *featuregate.Registry) exporter.Factory {
f := &factory{registry: registry}
return exporter.NewFactory(
Expand Down Expand Up @@ -163,8 +186,13 @@ func (f *factory) createMetricsExporter(
}

ctx, cancel := context.WithCancel(ctx)
// cancel() runs on shutdown
var pushMetricsFn consumer.ConsumeMetricsFunc

traceagent, err := f.TraceAgent(ctx, set, cfg, hostProvider)
if err != nil {
cancel()
return nil, fmt.Errorf("failed to start trace-agent: %w", err)
}
if cfg.OnlyMetadata {
pushMetricsFn = func(_ context.Context, md pmetric.Metrics) error {
// only sending metadata use only metrics
Expand All @@ -179,9 +207,10 @@ func (f *factory) createMetricsExporter(
return nil
}
} else {
exp, metricsErr := newMetricsExporter(ctx, set, cfg, &f.onceMetadata, hostProvider)
exp, metricsErr := newMetricsExporter(ctx, set, cfg, &f.onceMetadata, hostProvider, traceagent)
if metricsErr != nil {
cancel()
cancel() // first cancel context
f.wg.Wait() // then wait for shutdown
return nil, metricsErr
}
pushMetricsFn = exp.PushMetricsDataScrubbed
Expand Down Expand Up @@ -226,8 +255,13 @@ func (f *factory) createTracesExporter(
if err != nil {
return nil, fmt.Errorf("failed to build hostname provider: %w", err)
}
ctx, cancel := context.WithCancel(ctx) // nolint:govet
ctx, cancel := context.WithCancel(ctx)
// cancel() runs on shutdown
traceagent, err := f.TraceAgent(ctx, set, cfg, hostProvider)
if err != nil {
cancel()
return nil, fmt.Errorf("failed to start trace-agent: %w", err)
}
if cfg.OnlyMetadata {
// only host metadata needs to be sent, once.
pusher = func(_ context.Context, td ptrace.Traces) error {
Expand All @@ -245,15 +279,15 @@ func (f *factory) createTracesExporter(
return nil
}
} else {
tracex, err2 := newTracesExporter(ctx, set, cfg, &f.onceMetadata, hostProvider)
tracex, err2 := newTracesExporter(ctx, set, cfg, &f.onceMetadata, hostProvider, traceagent)
if err2 != nil {
cancel()
return nil, err2
}
pusher = tracex.consumeTraces
stop = func(context.Context) error {
cancel() // first cancel context
tracex.waitShutdown() // then wait for shutdown
cancel() // first cancel context
f.wg.Wait() // then wait for shutdown
return nil
}
}
Expand Down
11 changes: 6 additions & 5 deletions exporter/datadogexporter/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ go 1.18

require (
github.com/DataDog/agent-payload/v5 v5.0.43
github.com/DataDog/datadog-agent/pkg/otlp/model v0.41.0-rc.3.0.20221114173638-98b8cd5ae742
github.com/DataDog/datadog-agent/pkg/otlp/model v0.41.0-rc.3.0.20221207140548-a500ba1a95be
github.com/DataDog/datadog-agent/pkg/quantile v0.41.0-rc.3.0.20221114173638-98b8cd5ae742
github.com/DataDog/datadog-agent/pkg/trace v0.41.0-rc.3.0.20221114173638-98b8cd5ae742
github.com/DataDog/datadog-agent/pkg/trace v0.41.0-rc.3.0.20221207140548-a500ba1a95be
github.com/DataDog/datadog-api-client-go/v2 v2.5.0
github.com/DataDog/gohai v0.0.0-20220718130825-1776f9beb9cc
github.com/DataDog/sketches-go v1.4.1
github.com/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp v0.34.3-0.20221202192616-0186b89ba914
github.com/aws/aws-sdk-go v1.44.155
github.com/cenkalti/backoff/v4 v4.2.0
Expand All @@ -34,6 +35,7 @@ require (
go.opentelemetry.io/collector/semconv v0.67.0
go.uber.org/multierr v1.8.0
go.uber.org/zap v1.24.0
google.golang.org/protobuf v1.28.1
gopkg.in/yaml.v2 v2.4.0
gopkg.in/zorkian/go-datadog-api.v2 v2.30.0
k8s.io/apimachinery v0.25.4
Expand All @@ -45,12 +47,11 @@ require (
cloud.google.com/go/compute/metadata v0.2.1 // indirect
contrib.go.opencensus.io/exporter/prometheus v0.4.2 // indirect
github.com/DataDog/datadog-agent/pkg/obfuscate v0.41.0-rc.3 // indirect
github.com/DataDog/datadog-agent/pkg/remoteconfig/state v0.41.0-rc.3 // indirect
github.com/DataDog/datadog-agent/pkg/remoteconfig/state v0.41.0-rc.3.0.20221207140548-a500ba1a95be // indirect
github.com/DataDog/datadog-agent/pkg/util/cgroups v0.41.0-rc.3 // indirect
github.com/DataDog/datadog-agent/pkg/util/log v0.41.0-rc.3 // indirect
github.com/DataDog/datadog-agent/pkg/util/scrubber v0.41.0-rc.3 // indirect
github.com/DataDog/datadog-go/v5 v5.1.1 // indirect
github.com/DataDog/sketches-go v1.4.1 // indirect
github.com/DataDog/zstd v1.5.0 // indirect
github.com/Microsoft/go-winio v0.5.2 // indirect
github.com/PuerkitoBio/purell v1.1.1 // indirect
Expand Down Expand Up @@ -88,6 +89,7 @@ require (
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/glog v1.0.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/mock v1.6.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/gnostic v0.5.7-v3refs // indirect
Expand Down Expand Up @@ -177,7 +179,6 @@ require (
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20221202195650-67e5cbc046fd // indirect
google.golang.org/grpc v1.51.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/api v0.25.4 // indirect
Expand Down
Loading

0 comments on commit 135f02c

Please sign in to comment.