Skip to content

Commit

Permalink
Support configurable resources for NodeJS. (#225)
Browse files Browse the repository at this point in the history
  • Loading branch information
musa-asad committed Sep 9, 2024
1 parent 25d547c commit af44378
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func TestJavaOnlyDeployment(t *testing.T) {
updateTheOperator(t, clientSet, string(jsonStr))

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

Expand Down
6 changes: 3 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func main() {
pflag.Parse()

// 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
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"}}}
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"}}}
err := json.Unmarshal([]byte(autoInstrumentationConfigStr), &autoInstrumentationConfig)
if err != nil {
setupLog.Info(fmt.Sprintf("Using default values: %v", autoInstrumentationConfig))
Expand All @@ -157,8 +157,8 @@ func main() {
if dotNetVar, ok := autoInstrumentationConfig["dotnet"]; ok {
setLangEnvVars("DOTNET", dotNetVar)
}
if dotNetVar, ok := autoInstrumentationConfig["nodejs"]; ok {
setLangEnvVars("NODEJS", dotNetVar)
if nodeJSVar, ok := autoInstrumentationConfig["nodejs"]; ok {
setLangEnvVars("NODEJS", nodeJSVar)
}

// set supported language instrumentation images in environment variable to be used for default instrumentation
Expand Down
5 changes: 5 additions & 0 deletions pkg/instrumentation/defaultinstrumentation.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const (
java = "JAVA"
python = "PYTHON"
dotNet = "DOTNET"
nodeJS = "NODEJS"
limit = "LIMIT"
request = "REQUEST"
)
Expand Down Expand Up @@ -173,6 +174,10 @@ func getDefaultInstrumentation(agentConfig *adapters.CwaConfig, isWindowsPod boo
{Name: "OTEL_METRICS_EXPORTER", Value: "none"},
{Name: "OTEL_LOGS_EXPORTER", Value: "none"},
},
Resources: corev1.ResourceRequirements{
Limits: getInstrumentationConfigForResource(nodeJS, limit),
Requests: getInstrumentationConfigForResource(nodeJS, request),
},
},
},
}, nil
Expand Down
48 changes: 48 additions & 0 deletions pkg/instrumentation/defaultinstrumentation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ func Test_getDefaultInstrumentationLinux(t *testing.T) {
os.Setenv("AUTO_INSTRUMENTATION_DOTNET_MEM_LIMIT", "128Mi")
os.Setenv("AUTO_INSTRUMENTATION_DOTNET_CPU_REQUEST", "50m")
os.Setenv("AUTO_INSTRUMENTATION_DOTNET_MEM_REQUEST", "128Mi")
os.Setenv("AUTO_INSTRUMENTATION_NODEJS_CPU_LIMIT", "500m")
os.Setenv("AUTO_INSTRUMENTATION_NODEJS_MEM_LIMIT", "128Mi")
os.Setenv("AUTO_INSTRUMENTATION_NODEJS_CPU_REQUEST", "50m")
os.Setenv("AUTO_INSTRUMENTATION_NODEJS_MEM_REQUEST", "128Mi")

httpInst := &v1alpha1.Instrumentation{
Status: v1alpha1.InstrumentationStatus{},
Expand Down Expand Up @@ -143,6 +147,16 @@ func Test_getDefaultInstrumentationLinux(t *testing.T) {
{Name: "OTEL_METRICS_EXPORTER", Value: "none"},
{Name: "OTEL_LOGS_EXPORTER", Value: "none"},
},
Resources: corev1.ResourceRequirements{
Limits: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("500m"),
corev1.ResourceMemory: resource.MustParse("128Mi"),
},
Requests: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("50m"),
corev1.ResourceMemory: resource.MustParse("128Mi"),
},
},
},
},
}
Expand Down Expand Up @@ -254,6 +268,16 @@ func Test_getDefaultInstrumentationLinux(t *testing.T) {
{Name: "OTEL_METRICS_EXPORTER", Value: "none"},
{Name: "OTEL_LOGS_EXPORTER", Value: "none"},
},
Resources: corev1.ResourceRequirements{
Limits: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("500m"),
corev1.ResourceMemory: resource.MustParse("128Mi"),
},
Requests: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("50m"),
corev1.ResourceMemory: resource.MustParse("128Mi"),
},
},
},
},
}
Expand Down Expand Up @@ -333,6 +357,10 @@ func Test_getDefaultInstrumentationWindows(t *testing.T) {
os.Setenv("AUTO_INSTRUMENTATION_DOTNET_MEM_LIMIT", "128Mi")
os.Setenv("AUTO_INSTRUMENTATION_DOTNET_CPU_REQUEST", "50m")
os.Setenv("AUTO_INSTRUMENTATION_DOTNET_MEM_REQUEST", "128Mi")
os.Setenv("AUTO_INSTRUMENTATION_NODEJS_CPU_LIMIT", "500m")
os.Setenv("AUTO_INSTRUMENTATION_NODEJS_MEM_LIMIT", "128Mi")
os.Setenv("AUTO_INSTRUMENTATION_NODEJS_CPU_REQUEST", "50m")
os.Setenv("AUTO_INSTRUMENTATION_NODEJS_MEM_REQUEST", "128Mi")

httpInst := &v1alpha1.Instrumentation{
Status: v1alpha1.InstrumentationStatus{},
Expand Down Expand Up @@ -442,6 +470,16 @@ func Test_getDefaultInstrumentationWindows(t *testing.T) {
{Name: "OTEL_METRICS_EXPORTER", Value: "none"},
{Name: "OTEL_LOGS_EXPORTER", Value: "none"},
},
Resources: corev1.ResourceRequirements{
Limits: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("500m"),
corev1.ResourceMemory: resource.MustParse("128Mi"),
},
Requests: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("50m"),
corev1.ResourceMemory: resource.MustParse("128Mi"),
},
},
},
},
}
Expand Down Expand Up @@ -553,6 +591,16 @@ func Test_getDefaultInstrumentationWindows(t *testing.T) {
{Name: "OTEL_METRICS_EXPORTER", Value: "none"},
{Name: "OTEL_LOGS_EXPORTER", Value: "none"},
},
Resources: corev1.ResourceRequirements{
Limits: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("500m"),
corev1.ResourceMemory: resource.MustParse("128Mi"),
},
Requests: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("50m"),
corev1.ResourceMemory: resource.MustParse("128Mi"),
},
},
},
},
}
Expand Down

0 comments on commit af44378

Please sign in to comment.