Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions cfg/envconfig/envconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const (
RunInContainer = "RUN_IN_CONTAINER"
RunAsHostProcessContainer = "RUN_AS_HOST_PROCESS_CONTAINER"
RunInAWS = "RUN_IN_AWS"
RunInAKS = "RUN_IN_AKS"
RunWithIRSA = "RUN_WITH_IRSA"
RunWithSELinux = "RUN_WITH_SELINUX"
RunInROSA = "RUN_IN_ROSA"
Expand Down Expand Up @@ -89,6 +90,11 @@ func IsRunningInROSA() bool {
return os.Getenv(RunInROSA) == TrueValue
}

// IsRunningInAKS reports whether RUN_IN_AKS is set (by the AKS Helm chart) so AKS is detected without a metadata probe.
func IsRunningInAKS() bool {
return os.Getenv(RunInAKS) == TrueValue
}

func GetLogsBackpressureMode() string {
return os.Getenv(CWAgentLogsBackpressureMode)
}
86 changes: 44 additions & 42 deletions go.mod

Large diffs are not rendered by default.

170 changes: 86 additions & 84 deletions go.sum

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions service/defaultcomponents/components.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/open-telemetry/opentelemetry-collector-contrib/extension/headerssetterextension"
"github.com/open-telemetry/opentelemetry-collector-contrib/extension/healthcheckextension"
"github.com/open-telemetry/opentelemetry-collector-contrib/extension/observer/ecsobserver"
"github.com/open-telemetry/opentelemetry-collector-contrib/extension/oidctokenextension"
"github.com/open-telemetry/opentelemetry-collector-contrib/extension/pprofextension"
"github.com/open-telemetry/opentelemetry-collector-contrib/extension/sigv4authextension"
"github.com/open-telemetry/opentelemetry-collector-contrib/extension/storage/filestorage"
Expand Down Expand Up @@ -187,6 +188,7 @@ func Factories() (otelcol.Factories, error) {
ecsobserver.NewFactory(),
filestorage.NewFactory(),
healthcheckextension.NewFactory(),
oidctokenextension.NewFactory(),
pprofextension.NewFactory(),
sigv4authextension.NewFactory(),
zpagesextension.NewFactory(),
Expand Down
1 change: 1 addition & 0 deletions service/defaultcomponents/components_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ func TestComponents(t *testing.T) {
"health_check",
"k8smetadata",
"nodemetadatacache",
"oidctoken",
"pprof",
"server",
"sigv4auth",
Expand Down
2 changes: 2 additions & 0 deletions tool/paths/paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const (
ENV = "env-config.json"
AGENT_LOG_FILE = "amazon-cloudwatch-agent.log"
JMXJarName = "opentelemetry-jmx-metrics.jar"
OIDCToken = ".oidc-token"
)

var (
Expand All @@ -24,4 +25,5 @@ var (
TranslatorBinaryPath string
AgentBinaryPath string
JMXJarPath string
OIDCTokenPath string
)
1 change: 1 addition & 0 deletions tool/paths/paths_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ func init() {
TranslatorBinaryPath = filepath.Join(AgentDir, "bin", TranslatorBinaryName)
AgentBinaryPath = filepath.Join(AgentDir, "bin", AgentBinaryName)
JMXJarPath = filepath.Join(AgentDir, "bin", JMXJarName)
OIDCTokenPath = filepath.Join(AgentDir, "etc", OIDCToken)
}
1 change: 1 addition & 0 deletions tool/paths/paths_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,5 @@ func init() {
TranslatorBinaryPath = filepath.Join(AgentRootDir, TranslatorBinaryName)
AgentBinaryPath = filepath.Join(AgentRootDir, AgentBinaryName)
JMXJarPath = filepath.Join(AgentRootDir, JMXJarName)
OIDCTokenPath = filepath.Join(AgentConfigDir, OIDCToken)
}
8 changes: 8 additions & 0 deletions translator/config/mode.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,19 @@ const (
ModeK8sOnPrem = "K8sOnPrem"
)

// Azure platform modes: ModeAzureVM is host-level (like ModeEC2), ModeAKS is Kubernetes-level (like ModeEKS).
const (
ModeAzureVM = "AzureVM"
ModeAKS = "AKS"
)

const (
ShortModeEC2 = "EC2"
ShortModeOnPrem = "OP"
ShortModeWithIRSA = "WI"
ShortModeEKS = "EKS"
ShortModeK8sEC2 = "K8E"
ShortModeK8sOnPrem = "K8OP"
ShortModeAzureVM = "AZVM"
ShortModeAKS = "AKS"
)
8 changes: 7 additions & 1 deletion translator/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,11 @@ func (ctx *Context) SetMode(mode string) {
case config.ModeWithIRSA:
ctx.mode = config.ModeWithIRSA
ctx.shortMode = config.ShortModeWithIRSA
case config.ModeAzureVM:
Comment thread
jefchien marked this conversation as resolved.
ctx.mode = config.ModeAzureVM
ctx.shortMode = config.ShortModeAzureVM
default:
log.Panicf("Invalid mode %s. Valid mode values are %s, %s, %s, and %s.", mode, config.ModeEC2, config.ModeOnPrem, config.ModeOnPremise, config.ModeWithIRSA)
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)
}
}

Expand All @@ -145,6 +148,9 @@ func (ctx *Context) SetKubernetesMode(mode string) {
case config.ModeK8sOnPrem:
ctx.kubernetesMode = config.ModeK8sOnPrem
ctx.shortMode = config.ShortModeK8sOnPrem
case config.ModeAKS:
ctx.kubernetesMode = config.ModeAKS
ctx.shortMode = config.ShortModeAKS
default:
ctx.kubernetesMode = ""
}
Expand Down
91 changes: 91 additions & 0 deletions translator/context/context_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: MIT

package context

import (
"testing"

"github.com/stretchr/testify/assert"

"github.com/aws/amazon-cloudwatch-agent/translator/config"
)

func TestSetMode_Azure(t *testing.T) {
ResetContext()
ctx := CurrentContext()

ctx.SetMode(config.ModeAzureVM)
assert.Equal(t, config.ModeAzureVM, ctx.Mode())
assert.Equal(t, config.ShortModeAzureVM, ctx.ShortMode())
}

func TestSetMode_ExistingModesUnchanged(t *testing.T) {
cases := map[string]struct {
mode string
wantShort string
}{
"EC2": {config.ModeEC2, config.ShortModeEC2},
"OnPrem": {config.ModeOnPrem, config.ShortModeOnPrem},
"WithIRSA": {config.ModeWithIRSA, config.ShortModeWithIRSA},
}
for name, tc := range cases {
t.Run(name, func(t *testing.T) {
ResetContext()
ctx := CurrentContext()
ctx.SetMode(tc.mode)
assert.Equal(t, tc.mode, ctx.Mode())
assert.Equal(t, tc.wantShort, ctx.ShortMode())
})
}
}

func TestSetKubernetesMode_AKS(t *testing.T) {
ResetContext()
ctx := CurrentContext()

ctx.SetKubernetesMode(config.ModeAKS)
assert.Equal(t, config.ModeAKS, ctx.KubernetesMode())
assert.Equal(t, config.ShortModeAKS, ctx.ShortMode())
}

func TestSetKubernetesMode_ExistingModesUnchanged(t *testing.T) {
cases := map[string]struct {
mode string
wantShort string
}{
"EKS": {config.ModeEKS, config.ShortModeEKS},
"K8sEC2": {config.ModeK8sEC2, config.ShortModeK8sEC2},
"K8sOnPrem": {config.ModeK8sOnPrem, config.ShortModeK8sOnPrem},
}
for name, tc := range cases {
t.Run(name, func(t *testing.T) {
ResetContext()
ctx := CurrentContext()
ctx.SetKubernetesMode(tc.mode)
assert.Equal(t, tc.mode, ctx.KubernetesMode())
assert.Equal(t, tc.wantShort, ctx.ShortMode())
})
}
}

func TestSetKubernetesMode_UnknownClears(t *testing.T) {
ResetContext()
ctx := CurrentContext()
// A previously-set valid kubernetes mode is cleared by an unknown one.
ctx.SetKubernetesMode(config.ModeAKS)
ctx.SetKubernetesMode("not-a-real-mode")
assert.Equal(t, "", ctx.KubernetesMode())
// The default branch intentionally keeps shortMode (SetMode sets it first); with no host mode set it retains the last k8s shortMode.
assert.Equal(t, config.ShortModeAKS, ctx.ShortMode())
}

func TestSetKubernetesMode_EmptyPreservesHostShortMode(t *testing.T) {
ResetContext()
ctx := CurrentContext()
// Real startup ordering: host mode first, then empty (non-Kubernetes) mode; the host shortMode must survive.
ctx.SetMode(config.ModeAzureVM)
ctx.SetKubernetesMode("")
assert.Equal(t, "", ctx.KubernetesMode())
assert.Equal(t, config.ShortModeAzureVM, ctx.ShortMode())
}
Original file line number Diff line number Diff line change
Expand Up @@ -926,23 +926,23 @@ processors:
error_mode: ignore
statements:
- set(resource.attributes["service.name"], "unknown_service") where resource.attributes["service.name"] == nil
- set(resource.attributes["cloud.resource_id"], Concat(["arn:aws:ec2", resource.attributes["cloud.region"], resource.attributes["cloud.account.id"], Concat(["instance", resource.attributes["host.id"]], "/")], ":")) where resource.attributes["cloud.resource_id"] == nil and resource.attributes["host.id"] != nil
- set(resource.attributes["cloud.resource_id"], Concat(["arn:aws:ec2", resource.attributes["cloud.region"], resource.attributes["cloud.account.id"], Concat(["instance", resource.attributes["host.id"]], "/")], ":")) where resource.attributes["cloud.resource_id"] == nil and resource.attributes["host.id"] != nil and resource.attributes["cloud.platform"] == "aws_ec2"
- set(resource.attributes["deployment.environment.name"], Concat([resource.attributes["cloud.platform"], resource.attributes["ec2.tag.aws:autoscaling:groupName"]], ":")) where resource.attributes["deployment.environment.name"] == nil and resource.attributes["ec2.tag.aws:autoscaling:groupName"] != nil
- set(resource.attributes["deployment.environment.name"], Concat([resource.attributes["cloud.platform"], "default"], ":")) where resource.attributes["deployment.environment.name"] == nil and resource.attributes["cloud.platform"] != nil
metric_statements:
- context: resource
error_mode: ignore
statements:
- set(resource.attributes["service.name"], "unknown_service") where resource.attributes["service.name"] == nil
- set(resource.attributes["cloud.resource_id"], Concat(["arn:aws:ec2", resource.attributes["cloud.region"], resource.attributes["cloud.account.id"], Concat(["instance", resource.attributes["host.id"]], "/")], ":")) where resource.attributes["cloud.resource_id"] == nil and resource.attributes["host.id"] != nil
- set(resource.attributes["cloud.resource_id"], Concat(["arn:aws:ec2", resource.attributes["cloud.region"], resource.attributes["cloud.account.id"], Concat(["instance", resource.attributes["host.id"]], "/")], ":")) where resource.attributes["cloud.resource_id"] == nil and resource.attributes["host.id"] != nil and resource.attributes["cloud.platform"] == "aws_ec2"
- set(resource.attributes["deployment.environment.name"], Concat([resource.attributes["cloud.platform"], resource.attributes["ec2.tag.aws:autoscaling:groupName"]], ":")) where resource.attributes["deployment.environment.name"] == nil and resource.attributes["ec2.tag.aws:autoscaling:groupName"] != nil
- set(resource.attributes["deployment.environment.name"], Concat([resource.attributes["cloud.platform"], "default"], ":")) where resource.attributes["deployment.environment.name"] == nil and resource.attributes["cloud.platform"] != nil
trace_statements:
- context: resource
error_mode: ignore
statements:
- set(resource.attributes["service.name"], "unknown_service") where resource.attributes["service.name"] == nil
- set(resource.attributes["cloud.resource_id"], Concat(["arn:aws:ec2", resource.attributes["cloud.region"], resource.attributes["cloud.account.id"], Concat(["instance", resource.attributes["host.id"]], "/")], ":")) where resource.attributes["cloud.resource_id"] == nil and resource.attributes["host.id"] != nil
- set(resource.attributes["cloud.resource_id"], Concat(["arn:aws:ec2", resource.attributes["cloud.region"], resource.attributes["cloud.account.id"], Concat(["instance", resource.attributes["host.id"]], "/")], ":")) where resource.attributes["cloud.resource_id"] == nil and resource.attributes["host.id"] != nil and resource.attributes["cloud.platform"] == "aws_ec2"
- set(resource.attributes["deployment.environment.name"], Concat([resource.attributes["cloud.platform"], resource.attributes["ec2.tag.aws:autoscaling:groupName"]], ":")) where resource.attributes["deployment.environment.name"] == nil and resource.attributes["ec2.tag.aws:autoscaling:groupName"] != nil
- set(resource.attributes["deployment.environment.name"], Concat([resource.attributes["cloud.platform"], "default"], ":")) where resource.attributes["deployment.environment.name"] == nil and resource.attributes["cloud.platform"] != nil
transform/logs_cleanup:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -729,23 +729,23 @@ processors:
error_mode: ignore
statements:
- set(resource.attributes["service.name"], "unknown_service") where resource.attributes["service.name"] == nil
- set(resource.attributes["cloud.resource_id"], Concat(["arn:aws:ec2", resource.attributes["cloud.region"], resource.attributes["cloud.account.id"], Concat(["instance", resource.attributes["host.id"]], "/")], ":")) where resource.attributes["cloud.resource_id"] == nil and resource.attributes["host.id"] != nil
- set(resource.attributes["cloud.resource_id"], Concat(["arn:aws:ec2", resource.attributes["cloud.region"], resource.attributes["cloud.account.id"], Concat(["instance", resource.attributes["host.id"]], "/")], ":")) where resource.attributes["cloud.resource_id"] == nil and resource.attributes["host.id"] != nil and resource.attributes["cloud.platform"] == "aws_ec2"
- set(resource.attributes["deployment.environment.name"], Concat([resource.attributes["cloud.platform"], resource.attributes["ec2.tag.aws:autoscaling:groupName"]], ":")) where resource.attributes["deployment.environment.name"] == nil and resource.attributes["ec2.tag.aws:autoscaling:groupName"] != nil
- set(resource.attributes["deployment.environment.name"], Concat([resource.attributes["cloud.platform"], "default"], ":")) where resource.attributes["deployment.environment.name"] == nil and resource.attributes["cloud.platform"] != nil
metric_statements:
- context: resource
error_mode: ignore
statements:
- set(resource.attributes["service.name"], "unknown_service") where resource.attributes["service.name"] == nil
- set(resource.attributes["cloud.resource_id"], Concat(["arn:aws:ec2", resource.attributes["cloud.region"], resource.attributes["cloud.account.id"], Concat(["instance", resource.attributes["host.id"]], "/")], ":")) where resource.attributes["cloud.resource_id"] == nil and resource.attributes["host.id"] != nil
- set(resource.attributes["cloud.resource_id"], Concat(["arn:aws:ec2", resource.attributes["cloud.region"], resource.attributes["cloud.account.id"], Concat(["instance", resource.attributes["host.id"]], "/")], ":")) where resource.attributes["cloud.resource_id"] == nil and resource.attributes["host.id"] != nil and resource.attributes["cloud.platform"] == "aws_ec2"
- set(resource.attributes["deployment.environment.name"], Concat([resource.attributes["cloud.platform"], resource.attributes["ec2.tag.aws:autoscaling:groupName"]], ":")) where resource.attributes["deployment.environment.name"] == nil and resource.attributes["ec2.tag.aws:autoscaling:groupName"] != nil
- set(resource.attributes["deployment.environment.name"], Concat([resource.attributes["cloud.platform"], "default"], ":")) where resource.attributes["deployment.environment.name"] == nil and resource.attributes["cloud.platform"] != nil
trace_statements:
- context: resource
error_mode: ignore
statements:
- set(resource.attributes["service.name"], "unknown_service") where resource.attributes["service.name"] == nil
- set(resource.attributes["cloud.resource_id"], Concat(["arn:aws:ec2", resource.attributes["cloud.region"], resource.attributes["cloud.account.id"], Concat(["instance", resource.attributes["host.id"]], "/")], ":")) where resource.attributes["cloud.resource_id"] == nil and resource.attributes["host.id"] != nil
- set(resource.attributes["cloud.resource_id"], Concat(["arn:aws:ec2", resource.attributes["cloud.region"], resource.attributes["cloud.account.id"], Concat(["instance", resource.attributes["host.id"]], "/")], ":")) where resource.attributes["cloud.resource_id"] == nil and resource.attributes["host.id"] != nil and resource.attributes["cloud.platform"] == "aws_ec2"
- set(resource.attributes["deployment.environment.name"], Concat([resource.attributes["cloud.platform"], resource.attributes["ec2.tag.aws:autoscaling:groupName"]], ":")) where resource.attributes["deployment.environment.name"] == nil and resource.attributes["ec2.tag.aws:autoscaling:groupName"] != nil
- set(resource.attributes["deployment.environment.name"], Concat([resource.attributes["cloud.platform"], "default"], ":")) where resource.attributes["deployment.environment.name"] == nil and resource.attributes["cloud.platform"] != nil
transform/logs_cleanup:
Expand Down
Loading
Loading