-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
host.go
79 lines (67 loc) · 3.13 KB
/
host.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package hostmetadata // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/datadogexporter/internal/hostmetadata"
import (
"fmt"
"github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/attributes/source"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/featuregate"
"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/datadogexporter/internal/hostmetadata/internal/azure"
"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/datadogexporter/internal/hostmetadata/internal/ec2"
"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/datadogexporter/internal/hostmetadata/internal/ecs"
"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/datadogexporter/internal/hostmetadata/internal/gcp"
"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/datadogexporter/internal/hostmetadata/internal/k8s"
"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/datadogexporter/internal/hostmetadata/internal/system"
"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/datadogexporter/internal/hostmetadata/provider"
)
var _ = featuregate.GlobalRegistry().MustRegister(
"exporter.datadog.hostname.preview",
featuregate.StageStable,
featuregate.WithRegisterDescription("Use the 'preview' hostname resolution rules, which are consistent with Datadog cloud integration hostname resolution rules, and set 'host_metadata::hostname_source' to 'config_or_system' by default."),
featuregate.WithRegisterReferenceURL("https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/10424"),
featuregate.WithRegisterToVersion("0.75.0"),
)
func GetSourceProvider(set component.TelemetrySettings, configHostname string) (source.Provider, error) {
ecs, err := ecs.NewProvider(set)
if err != nil {
return nil, fmt.Errorf("failed to build ECS Fargate provider: %w", err)
}
azureProvider := azure.NewProvider()
ec2Provider, err := ec2.NewProvider(set.Logger)
if err != nil {
return nil, fmt.Errorf("failed to build EC2 provider: %w", err)
}
gcpProvider := gcp.NewProvider()
clusterNameProvider, err := provider.ChainCluster(set.Logger,
map[string]provider.ClusterNameProvider{
"azure": azureProvider,
"ec2": ec2Provider,
"gcp": gcpProvider,
},
[]string{"azure", "ec2", "gcp"},
)
if err != nil {
return nil, fmt.Errorf("failed to build Kubernetes cluster name provider: %w", err)
}
k8sProvider, err := k8s.NewProvider(set.Logger, clusterNameProvider)
if err != nil {
return nil, fmt.Errorf("failed to build Kubernetes hostname provider: %w", err)
}
chain, err := provider.Chain(
set.Logger,
map[string]source.Provider{
"config": provider.Config(configHostname),
"azure": azureProvider,
"ecs": ecs,
"ec2": ec2Provider,
"gcp": gcpProvider,
"kubernetes": k8sProvider,
"system": system.NewProvider(set.Logger),
},
[]string{"config", "azure", "ecs", "ec2", "gcp", "kubernetes", "system"},
)
if err != nil {
return nil, err
}
return provider.Once(chain), nil
}