Skip to content

Commit

Permalink
[chore] update statsd receiver to use mdatagen (#33525)
Browse files Browse the repository at this point in the history
This updates the receiver to use mdatagen for internal telemetry.

Fixes #33524

---------

Signed-off-by: Alex Boten <[email protected]>
  • Loading branch information
codeboten authored Jun 13, 2024
1 parent 5c765a3 commit 7dc158c
Show file tree
Hide file tree
Showing 8 changed files with 200 additions and 18 deletions.
27 changes: 27 additions & 0 deletions .chloggen/codeboten_mdatagen-statsd.yaml
Original file line number Diff line number Diff line change
@@ -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: statsdreceiver

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: update statsd receiver to use mdatagen

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [33524]

# (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:

# 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: []
15 changes: 15 additions & 0 deletions receiver/statsdreceiver/documentation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[comment]: <> (Code generated by mdatagen. DO NOT EDIT.)

# statsd

## Internal Telemetry

The following telemetry is emitted by this component.

### receiver_received_statsd_metrics

Number of statsd metrics received.

| Unit | Metric Type | Value Type | Monotonic |
| ---- | ----------- | ---------- | --------- |
| 1 | Sum | Int | true |
76 changes: 76 additions & 0 deletions receiver/statsdreceiver/generated_component_telemetry_test.go

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

4 changes: 2 additions & 2 deletions receiver/statsdreceiver/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ require (
go.opentelemetry.io/collector v0.102.2-0.20240611143128-7dfb57b9ad1c
go.opentelemetry.io/collector/component v0.102.2-0.20240611143128-7dfb57b9ad1c
go.opentelemetry.io/collector/config/confignet v0.102.2-0.20240611143128-7dfb57b9ad1c
go.opentelemetry.io/collector/config/configtelemetry v0.102.2-0.20240611143128-7dfb57b9ad1c
go.opentelemetry.io/collector/confmap v0.102.2-0.20240611143128-7dfb57b9ad1c
go.opentelemetry.io/collector/consumer v0.102.2-0.20240611143128-7dfb57b9ad1c
go.opentelemetry.io/collector/pdata v1.9.1-0.20240611143128-7dfb57b9ad1c
go.opentelemetry.io/collector/receiver v0.102.2-0.20240611143128-7dfb57b9ad1c
go.opentelemetry.io/collector/semconv v0.102.2-0.20240611143128-7dfb57b9ad1c
go.opentelemetry.io/otel v1.27.0
go.opentelemetry.io/otel/metric v1.27.0
go.opentelemetry.io/otel/sdk/metric v1.27.0
go.opentelemetry.io/otel/trace v1.27.0
go.uber.org/goleak v1.3.0
go.uber.org/multierr v1.11.0
Expand Down Expand Up @@ -47,11 +49,9 @@ require (
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.54.0 // indirect
github.com/prometheus/procfs v0.15.0 // indirect
go.opentelemetry.io/collector/config/configtelemetry v0.102.2-0.20240611143128-7dfb57b9ad1c // indirect
go.opentelemetry.io/collector/featuregate v1.9.1-0.20240611143128-7dfb57b9ad1c // indirect
go.opentelemetry.io/otel/exporters/prometheus v0.49.0 // indirect
go.opentelemetry.io/otel/sdk v1.27.0 // indirect
go.opentelemetry.io/otel/sdk/metric v1.27.0 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/text v0.16.0 // indirect
Expand Down
47 changes: 46 additions & 1 deletion receiver/statsdreceiver/internal/metadata/generated_telemetry.go

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

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

10 changes: 10 additions & 0 deletions receiver/statsdreceiver/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,13 @@ status:
distributions: [contrib]
codeowners:
active: [jmacd, dmitryax]

telemetry:
metrics:
receiver_received_statsd_metrics:
enabled: true
description: Number of statsd metrics received.
unit: "1"
sum:
value_type: int
monotonic: true
26 changes: 11 additions & 15 deletions receiver/statsdreceiver/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ import (
// reporter struct implements the transport.Reporter interface to give consistent
// observability per Collector metric observability package.
type reporter struct {
logger *zap.Logger
sugaredLogger *zap.SugaredLogger // Used for generic debug logging
receiverAttr attribute.KeyValue
receivedCount metric.Int64Counter
logger *zap.Logger
sugaredLogger *zap.SugaredLogger // Used for generic debug logging
receiverAttr attribute.KeyValue
telemetryBuilder *metadata.TelemetryBuilder
}

var (
Expand All @@ -29,19 +29,15 @@ var (
)

func newReporter(set receiver.Settings) (*reporter, error) {
receivedCount, err := metadata.Meter(set.TelemetrySettings).Int64Counter(
"receiver/received_statsd_metrics",
metric.WithDescription("Number of statsd metrics received."),
metric.WithUnit("1"),
)
telemetryBuilder, err := metadata.NewTelemetryBuilder(set.TelemetrySettings)
if err != nil {
return nil, err
}
return &reporter{
logger: set.Logger,
sugaredLogger: set.Logger.Sugar(),
receiverAttr: attribute.String("receiver", set.ID.String()),
receivedCount: receivedCount,
logger: set.Logger,
sugaredLogger: set.Logger.Sugar(),
receiverAttr: attribute.String("receiver", set.ID.String()),
telemetryBuilder: telemetryBuilder,
}, nil
}

Expand All @@ -52,7 +48,7 @@ func (r *reporter) OnDebugf(template string, args ...any) {
}

func (r *reporter) RecordParseFailure() {
r.receivedCount.Add(
r.telemetryBuilder.ReceiverReceivedStatsdMetrics.Add(
context.Background(),
1,
metric.WithAttributes(
Expand All @@ -62,7 +58,7 @@ func (r *reporter) RecordParseFailure() {
}

func (r *reporter) RecordParseSuccess(count int64) {
r.receivedCount.Add(
r.telemetryBuilder.ReceiverReceivedStatsdMetrics.Add(
context.Background(),
count,
metric.WithAttributes(
Expand Down

0 comments on commit 7dc158c

Please sign in to comment.