Skip to content
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

Rename metric to datadog.otlp_translator.resources.missing_source #229

Merged
merged 5 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .chloggen/mx-psi_rename-to-resource.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: breaking

# The name of the component (e.g. pkg/quantile)
component: pkg/otlp/metrics

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Rename `datadog.otlp_translator.metrics.missing_source` to `datadog.otlp_translator.resources.missing_source` with `signal:metrics` attribute.

# The PR related to this change
issues: [229]

# (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:
21 changes: 13 additions & 8 deletions pkg/otlp/metrics/metrics_translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/collector/pdata/pmetric"
"go.opentelemetry.io/otel/attribute"
otelmetric "go.opentelemetry.io/otel/metric"
"go.uber.org/zap"
"golang.org/x/exp/slices"
Expand All @@ -41,8 +42,12 @@ const (
metricName string = "metric name"
errNoBucketsNoSumCount string = "no buckets mode and no send count sum are incompatible"

meterName string = "github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/metrics"
missingSourceMetricName string = "datadog.otlp_translator.metrics.missing_source"
meterName string = "github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/attributes"
missingSourceMetricName string = "datadog.otlp_translator.resources.missing_source"
)

var (
signalTypeSet = attribute.NewSet(attribute.String("signal", "logs"))
mx-psi marked this conversation as resolved.
Show resolved Hide resolved
)

var _ source.Provider = (*noSourceProvider)(nil)
Expand Down Expand Up @@ -101,7 +106,7 @@ func NewTranslator(set component.TelemetrySettings, options ...TranslatorOption)
missingSources, err := meter.Int64Counter(
missingSourceMetricName,
otelmetric.WithDescription("OTLP metrics that are missing a source (e.g. hostname)"),
mx-psi marked this conversation as resolved.
Show resolved Hide resolved
otelmetric.WithUnit("[metric]"),
otelmetric.WithUnit("{resource}"),
)
if err != nil {
return nil, fmt.Errorf("failed to build missing source counter: %w", err)
Expand Down Expand Up @@ -678,6 +683,11 @@ func (t *Translator) MapMetrics(ctx context.Context, md pmetric.Metrics, consume
if err != nil {
return metadata, err
}
if !hasSource {
// Only count metrics if they do not come from the translator itself.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment seems outdated ?

t.instruments.missingSources.Add(ctx, 1, otelmetric.WithAttributeSet(signalTypeSet))
}

var host string
switch src.Kind {
case source.HostnameKind:
Expand All @@ -699,11 +709,6 @@ func (t *Translator) MapMetrics(ctx context.Context, md pmetric.Metrics, consume
ilm := ilms.At(j)
metricsArray := ilm.Metrics()

if !hasSource && ilm.Scope().Name() != meterName {
// Only count metrics if they do not come from the translator itself.
t.instruments.missingSources.Add(ctx, int64(metricsArray.Len()))
}

var additionalTags []string
if t.cfg.InstrumentationScopeMetadataAsTags {
additionalTags = append(attributeTags, instrumentationscope.TagsFromInstrumentationScopeMetadata(ilm.Scope())...)
Expand Down
2 changes: 1 addition & 1 deletion pkg/otlp/metrics/source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func TestInternalTelemetryMetrics(t *testing.T) {
name: "simple",
otlpfile: "testdata/otlpdata/source/simple.json",
ddogfile: "testdata/datadogdata/source/simple.json",
expectedNumMissing: 4,
expectedNumMissing: 1,
},
}

Expand Down
Loading