Skip to content

Commit

Permalink
[processor/probabilisticsampler] use generated status header (#22759)
Browse files Browse the repository at this point in the history
This PR updates the component to generate the status table using mdatagen.

Linked issue: #21213

Signed-off-by: Alex Boten <[email protected]>
  • Loading branch information
Alex Boten authored May 25, 2023
1 parent 475c130 commit a74f8e5
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 28 deletions.
29 changes: 15 additions & 14 deletions processor/probabilisticsamplerprocessor/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
# Probabilistic Sampling Processor

| Status | |
| ------------------------ | ----------------------------------------------- |
| Stability | traces [beta] |
| | logs [alpha] |
| Supported pipeline types | traces, logs |
| Distributions | [core], [contrib], [observiq], [splunk], [sumo] |
<!-- status autogenerated section -->
| Status | |
| ------------- |-----------|
| Stability | [alpha]: logs |
| | [beta]: traces |
| Distributions | [core], [contrib], [observiq], [splunk], [sumo] |

[alpha]: https://github.com/open-telemetry/opentelemetry-collector#alpha
[beta]: https://github.com/open-telemetry/opentelemetry-collector#beta
[core]: https://github.com/open-telemetry/opentelemetry-collector-releases/tree/main/distributions/otelcol
[contrib]: https://github.com/open-telemetry/opentelemetry-collector-releases/tree/main/distributions/otelcol-contrib
[observiq]: https://github.com/observIQ/observiq-otel-collector
[splunk]: https://github.com/signalfx/splunk-otel-collector
[sumo]: https://github.com/SumoLogic/sumologic-otel-collector
<!-- end autogenerated section -->

The probabilistic sampler supports two types of sampling for traces:

Expand Down Expand Up @@ -80,11 +89,3 @@ processors:

Refer to [config.yaml](./testdata/config.yaml) for detailed
examples on using the processor.

[alpha]: https://github.com/open-telemetry/opentelemetry-collector#alpha
[beta]: https://github.com/open-telemetry/opentelemetry-collector#beta
[contrib]: https://github.com/open-telemetry/opentelemetry-collector-releases/tree/main/distributions/otelcol-contrib
[core]: https://github.com/open-telemetry/opentelemetry-collector-releases/tree/main/distributions/otelcol
[splunk]: https://github.com/signalfx/splunk-otel-collector
[observiq]: https://github.com/observIQ/observiq-otel-collector
[sumo]: https://github.com/SumoLogic/sumologic-otel-collector
8 changes: 5 additions & 3 deletions processor/probabilisticsamplerprocessor/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/confmap/confmaptest"
"go.opentelemetry.io/collector/otelcol/otelcoltest"

"github.com/open-telemetry/opentelemetry-collector-contrib/processor/probabilisticsamplerprocessor/internal/metadata"
)

func TestLoadConfig(t *testing.T) {
Expand All @@ -21,15 +23,15 @@ func TestLoadConfig(t *testing.T) {
expected component.Config
}{
{
id: component.NewIDWithName(typeStr, ""),
id: component.NewIDWithName(metadata.Type, ""),
expected: &Config{
SamplingPercentage: 15.3,
HashSeed: 22,
AttributeSource: "traceID",
},
},
{
id: component.NewIDWithName(typeStr, "logs"),
id: component.NewIDWithName(metadata.Type, "logs"),
expected: &Config{
SamplingPercentage: 15.3,
HashSeed: 22,
Expand Down Expand Up @@ -65,7 +67,7 @@ func TestLoadInvalidConfig(t *testing.T) {
require.NoError(t, err)

factory := NewFactory()
factories.Processors[typeStr] = factory
factories.Processors[metadata.Type] = factory

_, err = otelcoltest.LoadConfigAndValidate(filepath.Join("testdata", "invalid.yaml"), factories)
require.ErrorContains(t, err, "negative sampling rate: -15.30")
Expand Down
15 changes: 6 additions & 9 deletions processor/probabilisticsamplerprocessor/factory.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

//go:generate mdatagen metadata.yaml

package probabilisticsamplerprocessor // import "github.com/open-telemetry/opentelemetry-collector-contrib/processor/probabilisticsamplerprocessor"

import (
Expand All @@ -12,13 +14,8 @@ import (
"go.opentelemetry.io/collector/config/configtelemetry"
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/processor"
)

const (
// The value of "type" trace-samplers in configuration.
typeStr = "probabilistic_sampler"
// The stability level of the processor.
stability = component.StabilityLevelBeta
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/probabilisticsamplerprocessor/internal/metadata"
)

var onceMetrics sync.Once
Expand All @@ -31,10 +28,10 @@ func NewFactory() processor.Factory {
})

return processor.NewFactory(
typeStr,
metadata.Type,
createDefaultConfig,
processor.WithTraces(createTracesProcessor, stability),
processor.WithLogs(createLogsProcessor, component.StabilityLevelAlpha))
processor.WithTraces(createTracesProcessor, metadata.TracesStability),
processor.WithLogs(createLogsProcessor, metadata.LogsStability))
}

func createDefaultConfig() component.Config {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions processor/probabilisticsamplerprocessor/metadata.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
type: probabilistic_sampler

status:
class: processor
stability:
beta: [traces]
alpha: [logs]
distributions: [core, contrib, observiq, splunk, sumo]
6 changes: 4 additions & 2 deletions processor/probabilisticsamplerprocessor/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"go.opencensus.io/tag"
"go.opentelemetry.io/collector/config/configtelemetry"
"go.opentelemetry.io/collector/obsreport"

"github.com/open-telemetry/opentelemetry-collector-contrib/processor/probabilisticsamplerprocessor/internal/metadata"
)

// Variables related to metrics specific to tail sampling.
Expand All @@ -28,14 +30,14 @@ func SamplingProcessorMetricViews(level configtelemetry.Level) []*view.View {

sampledTagKeys := []tag.Key{tagPolicyKey, tagSampledKey}
countTracesSampledView := &view.View{
Name: obsreport.BuildProcessorCustomMetricName(typeStr, statCountTracesSampled.Name()),
Name: obsreport.BuildProcessorCustomMetricName(metadata.Type, statCountTracesSampled.Name()),
Measure: statCountTracesSampled,
Description: statCountTracesSampled.Description(),
TagKeys: sampledTagKeys,
Aggregation: view.Sum(),
}
countLogsSampledView := &view.View{
Name: obsreport.BuildProcessorCustomMetricName(typeStr, statCountLogsSampled.Name()),
Name: obsreport.BuildProcessorCustomMetricName(metadata.Type, statCountLogsSampled.Name()),
Measure: statCountLogsSampled,
Description: statCountLogsSampled.Description(),
TagKeys: sampledTagKeys,
Expand Down

0 comments on commit a74f8e5

Please sign in to comment.