Skip to content

Commit af44378

Browse files
authored
Support configurable resources for NodeJS. (#225)
1 parent 25d547c commit af44378

File tree

4 files changed

+57
-4
lines changed

4 files changed

+57
-4
lines changed

integration-tests/manifests/annotations/validate_annotations_deployment_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func TestJavaOnlyDeployment(t *testing.T) {
9595
updateTheOperator(t, clientSet, string(jsonStr))
9696

9797
if err := checkResourceAnnotations(t, clientSet, "deployment", uniqueNamespace, deploymentName, sampleDeploymentYamlNameRelPath, startTime, []string{injectJavaAnnotation, autoAnnotateJavaAnnotation}, false); err != nil {
98-
t.Fatalf("Failed annotation check: %s", err.Error())
98+
t.Fatalf("Failed annotation check: %s", err.Error())
9999
}
100100
}
101101

main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ func main() {
143143
pflag.Parse()
144144

145145
// set instrumentation cpu and memory limits in environment variables to be used for default instrumentation; default values received from https://github.com/open-telemetry/opentelemetry-operator/blob/main/apis/v1alpha1/instrumentation_webhook.go
146-
autoInstrumentationConfig := map[string]map[string]map[string]string{"java": {"limits": {"cpu": "500m", "memory": "64Mi"}, "requests": {"cpu": "50m", "memory": "64Mi"}}, "python": {"limits": {"cpu": "500m", "memory": "32Mi"}, "requests": {"cpu": "50m", "memory": "32Mi"}}, "dotnet": {"limits": {"cpu": "500m", "memory": "128Mi"}, "requests": {"cpu": "50m", "memory": "128Mi"}}}
146+
autoInstrumentationConfig := map[string]map[string]map[string]string{"java": {"limits": {"cpu": "500m", "memory": "64Mi"}, "requests": {"cpu": "50m", "memory": "64Mi"}}, "python": {"limits": {"cpu": "500m", "memory": "32Mi"}, "requests": {"cpu": "50m", "memory": "32Mi"}}, "dotnet": {"limits": {"cpu": "500m", "memory": "128Mi"}, "requests": {"cpu": "50m", "memory": "128Mi"}}, "nodejs": {"limits": {"cpu": "500m", "memory": "128Mi"}, "requests": {"cpu": "50m", "memory": "128Mi"}}}
147147
err := json.Unmarshal([]byte(autoInstrumentationConfigStr), &autoInstrumentationConfig)
148148
if err != nil {
149149
setupLog.Info(fmt.Sprintf("Using default values: %v", autoInstrumentationConfig))
@@ -157,8 +157,8 @@ func main() {
157157
if dotNetVar, ok := autoInstrumentationConfig["dotnet"]; ok {
158158
setLangEnvVars("DOTNET", dotNetVar)
159159
}
160-
if dotNetVar, ok := autoInstrumentationConfig["nodejs"]; ok {
161-
setLangEnvVars("NODEJS", dotNetVar)
160+
if nodeJSVar, ok := autoInstrumentationConfig["nodejs"]; ok {
161+
setLangEnvVars("NODEJS", nodeJSVar)
162162
}
163163

164164
// set supported language instrumentation images in environment variable to be used for default instrumentation

pkg/instrumentation/defaultinstrumentation.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const (
2929
java = "JAVA"
3030
python = "PYTHON"
3131
dotNet = "DOTNET"
32+
nodeJS = "NODEJS"
3233
limit = "LIMIT"
3334
request = "REQUEST"
3435
)
@@ -173,6 +174,10 @@ func getDefaultInstrumentation(agentConfig *adapters.CwaConfig, isWindowsPod boo
173174
{Name: "OTEL_METRICS_EXPORTER", Value: "none"},
174175
{Name: "OTEL_LOGS_EXPORTER", Value: "none"},
175176
},
177+
Resources: corev1.ResourceRequirements{
178+
Limits: getInstrumentationConfigForResource(nodeJS, limit),
179+
Requests: getInstrumentationConfigForResource(nodeJS, request),
180+
},
176181
},
177182
},
178183
}, nil

pkg/instrumentation/defaultinstrumentation_test.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ func Test_getDefaultInstrumentationLinux(t *testing.T) {
3434
os.Setenv("AUTO_INSTRUMENTATION_DOTNET_MEM_LIMIT", "128Mi")
3535
os.Setenv("AUTO_INSTRUMENTATION_DOTNET_CPU_REQUEST", "50m")
3636
os.Setenv("AUTO_INSTRUMENTATION_DOTNET_MEM_REQUEST", "128Mi")
37+
os.Setenv("AUTO_INSTRUMENTATION_NODEJS_CPU_LIMIT", "500m")
38+
os.Setenv("AUTO_INSTRUMENTATION_NODEJS_MEM_LIMIT", "128Mi")
39+
os.Setenv("AUTO_INSTRUMENTATION_NODEJS_CPU_REQUEST", "50m")
40+
os.Setenv("AUTO_INSTRUMENTATION_NODEJS_MEM_REQUEST", "128Mi")
3741

3842
httpInst := &v1alpha1.Instrumentation{
3943
Status: v1alpha1.InstrumentationStatus{},
@@ -143,6 +147,16 @@ func Test_getDefaultInstrumentationLinux(t *testing.T) {
143147
{Name: "OTEL_METRICS_EXPORTER", Value: "none"},
144148
{Name: "OTEL_LOGS_EXPORTER", Value: "none"},
145149
},
150+
Resources: corev1.ResourceRequirements{
151+
Limits: corev1.ResourceList{
152+
corev1.ResourceCPU: resource.MustParse("500m"),
153+
corev1.ResourceMemory: resource.MustParse("128Mi"),
154+
},
155+
Requests: corev1.ResourceList{
156+
corev1.ResourceCPU: resource.MustParse("50m"),
157+
corev1.ResourceMemory: resource.MustParse("128Mi"),
158+
},
159+
},
146160
},
147161
},
148162
}
@@ -254,6 +268,16 @@ func Test_getDefaultInstrumentationLinux(t *testing.T) {
254268
{Name: "OTEL_METRICS_EXPORTER", Value: "none"},
255269
{Name: "OTEL_LOGS_EXPORTER", Value: "none"},
256270
},
271+
Resources: corev1.ResourceRequirements{
272+
Limits: corev1.ResourceList{
273+
corev1.ResourceCPU: resource.MustParse("500m"),
274+
corev1.ResourceMemory: resource.MustParse("128Mi"),
275+
},
276+
Requests: corev1.ResourceList{
277+
corev1.ResourceCPU: resource.MustParse("50m"),
278+
corev1.ResourceMemory: resource.MustParse("128Mi"),
279+
},
280+
},
257281
},
258282
},
259283
}
@@ -333,6 +357,10 @@ func Test_getDefaultInstrumentationWindows(t *testing.T) {
333357
os.Setenv("AUTO_INSTRUMENTATION_DOTNET_MEM_LIMIT", "128Mi")
334358
os.Setenv("AUTO_INSTRUMENTATION_DOTNET_CPU_REQUEST", "50m")
335359
os.Setenv("AUTO_INSTRUMENTATION_DOTNET_MEM_REQUEST", "128Mi")
360+
os.Setenv("AUTO_INSTRUMENTATION_NODEJS_CPU_LIMIT", "500m")
361+
os.Setenv("AUTO_INSTRUMENTATION_NODEJS_MEM_LIMIT", "128Mi")
362+
os.Setenv("AUTO_INSTRUMENTATION_NODEJS_CPU_REQUEST", "50m")
363+
os.Setenv("AUTO_INSTRUMENTATION_NODEJS_MEM_REQUEST", "128Mi")
336364

337365
httpInst := &v1alpha1.Instrumentation{
338366
Status: v1alpha1.InstrumentationStatus{},
@@ -442,6 +470,16 @@ func Test_getDefaultInstrumentationWindows(t *testing.T) {
442470
{Name: "OTEL_METRICS_EXPORTER", Value: "none"},
443471
{Name: "OTEL_LOGS_EXPORTER", Value: "none"},
444472
},
473+
Resources: corev1.ResourceRequirements{
474+
Limits: corev1.ResourceList{
475+
corev1.ResourceCPU: resource.MustParse("500m"),
476+
corev1.ResourceMemory: resource.MustParse("128Mi"),
477+
},
478+
Requests: corev1.ResourceList{
479+
corev1.ResourceCPU: resource.MustParse("50m"),
480+
corev1.ResourceMemory: resource.MustParse("128Mi"),
481+
},
482+
},
445483
},
446484
},
447485
}
@@ -553,6 +591,16 @@ func Test_getDefaultInstrumentationWindows(t *testing.T) {
553591
{Name: "OTEL_METRICS_EXPORTER", Value: "none"},
554592
{Name: "OTEL_LOGS_EXPORTER", Value: "none"},
555593
},
594+
Resources: corev1.ResourceRequirements{
595+
Limits: corev1.ResourceList{
596+
corev1.ResourceCPU: resource.MustParse("500m"),
597+
corev1.ResourceMemory: resource.MustParse("128Mi"),
598+
},
599+
Requests: corev1.ResourceList{
600+
corev1.ResourceCPU: resource.MustParse("50m"),
601+
corev1.ResourceMemory: resource.MustParse("128Mi"),
602+
},
603+
},
556604
},
557605
},
558606
}

0 commit comments

Comments
 (0)