Skip to content

Commit

Permalink
datadogmetricreceiver (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
meenal-developer authored May 14, 2024
1 parent da9659b commit a783dcc
Show file tree
Hide file tree
Showing 15 changed files with 1,530 additions and 0 deletions.
1 change: 1 addition & 0 deletions receiver/datadogmetricreceiver/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../../Makefile.Common
16 changes: 16 additions & 0 deletions receiver/datadogmetricreceiver/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Datadog Metrics Receiver

## Configuration

Example:

```yaml
receivers:
datadogmetrics:
endpoint: localhost:8122
read_timeout: 60s
```
### read_timeout (Optional)
The read timeout of the HTTP Server
Default: 60s
17 changes: 17 additions & 0 deletions receiver/datadogmetricreceiver/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0 language governing permissions and
// limitations under the License.

package datadogmetricreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/datadogmetricreceiver"

import (
"time"

"go.opentelemetry.io/collector/config/confighttp"
)

type Config struct {
confighttp.HTTPServerSettings `mapstructure:",squash"`
// ReadTimeout of the http server
ReadTimeout time.Duration `mapstructure:"read_timeout"`
}
16 changes: 16 additions & 0 deletions receiver/datadogmetricreceiver/config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package datadogmetricreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/datadogmetricreceiver"

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestCreateDefaultConfig(t *testing.T) {
factory := NewFactory()
cfg := factory.CreateDefaultConfig()
assert.NotNil(t, cfg, "failed to create default config")
}
7 changes: 7 additions & 0 deletions receiver/datadogmetricreceiver/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

//go:generate mdatagen metadata.yaml

// Package datadogmetricreceiver ingests traces in the Datadog APM format and translates them OpenTelemetry for collector usage
package datadogmetricreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/datadogmetricreceiver"
46 changes: 46 additions & 0 deletions receiver/datadogmetricreceiver/factory.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package datadogmetricreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/datadogmetricreceiver"

import (
"context"
"time"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/confighttp"
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/receiver"

"github.com/open-telemetry/opentelemetry-collector-contrib/internal/sharedcomponent"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/datadogmetricreceiver/internal/metadata"
)

// NewFactory creates a factory for DataDog receiver.
func NewFactory() receiver.Factory {
return receiver.NewFactory(
metadata.Type,
createDefaultConfig,
receiver.WithMetrics(createMetricsReceiver, metadata.MetricStability))

}

func createDefaultConfig() component.Config {
return &Config{
HTTPServerSettings: confighttp.HTTPServerSettings{
Endpoint: "localhost:8122",
},
ReadTimeout: 60 * time.Second,
}
}

func createMetricsReceiver(_ context.Context, params receiver.CreateSettings, cfg component.Config, consumer consumer.Metrics) (r receiver.Metrics, err error) {
rcfg := cfg.(*Config)
r = receivers.GetOrAdd(cfg, func() component.Component {
dd, _ := newdatadogmetricreceiver(rcfg, consumer, params)
return dd
})
return r, nil
}

var receivers = sharedcomponent.NewSharedComponents()
23 changes: 23 additions & 0 deletions receiver/datadogmetricreceiver/factory_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package datadogmetricreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/datadogmetricreceiver"

import (
"context"
"testing"

"github.com/stretchr/testify/assert"
"go.opentelemetry.io/collector/consumer/consumertest"
"go.opentelemetry.io/collector/receiver/receivertest"
)

func TestCreateReceiver(t *testing.T) {
factory := NewFactory()
cfg := factory.CreateDefaultConfig()
cfg.(*Config).Endpoint = "http://localhost:0"

tReceiver, err := factory.CreateMetricsReceiver(context.Background(), receivertest.NewNopCreateSettings(), cfg, consumertest.NewNop())
assert.NoError(t, err)
assert.NotNil(t, tReceiver, "receiver creation failed")
}
80 changes: 80 additions & 0 deletions receiver/datadogmetricreceiver/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
module github.com/open-telemetry/opentelemetry-collector-contrib/receiver/datadogmetricreceiver

go 1.20

require (
github.com/DataDog/agent-payload/v5 v5.0.115
github.com/DataDog/datadog-api-client-go/v2 v2.25.0
github.com/open-telemetry/opentelemetry-collector-contrib/internal/sharedcomponent v0.84.0
github.com/stretchr/testify v1.8.4
go.opentelemetry.io/collector v0.84.0
go.opentelemetry.io/collector/component v0.84.0
go.opentelemetry.io/collector/config/confighttp v0.84.0
go.opentelemetry.io/collector/consumer v0.84.0
go.opentelemetry.io/collector/pdata v1.0.0-rcv0014
go.opentelemetry.io/collector/receiver v0.84.0
go.uber.org/multierr v1.11.0
)

require (
github.com/DataDog/zstd v1.5.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/felixge/httpsnoop v1.0.3 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.16.7 // indirect
github.com/knadh/koanf v1.5.0 // indirect
github.com/knadh/koanf/v2 v2.0.1 // 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/pmezard/go-difflib v1.0.0 // indirect
github.com/rs/cors v1.9.0 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/collector/config/configauth v0.84.0 // indirect
go.opentelemetry.io/collector/config/configcompression v0.84.0 // indirect
go.opentelemetry.io/collector/config/configopaque v0.84.0 // indirect
go.opentelemetry.io/collector/config/configtelemetry v0.84.0 // indirect
go.opentelemetry.io/collector/config/configtls v0.84.0 // indirect
go.opentelemetry.io/collector/config/internal v0.84.0 // indirect
go.opentelemetry.io/collector/confmap v0.84.0 // indirect
go.opentelemetry.io/collector/exporter v0.84.0 // indirect
go.opentelemetry.io/collector/extension v0.84.0 // indirect
go.opentelemetry.io/collector/extension/auth v0.84.0 // indirect
go.opentelemetry.io/collector/featuregate v1.0.0-rcv0014 // indirect
go.opentelemetry.io/collector/processor v0.84.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.42.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/zap v1.25.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/oauth2 v0.10.0 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/text v0.13.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230530153820-e85fd2cbaebc // indirect
google.golang.org/grpc v1.57.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

// v0.47.x and v0.48.x are incompatible, prefer to use v0.48.x
replace github.com/DataDog/datadog-agent/pkg/proto => github.com/DataDog/datadog-agent/pkg/proto v0.48.0-beta.1

replace github.com/DataDog/datadog-agent/pkg/trace => github.com/DataDog/datadog-agent/pkg/trace v0.48.0-beta.1

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

retract (
v0.76.2
v0.76.1
)
Loading

0 comments on commit a783dcc

Please sign in to comment.