Skip to content

Commit

Permalink
Olivierg/gateway usage gauge (open-telemetry#37499)
Browse files Browse the repository at this point in the history
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
#### Description

This PR adds a new gauge metric `datadog.otel.gateway`. This metric is
set at `1` when the collector is used as a gateway otherwise, the value
is `0`.
If `datadog.host.name` was sent with two different values, then the
collector is used as a gateway.

Note: [The PR on
opentelemetry-mapping-go](DataDog/opentelemetry-mapping-go#479)
should be merged before this PR and `go.mod` must use a commit on main
instead of `0.24.1-0.20250124131402-bcd6fd1617a6`

Associated PRs:
- DataDog/opentelemetry-mapping-go#479
- DataDog/datadog-agent#33370
<!-- Issue number (e.g. open-telemetry#1234) or full URL to issue, if applicable. -->
#### Link to tracking issue
Fixes

<!--Describe what testing was performed and which tests were added.-->
#### Testing
The following commands generates the metric `datadog.otel.gateway` at
`1`
```
telemetrygen metrics --otlp-insecure   --otlp-attributes "datadog.host.name"=\"host1\"
telemetrygen metrics --otlp-insecure   --otlp-attributes "datadog.host.name"=\"host2\"
```

Same tests were performed for `traces` and for `logs` when
`isLogsAgentExporterEnabled` is false.


<!--Describe the documentation added.-->
#### Documentation

<!--Please delete paragraphs that you did not use before submitting.-->

---------

Co-authored-by: Yang Song <[email protected]>
  • Loading branch information
2 people authored and chengchuanpeng committed Feb 8, 2025
1 parent 11cda6f commit 5fa1119
Show file tree
Hide file tree
Showing 21 changed files with 369 additions and 230 deletions.
27 changes: 27 additions & 0 deletions .chloggen/olivierg_gateway-usage-gauge.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: datadogexporter

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Add a gauge metric datadog.otel.gateway which is 1 if the collector is used as a gateway or 0 otherwise.

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

# (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: []
6 changes: 3 additions & 3 deletions connector/datadogconnector/connector_native_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func TestContainerTagsNative(t *testing.T) {

ch := make(chan []byte, 100)
tr := newTranslatorWithStatsChannel(t, zap.NewNop(), ch)
_, err = tr.MapMetrics(context.Background(), metrics[0], nil)
_, err = tr.MapMetrics(context.Background(), metrics[0], nil, nil)
require.NoError(t, err)
msg := <-ch
sp := &pb.StatsPayload{}
Expand Down Expand Up @@ -211,7 +211,7 @@ func testMeasuredAndClientKindNative(t *testing.T, enableOperationAndResourceNam

ch := make(chan []byte, 100)
tr := newTranslatorWithStatsChannel(t, zap.NewNop(), ch)
_, err = tr.MapMetrics(context.Background(), metrics[0], nil)
_, err = tr.MapMetrics(context.Background(), metrics[0], nil, nil)
require.NoError(t, err)
msg := <-ch
sp := &pb.StatsPayload{}
Expand Down Expand Up @@ -326,7 +326,7 @@ func TestObfuscate(t *testing.T) {

ch := make(chan []byte, 100)
tr := newTranslatorWithStatsChannel(t, zap.NewNop(), ch)
_, err = tr.MapMetrics(context.Background(), metrics[0], nil)
_, err = tr.MapMetrics(context.Background(), metrics[0], nil, nil)
require.NoError(t, err)
msg := <-ch
sp := &pb.StatsPayload{}
Expand Down
6 changes: 3 additions & 3 deletions connector/datadogconnector/connector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func TestContainerTags(t *testing.T) {

ch := make(chan []byte, 100)
tr := newTranslatorWithStatsChannel(t, zap.NewNop(), ch)
_, err = tr.MapMetrics(context.Background(), metrics[0], nil)
_, err = tr.MapMetrics(context.Background(), metrics[0], nil, nil)
require.NoError(t, err)
msg := <-ch
sp := &pb.StatsPayload{}
Expand Down Expand Up @@ -240,7 +240,7 @@ func testReceiveResourceSpansV2(t *testing.T, enableReceiveResourceSpansV2 bool)

ch := make(chan []byte, 100)
tr := newTranslatorWithStatsChannel(t, zap.NewNop(), ch)
_, err = tr.MapMetrics(context.Background(), metrics[0], nil)
_, err = tr.MapMetrics(context.Background(), metrics[0], nil, nil)
require.NoError(t, err)
msg := <-ch
sp := &pb.StatsPayload{}
Expand Down Expand Up @@ -299,7 +299,7 @@ func testOperationAndResourceNameV2(t *testing.T, enableOperationAndResourceName

ch := make(chan []byte, 100)
tr := newTranslatorWithStatsChannel(t, zap.NewNop(), ch)
_, err = tr.MapMetrics(context.Background(), metrics[0], nil)
_, err = tr.MapMetrics(context.Background(), metrics[0], nil, nil)
require.NoError(t, err)
msg := <-ch
sp := &pb.StatsPayload{}
Expand Down
38 changes: 19 additions & 19 deletions connector/datadogconnector/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ go 1.22.0

require (
github.com/DataDog/datadog-agent/comp/otelcol/otlp/components/metricsclient v0.61.0
github.com/DataDog/datadog-agent/comp/otelcol/otlp/components/statsprocessor v0.61.0
github.com/DataDog/datadog-agent/pkg/obfuscate v0.63.0-devel.0.20250123185937-1feb84b482c8
github.com/DataDog/datadog-agent/pkg/proto v0.63.0-devel.0.20250123185937-1feb84b482c8
github.com/DataDog/datadog-agent/pkg/trace v0.64.0-devel.0.20250129182827-bab631c10d61
github.com/DataDog/datadog-agent/comp/otelcol/otlp/components/statsprocessor v0.64.0-devel.0.20250203170818-31c3d5c28ba0
github.com/DataDog/datadog-agent/pkg/obfuscate v0.64.0-devel.0.20250129111638-01c8fb06949e
github.com/DataDog/datadog-agent/pkg/proto v0.64.0-devel
github.com/DataDog/datadog-agent/pkg/trace v0.64.0-devel.0.20250203170818-31c3d5c28ba0
github.com/DataDog/datadog-go/v5 v5.6.0
github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/attributes v0.24.0
github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/metrics v0.24.0
github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/attributes v0.25.0
github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/metrics v0.25.0
github.com/google/go-cmp v0.6.0
github.com/open-telemetry/opentelemetry-collector-contrib/exporter/datadogexporter v0.119.0
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/datadog v0.119.0
Expand Down Expand Up @@ -50,7 +50,7 @@ require (
github.com/DataDog/datadog-agent/comp/core/hostname/hostnameinterface v0.61.0 // indirect
github.com/DataDog/datadog-agent/comp/core/log/def v0.61.0 // indirect
github.com/DataDog/datadog-agent/comp/core/secrets v0.61.0 // indirect
github.com/DataDog/datadog-agent/comp/core/tagger/origindetection v0.0.0-20241217122454-175edb6c74f2 // indirect
github.com/DataDog/datadog-agent/comp/core/tagger/origindetection v0.64.0-devel // indirect
github.com/DataDog/datadog-agent/comp/core/telemetry v0.61.0 // indirect
github.com/DataDog/datadog-agent/comp/def v0.61.0 // indirect
github.com/DataDog/datadog-agent/comp/logs/agent/config v0.61.0 // indirect
Expand Down Expand Up @@ -90,7 +90,7 @@ require (
github.com/DataDog/datadog-agent/pkg/util/fxutil v0.61.0 // indirect
github.com/DataDog/datadog-agent/pkg/util/hostname/validate v0.61.0 // indirect
github.com/DataDog/datadog-agent/pkg/util/http v0.61.0 // indirect
github.com/DataDog/datadog-agent/pkg/util/log v0.63.0-devel.0.20250123185937-1feb84b482c8 // indirect
github.com/DataDog/datadog-agent/pkg/util/log v0.64.0-devel.0.20250129111638-01c8fb06949e // indirect
github.com/DataDog/datadog-agent/pkg/util/optional v0.61.0 // indirect
github.com/DataDog/datadog-agent/pkg/util/pointer v0.61.0 // indirect
github.com/DataDog/datadog-agent/pkg/util/scrubber v0.61.0 // indirect
Expand All @@ -105,9 +105,9 @@ require (
github.com/DataDog/go-sqllexer v0.0.20 // indirect
github.com/DataDog/go-tuf v1.1.0-0.5.2 // indirect
github.com/DataDog/gohai v0.0.0-20230524154621-4316413895ee // indirect
github.com/DataDog/opentelemetry-mapping-go/pkg/inframetadata v0.24.0 // indirect
github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/logs v0.24.0 // indirect
github.com/DataDog/opentelemetry-mapping-go/pkg/quantile v0.24.0 // indirect
github.com/DataDog/opentelemetry-mapping-go/pkg/inframetadata v0.25.0 // indirect
github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/logs v0.25.0 // indirect
github.com/DataDog/opentelemetry-mapping-go/pkg/quantile v0.25.0 // indirect
github.com/DataDog/sketches-go v1.4.6 // indirect
github.com/DataDog/viper v1.14.0 // indirect
github.com/DataDog/zstd v1.5.6 // indirect
Expand Down Expand Up @@ -187,7 +187,7 @@ require (
github.com/knadh/koanf/maps v0.1.1 // indirect
github.com/knadh/koanf/providers/confmap v0.1.0 // indirect
github.com/knadh/koanf/v2 v2.1.2 // indirect
github.com/lufia/plan9stats v0.0.0-20220913051719-115f729f3c8c // indirect
github.com/lufia/plan9stats v0.0.0-20240909124753-873cd0166683 // indirect
github.com/magefile/mage v1.15.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
Expand Down Expand Up @@ -220,13 +220,13 @@ require (
github.com/pkg/errors v0.9.1 // indirect
github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/power-devops/perfstat v0.0.0-20220216144756-c35f1ee13d7c // indirect
github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 // indirect
github.com/prometheus/client_golang v1.20.5 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.62.0 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/rs/cors v1.11.1 // indirect
github.com/secure-systems-lab/go-securesystemslib v0.8.0 // indirect
github.com/secure-systems-lab/go-securesystemslib v0.9.0 // indirect
github.com/shirou/gopsutil/v3 v3.24.5 // indirect
github.com/shirou/gopsutil/v4 v4.25.1 // indirect
github.com/shoenig/go-m1cpu v0.1.6 // indirect
Expand All @@ -239,7 +239,7 @@ require (
github.com/stretchr/objx v0.5.2 // indirect
github.com/tinylib/msgp v1.2.5 // indirect
github.com/tklauser/go-sysconf v0.3.14 // indirect
github.com/tklauser/numcpus v0.8.0 // indirect
github.com/tklauser/numcpus v0.9.0 // indirect
github.com/ua-parser/uap-go v0.0.0-20240611065828-3a4781585db6 // indirect
github.com/x448/float16 v0.8.4 // indirect
github.com/yusufpapurcu/wmi v1.2.4 // indirect
Expand Down Expand Up @@ -309,16 +309,16 @@ require (
go.uber.org/dig v1.18.0 // indirect
go.uber.org/fx v1.22.2 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/exp v0.0.0-20241217172543-b2144cdd0a67 // indirect
golang.org/x/exp v0.0.0-20250128182459-e0ece0dbea4c // indirect
golang.org/x/net v0.34.0 // indirect
golang.org/x/oauth2 v0.24.0 // indirect
golang.org/x/oauth2 v0.25.0 // indirect
golang.org/x/sys v0.30.0 // indirect
golang.org/x/term v0.28.0 // indirect
golang.org/x/text v0.22.0 // indirect
golang.org/x/time v0.8.0 // indirect
golang.org/x/time v0.9.0 // indirect
gonum.org/v1/gonum v0.15.1 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20250115164207-1a7da9e5054f // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20250115164207-1a7da9e5054f // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20250127172529-29210b9bc287 // indirect
google.golang.org/grpc v1.70.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
Expand Down
Loading

0 comments on commit 5fa1119

Please sign in to comment.