Debian Codegraph @

service/internal/promtest/server_util.go

raw
1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
3
4 package promtest // import "go.opentelemetry.io/collector/service/internal/promtest"
5
6 import (
7 "net"
8 "strconv"
9 "testing"
10
11 config "go.opentelemetry.io/contrib/otelconf/v0.3.0"
12
13 "go.opentelemetry.io/collector/internal/testutil"
14 )
15
16 func GetAvailableLocalIPv6AddressPrometheus(tb testing.TB) *config.Prometheus {
17 return addrToPrometheus(testutil.GetAvailableLocalIPv6Address(tb))
18 }
19
20 func GetAvailableLocalAddressPrometheus(tb testing.TB) *config.Prometheus {
21 return addrToPrometheus(testutil.GetAvailableLocalAddress(tb))
22 }
23
24 func addrToPrometheus(address string) *config.Prometheus {
25 host, port, err := net.SplitHostPort(address)
26 if host == "::1" {
27 host = "[::1]"
28 }
29 if err != nil {
30 return nil
31 }
32 portInt, err := strconv.Atoi(port)
33 if err != nil {
34 return nil
35 }
36 return &config.Prometheus{
37 Host: &host,
38 Port: &portInt,
39 WithoutScopeInfo: ptr(true),
40 WithoutUnits: ptr(true),
41 WithoutTypeSuffix: ptr(true),
42 WithResourceConstantLabels: &config.IncludeExclude{
43 Included: []string{},
44 },
45 }
46 }
47
48 func ptr[T any](v T) *T {
49 return &v
50 }