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

Datadog Connector Component #25057

Closed
wants to merge 36 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
ae96cd6
moving agent to an internal shared datadog folder
gord02 Jul 25, 2023
4fa8eee
resolving issues with go dependencies for internal datadog module
gord02 Jul 27, 2023
22bd82a
merging with main
gord02 Jul 27, 2023
b91c4b3
merging main into branch to resolve issues
gord02 Jul 27, 2023
1ae8754
resloving package requirements in datadog processor
gord02 Jul 27, 2023
9b72ac5
Merge branch 'open-telemetry:main' into internal
gord02 Jul 27, 2023
5d7a006
resolving issues for checks including codeowners and issues with unit…
gord02 Jul 28, 2023
d3e1eaa
Merge branch 'internal' of github.com:gord02/opentelemetry-collector-…
gord02 Jul 28, 2023
a4fcdaa
fixing code to pass checks
gord02 Jul 28, 2023
7b8dc5a
resloving issues preventing checks from passing
gord02 Jul 31, 2023
15a1921
Revert "resolving issues with go dependencies for internal datadog mo…
gord02 Jul 31, 2023
4ce4c8f
removing file files from previous commit
gord02 Jul 31, 2023
81e336a
resolving merge conflicts
gord02 Jul 31, 2023
d182bcd
working on components.go conflict issues
gord02 Aug 1, 2023
81aaf26
resolving version issues for modules
gord02 Aug 1, 2023
d3a7c40
ran make gengithub
gord02 Aug 1, 2023
c93064a
updating version of datadogexporter in go.mod file
gord02 Aug 2, 2023
36ba079
correcting other module verisons to v0.82.0
gord02 Aug 2, 2023
5cf1fda
updating dependabot
gord02 Aug 2, 2023
125a6df
Merge branch 'main' into internal
songy23 Aug 2, 2023
0c886c6
Merge branch 'main' into internal
gord02 Aug 3, 2023
a43bbae
Merge branch 'internal' of github.com:gord02/opentelemetry-collector-…
gord02 Aug 3, 2023
a91a74a
Merge branch 'main' into internal
gord02 Aug 4, 2023
b8fe633
adding new code owner
gord02 Aug 4, 2023
616cf15
Merge branch 'main' into internal
gord02 Aug 4, 2023
8b7fc12
Merge branch 'internal' of github.com:gord02/opentelemetry-collector-…
gord02 Aug 4, 2023
b7c7490
minor changes to internal moudle files
gord02 Aug 4, 2023
950a42d
Merge branch 'main' into internal
gord02 Aug 4, 2023
dd0e54e
ran 'make gengithub'
gord02 Aug 4, 2023
c8da169
manually making fixes to dependabot.yml
gord02 Aug 4, 2023
f7b7a94
removing blank and unnecessary lines
gord02 Aug 4, 2023
47c326e
Merge branch 'main' into internal
gord02 Aug 4, 2023
2cbac1e
ran 'make gendependabot'
gord02 Aug 4, 2023
1935bd1
updating versions.yaml to include internal datadog module
gord02 Aug 4, 2023
3a1f987
updating the github files
gord02 Aug 4, 2023
d2e35e9
adding code and testing for connector
gord02 Aug 7, 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
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ extension/storage/filestorage/ @open-telemetry/collect

