Skip to content

Commit f8bb908

Browse files
committed
add support for jmx container insights port and updating env vars for JMX
1 parent c8e6e2f commit f8bb908

File tree

7 files changed

+40
-6
lines changed

7 files changed

+40
-6
lines changed

internal/manifests/collector/adapters/config_from.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ type jmx struct{}
9393
type kubernetes struct {
9494
EnhancedContainerInsights bool `json:"enhanced_container_insights,omitempty"`
9595
AcceleratedComputeMetrics bool `json:"accelerated_compute_metrics,omitempty"`
96+
JMXContainerInsights bool `json:"jmx_container_insights,omitempty"`
9697
}
9798

9899
type xray struct {

internal/manifests/collector/ports.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,20 @@ func getLogsReceiversServicePorts(logger logr.Logger, config *adapters.CwaConfig
200200
servicePortsMap[receiverDefaultPortsMap[EMF]] = []corev1.ServicePort{tcp, udp}
201201
}
202202
}
203+
204+
//JMX Container Insights
205+
if config.Logs != nil && config.Logs.LogMetricsCollected != nil && config.Logs.LogMetricsCollected.Kubernetes != nil && config.Logs.LogMetricsCollected.Kubernetes.JMXContainerInsights {
206+
if _, ok := servicePortsMap[receiverDefaultPortsMap[JmxHttp]]; ok {
207+
logger.Info("Duplicate port has been configured in Agent Config for port", zap.Int32("port", receiverDefaultPortsMap[JmxHttp]))
208+
} else {
209+
tcp := corev1.ServicePort{
210+
Name: JmxHttp,
211+
Port: receiverDefaultPortsMap[JmxHttp],
212+
Protocol: corev1.ProtocolTCP,
213+
}
214+
servicePortsMap[receiverDefaultPortsMap[JmxHttp]] = []corev1.ServicePort{tcp}
215+
}
216+
}
203217
}
204218

205219
func getTracesReceiversServicePorts(logger logr.Logger, config *adapters.CwaConfig, servicePortsMap map[int32][]corev1.ServicePort) []corev1.ServicePort {

internal/manifests/collector/ports_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,15 @@ func TestJMXGetContainerPorts(t *testing.T) {
213213
assert.Equal(t, corev1.ProtocolTCP, containerPorts[JmxHttp].Protocol)
214214
}
215215

216+
func TestJMXContainerInsightsGetContainerPorts(t *testing.T) {
217+
cfg := getJSONStringFromFile("./test-resources/jmxContainerInsightsConfig.json")
218+
containerPorts := getContainerPorts(logger, cfg, []corev1.ServicePort{})
219+
assert.Equal(t, 1, len(containerPorts))
220+
assert.Equal(t, int32(4314), containerPorts[JmxHttp].ContainerPort)
221+
assert.Equal(t, JmxHttp, containerPorts[JmxHttp].Name)
222+
assert.Equal(t, corev1.ProtocolTCP, containerPorts[JmxHttp].Protocol)
223+
}
224+
216225
func getJSONStringFromFile(path string) string {
217226
buf, err := os.ReadFile(path)
218227
if err != nil {
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"logs": {
3+
"metrics_collected": {
4+
"kubernetes": {
5+
"cluster_name": "TestCluster",
6+
"jmx_container_insights": true
7+
}
8+
}
9+
}
10+
}

pkg/instrumentation/defaultinstrumentation.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,8 @@ func getJavaEnvs(isAppSignalsEnabled bool, cloudwatchAgentServiceEndpoint, expor
159159
var jmxEnvs []corev1.EnvVar
160160
if targetSystems, ok := additionalEnvs[jmx.EnvTargetSystem]; ok {
161161
jmxEnvs = []corev1.EnvVar{
162-
{Name: "OTEL_JMX_EXPORTER_METRICS_ENDPOINT", Value: fmt.Sprintf("%s://%s:4314/v1/metrics", http, cloudwatchAgentServiceEndpoint)},
163-
{Name: "OTEL_JMX_ENABLED", Value: "true"},
162+
{Name: "OTEL_AWS_JMX_EXPORTER_METRICS_ENDPOINT", Value: fmt.Sprintf("%s://%s:4314/v1/metrics", http, cloudwatchAgentServiceEndpoint)},
163+
{Name: "OTEL_AWS_JMX_ENABLED", Value: "true"},
164164
{Name: "OTEL_JMX_TARGET_SYSTEM", Value: targetSystems},
165165
}
166166
}

pkg/instrumentation/defaultinstrumentation_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -788,8 +788,8 @@ func Test_getDefaultInstrumentationLinuxWithApplicationSignalsDisabled(t *testin
788788
{Name: "OTEL_EXPORTER_OTLP_PROTOCOL", Value: "http/protobuf"},
789789
{Name: "OTEL_METRICS_EXPORTER", Value: "none"},
790790
{Name: "OTEL_LOGS_EXPORTER", Value: "none"},
791-
{Name: "OTEL_JMX_EXPORTER_METRICS_ENDPOINT", Value: "http://cloudwatch-agent.amazon-cloudwatch:4314/v1/metrics"},
792-
{Name: "OTEL_JMX_ENABLED", Value: "true"},
791+
{Name: "OTEL_AWS_JMX_EXPORTER_METRICS_ENDPOINT", Value: "http://cloudwatch-agent.amazon-cloudwatch:4314/v1/metrics"},
792+
{Name: "OTEL_AWS_JMX_ENABLED", Value: "true"},
793793
{Name: "OTEL_JMX_TARGET_SYSTEM", Value: "jvm"},
794794
},
795795
Resources: corev1.ResourceRequirements{

pkg/instrumentation/podmutator_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ func TestGetInstrumentationInstanceJMX(t *testing.T) {
8686
{Name: "OTEL_EXPORTER_OTLP_PROTOCOL", Value: "http/protobuf"},
8787
{Name: "OTEL_METRICS_EXPORTER", Value: "none"},
8888
{Name: "OTEL_LOGS_EXPORTER", Value: "none"},
89-
{Name: "OTEL_JMX_EXPORTER_METRICS_ENDPOINT", Value: "http://cloudwatch-agent.amazon-cloudwatch:4314/v1/metrics"},
90-
{Name: "OTEL_JMX_ENABLED", Value: "true"},
89+
{Name: "OTEL_AWS_JMX_EXPORTER_METRICS_ENDPOINT", Value: "http://cloudwatch-agent.amazon-cloudwatch:4314/v1/metrics"},
90+
{Name: "OTEL_AWS_JMX_ENABLED", Value: "true"},
9191
{Name: "OTEL_JMX_TARGET_SYSTEM", Value: "jvm,tomcat"},
9292
},
9393
},

0 commit comments

Comments
 (0)