diff --git a/.chloggen/statsd-public-config.yaml b/.chloggen/statsd-public-config.yaml new file mode 100644 index 000000000000..e9f20e678d37 --- /dev/null +++ b/.chloggen/statsd-public-config.yaml @@ -0,0 +1,27 @@ +# Use this changelog template to create an entry for release notes. + +# 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: receiver/statsd + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Make all types within the config struct public + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +issues: [38186] + +# (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: This allows programmatically generating the receiver's config using the module's public types. + +# If your change doesn't affect end users or the exported elements of any package, +# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. +# Optional: The change log or logs in which this entry should be included. +# e.g. '[user]' or '[user, api]' +# Include 'user' if the change is relevant to end users. +# Include 'api' if there is a change to a library API. +# Default: '[user]' +change_logs: [api] diff --git a/receiver/statsdreceiver/config.go b/receiver/statsdreceiver/config.go index 150c4aecd6ea..4a1f08ba5cde 100644 --- a/receiver/statsdreceiver/config.go +++ b/receiver/statsdreceiver/config.go @@ -12,7 +12,7 @@ import ( "go.opentelemetry.io/collector/config/confignet" "go.uber.org/multierr" - "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/statsdreceiver/internal/protocol" + "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/statsdreceiver/protocol" ) // Config defines configuration for StatsD receiver. diff --git a/receiver/statsdreceiver/config_test.go b/receiver/statsdreceiver/config_test.go index f755ea6f0920..3a39e945f94a 100644 --- a/receiver/statsdreceiver/config_test.go +++ b/receiver/statsdreceiver/config_test.go @@ -18,7 +18,7 @@ import ( "go.opentelemetry.io/collector/confmap/xconfmap" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/statsdreceiver/internal/metadata" - "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/statsdreceiver/internal/protocol" + "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/statsdreceiver/protocol" ) func TestLoadConfig(t *testing.T) { diff --git a/receiver/statsdreceiver/factory.go b/receiver/statsdreceiver/factory.go index f3cf38da4d5a..7c07226458fa 100644 --- a/receiver/statsdreceiver/factory.go +++ b/receiver/statsdreceiver/factory.go @@ -13,7 +13,7 @@ import ( "go.opentelemetry.io/collector/receiver" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/statsdreceiver/internal/metadata" - "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/statsdreceiver/internal/protocol" + "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/statsdreceiver/protocol" ) const ( diff --git a/receiver/statsdreceiver/internal/protocol/metric_translator.go b/receiver/statsdreceiver/internal/parser/metric_translator.go similarity index 97% rename from receiver/statsdreceiver/internal/protocol/metric_translator.go rename to receiver/statsdreceiver/internal/parser/metric_translator.go index 1cec9821cffd..8ceee545b70b 100644 --- a/receiver/statsdreceiver/internal/protocol/metric_translator.go +++ b/receiver/statsdreceiver/internal/parser/metric_translator.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package protocol // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/statsdreceiver/internal/protocol" +package parser // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/statsdreceiver/internal/parser" import ( "sort" diff --git a/receiver/statsdreceiver/internal/protocol/metric_translator_test.go b/receiver/statsdreceiver/internal/parser/metric_translator_test.go similarity index 99% rename from receiver/statsdreceiver/internal/protocol/metric_translator_test.go rename to receiver/statsdreceiver/internal/parser/metric_translator_test.go index 95f18b16f01f..6354e3c75420 100644 --- a/receiver/statsdreceiver/internal/protocol/metric_translator_test.go +++ b/receiver/statsdreceiver/internal/parser/metric_translator_test.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package protocol +package parser import ( "testing" diff --git a/receiver/statsdreceiver/internal/protocol/package_test.go b/receiver/statsdreceiver/internal/parser/package_test.go similarity index 91% rename from receiver/statsdreceiver/internal/protocol/package_test.go rename to receiver/statsdreceiver/internal/parser/package_test.go index 9f01ff63e427..feabbe79a524 100644 --- a/receiver/statsdreceiver/internal/protocol/package_test.go +++ b/receiver/statsdreceiver/internal/parser/package_test.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package protocol +package parser import ( "testing" diff --git a/receiver/statsdreceiver/internal/protocol/parser.go b/receiver/statsdreceiver/internal/parser/parser.go similarity index 68% rename from receiver/statsdreceiver/internal/protocol/parser.go rename to receiver/statsdreceiver/internal/parser/parser.go index 431847816ded..dc33a8eff1cc 100644 --- a/receiver/statsdreceiver/internal/protocol/parser.go +++ b/receiver/statsdreceiver/internal/parser/parser.go @@ -1,18 +1,20 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package protocol // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/statsdreceiver/internal/protocol" +package parser // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/statsdreceiver/internal/parser" import ( "net" "go.opentelemetry.io/collector/client" "go.opentelemetry.io/collector/pdata/pmetric" + + "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/statsdreceiver/protocol" ) // Parser is something that can map input StatsD strings to OTLP Metric representations. type Parser interface { - Initialize(enableMetricType bool, enableSimpleTags bool, isMonotonicCounter bool, enableIPOnlyAggregation bool, sendTimerHistogram []TimerHistogramMapping) error + Initialize(enableMetricType bool, enableSimpleTags bool, isMonotonicCounter bool, enableIPOnlyAggregation bool, sendTimerHistogram []protocol.TimerHistogramMapping) error GetMetrics() []BatchMetrics Aggregate(line string, addr net.Addr) error } diff --git a/receiver/statsdreceiver/internal/protocol/statsd_parser.go b/receiver/statsdreceiver/internal/parser/statsd_parser.go similarity index 87% rename from receiver/statsdreceiver/internal/protocol/statsd_parser.go rename to receiver/statsdreceiver/internal/parser/statsd_parser.go index 062403bedc52..bfa2e537fb5c 100644 --- a/receiver/statsdreceiver/internal/protocol/statsd_parser.go +++ b/receiver/statsdreceiver/internal/parser/statsd_parser.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package protocol // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/statsdreceiver/internal/protocol" +package parser // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/statsdreceiver/internal/parser" import ( "errors" @@ -18,6 +18,8 @@ import ( "go.opentelemetry.io/collector/pdata/pmetric" semconv "go.opentelemetry.io/collector/semconv/v1.22.0" "go.opentelemetry.io/otel/attribute" + + "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/statsdreceiver/protocol" ) var ( @@ -25,11 +27,7 @@ var ( errEmptyMetricValue = errors.New("empty metric value") ) -type ( - MetricType string // From the statsd line e.g., "c", "g", "h" - TypeName string // How humans describe the MetricTypes ("counter", "gauge") - ObserverType string // How the server will aggregate histogram and timings ("gauge", "summary") -) +type MetricType string // From the statsd line e.g., "c", "g", "h" const ( tagMetricType = "metric_type" @@ -40,46 +38,17 @@ const ( TimingType MetricType = "ms" DistributionType MetricType = "d" - CounterTypeName TypeName = "counter" - GaugeTypeName TypeName = "gauge" - HistogramTypeName TypeName = "histogram" - TimingTypeName TypeName = "timing" - TimingAltTypeName TypeName = "timer" - DistributionTypeName TypeName = "distribution" - - GaugeObserver ObserverType = "gauge" - SummaryObserver ObserverType = "summary" - HistogramObserver ObserverType = "histogram" - DisableObserver ObserverType = "disabled" - - DefaultObserverType = DisableObserver - receiverName = "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/statsdreceiver" ) -type TimerHistogramMapping struct { - StatsdType TypeName `mapstructure:"statsd_type"` - ObserverType ObserverType `mapstructure:"observer_type"` - Histogram HistogramConfig `mapstructure:"histogram"` - Summary SummaryConfig `mapstructure:"summary"` -} - -type HistogramConfig struct { - MaxSize int32 `mapstructure:"max_size"` -} - -type SummaryConfig struct { - Percentiles []float64 `mapstructure:"percentiles"` -} - type ObserverCategory struct { - method ObserverType + method protocol.ObserverType histogramConfig structure.Config summaryPercentiles []float64 } var defaultObserverCategory = ObserverCategory{ - method: DefaultObserverType, + method: protocol.DefaultObserverType, } // StatsDParser supports the Parse method for parsing StatsD messages with Tags. @@ -146,20 +115,20 @@ type statsDMetricDescription struct { attrs attribute.Set } -func (t MetricType) FullName() TypeName { +func (t MetricType) FullName() protocol.TypeName { switch t { case GaugeType: - return GaugeTypeName + return protocol.GaugeTypeName case CounterType: - return CounterTypeName + return protocol.CounterTypeName case TimingType: - return TimingTypeName + return protocol.TimingTypeName case HistogramType: - return HistogramTypeName + return protocol.HistogramTypeName case DistributionType: - return DistributionTypeName + return protocol.DistributionTypeName } - return TypeName(fmt.Sprintf("unknown(%s)", t)) + return protocol.TypeName(fmt.Sprintf("unknown(%s)", t)) } func (p *StatsDParser) resetState(when time.Time) { @@ -167,7 +136,7 @@ func (p *StatsDParser) resetState(when time.Time) { p.instrumentsByAddress = make(map[netAddr]*instruments) } -func (p *StatsDParser) Initialize(enableMetricType bool, enableSimpleTags bool, isMonotonicCounter bool, enableIPOnlyAggregation bool, sendTimerHistogram []TimerHistogramMapping) error { +func (p *StatsDParser) Initialize(enableMetricType bool, enableSimpleTags bool, isMonotonicCounter bool, enableIPOnlyAggregation bool, sendTimerHistogram []protocol.TimerHistogramMapping) error { p.resetState(timeNowFunc()) p.histogramEvents = defaultObserverCategory @@ -180,21 +149,21 @@ func (p *StatsDParser) Initialize(enableMetricType bool, enableSimpleTags bool, // Note: validation occurs in ("../".Config).validate() for _, eachMap := range sendTimerHistogram { switch eachMap.StatsdType { - case HistogramTypeName, DistributionTypeName: + case protocol.HistogramTypeName, protocol.DistributionTypeName: p.histogramEvents.method = eachMap.ObserverType p.histogramEvents.histogramConfig = expoHistogramConfig(eachMap.Histogram) p.histogramEvents.summaryPercentiles = eachMap.Summary.Percentiles - case TimingTypeName, TimingAltTypeName: + case protocol.TimingTypeName, protocol.TimingAltTypeName: p.timerEvents.method = eachMap.ObserverType p.timerEvents.histogramConfig = expoHistogramConfig(eachMap.Histogram) p.timerEvents.summaryPercentiles = eachMap.Summary.Percentiles - case CounterTypeName, GaugeTypeName: + case protocol.CounterTypeName, protocol.GaugeTypeName: } } return nil } -func expoHistogramConfig(opts HistogramConfig) structure.Config { +func expoHistogramConfig(opts protocol.HistogramConfig) structure.Config { var r []structure.Option if opts.MaxSize >= structure.MinSize { r = append(r, structure.WithMaxSize(opts.MaxSize)) @@ -331,9 +300,9 @@ func (p *StatsDParser) Aggregate(line string, addr net.Addr) error { case TimingType, HistogramType, DistributionType: category := p.observerCategoryFor(parsedMetric.description.metricType) switch category.method { - case GaugeObserver: + case protocol.GaugeObserver: instrument.timersAndDistributions = append(instrument.timersAndDistributions, buildGaugeMetric(parsedMetric, timeNowFunc())) - case SummaryObserver: + case protocol.SummaryObserver: raw := parsedMetric.sampleValue() if existing, ok := instrument.summaries[parsedMetric.description]; !ok { instrument.summaries[parsedMetric.description] = summaryMetric{ @@ -348,7 +317,7 @@ func (p *StatsDParser) Aggregate(line string, addr net.Addr) error { percentiles: category.summaryPercentiles, } } - case HistogramObserver: + case protocol.HistogramObserver: raw := parsedMetric.sampleValue() var agg *histogramStructure if existing, ok := instrument.histograms[parsedMetric.description]; ok { @@ -366,7 +335,7 @@ func (p *StatsDParser) Aggregate(line string, addr net.Addr) error { uint64(raw.count), // Note! Rounding float64 to uint64 here. ) - case DisableObserver: + case protocol.DisableObserver: // No action. } } diff --git a/receiver/statsdreceiver/internal/protocol/statsd_parser_test.go b/receiver/statsdreceiver/internal/parser/statsd_parser_test.go similarity index 96% rename from receiver/statsdreceiver/internal/protocol/statsd_parser_test.go rename to receiver/statsdreceiver/internal/parser/statsd_parser_test.go index bfdab7167128..99797063cae6 100644 --- a/receiver/statsdreceiver/internal/protocol/statsd_parser_test.go +++ b/receiver/statsdreceiver/internal/parser/statsd_parser_test.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package protocol +package parser import ( "errors" @@ -18,6 +18,7 @@ import ( "go.opentelemetry.io/otel/attribute" "github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal/metricstestutil" + "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/statsdreceiver/protocol" ) func Test_ParseMessageToMetric(t *testing.T) { @@ -1049,7 +1050,7 @@ func TestStatsDParser_Aggregate(t *testing.T) { t.Run(tt.name, func(t *testing.T) { var err error p := &StatsDParser{} - assert.NoError(t, p.Initialize(false, false, false, false, []TimerHistogramMapping{{StatsdType: "timer", ObserverType: "gauge"}, {StatsdType: "histogram", ObserverType: "gauge"}})) + assert.NoError(t, p.Initialize(false, false, false, false, []protocol.TimerHistogramMapping{{StatsdType: "timer", ObserverType: "gauge"}, {StatsdType: "histogram", ObserverType: "gauge"}})) p.lastIntervalTime = time.Unix(611, 0) addr, _ := net.ResolveUDPAddr("udp", "1.2.3.4:5678") addrKey := newNetAddr(addr) @@ -1158,7 +1159,7 @@ func TestStatsDParser_AggregateByAddress(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { p := &StatsDParser{} - assert.NoError(t, p.Initialize(true, false, false, false, []TimerHistogramMapping{{StatsdType: "timer", ObserverType: "gauge"}, {StatsdType: "histogram", ObserverType: "gauge"}})) + assert.NoError(t, p.Initialize(true, false, false, false, []protocol.TimerHistogramMapping{{StatsdType: "timer", ObserverType: "gauge"}, {StatsdType: "histogram", ObserverType: "gauge"}})) p.lastIntervalTime = time.Unix(611, 0) for i, addr := range tt.addresses { for _, line := range tt.input[i] { @@ -1266,7 +1267,7 @@ func TestStatsDParser_AggregateWithMetricType(t *testing.T) { t.Run(tt.name, func(t *testing.T) { var err error p := &StatsDParser{} - assert.NoError(t, p.Initialize(true, false, false, false, []TimerHistogramMapping{{StatsdType: "timer", ObserverType: "gauge"}, {StatsdType: "histogram", ObserverType: "gauge"}})) + assert.NoError(t, p.Initialize(true, false, false, false, []protocol.TimerHistogramMapping{{StatsdType: "timer", ObserverType: "gauge"}, {StatsdType: "histogram", ObserverType: "gauge"}})) p.lastIntervalTime = time.Unix(611, 0) addr, _ := net.ResolveUDPAddr("udp", "1.2.3.4:5678") addrKey := newNetAddr(addr) @@ -1336,7 +1337,7 @@ func TestStatsDParser_AggregateWithIsMonotonicCounter(t *testing.T) { t.Run(tt.name, func(t *testing.T) { var err error p := &StatsDParser{} - assert.NoError(t, p.Initialize(false, false, true, false, []TimerHistogramMapping{{StatsdType: "timer", ObserverType: "gauge"}, {StatsdType: "histogram", ObserverType: "gauge"}})) + assert.NoError(t, p.Initialize(false, false, true, false, []protocol.TimerHistogramMapping{{StatsdType: "timer", ObserverType: "gauge"}, {StatsdType: "histogram", ObserverType: "gauge"}})) p.lastIntervalTime = time.Unix(611, 0) addr, _ := net.ResolveUDPAddr("udp", "1.2.3.4:5678") addrKey := newNetAddr(addr) @@ -1463,7 +1464,7 @@ func TestStatsDParser_AggregateTimerWithSummary(t *testing.T) { t.Run(tt.name, func(t *testing.T) { var err error p := &StatsDParser{} - assert.NoError(t, p.Initialize(false, false, false, false, []TimerHistogramMapping{{StatsdType: "timer", ObserverType: "summary"}, {StatsdType: "histogram", ObserverType: "summary", Summary: SummaryConfig{Percentiles: []float64{0, 95, 99}}}})) + assert.NoError(t, p.Initialize(false, false, false, false, []protocol.TimerHistogramMapping{{StatsdType: "timer", ObserverType: "summary"}, {StatsdType: "histogram", ObserverType: "summary", Summary: protocol.SummaryConfig{Percentiles: []float64{0, 95, 99}}}})) addr, _ := net.ResolveUDPAddr("udp", "1.2.3.4:5678") addrKey := newNetAddr(addr) for _, line := range tt.input { @@ -1480,7 +1481,7 @@ func TestStatsDParser_AggregateTimerWithSummary(t *testing.T) { func TestStatsDParser_Initialize(t *testing.T) { p := &StatsDParser{} - assert.NoError(t, p.Initialize(true, false, false, false, []TimerHistogramMapping{{StatsdType: "timer", ObserverType: "gauge"}, {StatsdType: "histogram", ObserverType: "gauge"}})) + assert.NoError(t, p.Initialize(true, false, false, false, []protocol.TimerHistogramMapping{{StatsdType: "timer", ObserverType: "gauge"}, {StatsdType: "histogram", ObserverType: "gauge"}})) teststatsdDMetricdescription := statsDMetricDescription{ name: "test", metricType: "g", @@ -1493,13 +1494,13 @@ func TestStatsDParser_Initialize(t *testing.T) { p.instrumentsByAddress[addrKey] = instrument assert.Len(t, p.instrumentsByAddress, 1) assert.Len(t, p.instrumentsByAddress[addrKey].gauges, 1) - assert.Equal(t, GaugeObserver, p.timerEvents.method) - assert.Equal(t, GaugeObserver, p.histogramEvents.method) + assert.Equal(t, protocol.GaugeObserver, p.timerEvents.method) + assert.Equal(t, protocol.GaugeObserver, p.histogramEvents.method) } func TestStatsDParser_GetMetricsWithMetricType(t *testing.T) { p := &StatsDParser{} - assert.NoError(t, p.Initialize(true, false, false, false, []TimerHistogramMapping{{StatsdType: "timer", ObserverType: "gauge"}, {StatsdType: "histogram", ObserverType: "gauge"}})) + assert.NoError(t, p.Initialize(true, false, false, false, []protocol.TimerHistogramMapping{{StatsdType: "timer", ObserverType: "gauge"}, {StatsdType: "histogram", ObserverType: "gauge"}})) instrument := newInstruments(nil) instrument.gauges[testDescription("statsdTestMetric1", "g", []string{"mykey", "metric_type"}, []string{"myvalue", "gauge"})] = buildGaugeMetric( @@ -1563,14 +1564,14 @@ func TestStatsDParser_GetMetricsWithMetricType(t *testing.T) { func TestStatsDParser_Mappings(t *testing.T) { type testCase struct { name string - mapping []TimerHistogramMapping + mapping []protocol.TimerHistogramMapping expect map[string]string } for _, tc := range []testCase{ { name: "timer-gauge-histo-summary", - mapping: []TimerHistogramMapping{ + mapping: []protocol.TimerHistogramMapping{ {StatsdType: "timer", ObserverType: "gauge"}, {StatsdType: "histogram", ObserverType: "summary"}, }, @@ -1581,7 +1582,7 @@ func TestStatsDParser_Mappings(t *testing.T) { }, { name: "histo-to-summary", - mapping: []TimerHistogramMapping{ + mapping: []protocol.TimerHistogramMapping{ {StatsdType: "histogram", ObserverType: "summary"}, }, expect: map[string]string{ @@ -1590,7 +1591,7 @@ func TestStatsDParser_Mappings(t *testing.T) { }, { name: "timer-summary-histo-gauge", - mapping: []TimerHistogramMapping{ + mapping: []protocol.TimerHistogramMapping{ {StatsdType: "timer", ObserverType: "summary"}, {StatsdType: "histogram", ObserverType: "gauge"}, }, @@ -1601,7 +1602,7 @@ func TestStatsDParser_Mappings(t *testing.T) { }, { name: "timer-to-gauge", - mapping: []TimerHistogramMapping{ + mapping: []protocol.TimerHistogramMapping{ {StatsdType: "timer", ObserverType: "gauge"}, }, expect: map[string]string{ @@ -1646,7 +1647,7 @@ func TestStatsDParser_ScopeIsIncluded(t *testing.T) { testAddress, _ := net.ResolveUDPAddr("udp", "1.2.3.4:5678") err := p.Initialize(true, false, false, false, - []TimerHistogramMapping{ + []protocol.TimerHistogramMapping{ {StatsdType: "timer", ObserverType: "summary"}, {StatsdType: "histogram", ObserverType: "histogram"}, }, @@ -1685,18 +1686,18 @@ func TestStatsDParser_AggregateTimerWithHistogram(t *testing.T) { // histogram size to a small number and then setting the maximum range // to test at scale 0, which is easy to reason about. The tests use // max size 10, so tests w/ a range of 2**10 appear below. - normalMapping := []TimerHistogramMapping{ + normalMapping := []protocol.TimerHistogramMapping{ { StatsdType: "timer", ObserverType: "histogram", - Histogram: HistogramConfig{ + Histogram: protocol.HistogramConfig{ MaxSize: 10, }, }, { StatsdType: "histogram", ObserverType: "histogram", - Histogram: HistogramConfig{ + Histogram: protocol.HistogramConfig{ MaxSize: 10, }, }, @@ -1719,7 +1720,7 @@ func TestStatsDParser_AggregateTimerWithHistogram(t *testing.T) { name string input []string expected pmetric.Metrics - mapping []TimerHistogramMapping + mapping []protocol.TimerHistogramMapping }{ { name: "basic", @@ -1937,7 +1938,7 @@ func TestStatsDParser_IPOnlyAggregation(t *testing.T) { testAddr02, _ := net.ResolveUDPAddr("udp", "1.2.3.4:8765") err := p.Initialize(true, false, false, true, - []TimerHistogramMapping{ + []protocol.TimerHistogramMapping{ {StatsdType: "timer", ObserverType: "summary"}, {StatsdType: "histogram", ObserverType: "histogram"}, }, diff --git a/receiver/statsdreceiver/protocol/protocol.go b/receiver/statsdreceiver/protocol/protocol.go new file mode 100644 index 000000000000..2d8e6c51f070 --- /dev/null +++ b/receiver/statsdreceiver/protocol/protocol.go @@ -0,0 +1,40 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +package protocol // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/statsdreceiver/protocol" + +type ( + TypeName string // How humans describe the MetricTypes ("counter", "gauge") + ObserverType string // How the server will aggregate histogram and timings ("gauge", "summary") +) + +const ( + CounterTypeName TypeName = "counter" + GaugeTypeName TypeName = "gauge" + HistogramTypeName TypeName = "histogram" + TimingTypeName TypeName = "timing" + TimingAltTypeName TypeName = "timer" + DistributionTypeName TypeName = "distribution" + + GaugeObserver ObserverType = "gauge" + SummaryObserver ObserverType = "summary" + HistogramObserver ObserverType = "histogram" + DisableObserver ObserverType = "disabled" + + DefaultObserverType = DisableObserver +) + +type TimerHistogramMapping struct { + StatsdType TypeName `mapstructure:"statsd_type"` + ObserverType ObserverType `mapstructure:"observer_type"` + Histogram HistogramConfig `mapstructure:"histogram"` + Summary SummaryConfig `mapstructure:"summary"` +} + +type HistogramConfig struct { + MaxSize int32 `mapstructure:"max_size"` +} + +type SummaryConfig struct { + Percentiles []float64 `mapstructure:"percentiles"` +} diff --git a/receiver/statsdreceiver/receiver.go b/receiver/statsdreceiver/receiver.go index f5114d6c66dc..788a387359e4 100644 --- a/receiver/statsdreceiver/receiver.go +++ b/receiver/statsdreceiver/receiver.go @@ -21,7 +21,7 @@ import ( "go.uber.org/zap" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/statsdreceiver/internal/metadata" - "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/statsdreceiver/internal/protocol" + "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/statsdreceiver/internal/parser" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/statsdreceiver/internal/transport" ) @@ -35,7 +35,7 @@ type statsdReceiver struct { server transport.Server reporter *reporter obsrecv *receiverhelper.ObsReport - parser protocol.Parser + parser parser.Parser nextConsumer consumer.Metrics cancel context.CancelFunc } @@ -77,7 +77,7 @@ func newReceiver( nextConsumer: nextConsumer, obsrecv: obsrecv, reporter: rep, - parser: &protocol.StatsDParser{ + parser: &parser.StatsDParser{ BuildInfo: set.BuildInfo, }, }