mirror of
https://github.com/hanzoai/telemetry.git
synced 2026-10-30 20:01:49 +00:00
Partially resolves https://github.com/open-telemetry/opentelemetry-collector/issues/14814 (removes duplicated attributes) Internal collector metrics exposed with Prometheus by default have duplicated service labels (`service_name`, `service_instance_id`, `service_version`) on every datapoint while the same service attributes emitted as `target_info` labels ending up as proper resource attributes which the metrics scraped with Prometheus receiver (`service.name`, `service.instance.id`, `service. version`) The duplicated labels on every internal metric datapoint were added for OpenCensus backwards compatibility in #9029 long time ago. Given that now the `target_info` is correctly translated to Resource attributes and the duplication leads to https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/47011, it should be good time to remove it. --------- Co-authored-by: Yang Song <[email protected]>
48 lines
1.1 KiB
Go
48 lines
1.1 KiB
Go
// Copyright The OpenTelemetry Authors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package promtest // import "go.opentelemetry.io/collector/service/internal/promtest"
|
|
|
|
import (
|
|
"net"
|
|
"strconv"
|
|
"testing"
|
|
|
|
config "go.opentelemetry.io/contrib/otelconf/v0.3.0"
|
|
|
|
"go.opentelemetry.io/collector/internal/testutil"
|
|
)
|
|
|
|
func GetAvailableLocalIPv6AddressPrometheus(tb testing.TB) *config.Prometheus {
|
|
return addrToPrometheus(testutil.GetAvailableLocalIPv6Address(tb))
|
|
}
|
|
|
|
func GetAvailableLocalAddressPrometheus(tb testing.TB) *config.Prometheus {
|
|
return addrToPrometheus(testutil.GetAvailableLocalAddress(tb))
|
|
}
|
|
|
|
func addrToPrometheus(address string) *config.Prometheus {
|
|
host, port, err := net.SplitHostPort(address)
|
|
if host == "::1" {
|
|
host = "[::1]"
|
|
}
|
|
if err != nil {
|
|
return nil
|
|
}
|
|
portInt, err := strconv.Atoi(port)
|
|
if err != nil {
|
|
return nil
|
|
}
|
|
return &config.Prometheus{
|
|
Host: &host,
|
|
Port: &portInt,
|
|
WithoutScopeInfo: ptr(true),
|
|
WithoutUnits: ptr(true),
|
|
WithoutTypeSuffix: ptr(true),
|
|
}
|
|
}
|
|
|
|
func ptr[T any](v T) *T {
|
|
return &v
|
|
}
|