Skip to content

Commit 5e34d71

Browse files
authored
Add Azure platform detection to the translator (#2183)
1 parent efeca8f commit 5e34d71

43 files changed

Lines changed: 2383 additions & 164 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

cfg/envconfig/envconfig.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const (
2626
RunInContainer = "RUN_IN_CONTAINER"
2727
RunAsHostProcessContainer = "RUN_AS_HOST_PROCESS_CONTAINER"
2828
RunInAWS = "RUN_IN_AWS"
29+
RunInAKS = "RUN_IN_AKS"
2930
RunWithIRSA = "RUN_WITH_IRSA"
3031
RunWithSELinux = "RUN_WITH_SELINUX"
3132
RunInROSA = "RUN_IN_ROSA"
@@ -89,6 +90,11 @@ func IsRunningInROSA() bool {
8990
return os.Getenv(RunInROSA) == TrueValue
9091
}
9192

93+
// IsRunningInAKS reports whether RUN_IN_AKS is set (by the AKS Helm chart) so AKS is detected without a metadata probe.
94+
func IsRunningInAKS() bool {
95+
return os.Getenv(RunInAKS) == TrueValue
96+
}
97+
9298
func GetLogsBackpressureMode() string {
9399
return os.Getenv(CWAgentLogsBackpressureMode)
94100
}

go.mod

Lines changed: 44 additions & 42 deletions
Large diffs are not rendered by default.

go.sum

Lines changed: 86 additions & 84 deletions
Large diffs are not rendered by default.

service/defaultcomponents/components.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"github.com/open-telemetry/opentelemetry-collector-contrib/extension/headerssetterextension"
1818
"github.com/open-telemetry/opentelemetry-collector-contrib/extension/healthcheckextension"
1919
"github.com/open-telemetry/opentelemetry-collector-contrib/extension/observer/ecsobserver"
20+
"github.com/open-telemetry/opentelemetry-collector-contrib/extension/oidctokenextension"
2021
"github.com/open-telemetry/opentelemetry-collector-contrib/extension/pprofextension"
2122
"github.com/open-telemetry/opentelemetry-collector-contrib/extension/sigv4authextension"
2223
"github.com/open-telemetry/opentelemetry-collector-contrib/extension/storage/filestorage"
@@ -187,6 +188,7 @@ func Factories() (otelcol.Factories, error) {
187188
ecsobserver.NewFactory(),
188189
filestorage.NewFactory(),
189190
healthcheckextension.NewFactory(),
191+
oidctokenextension.NewFactory(),
190192
pprofextension.NewFactory(),
191193
sigv4authextension.NewFactory(),
192194
zpagesextension.NewFactory(),

service/defaultcomponents/components_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ func TestComponents(t *testing.T) {
126126
"health_check",
127127
"k8smetadata",
128128
"nodemetadatacache",
129+
"oidctoken",
129130
"pprof",
130131
"server",
131132
"sigv4auth",

tool/paths/paths.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const (
1111
ENV = "env-config.json"
1212
AGENT_LOG_FILE = "amazon-cloudwatch-agent.log"
1313
JMXJarName = "opentelemetry-jmx-metrics.jar"
14+
OIDCToken = ".oidc-token"
1415
)
1516

1617
var (
@@ -24,4 +25,5 @@ var (
2425
TranslatorBinaryPath string
2526
AgentBinaryPath string
2627
JMXJarPath string
28+
OIDCTokenPath string
2729
)

tool/paths/paths_unix.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,5 @@ func init() {
3131
TranslatorBinaryPath = filepath.Join(AgentDir, "bin", TranslatorBinaryName)
3232
AgentBinaryPath = filepath.Join(AgentDir, "bin", AgentBinaryName)
3333
JMXJarPath = filepath.Join(AgentDir, "bin", JMXJarName)
34+
OIDCTokenPath = filepath.Join(AgentDir, "etc", OIDCToken)
3435
}

tool/paths/paths_windows.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,5 @@ func init() {
5353
TranslatorBinaryPath = filepath.Join(AgentRootDir, TranslatorBinaryName)
5454
AgentBinaryPath = filepath.Join(AgentRootDir, AgentBinaryName)
5555
JMXJarPath = filepath.Join(AgentRootDir, JMXJarName)
56+
OIDCTokenPath = filepath.Join(AgentConfigDir, OIDCToken)
5657
}

translator/config/mode.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,19 @@ const (
2020
ModeK8sOnPrem = "K8sOnPrem"
2121
)
2222

23+
// Azure platform modes: ModeAzureVM is host-level (like ModeEC2), ModeAKS is Kubernetes-level (like ModeEKS).
24+
const (
25+
ModeAzureVM = "AzureVM"
26+
ModeAKS = "AKS"
27+
)
28+
2329
const (
2430
ShortModeEC2 = "EC2"
2531
ShortModeOnPrem = "OP"
2632
ShortModeWithIRSA = "WI"
2733
ShortModeEKS = "EKS"
2834
ShortModeK8sEC2 = "K8E"
2935
ShortModeK8sOnPrem = "K8OP"
36+
ShortModeAzureVM = "AZVM"
37+
ShortModeAKS = "AKS"
3038
)

translator/context/context.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,11 @@ func (ctx *Context) SetMode(mode string) {
129129
case config.ModeWithIRSA:
130130
ctx.mode = config.ModeWithIRSA
131131
ctx.shortMode = config.ShortModeWithIRSA
132+
case config.ModeAzureVM:
133+
ctx.mode = config.ModeAzureVM
134+
ctx.shortMode = config.ShortModeAzureVM
132135
default:
133-
log.Panicf("Invalid mode %s. Valid mode values are %s, %s, %s, and %s.", mode, config.ModeEC2, config.ModeOnPrem, config.ModeOnPremise, config.ModeWithIRSA)
136+
log.Panicf("Invalid mode %s. Valid mode values are %s, %s, %s, %s, and %s.", mode, config.ModeEC2, config.ModeOnPrem, config.ModeOnPremise, config.ModeWithIRSA, config.ModeAzureVM)
134137
}
135138
}
136139

@@ -145,6 +148,9 @@ func (ctx *Context) SetKubernetesMode(mode string) {
145148
case config.ModeK8sOnPrem:
146149
ctx.kubernetesMode = config.ModeK8sOnPrem
147150
ctx.shortMode = config.ShortModeK8sOnPrem
151+
case config.ModeAKS:
152+
ctx.kubernetesMode = config.ModeAKS
153+
ctx.shortMode = config.ShortModeAKS
148154
default:
149155
ctx.kubernetesMode = ""
150156
}

0 commit comments

Comments
 (0)