Skip to content

Commit c8e6e2f

Browse files
committed
Supporting JMX annotations
1 parent b8dfc39 commit c8e6e2f

File tree

6 files changed

+375
-91
lines changed

6 files changed

+375
-91
lines changed

internal/manifests/collector/ports.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ const (
2727
XrayTraces = "aws-traces"
2828
OtlpGrpc = "otlp-grpc"
2929
OtlpHttp = "otlp-http"
30-
AppSignalsGrpc = "appsignals-grpc"
31-
AppSignalsHttp = "appsignals-http"
32-
AppSignalsProxy = "appsignals-xray"
30+
AppSignalsGrpc = "appsig-grpc"
31+
AppSignalsHttp = "appsig-http"
32+
AppSignalsProxy = "appsig-xray"
3333
AppSignalsGrpcSA = ":4315"
3434
AppSignalsHttpSA = ":4316"
3535
AppSignalsProxySA = ":2000"
@@ -85,7 +85,6 @@ func getContainerPorts(logger logr.Logger, cfg string, specPorts []corev1.Servic
8585
if err != nil {
8686
logger.Error(err, "error parsing cw agent config")
8787
} else {
88-
logger.Info("%v", config)
8988
servicePorts = getServicePortsFromCWAgentConfig(logger, config)
9089
}
9190

internal/manifests/collector/ports_test.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -205,15 +205,9 @@ func TestInvalidConfigGetContainerPorts(t *testing.T) {
205205
}
206206

207207
func TestJMXGetContainerPorts(t *testing.T) {
208-
cfg := getJSONStringFromFile("testdata/jmx.json")
208+
cfg := getJSONStringFromFile("./test-resources/jmxAgentConfig.json")
209209
containerPorts := getContainerPorts(logger, cfg, []corev1.ServicePort{})
210-
assert.Equal(t, 4, len(containerPorts))
211-
assert.Equal(t, int32(4315), containerPorts[AppSignalsGrpc].ContainerPort)
212-
assert.Equal(t, AppSignalsGrpc, containerPorts[AppSignalsGrpc].Name)
213-
assert.Equal(t, int32(4316), containerPorts[AppSignalsHttp].ContainerPort)
214-
assert.Equal(t, AppSignalsHttp, containerPorts[AppSignalsHttp].Name)
215-
assert.Equal(t, int32(2000), containerPorts[AppSignalsProxy].ContainerPort)
216-
assert.Equal(t, AppSignalsProxy, containerPorts[AppSignalsProxy].Name)
210+
assert.Equal(t, 1, len(containerPorts))
217211
assert.Equal(t, int32(4314), containerPorts[JmxHttp].ContainerPort)
218212
assert.Equal(t, JmxHttp, containerPorts[JmxHttp].Name)
219213
assert.Equal(t, corev1.ProtocolTCP, containerPorts[JmxHttp].Protocol)

pkg/instrumentation/defaultinstrumentation.go

Lines changed: 91 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,8 @@ func getDefaultInstrumentation(agentConfig *adapters.CwaConfig, additionalEnvs m
7777

7878
// set protocol by checking cloudwatch agent config for tls setting
7979
exporterPrefix := http
80-
if agentConfig != nil {
81-
appSignalsConfig := agentConfig.GetApplicationSignalsConfig()
82-
if appSignalsConfig != nil && appSignalsConfig.TLS != nil {
80+
if isApplicationSignalsEnabled(agentConfig) {
81+
if agentConfig.GetApplicationSignalsConfig().TLS != nil {
8382
exporterPrefix = https
8483
}
8584
}
@@ -103,66 +102,31 @@ func getDefaultInstrumentation(agentConfig *adapters.CwaConfig, additionalEnvs m
103102
},
104103
Java: v1alpha1.Java{
105104
Image: javaInstrumentationImage,
106-
Env: getJavaEnvs(cloudwatchAgentServiceEndpoint, exporterPrefix, additionalEnvs[TypeJava]),
105+
Env: getJavaEnvs(isApplicationSignalsEnabled(agentConfig), cloudwatchAgentServiceEndpoint, exporterPrefix, additionalEnvs[TypeJava]),
107106
Resources: corev1.ResourceRequirements{
108107
Limits: getInstrumentationConfigForResource(java, limit),
109108
Requests: getInstrumentationConfigForResource(java, request),
110109
},
111110
},
112111
Python: v1alpha1.Python{
113112
Image: pythonInstrumentationImage,
114-
Env: []corev1.EnvVar{
115-
{Name: "OTEL_AWS_APP_SIGNALS_ENABLED", Value: "true"}, //TODO: remove in favor of new name once safe
116-
{Name: "OTEL_AWS_APPLICATION_SIGNALS_ENABLED", Value: "true"},
117-
{Name: "OTEL_TRACES_SAMPLER_ARG", Value: fmt.Sprintf("endpoint=%s://%s:2000", http, cloudwatchAgentServiceEndpoint)},
118-
{Name: "OTEL_TRACES_SAMPLER", Value: "xray"},
119-
{Name: "OTEL_EXPORTER_OTLP_PROTOCOL", Value: "http/protobuf"},
120-
{Name: "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", Value: fmt.Sprintf("%s://%s:4316/v1/traces", exporterPrefix, cloudwatchAgentServiceEndpoint)},
121-
{Name: "OTEL_AWS_APP_SIGNALS_EXPORTER_ENDPOINT", Value: fmt.Sprintf("%s://%s:4316/v1/metrics", exporterPrefix, cloudwatchAgentServiceEndpoint)}, //TODO: remove in favor of new name once safe
122-
{Name: "OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT", Value: fmt.Sprintf("%s://%s:4316/v1/metrics", exporterPrefix, cloudwatchAgentServiceEndpoint)},
123-
{Name: "OTEL_METRICS_EXPORTER", Value: "none"},
124-
{Name: "OTEL_PYTHON_DISTRO", Value: "aws_distro"},
125-
{Name: "OTEL_PYTHON_CONFIGURATOR", Value: "aws_configurator"},
126-
{Name: "OTEL_LOGS_EXPORTER", Value: "none"},
127-
},
113+
Env: getPythonEnvs(isApplicationSignalsEnabled(agentConfig), cloudwatchAgentServiceEndpoint, exporterPrefix, additionalEnvs[TypePython]),
128114
Resources: corev1.ResourceRequirements{
129115
Limits: getInstrumentationConfigForResource(python, limit),
130116
Requests: getInstrumentationConfigForResource(python, request),
131117
},
132118
},
133119
DotNet: v1alpha1.DotNet{
134120
Image: dotNetInstrumentationImage,
135-
Env: []corev1.EnvVar{
136-
{Name: "OTEL_AWS_APPLICATION_SIGNALS_ENABLED", Value: "true"},
137-
{Name: "OTEL_TRACES_SAMPLER_ARG", Value: fmt.Sprintf("endpoint=%s://%s:2000", http, cloudwatchAgentServiceEndpoint)},
138-
{Name: "OTEL_TRACES_SAMPLER", Value: "xray"},
139-
{Name: "OTEL_EXPORTER_OTLP_PROTOCOL", Value: "http/protobuf"},
140-
{Name: "OTEL_EXPORTER_OTLP_ENDPOINT", Value: fmt.Sprintf("%s://%s:4316", exporterPrefix, cloudwatchAgentServiceEndpoint)},
141-
{Name: "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", Value: fmt.Sprintf("%s://%s:4316/v1/traces", exporterPrefix, cloudwatchAgentServiceEndpoint)},
142-
{Name: "OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT", Value: fmt.Sprintf("%s://%s:4316/v1/metrics", exporterPrefix, cloudwatchAgentServiceEndpoint)},
143-
{Name: "OTEL_METRICS_EXPORTER", Value: "none"},
144-
{Name: "OTEL_DOTNET_DISTRO", Value: "aws_distro"},
145-
{Name: "OTEL_DOTNET_CONFIGURATOR", Value: "aws_configurator"},
146-
{Name: "OTEL_LOGS_EXPORTER", Value: "none"},
147-
{Name: "OTEL_DOTNET_AUTO_PLUGINS", Value: "AWS.Distro.OpenTelemetry.AutoInstrumentation.Plugin, AWS.Distro.OpenTelemetry.AutoInstrumentation"},
148-
},
121+
Env: getDotNetEnvs(isApplicationSignalsEnabled(agentConfig), cloudwatchAgentServiceEndpoint, exporterPrefix, additionalEnvs[TypeDotNet]),
149122
Resources: corev1.ResourceRequirements{
150123
Limits: getInstrumentationConfigForResource(dotNet, limit),
151124
Requests: getInstrumentationConfigForResource(dotNet, request),
152125
},
153126
},
154127
NodeJS: v1alpha1.NodeJS{
155128
Image: nodeJSInstrumentationImage,
156-
Env: []corev1.EnvVar{
157-
{Name: "OTEL_AWS_APPLICATION_SIGNALS_ENABLED", Value: "true"},
158-
{Name: "OTEL_TRACES_SAMPLER_ARG", Value: fmt.Sprintf("endpoint=%s://%s:2000", exporterPrefix, cloudwatchAgentServiceEndpoint)},
159-
{Name: "OTEL_TRACES_SAMPLER", Value: "xray"},
160-
{Name: "OTEL_EXPORTER_OTLP_PROTOCOL", Value: "http/protobuf"},
161-
{Name: "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", Value: fmt.Sprintf("%s://%s:4316/v1/traces", exporterPrefix, cloudwatchAgentServiceEndpoint)},
162-
{Name: "OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT", Value: fmt.Sprintf("%s://%s:4316/v1/metrics", exporterPrefix, cloudwatchAgentServiceEndpoint)},
163-
{Name: "OTEL_METRICS_EXPORTER", Value: "none"},
164-
{Name: "OTEL_LOGS_EXPORTER", Value: "none"},
165-
},
129+
Env: getNodeJSEnvs(isApplicationSignalsEnabled(agentConfig), cloudwatchAgentServiceEndpoint, exporterPrefix, additionalEnvs[TypeDotNet]),
166130
Resources: corev1.ResourceRequirements{
167131
Limits: getInstrumentationConfigForResource(nodeJS, limit),
168132
Requests: getInstrumentationConfigForResource(nodeJS, request),
@@ -172,37 +136,102 @@ func getDefaultInstrumentation(agentConfig *adapters.CwaConfig, additionalEnvs m
172136
}, nil
173137
}
174138

175-
func getJavaEnvs(cloudwatchAgentServiceEndpoint, exporterPrefix string, additionalEnvs map[string]string) []corev1.EnvVar {
139+
func getJavaEnvs(isAppSignalsEnabled bool, cloudwatchAgentServiceEndpoint, exporterPrefix string, additionalEnvs map[string]string) []corev1.EnvVar {
176140
envs := []corev1.EnvVar{
177-
{Name: "OTEL_AWS_APP_SIGNALS_ENABLED", Value: "true"}, //TODO: remove in favor of new name once safe
178-
{Name: "OTEL_AWS_APPLICATION_SIGNALS_ENABLED", Value: "true"},
179-
{Name: "OTEL_TRACES_SAMPLER_ARG", Value: fmt.Sprintf("endpoint=%s://%s:2000", http, cloudwatchAgentServiceEndpoint)},
180-
{Name: "OTEL_TRACES_SAMPLER", Value: "xray"},
181141
{Name: "OTEL_EXPORTER_OTLP_PROTOCOL", Value: "http/protobuf"},
182-
{Name: "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", Value: fmt.Sprintf("%s://%s:4316/v1/traces", exporterPrefix, cloudwatchAgentServiceEndpoint)},
183-
{Name: "OTEL_AWS_APP_SIGNALS_EXPORTER_ENDPOINT", Value: fmt.Sprintf("%s://%s:4316/v1/metrics", exporterPrefix, cloudwatchAgentServiceEndpoint)}, //TODO: remove in favor of new name once safe
184-
{Name: "OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT", Value: fmt.Sprintf("%s://%s:4316/v1/metrics", exporterPrefix, cloudwatchAgentServiceEndpoint)},
142+
{Name: "OTEL_METRICS_EXPORTER", Value: "none"},
143+
{Name: "OTEL_LOGS_EXPORTER", Value: "none"},
144+
}
145+
146+
if isAppSignalsEnabled {
147+
appSignalsEnvs := []corev1.EnvVar{
148+
{Name: "OTEL_AWS_APP_SIGNALS_ENABLED", Value: "true"}, //TODO: remove in favor of new name once safe
149+
{Name: "OTEL_AWS_APPLICATION_SIGNALS_ENABLED", Value: "true"},
150+
{Name: "OTEL_TRACES_SAMPLER_ARG", Value: fmt.Sprintf("endpoint=%s://%s:2000", http, cloudwatchAgentServiceEndpoint)},
151+
{Name: "OTEL_TRACES_SAMPLER", Value: "xray"},
152+
{Name: "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", Value: fmt.Sprintf("%s://%s:4316/v1/traces", exporterPrefix, cloudwatchAgentServiceEndpoint)},
153+
{Name: "OTEL_AWS_APP_SIGNALS_EXPORTER_ENDPOINT", Value: fmt.Sprintf("%s://%s:4316/v1/metrics", exporterPrefix, cloudwatchAgentServiceEndpoint)}, //TODO: remove in favor of new name once safe
154+
{Name: "OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT", Value: fmt.Sprintf("%s://%s:4316/v1/metrics", exporterPrefix, cloudwatchAgentServiceEndpoint)},
155+
}
156+
envs = append(envs, appSignalsEnvs...)
185157
}
158+
186159
var jmxEnvs []corev1.EnvVar
187160
if targetSystems, ok := additionalEnvs[jmx.EnvTargetSystem]; ok {
188161
jmxEnvs = []corev1.EnvVar{
189-
{Name: "OTEL_EXPORTER_OTLP_METRICS_ENDPOINT", Value: fmt.Sprintf("%s://%s:4314/v1/metrics", http, cloudwatchAgentServiceEndpoint)},
190-
{Name: "OTEL_INSTRUMENTATION_RUNTIME_TELEMETRY_ENABLED", Value: "false"},
191-
{Name: "OTEL_INSTRUMENTATION_COMMON_DEFAULT_ENABLED", Value: "false"},
162+
{Name: "OTEL_JMX_EXPORTER_METRICS_ENDPOINT", Value: fmt.Sprintf("%s://%s:4314/v1/metrics", http, cloudwatchAgentServiceEndpoint)},
192163
{Name: "OTEL_JMX_ENABLED", Value: "true"},
193164
{Name: "OTEL_JMX_TARGET_SYSTEM", Value: targetSystems},
194-
{Name: "OTEL_EXPERIMENTAL_METRICS_VIEW_CONFIG", Value: "classpath:/jmx/view.yaml"},
195165
}
196166
}
197-
if len(jmxEnvs) == 0 {
198-
envs = append(
199-
envs,
200-
corev1.EnvVar{Name: "OTEL_METRICS_EXPORTER", Value: "none"},
201-
corev1.EnvVar{Name: "OTEL_LOGS_EXPORTER", Value: "none"},
202-
)
203-
} else {
204-
envs = append(envs, corev1.EnvVar{Name: "OTEL_LOGS_EXPORTER", Value: "none"})
167+
if len(jmxEnvs) != 0 {
205168
envs = append(envs, jmxEnvs...)
206169
}
207170
return envs
208171
}
172+
173+
func getPythonEnvs(isAppSignalsEnabled bool, cloudwatchAgentServiceEndpoint, exporterPrefix string, additionalEnvs map[string]string) []corev1.EnvVar {
174+
var envs []corev1.EnvVar
175+
if isAppSignalsEnabled {
176+
envs = []corev1.EnvVar{
177+
{Name: "OTEL_AWS_APP_SIGNALS_ENABLED", Value: "true"}, //TODO: remove in favor of new name once safe
178+
{Name: "OTEL_AWS_APPLICATION_SIGNALS_ENABLED", Value: "true"},
179+
{Name: "OTEL_TRACES_SAMPLER_ARG", Value: fmt.Sprintf("endpoint=%s://%s:2000", http, cloudwatchAgentServiceEndpoint)},
180+
{Name: "OTEL_TRACES_SAMPLER", Value: "xray"},
181+
{Name: "OTEL_EXPORTER_OTLP_PROTOCOL", Value: "http/protobuf"},
182+
{Name: "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", Value: fmt.Sprintf("%s://%s:4316/v1/traces", exporterPrefix, cloudwatchAgentServiceEndpoint)},
183+
{Name: "OTEL_AWS_APP_SIGNALS_EXPORTER_ENDPOINT", Value: fmt.Sprintf("%s://%s:4316/v1/metrics", exporterPrefix, cloudwatchAgentServiceEndpoint)}, //TODO: remove in favor of new name once safe
184+
{Name: "OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT", Value: fmt.Sprintf("%s://%s:4316/v1/metrics", exporterPrefix, cloudwatchAgentServiceEndpoint)},
185+
{Name: "OTEL_METRICS_EXPORTER", Value: "none"},
186+
{Name: "OTEL_PYTHON_DISTRO", Value: "aws_distro"},
187+
{Name: "OTEL_PYTHON_CONFIGURATOR", Value: "aws_configurator"},
188+
{Name: "OTEL_LOGS_EXPORTER", Value: "none"},
189+
}
190+
}
191+
return envs
192+
}
193+
194+
func getDotNetEnvs(isAppSignalsEnabled bool, cloudwatchAgentServiceEndpoint, exporterPrefix string, additionalEnvs map[string]string) []corev1.EnvVar {
195+
var envs []corev1.EnvVar
196+
if isAppSignalsEnabled {
197+
envs = []corev1.EnvVar{
198+
{Name: "OTEL_AWS_APPLICATION_SIGNALS_ENABLED", Value: "true"},
199+
{Name: "OTEL_TRACES_SAMPLER_ARG", Value: fmt.Sprintf("endpoint=%s://%s:2000", http, cloudwatchAgentServiceEndpoint)},
200+
{Name: "OTEL_TRACES_SAMPLER", Value: "xray"},
201+
{Name: "OTEL_EXPORTER_OTLP_PROTOCOL", Value: "http/protobuf"},
202+
{Name: "OTEL_EXPORTER_OTLP_ENDPOINT", Value: fmt.Sprintf("%s://%s:4316", exporterPrefix, cloudwatchAgentServiceEndpoint)},
203+
{Name: "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", Value: fmt.Sprintf("%s://%s:4316/v1/traces", exporterPrefix, cloudwatchAgentServiceEndpoint)},
204+
{Name: "OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT", Value: fmt.Sprintf("%s://%s:4316/v1/metrics", exporterPrefix, cloudwatchAgentServiceEndpoint)},
205+
{Name: "OTEL_METRICS_EXPORTER", Value: "none"},
206+
{Name: "OTEL_DOTNET_DISTRO", Value: "aws_distro"},
207+
{Name: "OTEL_DOTNET_CONFIGURATOR", Value: "aws_configurator"},
208+
{Name: "OTEL_LOGS_EXPORTER", Value: "none"},
209+
{Name: "OTEL_DOTNET_AUTO_PLUGINS", Value: "AWS.Distro.OpenTelemetry.AutoInstrumentation.Plugin, AWS.Distro.OpenTelemetry.AutoInstrumentation"},
210+
}
211+
}
212+
return envs
213+
}
214+
215+
func getNodeJSEnvs(isAppSignalsEnabled bool, cloudwatchAgentServiceEndpoint, exporterPrefix string, additionalEnvs map[string]string) []corev1.EnvVar {
216+
var envs []corev1.EnvVar
217+
if isAppSignalsEnabled {
218+
envs = []corev1.EnvVar{
219+
{Name: "OTEL_AWS_APPLICATION_SIGNALS_ENABLED", Value: "true"},
220+
{Name: "OTEL_TRACES_SAMPLER_ARG", Value: fmt.Sprintf("endpoint=%s://%s:2000", exporterPrefix, cloudwatchAgentServiceEndpoint)},
221+
{Name: "OTEL_TRACES_SAMPLER", Value: "xray"},
222+
{Name: "OTEL_EXPORTER_OTLP_PROTOCOL", Value: "http/protobuf"},
223+
{Name: "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", Value: fmt.Sprintf("%s://%s:4316/v1/traces", exporterPrefix, cloudwatchAgentServiceEndpoint)},
224+
{Name: "OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT", Value: fmt.Sprintf("%s://%s:4316/v1/metrics", exporterPrefix, cloudwatchAgentServiceEndpoint)},
225+
{Name: "OTEL_METRICS_EXPORTER", Value: "none"},
226+
{Name: "OTEL_LOGS_EXPORTER", Value: "none"},
227+
}
228+
}
229+
return envs
230+
}
231+
232+
func isApplicationSignalsEnabled(agentConfig *adapters.CwaConfig) bool {
233+
if agentConfig != nil {
234+
return agentConfig.GetApplicationSignalsConfig() != nil
235+
}
236+
return false
237+
}

0 commit comments

Comments
 (0)