-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Add statsdreceiver skeleton #566
Merged
Merged
Changes from 13 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
01393f6
Add statsdreceiver skeleton
2034105
Add DogStatsD parser and UDP server transport
7de4fcb
Add unit tests and copyright headers
88b71d1
Remove unused timeout configuration option
08abd1b
Use componenterror package errors
80ec2de
Parse counters
7d73e3c
Remove docker dependency from go.sum
96da9f9
Remove unused defaultTimeout variable
ceec405
Merge remote-tracking branch 'upstream/master' into statsd
80ecf24
Adopt confignet.NetAddr configuration struct
d8f9076
Fix import ordering
ba939df
Add Reporter construct and expand test coverage
77fc6c4
Improve metric name and value parsing
0d2870e
Handle float values gracefully in counter messages
99d53a7
Fill in receiver e2e test
588cf6b
Initialize transport based on configuration option
7fec737
Update README and add TODOs from PR feedback
c2d9ada
Merge remote-tracking branch 'upstream/master' into statsd
d1f7621
Merge remote-tracking branch 'upstream/master' into statsd
df4bbe8
Replace ReceiverFactoryOld usage in favor of receiverhelper package
0d26db0
Merge remote-tracking branch 'upstream/master' into statsd
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include ../../Makefile.Common |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# StatsD Receiver | ||
|
||
StatsD receiver for ingesting StatsD messages into the OpenTelemetry Collector. | ||
|
||
## Status | ||
|
||
This plugin is still being developed and is **not** ready to be used in a production grade environment. | ||
|
||
## Configuration | ||
|
||
```yaml | ||
receivers: | ||
statsd: | ||
endpoint: "localhost:8125" # default | ||
``` | ||
|
||
### endpoint | ||
|
||
The `"<host>:<port>"` to listen on. By default listen on `"localhost:8125"`. | ||
|
||
## Aggregation | ||
|
||
Currently the `statsdreceiver` is not providing any aggregation. There are ideas such as the [Metrics Transform Processor Proposal](https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/332) that intend to enable control over Metric aggregation in a processor. | ||
|
||
An alternative will be to implement some simple aggregation in this receiver. | ||
|
||
## Metrics | ||
|
||
General format is: | ||
|
||
`<name>:<value>|<type>|@<sample-rate>|#<tag1-key>:<tag1-value>,<tag2-k/v>` | ||
|
||
### Counter | ||
|
||
`<name>:<value>|c` | ||
|
||
<!-- ### Gauge | ||
|
||
`<name>:<value>|g` | ||
|
||
### Timer/Histogram | ||
|
||
`<name>:<value>|<ms/h>|@<sample-rate>` --> | ||
|
||
## Testing | ||
|
||
### Full sample collector config | ||
|
||
```yaml | ||
receivers: | ||
statsd: | ||
endpoint: "localhost:8125" # default | ||
|
||
exporters: | ||
file: | ||
path: ./test.json | ||
|
||
service: | ||
pipelines: | ||
metrics: | ||
receivers: [statsd] | ||
exporters: [file] | ||
``` | ||
|
||
### Send StatsD message into the receiver | ||
|
||
A simple way to send a metric to `localhost:8125`: | ||
|
||
`echo "test.metric:1|c" | nc -w 1 -u localhost 8125` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright 2020, OpenTelemetry Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package statsdreceiver | ||
|
||
import ( | ||
"go.opentelemetry.io/collector/config/configmodels" | ||
"go.opentelemetry.io/collector/config/confignet" | ||
) | ||
|
||
// Config defines configuration for StatsD receiver. | ||
type Config struct { | ||
configmodels.ReceiverSettings `mapstructure:",squash"` | ||
NetAddr confignet.NetAddr `mapstructure:",squash"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Copyright 2020, OpenTelemetry Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package statsdreceiver | ||
|
||
import ( | ||
"path" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"go.opentelemetry.io/collector/component/componenttest" | ||
"go.opentelemetry.io/collector/config/configmodels" | ||
"go.opentelemetry.io/collector/config/confignet" | ||
"go.opentelemetry.io/collector/config/configtest" | ||
) | ||
|
||
func TestLoadConfig(t *testing.T) { | ||
factories, err := componenttest.ExampleComponents() | ||
assert.Nil(t, err) | ||
|
||
factory := &Factory{} | ||
factories.Receivers[configmodels.Type(typeStr)] = factory | ||
cfg, err := configtest.LoadConfigFile( | ||
t, path.Join(".", "testdata", "config.yaml"), factories, | ||
) | ||
|
||
require.NoError(t, err) | ||
require.NotNil(t, cfg) | ||
|
||
assert.Equal(t, len(cfg.Receivers), 2) | ||
|
||
r0 := cfg.Receivers["statsd"] | ||
assert.Equal(t, factory.CreateDefaultConfig(), r0) | ||
|
||
r1 := cfg.Receivers["statsd/receiver_settings"] | ||
assert.Equal(t, &Config{ | ||
ReceiverSettings: configmodels.ReceiverSettings{ | ||
TypeVal: configmodels.Type(typeStr), | ||
NameVal: "statsd/receiver_settings", | ||
}, | ||
NetAddr: confignet.NetAddr{ | ||
Endpoint: "localhost:12345", | ||
}, | ||
}, r1) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright 2020, OpenTelemetry Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
// Package statsdreceiver implements a collector receiver that listens | ||
// on UDP port 8125 by default for incoming StatsD messages and parses | ||
// them into OTLP equivalent metric representations. | ||
package statsdreceiver |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// Copyright 2020, OpenTelemetry Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package statsdreceiver | ||
|
||
import ( | ||
"context" | ||
|
||
"go.opentelemetry.io/collector/component" | ||
"go.opentelemetry.io/collector/config/configerror" | ||
"go.opentelemetry.io/collector/config/configmodels" | ||
"go.opentelemetry.io/collector/config/confignet" | ||
"go.opentelemetry.io/collector/consumer" | ||
"go.uber.org/zap" | ||
) | ||
|
||
const ( | ||
// The value of "type" key in configuration. | ||
typeStr = "statsd" | ||
defaultBindEndpoint = "localhost:8125" | ||
) | ||
|
||
// Factory is the factory for StatsD receiver. | ||
type Factory struct { | ||
} | ||
|
||
var _ component.ReceiverFactoryOld = (*Factory)(nil) | ||
bogdandrutu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// 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, | ||
}, | ||
NetAddr: confignet.NetAddr{ | ||
Endpoint: defaultBindEndpoint, | ||
}, | ||
} | ||
} | ||
|
||
// 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( | ||
ctx context.Context, | ||
logger *zap.Logger, | ||
cfg configmodels.Receiver, | ||
nextConsumer consumer.MetricsConsumerOld, | ||
) (component.MetricsReceiver, error) { | ||
c := cfg.(*Config) | ||
return New(logger, *c, nextConsumer) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Copyright 2020, OpenTelemetry Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package statsdreceiver | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"go.opentelemetry.io/collector/config/configcheck" | ||
"go.opentelemetry.io/collector/config/configerror" | ||
"go.opentelemetry.io/collector/consumer" | ||
"go.opentelemetry.io/collector/consumer/consumerdata" | ||
"go.uber.org/zap" | ||
) | ||
|
||
func TestCreateDefaultConfig(t *testing.T) { | ||
factory := &Factory{} | ||
cfg := factory.CreateDefaultConfig() | ||
assert.NotNil(t, cfg, "failed to create default config") | ||
assert.NoError(t, configcheck.ValidateConfig(cfg)) | ||
} | ||
|
||
type mockMetricsConsumer struct { | ||
} | ||
|
||
var _ (consumer.MetricsConsumerOld) = (*mockMetricsConsumer)(nil) | ||
|
||
func (m *mockMetricsConsumer) ConsumeMetricsData(ctx context.Context, md consumerdata.MetricsData) error { | ||
return nil | ||
} | ||
|
||
func TestCreateReceiver(t *testing.T) { | ||
factory := &Factory{} | ||
cfg := factory.CreateDefaultConfig().(*Config) | ||
cfg.NetAddr.Endpoint = "localhost:0" // Endpoint is required, not going to be used here. | ||
|
||
tReceiver, err := factory.CreateMetricsReceiver(context.Background(), zap.NewNop(), cfg, &mockMetricsConsumer{}) | ||
assert.Nil(t, err, "receiver creation failed") | ||
assert.NotNil(t, tReceiver, "receiver creation failed") | ||
|
||
tReceiver, err = factory.CreateMetricsReceiver(context.Background(), zap.NewNop(), cfg, &mockMetricsConsumer{}) | ||
assert.Nil(t, err, "receiver creation failed") | ||
assert.NotNil(t, tReceiver, "receiver creation failed") | ||
|
||
mReceiver, err := factory.CreateTraceReceiver(context.Background(), zap.NewNop(), cfg, nil) | ||
assert.Equal(t, err, configerror.ErrDataTypeIsNotSupported) | ||
assert.Nil(t, mReceiver) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module github.com/open-telemetry/opentelemetry-collector-contrib/receiver/statsdreceiver | ||
|
||
go 1.14 | ||
|
||
require ( | ||
github.com/census-instrumentation/opencensus-proto v0.3.0 | ||
github.com/golang/protobuf v1.4.2 | ||
github.com/shirou/gopsutil v2.20.4+incompatible // indirect | ||
github.com/stretchr/testify v1.6.1 | ||
go.opencensus.io v0.22.4 | ||
go.opentelemetry.io/collector v0.5.1-0.20200723232356-d4053cc823a0 | ||
go.uber.org/zap v1.15.0 | ||
) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The @sample-rate parameter won't have a place to go in the protocol yet, but we can leave a TODO about how to handle it.
These Timer/Histogram events should be translated the same way a ValueRecorder event from the OTel API would be, and we are meant to multiply the Count of this event by 1/sample-rate. In open-telemetry/opentelemetry-proto#159 we have discussed a potential future for OTLP exemplars that include this inverse-of-sample-rate value as well, which we termed sample-count. In other words, I like the idea of sample-rate, but I prefer to think in terms of its inverse; sample-count is a floating-point > 1, whereas sample-rate is a floating-point > 0 and < 1. (It's one less byte when sample-rate is the inverse of an integer, due to the
.
, which is a common case for simple probability sampling.)What interested me the most here was that you omitted @sample-rate from Counter and Gauge events. I believe the
@sample-rate
may be used with Counter and Gauge events as well as Timer/Histogram events. In the PR linked above, any raw or exemplar value could include an optionalsample-count
> 1 to indicate that it was probabilistically sampled. There are not many (if any) definitive documents about the statsd format across the internet, so this README will be a great resource. (I think I'm asking that you add @sample-rate to the Counter and Gauge syntax above, otherwise to be proven wrong and that there exists a StatsD specification 😀 .)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you suggesting that we should expect
@<sample-count>
instead@<sample-rate>
on incoming messages, or when processing incoming@<sample-rate>
to translate it into sample-count? I expect sample-rate on incoming messages currently as that seems to be standard.I will update the Counter and Gauge examples to include sample rates 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I expect
@<sample-rate>
, I was just explaining my thoughts for how to get this information into OTLP at a later date.