internal/aws/ @open-telemetry/collector-contrib-approvers @Aneurysm9 @mxiamxia
internal/coreinternal/ @open-telemetry/collector-contrib-approvers @open-telemetry/collector-approvers
internal/datadog/ @open-telemetry/collector-contrib-approvers @mx-psi @gbbr @dineshg13
internal/docker/ @open-telemetry/collector-contrib-approvers @rmfitzpatrick @jamesmoessis
internal/filter/ @open-telemetry/collector-contrib-approvers @open-telemetry/collector-approvers
internal/k8sconfig/ @open-telemetry/collector-contrib-approvers @dmitryax
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 @@ -103,6 +103,7 @@ body:
- extension/storage/filestorage
- internal/aws
- internal/core
- internal/datadog
- internal/docker
- internal/filter
- internal/k8sconfig
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 @@ -97,6 +97,7 @@ body:
- extension/storage/filestorage
- internal/aws
- internal/core
- internal/datadog
- internal/docker
- internal/filter
- internal/k8sconfig
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 @@ -97,6 +97,7 @@ body:
- extension/storage/filestorage
- internal/aws
- internal/core
- internal/datadog
- internal/docker
- internal/filter
- internal/k8sconfig
Expand Down
10 changes: 5 additions & 5 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,11 @@ updates:
schedule:
interval: "weekly"
day: "wednesday"
- package-ecosystem: "gomod"
directory: "/internal/datadog"
schedule:
interval: "weekly"
day: "wednesday"
- package-ecosystem: "gomod"
directory: "/internal/docker"
schedule:
Expand Down Expand Up @@ -1097,8 +1102,3 @@ updates:
schedule:
interval: "weekly"
day: "wednesday"
- package-ecosystem: "gomod"
directory: "/receiver/sqlqueryreceiver"
schedule:
interval: "weekly"
day: "wednesday"
3 changes: 3 additions & 0 deletions cmd/configschema/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,7 @@ require (
github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/proxy v0.82.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/xray v0.82.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/internal/common v0.82.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/internal/datadog v0.82.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/internal/sharedcomponent v0.82.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/experimentalmetricmetadata v0.82.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/winperfcounters v0.82.0 // indirect
Expand Down Expand Up @@ -1119,4 +1120,6 @@ replace github.com/open-telemetry/opentelemetry-collector-contrib/extension/obse

replace github.com/open-telemetry/opentelemetry-collector-contrib/internal/k8stest => ../../internal/k8stest

replace github.com/open-telemetry/opentelemetry-collector-contrib/internal/datadog => ../../internal/datadog

replace github.com/open-telemetry/opentelemetry-collector-contrib/extension/jaegerremotesampling => ../../extension/jaegerremotesampling
1 change: 1 addition & 0 deletions cmd/otelcontribcol/builder-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ replaces:
- github.com/open-telemetry/opentelemetry-collector-contrib/exporter/cassandraexporter => ../../exporter/cassandraexporter
- github.com/open-telemetry/opentelemetry-collector-contrib/receiver/udplogreceiver => ../../receiver/udplogreceiver
- github.com/open-telemetry/opentelemetry-collector-contrib/internal/splunk => ../../internal/splunk
- github.com/open-telemetry/opentelemetry-collector-contrib/internal/datadog => ../../internal/datadog
- github.com/open-telemetry/opentelemetry-collector-contrib/receiver/podmanreceiver => ../../receiver/podmanreceiver
- github.com/open-telemetry/opentelemetry-collector-contrib/receiver/flinkmetricsreceiver => ../../receiver/flinkmetricsreceiver
- github.com/open-telemetry/opentelemetry-collector-contrib/receiver/awsecscontainermetricsreceiver => ../../receiver/awsecscontainermetricsreceiver
Expand Down
3 changes: 3 additions & 0 deletions cmd/otelcontribcol/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,7 @@ require (
github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/metrics v0.82.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/proxy v0.82.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/xray v0.82.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/internal/datadog v0.82.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/internal/docker v0.82.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/internal/filter v0.82.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/internal/k8sconfig v0.82.0 // indirect
Expand Down Expand Up @@ -782,6 +783,8 @@ replace github.com/open-telemetry/opentelemetry-collector-contrib/receiver/udplo

replace github.com/open-telemetry/opentelemetry-collector-contrib/internal/splunk => ../../internal/splunk

replace github.com/open-telemetry/opentelemetry-collector-contrib/internal/datadog => ../../internal/datadog

replace github.com/open-telemetry/opentelemetry-collector-contrib/receiver/podmanreceiver => ../../receiver/podmanreceiver

replace github.com/open-telemetry/opentelemetry-collector-contrib/receiver/flinkmetricsreceiver => ../../receiver/flinkmetricsreceiver
Expand Down
1 change: 1 addition & 0 deletions connector/datadogconnector/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../../Makefile.Common
119 changes: 119 additions & 0 deletions connector/datadogconnector/connector.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package datadogconnector // import "github.com/open-telemetry/opentelemetry-collector-contrib/connector/datadogconnector"

import (
"context"

"github.com/DataDog/datadog-agent/pkg/trace/pb"
"github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/metrics"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/pdata/ptrace"
"go.uber.org/zap"

"github.com/open-telemetry/opentelemetry-collector-contrib/internal/datadog"
)

// schema for connector
type connectorImp struct {
metricsConsumer consumer.Metrics // the next component in the pipeline to ingest data after connector
count int
logger *zap.Logger
started bool

// agent specifies the agent used to ingest traces and output APM Stats.
// It is implemented by the traceagent structure; replaced in tests.
agent datadog.Ingester

// translator specifies the translator used to transform APM Stats Payloads
// from the agent to OTLP Metrics.
translator *metrics.Translator

// in specifies the channel through which the agent will output Stats Payloads
// resulting from ingested traces.
in chan pb.StatsPayload

// exit specifies the exit channel, which will be closed upon shutdown.
exit chan struct{}
}

// function to create a new connector
func newConnector(logger *zap.Logger, config component.Config) (*connectorImp, error) {
logger.Info("Building datadog connector")
in := make(chan pb.StatsPayload, 100)
trans, err := metrics.NewTranslator(logger)

ctx := context.Background()
if err != nil {
return nil, err
}
return &connectorImp{
logger: logger,
agent: datadog.NewAgent(ctx, in),
translator: trans,
in: in,
exit: make(chan struct{}),
}, nil
}

// Start implements the component.Component interface.
func (c *connectorImp) Start(ctx context.Context, _ component.Host) error {
c.logger.Info("Starting datadogconnector")
c.started = true
c.agent.Start()
go c.run()
return nil
}

// Shutdown implements the component.Component interface.
func (c *connectorImp) Shutdown(context.Context) error {
c.logger.Info("Shutting down datadog connector")
if !c.started {
return nil
}
c.started = false
c.agent.Stop()
c.exit <- struct{}{} // signal exit
<-c.exit // wait for close
return nil
}

// Capabilities implements the consumer interface.
// tells use whether the component(connector) will mutate the data passed into it. if set to true the processor does modify the data
func (c *connectorImp) Capabilities() consumer.Capabilities {
return consumer.Capabilities{MutatesData: false}
}

func (c *connectorImp) ConsumeTraces(ctx context.Context, traces ptrace.Traces) error {
c.logger.Debug("Received traces.", zap.Int("spans", traces.SpanCount()))
c.agent.Ingest(ctx, traces)
return nil
}

// run awaits incoming stats resulting from the agent's ingestion, converts them
// to metrics and flushes them using the configured metrics exporter.
func (c *connectorImp) run() {
defer close(c.exit)
for {
select {
case stats := <-c.in:
if len(stats.Stats) == 0 {
continue
}
// APM stats as metrics
mx := c.translator.StatsPayloadToMetrics(stats)
ctx := context.TODO()
c.logger.Debug("Exporting APM Stats metrics.", zap.Int("count", mx.MetricCount()))

// send metrics to the consumer or next compoonet in pipeline
if err := c.metricsConsumer.ConsumeMetrics(ctx, mx); err != nil {
c.logger.Error("Failed ConsumeMetrics", zap.Error(err))
return
}
case <-c.exit:
return
}
}
}
27 changes: 27 additions & 0 deletions connector/datadogconnector/connector_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package datadogconnector

import (
"go.opentelemetry.io/collector/component"
"go.uber.org/zap"
"reflect"
"testing"
)

var _ component.Component = (*connectorImp)(nil) // testing that the connectorImp properly implements the type Component interface

// create test to create a connector, check that basic code compiles
func TestNewConnector(t *testing.T) {
logger := zap.NewNop()
config := createDefaultConfig()

connector, err := newConnector(logger, config)
if err != nil {
t.Errorf("Failed to create new connector: %v", err)
}

if reflect.TypeOf(*connector) != reflect.TypeOf(connectorImp{}) {
t.Errorf("Wrong type for created connector")
}
}

// test for flag
39 changes: 39 additions & 0 deletions connector/datadogconnector/factory.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package datadogconnector // import "github.com/open-telemetry/opentelemetry-collector-contrib/connector/datadogconnector"

import (
"context"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/connector"
"go.opentelemetry.io/collector/consumer"
)

const (
defaultVal = 0
// this is the name used to refer to the connector in the config.yaml
typeStr = "datadog"
)

// NewFactory creates a factory for tailtracer connector.
func NewFactory() connector.Factory {
// OTel connector factory to make a factory for connectors
return connector.NewFactory(
typeStr,
createDefaultConfig,
connector.WithTracesToMetrics(createTracesToMetricsConnector, component.StabilityLevelAlpha))
}

func createDefaultConfig() component.Config {
return &struct{}{}
}

// defines the consumer type of the connector
// we want to consume traces and export metrics therefore define nextConsumer as metrics, consumer is the next component in the pipeline
func createTracesToMetricsConnector(ctx context.Context, params connector.CreateSettings, cfg component.Config, nextConsumer consumer.Metrics) (connector.Traces, error) {
c, err := newConnector(params.Logger, cfg)
if err != nil {
return nil, err
}
c.metricsConsumer = nextConsumer
return c, nil
}
86 changes: 86 additions & 0 deletions connector/datadogconnector/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
module github.com/open-telemetry/opentelemetry-collector-contrib/connector/datadogconnector

go 1.20

require (
github.com/DataDog/datadog-agent/pkg/trace v0.48.0-devel
github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/metrics v0.5.2
github.com/open-telemetry/opentelemetry-collector-contrib/internal/datadog v0.82.0
go.opentelemetry.io/collector/component v0.82.0
go.opentelemetry.io/collector/connector v0.82.0
go.opentelemetry.io/collector/consumer v0.82.0
go.opentelemetry.io/collector/pdata v1.0.0-rcv0014
go.uber.org/zap v1.24.0
)

require (
github.com/DataDog/datadog-agent/pkg/obfuscate v0.47.0-rc.3 // indirect
github.com/DataDog/datadog-agent/pkg/remoteconfig/state v0.47.0-rc.3 // indirect
github.com/DataDog/datadog-agent/pkg/util/cgroups v0.47.0-rc.3 // indirect
github.com/DataDog/datadog-agent/pkg/util/log v0.47.0-rc.3 // indirect
github.com/DataDog/datadog-agent/pkg/util/pointer v0.47.0-rc.3 // indirect
github.com/DataDog/datadog-agent/pkg/util/scrubber v0.47.0-rc.3 // indirect
github.com/DataDog/datadog-go/v5 v5.1.1 // indirect
github.com/DataDog/go-tuf v0.3.0--fix-localmeta-fork // indirect
github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/attributes v0.5.2 // indirect
github.com/DataDog/opentelemetry-mapping-go/pkg/quantile v0.5.2 // indirect
github.com/DataDog/sketches-go v1.4.2 // indirect
github.com/Microsoft/go-winio v0.6.0 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/cihub/seelog v0.0.0-20170130134532-f561c5e57575 // indirect
github.com/containerd/cgroups v1.0.4 // indirect
github.com/coreos/go-systemd/v22 v22.3.2 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/godbus/dbus/v5 v5.0.6 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/mock v1.6.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/karrick/godirwalk v1.17.0 // indirect
github.com/knadh/koanf v1.5.0 // indirect
github.com/knadh/koanf/v2 v2.0.1 // indirect
github.com/lufia/plan9stats v0.0.0-20220913051719-115f729f3c8c // 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
github.com/opencontainers/runtime-spec v1.0.3-0.20210326190908-1c3f411f0417 // indirect
github.com/outcaste-io/ristretto v0.2.1 // indirect
github.com/patrickmn/go-cache v2.1.0+incompatible // indirect
github.com/philhofer/fwd v1.1.2 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/power-devops/perfstat v0.0.0-20220216144756-c35f1ee13d7c // indirect
github.com/secure-systems-lab/go-securesystemslib v0.5.0 // indirect
github.com/shirou/gopsutil/v3 v3.23.2 // indirect
github.com/tinylib/msgp v1.1.8 // indirect
github.com/tklauser/go-sysconf v0.3.11 // indirect
github.com/tklauser/numcpus v0.6.0 // indirect
github.com/yusufpapurcu/wmi v1.2.2 // indirect
go.opentelemetry.io/collector/config/configtelemetry v0.82.0 // indirect
go.opentelemetry.io/collector/confmap v0.82.0 // indirect
go.opentelemetry.io/collector/featuregate v1.0.0-rcv0014 // indirect
go.opentelemetry.io/collector/semconv v0.82.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.11.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df // indirect
golang.org/x/mod v0.11.0 // indirect
golang.org/x/net v0.12.0 // indirect
golang.org/x/sys v0.10.0 // indirect
golang.org/x/text v0.11.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.9.1 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230629202037-9506855d4529 // indirect
google.golang.org/grpc v1.57.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)

replace github.com/open-telemetry/opentelemetry-collector-contrib/internal/datadog => ../../internal/datadog
Loading