Skip to content

Commit

Permalink
Add statsdreceiver skeleton
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick Fischer committed Jun 15, 2020
1 parent ab093e2 commit 01393f6
Show file tree
Hide file tree
Showing 11 changed files with 1,524 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cmd/otelcontribcol/components.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import (
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/sapmreceiver"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/signalfxreceiver"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/simpleprometheusreceiver"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/statsdreceiver"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/wavefrontreceiver"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/zipkinscribereceiver"
)
Expand Down Expand Up @@ -82,6 +83,7 @@ func components() (config.Factories, error) {
&simpleprometheusreceiver.Factory{},
&k8sclusterreceiver.Factory{},
&receivercreator.Factory{},
&statsdreceiver.Factory{},
}
for _, rcv := range factories.Receivers {
receivers = append(receivers, rcv)
Expand Down
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ require (
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/sapmreceiver v0.0.0
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/signalfxreceiver v0.0.0
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/simpleprometheusreceiver v0.0.0
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/statsdreceiver v0.0.0
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/wavefrontreceiver v0.0.0
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/zipkinscribereceiver v0.0.0
github.com/pavius/impi v0.0.0-20180302134524-c1cbdcb8df2b
Expand Down Expand Up @@ -83,6 +84,8 @@ replace github.com/open-telemetry/opentelemetry-collector-contrib/receiver/carbo

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

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

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

replace github.com/open-telemetry/opentelemetry-collector-contrib/receiver/kubeletstatsreceiver => ./receiver/kubeletstatsreceiver
Expand Down
1 change: 1 addition & 0 deletions receiver/statsdreceiver/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../../Makefile.Common
3 changes: 3 additions & 0 deletions receiver/statsdreceiver/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# StatsD Receiver

StatsD/DogStatsD receiver.
14 changes: 14 additions & 0 deletions receiver/statsdreceiver/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package statsdreceiver

import (
"time"

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

// Config defines configuration for StatsD receiver.
type Config struct {
configmodels.ReceiverSettings `mapstructure:",squash"`

Timeout time.Duration `mapstructure:"timeout"`
}
1 change: 1 addition & 0 deletions receiver/statsdreceiver/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package statsdreceiver
65 changes: 65 additions & 0 deletions receiver/statsdreceiver/factory.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package statsdreceiver

import (
"context"
"time"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/configerror"
"go.opentelemetry.io/collector/config/configmodels"
"go.opentelemetry.io/collector/consumer"
"go.uber.org/zap"
)

const (
// The value of "type" key in configuration.
typeStr = "statsd"
defaultBindEndpoint = "localhost:8125"
defaultTimeout = time.Duration(time.Second * 30)
)

// Factory is the factory for StatsD receiver.
type Factory struct {
}

// Type gets the type of the Receiver config created by this factory.
func (f *Factory) Type() configmodels.Type {
return configmodels.Type(typeStr)
}

// CustomUnmarshaler returns nil because we don't need custom unmarshaling for this config.
func (f *Factory) CustomUnmarshaler() component.CustomUnmarshaler {
return nil
}

// CreateDefaultConfig creates the default configuration for StatsD receiver.
func (f *Factory) CreateDefaultConfig() configmodels.Receiver {
return &Config{
ReceiverSettings: configmodels.ReceiverSettings{
TypeVal: configmodels.Type(typeStr),
NameVal: typeStr,
Endpoint: defaultBindEndpoint,
},
Timeout: defaultTimeout,
}
}

// CreateTraceReceiver creates a trace receiver based on provided config.
func (f *Factory) CreateTraceReceiver(
ctx context.Context,
logger *zap.Logger,
cfg configmodels.Receiver,
nextConsumer consumer.TraceConsumerOld,
) (component.TraceReceiver, error) {
return nil, configerror.ErrDataTypeIsNotSupported
}

// CreateMetricsReceiver creates a metrics receiver based on provided config.
func (f *Factory) CreateMetricsReceiver(
logger *zap.Logger,
cfg configmodels.Receiver,
nextConsumer consumer.MetricsConsumerOld,
) (component.MetricsReceiver, error) {
c := cfg.(*Config)
return New(logger, c.Endpoint, c.Timeout, nextConsumer)
}
8 changes: 8 additions & 0 deletions receiver/statsdreceiver/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module github.com/open-telemetry/opentelemetry-collector-contrib/receiver/statsdreceiver

go 1.14

require (
go.opentelemetry.io/collector v0.3.1-0.20200601172059-a776048b653c
go.uber.org/zap v1.10.0
)
Loading

0 comments on commit 01393f6

Please sign in to comment.