From de7eab264dc8ca8996fc7c59e15375f5907a800f Mon Sep 17 00:00:00 2001 From: musa-asad Date: Wed, 17 Jul 2024 03:27:15 -0400 Subject: [PATCH 01/20] Added ability for operator to have resource values configured from helm chart for init containers. --- main.go | 29 +++++++++++-------- pkg/instrumentation/defaultinstrumentation.go | 28 ++++++++++++++++++ 2 files changed, 45 insertions(+), 12 deletions(-) diff --git a/main.go b/main.go index 4ec1d6a76..9f175016e 100644 --- a/main.go +++ b/main.go @@ -93,23 +93,25 @@ func main() { // add flags related to this operator var ( - metricsAddr string - probeAddr string - pprofAddr string - agentImage string - autoInstrumentationJava string - autoInstrumentationPython string - autoInstrumentationDotNet string - autoAnnotationConfigStr string - webhookPort int - tlsOpt tlsConfig - dcgmExporterImage string - neuronMonitorImage string + metricsAddr string + probeAddr string + pprofAddr string + autoInstrumentationConfigStr string + agentImage string + autoInstrumentationJava string + autoInstrumentationPython string + autoInstrumentationDotNet string + autoAnnotationConfigStr string + webhookPort int + tlsOpt tlsConfig + dcgmExporterImage string + neuronMonitorImage string ) pflag.StringVar(&metricsAddr, "metrics-addr", ":8080", "The address the metric endpoint binds to.") pflag.StringVar(&probeAddr, "health-probe-addr", ":8081", "The address the probe endpoint binds to.") pflag.StringVar(&pprofAddr, "pprof-addr", "", "The address to expose the pprof server. Default is empty string which disables the pprof server.") + pflag.StringVar(&autoInstrumentationConfigStr, "auto-instrumentation-config", "", "The configuration for auto-instrumentation.") stringFlagOrEnv(&agentImage, "agent-image", "RELATED_IMAGE_COLLECTOR", fmt.Sprintf("%s:%s", cloudwatchAgentImageRepository, v.AmazonCloudWatchAgent), "The default CloudWatch Agent image. This image is used when no image is specified in the CustomResource.") stringFlagOrEnv(&autoInstrumentationJava, "auto-instrumentation-java-image", "RELATED_IMAGE_AUTO_INSTRUMENTATION_JAVA", fmt.Sprintf("%s:%s", autoInstrumentationJavaImageRepository, v.AutoInstrumentationJava), "The default OpenTelemetry Java instrumentation image. This image is used when no image is specified in the CustomResource.") stringFlagOrEnv(&autoInstrumentationPython, "auto-instrumentation-python-image", "RELATED_IMAGE_AUTO_INSTRUMENTATION_PYTHON", fmt.Sprintf("%s:%s", autoInstrumentationPythonImageRepository, v.AutoInstrumentationPython), "The default OpenTelemetry Python instrumentation image. This image is used when no image is specified in the CustomResource.") @@ -119,6 +121,9 @@ func main() { stringFlagOrEnv(&neuronMonitorImage, "neuron-monitor-image", "RELATED_IMAGE_NEURON_MONITOR", fmt.Sprintf("%s:%s", neuronMonitorImageRepository, v.NeuronMonitor), "The default Neuron monitor image. This image is used when no image is specified in the CustomResource.") pflag.Parse() + // set instrumentation config in environment variable to be used for default instrumentation + os.Setenv("AUTO_INSTRUMENTATION_CONFIG", autoInstrumentationConfigStr) + // set supported language instrumentation images in environment variable to be used for default instrumentation os.Setenv("AUTO_INSTRUMENTATION_JAVA", autoInstrumentationJava) os.Setenv("AUTO_INSTRUMENTATION_PYTHON", autoInstrumentationPython) diff --git a/pkg/instrumentation/defaultinstrumentation.go b/pkg/instrumentation/defaultinstrumentation.go index b0f446c1d..df6c1c8a4 100644 --- a/pkg/instrumentation/defaultinstrumentation.go +++ b/pkg/instrumentation/defaultinstrumentation.go @@ -4,8 +4,10 @@ package instrumentation import ( + "encoding/json" "errors" "fmt" + "k8s.io/apimachinery/pkg/api/resource" "os" corev1 "k8s.io/api/core/v1" @@ -38,6 +40,14 @@ func getDefaultInstrumentation(agentConfig *adapters.CwaConfig, isWindowsPod boo if !ok { return nil, errors.New("unable to determine dotnet instrumentation image") } + autoInstrumentationConfigStr, ok := os.LookupEnv("AUTO_INSTRUMENTATION_CONFIG") + autoInstrumentationConfig := map[string]string{ + "cpu": "100m", + "memory": "64Mi", + } + if ok { + json.Unmarshal([]byte(autoInstrumentationConfigStr), &autoInstrumentationConfig) + } cloudwatchAgentServiceEndpoint := "cloudwatch-agent.amazon-cloudwatch" if isWindowsPod { @@ -86,6 +96,12 @@ func getDefaultInstrumentation(agentConfig *adapters.CwaConfig, isWindowsPod boo {Name: "OTEL_METRICS_EXPORTER", Value: "none"}, {Name: "OTEL_LOGS_EXPORTER", Value: "none"}, }, + Resources: corev1.ResourceRequirements{ + Limits: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse(autoInstrumentationConfig["cpu"]), + corev1.ResourceMemory: resource.MustParse(autoInstrumentationConfig["memory"]), + }, + }, }, Python: v1alpha1.Python{ Image: pythonInstrumentationImage, @@ -103,6 +119,12 @@ func getDefaultInstrumentation(agentConfig *adapters.CwaConfig, isWindowsPod boo {Name: "OTEL_PYTHON_CONFIGURATOR", Value: "aws_configurator"}, {Name: "OTEL_LOGS_EXPORTER", Value: "none"}, }, + Resources: corev1.ResourceRequirements{ + Limits: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse(autoInstrumentationConfig["cpu"]), + corev1.ResourceMemory: resource.MustParse(autoInstrumentationConfig["memory"]), + }, + }, }, DotNet: v1alpha1.DotNet{ Image: dotNetInstrumentationImage, @@ -120,6 +142,12 @@ func getDefaultInstrumentation(agentConfig *adapters.CwaConfig, isWindowsPod boo {Name: "OTEL_LOGS_EXPORTER", Value: "none"}, {Name: "OTEL_DOTNET_AUTO_PLUGINS", Value: "AWS.Distro.OpenTelemetry.AutoInstrumentation.Plugin, AWS.Distro.OpenTelemetry.AutoInstrumentation"}, }, + Resources: corev1.ResourceRequirements{ + Limits: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse(autoInstrumentationConfig["cpu"]), + corev1.ResourceMemory: resource.MustParse(autoInstrumentationConfig["memory"]), + }, + }, }, }, }, nil From 63c2aaef334387c94ce5d464b283916fc6a82ed2 Mon Sep 17 00:00:00 2001 From: musa-asad Date: Thu, 18 Jul 2024 02:28:00 -0400 Subject: [PATCH 02/20] Changed environmental variables to be specific values, get default from upstream or helm chart, and added unit tests. --- main.go | 12 ++- pkg/instrumentation/defaultinstrumentation.go | 34 ++++---- .../defaultinstrumentation_test.go | 77 +++++++++++++++++++ 3 files changed, 100 insertions(+), 23 deletions(-) diff --git a/main.go b/main.go index 9f175016e..d9415793e 100644 --- a/main.go +++ b/main.go @@ -121,8 +121,14 @@ func main() { stringFlagOrEnv(&neuronMonitorImage, "neuron-monitor-image", "RELATED_IMAGE_NEURON_MONITOR", fmt.Sprintf("%s:%s", neuronMonitorImageRepository, v.NeuronMonitor), "The default Neuron monitor image. This image is used when no image is specified in the CustomResource.") pflag.Parse() - // set instrumentation config in environment variable to be used for default instrumentation - os.Setenv("AUTO_INSTRUMENTATION_CONFIG", autoInstrumentationConfigStr) + // set instrumentation cpu and memory limits in environment variables to be used for default instrumentation + autoInstrumentationConfig := map[string]string{"cpu": "", "memory": ""} + err := json.Unmarshal([]byte(autoInstrumentationConfigStr), &autoInstrumentationConfig) + if err != nil { + setupLog.Error(err, "Unable to unmarshal auto-instrumentation config, assuming default values") + } + os.Setenv("AUTO_INSTRUMENTATION_LIMIT_CPU", autoInstrumentationConfig["cpu"]) + os.Setenv("AUTO_INSTRUMENTATION_LIMIT_MEMORY", autoInstrumentationConfig["memory"]) // set supported language instrumentation images in environment variable to be used for default instrumentation os.Setenv("AUTO_INSTRUMENTATION_JAVA", autoInstrumentationJava) @@ -278,7 +284,7 @@ func main() { setupLog.Error(err, "unable to create webhook", "webhook", "Instrumentation") os.Exit(1) } - mgr.GetWebhookServer().Register("/mutate-v1-pod", &webhook.Admission{ + mgr.GetWebhookServer().Register("/mut ate-v1-pod", &webhook.Admission{ Handler: podmutation.NewWebhookHandler(cfg, ctrl.Log.WithName("pod-webhook"), decoder, mgr.GetClient(), []podmutation.PodMutator{ sidecar.NewMutator(logger, cfg, mgr.GetClient()), diff --git a/pkg/instrumentation/defaultinstrumentation.go b/pkg/instrumentation/defaultinstrumentation.go index df6c1c8a4..f4acae89a 100644 --- a/pkg/instrumentation/defaultinstrumentation.go +++ b/pkg/instrumentation/defaultinstrumentation.go @@ -4,7 +4,6 @@ package instrumentation import ( - "encoding/json" "errors" "fmt" "k8s.io/apimachinery/pkg/api/resource" @@ -40,13 +39,17 @@ func getDefaultInstrumentation(agentConfig *adapters.CwaConfig, isWindowsPod boo if !ok { return nil, errors.New("unable to determine dotnet instrumentation image") } - autoInstrumentationConfigStr, ok := os.LookupEnv("AUTO_INSTRUMENTATION_CONFIG") - autoInstrumentationConfig := map[string]string{ - "cpu": "100m", - "memory": "64Mi", - } - if ok { - json.Unmarshal([]byte(autoInstrumentationConfigStr), &autoInstrumentationConfig) + autoInstrumentationConfigCpu, _ := os.LookupEnv("AUTO_INSTRUMENTATION_LIMIT_CPU") + autoInstrumentationConfigMemory, _ := os.LookupEnv("AUTO_INSTRUMENTATION_LIMIT_MEMORY") + + var autoInstrumentationConfigLimits corev1.ResourceList + if autoInstrumentationConfigCpu == "" || autoInstrumentationConfigMemory == "" { + autoInstrumentationConfigLimits = nil + } else { + autoInstrumentationConfigLimits = corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse(autoInstrumentationConfigCpu), + corev1.ResourceMemory: resource.MustParse(autoInstrumentationConfigMemory), + } } cloudwatchAgentServiceEndpoint := "cloudwatch-agent.amazon-cloudwatch" @@ -97,10 +100,7 @@ func getDefaultInstrumentation(agentConfig *adapters.CwaConfig, isWindowsPod boo {Name: "OTEL_LOGS_EXPORTER", Value: "none"}, }, Resources: corev1.ResourceRequirements{ - Limits: corev1.ResourceList{ - corev1.ResourceCPU: resource.MustParse(autoInstrumentationConfig["cpu"]), - corev1.ResourceMemory: resource.MustParse(autoInstrumentationConfig["memory"]), - }, + Limits: autoInstrumentationConfigLimits, }, }, Python: v1alpha1.Python{ @@ -120,10 +120,7 @@ func getDefaultInstrumentation(agentConfig *adapters.CwaConfig, isWindowsPod boo {Name: "OTEL_LOGS_EXPORTER", Value: "none"}, }, Resources: corev1.ResourceRequirements{ - Limits: corev1.ResourceList{ - corev1.ResourceCPU: resource.MustParse(autoInstrumentationConfig["cpu"]), - corev1.ResourceMemory: resource.MustParse(autoInstrumentationConfig["memory"]), - }, + Limits: autoInstrumentationConfigLimits, }, }, DotNet: v1alpha1.DotNet{ @@ -143,10 +140,7 @@ func getDefaultInstrumentation(agentConfig *adapters.CwaConfig, isWindowsPod boo {Name: "OTEL_DOTNET_AUTO_PLUGINS", Value: "AWS.Distro.OpenTelemetry.AutoInstrumentation.Plugin, AWS.Distro.OpenTelemetry.AutoInstrumentation"}, }, Resources: corev1.ResourceRequirements{ - Limits: corev1.ResourceList{ - corev1.ResourceCPU: resource.MustParse(autoInstrumentationConfig["cpu"]), - corev1.ResourceMemory: resource.MustParse(autoInstrumentationConfig["memory"]), - }, + Limits: autoInstrumentationConfigLimits, }, }, }, diff --git a/pkg/instrumentation/defaultinstrumentation_test.go b/pkg/instrumentation/defaultinstrumentation_test.go index c553f9fac..9001be5c1 100644 --- a/pkg/instrumentation/defaultinstrumentation_test.go +++ b/pkg/instrumentation/defaultinstrumentation_test.go @@ -4,6 +4,7 @@ package instrumentation import ( + "k8s.io/apimachinery/pkg/api/resource" "os" "reflect" "testing" @@ -19,6 +20,8 @@ func Test_getDefaultInstrumentationLinux(t *testing.T) { os.Setenv("AUTO_INSTRUMENTATION_JAVA", defaultJavaInstrumentationImage) os.Setenv("AUTO_INSTRUMENTATION_PYTHON", defaultPythonInstrumentationImage) os.Setenv("AUTO_INSTRUMENTATION_DOTNET", defaultDotNetInstrumentationImage) + os.Setenv("AUTO_INSTRUMENTATION_LIMIT_CPU", "500m") + os.Setenv("AUTO_INSTRUMENTATION_LIMIT_MEMORY", "64Mi") httpInst := &v1alpha1.Instrumentation{ Status: v1alpha1.InstrumentationStatus{}, @@ -51,6 +54,12 @@ 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("64Mi"), + }, + }, }, Python: v1alpha1.Python{ Image: defaultPythonInstrumentationImage, @@ -68,6 +77,12 @@ func Test_getDefaultInstrumentationLinux(t *testing.T) { {Name: "OTEL_PYTHON_CONFIGURATOR", Value: "aws_configurator"}, {Name: "OTEL_LOGS_EXPORTER", Value: "none"}, }, + Resources: corev1.ResourceRequirements{ + Limits: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("500m"), + corev1.ResourceMemory: resource.MustParse("64Mi"), + }, + }, }, DotNet: v1alpha1.DotNet{ Image: defaultDotNetInstrumentationImage, @@ -85,6 +100,12 @@ func Test_getDefaultInstrumentationLinux(t *testing.T) { {Name: "OTEL_LOGS_EXPORTER", Value: "none"}, {Name: "OTEL_DOTNET_AUTO_PLUGINS", Value: "AWS.Distro.OpenTelemetry.AutoInstrumentation.Plugin, AWS.Distro.OpenTelemetry.AutoInstrumentation"}, }, + Resources: corev1.ResourceRequirements{ + Limits: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("500m"), + corev1.ResourceMemory: resource.MustParse("64Mi"), + }, + }, }, }, } @@ -119,6 +140,12 @@ 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("64Mi"), + }, + }, }, Python: v1alpha1.Python{ Image: defaultPythonInstrumentationImage, @@ -136,6 +163,12 @@ func Test_getDefaultInstrumentationLinux(t *testing.T) { {Name: "OTEL_PYTHON_CONFIGURATOR", Value: "aws_configurator"}, {Name: "OTEL_LOGS_EXPORTER", Value: "none"}, }, + Resources: corev1.ResourceRequirements{ + Limits: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("500m"), + corev1.ResourceMemory: resource.MustParse("64Mi"), + }, + }, }, DotNet: v1alpha1.DotNet{ Image: defaultDotNetInstrumentationImage, @@ -153,6 +186,12 @@ func Test_getDefaultInstrumentationLinux(t *testing.T) { {Name: "OTEL_LOGS_EXPORTER", Value: "none"}, {Name: "OTEL_DOTNET_AUTO_PLUGINS", Value: "AWS.Distro.OpenTelemetry.AutoInstrumentation.Plugin, AWS.Distro.OpenTelemetry.AutoInstrumentation"}, }, + Resources: corev1.ResourceRequirements{ + Limits: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("500m"), + corev1.ResourceMemory: resource.MustParse("64Mi"), + }, + }, }, }, } @@ -218,6 +257,8 @@ func Test_getDefaultInstrumentationWindows(t *testing.T) { os.Setenv("AUTO_INSTRUMENTATION_JAVA", defaultJavaInstrumentationImage) os.Setenv("AUTO_INSTRUMENTATION_PYTHON", defaultPythonInstrumentationImage) os.Setenv("AUTO_INSTRUMENTATION_DOTNET", defaultDotNetInstrumentationImage) + os.Setenv("AUTO_INSTRUMENTATION_LIMIT_CPU", "500m") + os.Setenv("AUTO_INSTRUMENTATION_LIMIT_MEMORY", "64Mi") httpInst := &v1alpha1.Instrumentation{ Status: v1alpha1.InstrumentationStatus{}, @@ -250,6 +291,12 @@ 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("64Mi"), + }, + }, }, Python: v1alpha1.Python{ Image: defaultPythonInstrumentationImage, @@ -267,6 +314,12 @@ func Test_getDefaultInstrumentationWindows(t *testing.T) { {Name: "OTEL_PYTHON_CONFIGURATOR", Value: "aws_configurator"}, {Name: "OTEL_LOGS_EXPORTER", Value: "none"}, }, + Resources: corev1.ResourceRequirements{ + Limits: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("500m"), + corev1.ResourceMemory: resource.MustParse("64Mi"), + }, + }, }, DotNet: v1alpha1.DotNet{ Image: defaultDotNetInstrumentationImage, @@ -284,6 +337,12 @@ func Test_getDefaultInstrumentationWindows(t *testing.T) { {Name: "OTEL_LOGS_EXPORTER", Value: "none"}, {Name: "OTEL_DOTNET_AUTO_PLUGINS", Value: "AWS.Distro.OpenTelemetry.AutoInstrumentation.Plugin, AWS.Distro.OpenTelemetry.AutoInstrumentation"}, }, + Resources: corev1.ResourceRequirements{ + Limits: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("500m"), + corev1.ResourceMemory: resource.MustParse("64Mi"), + }, + }, }, }, } @@ -318,6 +377,12 @@ 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("64Mi"), + }, + }, }, Python: v1alpha1.Python{ Image: defaultPythonInstrumentationImage, @@ -335,6 +400,12 @@ func Test_getDefaultInstrumentationWindows(t *testing.T) { {Name: "OTEL_PYTHON_CONFIGURATOR", Value: "aws_configurator"}, {Name: "OTEL_LOGS_EXPORTER", Value: "none"}, }, + Resources: corev1.ResourceRequirements{ + Limits: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("500m"), + corev1.ResourceMemory: resource.MustParse("64Mi"), + }, + }, }, DotNet: v1alpha1.DotNet{ Image: defaultDotNetInstrumentationImage, @@ -352,6 +423,12 @@ func Test_getDefaultInstrumentationWindows(t *testing.T) { {Name: "OTEL_LOGS_EXPORTER", Value: "none"}, {Name: "OTEL_DOTNET_AUTO_PLUGINS", Value: "AWS.Distro.OpenTelemetry.AutoInstrumentation.Plugin, AWS.Distro.OpenTelemetry.AutoInstrumentation"}, }, + Resources: corev1.ResourceRequirements{ + Limits: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("500m"), + corev1.ResourceMemory: resource.MustParse("64Mi"), + }, + }, }, }, } From 75cee1efd3484aee2996fe80aad5edaa1072e299 Mon Sep 17 00:00:00 2001 From: musa-asad Date: Thu, 18 Jul 2024 02:30:53 -0400 Subject: [PATCH 03/20] Fixed typo. --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index d9415793e..7ba4881bc 100644 --- a/main.go +++ b/main.go @@ -284,7 +284,7 @@ func main() { setupLog.Error(err, "unable to create webhook", "webhook", "Instrumentation") os.Exit(1) } - mgr.GetWebhookServer().Register("/mut ate-v1-pod", &webhook.Admission{ + mgr.GetWebhookServer().Register("/mutate-v1-pod", &webhook.Admission{ Handler: podmutation.NewWebhookHandler(cfg, ctrl.Log.WithName("pod-webhook"), decoder, mgr.GetClient(), []podmutation.PodMutator{ sidecar.NewMutator(logger, cfg, mgr.GetClient()), From 3441437fb168e3ffdd4b3d0abacaa8d87f005bca Mon Sep 17 00:00:00 2001 From: musa-asad Date: Tue, 23 Jul 2024 15:26:49 -0400 Subject: [PATCH 04/20] Let users configure them individually. --- pkg/instrumentation/defaultinstrumentation.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pkg/instrumentation/defaultinstrumentation.go b/pkg/instrumentation/defaultinstrumentation.go index f4acae89a..9e800bd63 100644 --- a/pkg/instrumentation/defaultinstrumentation.go +++ b/pkg/instrumentation/defaultinstrumentation.go @@ -43,8 +43,16 @@ func getDefaultInstrumentation(agentConfig *adapters.CwaConfig, isWindowsPod boo autoInstrumentationConfigMemory, _ := os.LookupEnv("AUTO_INSTRUMENTATION_LIMIT_MEMORY") var autoInstrumentationConfigLimits corev1.ResourceList - if autoInstrumentationConfigCpu == "" || autoInstrumentationConfigMemory == "" { + if autoInstrumentationConfigCpu == "" && autoInstrumentationConfigMemory == "" { autoInstrumentationConfigLimits = nil + } else if autoInstrumentationConfigCpu == "" { + autoInstrumentationConfigLimits = corev1.ResourceList{ + corev1.ResourceMemory: resource.MustParse(autoInstrumentationConfigMemory), + } + } else if autoInstrumentationConfigMemory == "" { + autoInstrumentationConfigLimits = corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse(autoInstrumentationConfigCpu), + } } else { autoInstrumentationConfigLimits = corev1.ResourceList{ corev1.ResourceCPU: resource.MustParse(autoInstrumentationConfigCpu), From 9ebd7d4d472dfa1632d1a6ee33ce55dc8afe2534 Mon Sep 17 00:00:00 2001 From: musa-asad Date: Tue, 23 Jul 2024 17:58:49 -0400 Subject: [PATCH 05/20] Allowed configurable languages. --- main.go | 12 +++-- pkg/instrumentation/defaultinstrumentation.go | 50 ++++++++++--------- 2 files changed, 36 insertions(+), 26 deletions(-) diff --git a/main.go b/main.go index 7ba4881bc..faf1b7c64 100644 --- a/main.go +++ b/main.go @@ -81,6 +81,11 @@ func stringFlagOrEnv(p *string, name string, envName string, defaultValue string pflag.StringVar(p, name, defaultValue, usage) } +func setEnvLang(lang string, cfg map[string]string) { + os.Setenv("AUTO_INSTRUMENTATION_LIMIT_CPU_"+lang, cfg["cpu"]) + os.Setenv("AUTO_INSTRUMENTATION_LIMIT_MEMORY_"+lang, cfg["memory"]) +} + func main() { // registers any flags that underlying libraries might use opts := zap.Options{} @@ -122,13 +127,14 @@ func main() { pflag.Parse() // set instrumentation cpu and memory limits in environment variables to be used for default instrumentation - autoInstrumentationConfig := map[string]string{"cpu": "", "memory": ""} + autoInstrumentationConfig := map[string]map[string]string{"java": {"cpu": "500m", "memory": "64Mi"}, "python": {"cpu": "500m", "memory": "32Mi"}, "dotnet": {"cpu": "500m", "memory": "128Mi"}} err := json.Unmarshal([]byte(autoInstrumentationConfigStr), &autoInstrumentationConfig) if err != nil { setupLog.Error(err, "Unable to unmarshal auto-instrumentation config, assuming default values") } - os.Setenv("AUTO_INSTRUMENTATION_LIMIT_CPU", autoInstrumentationConfig["cpu"]) - os.Setenv("AUTO_INSTRUMENTATION_LIMIT_MEMORY", autoInstrumentationConfig["memory"]) + setEnvLang("JAVA", autoInstrumentationConfig["java"]) + setEnvLang("PYTHON", autoInstrumentationConfig["python"]) + setEnvLang("DOTNET", autoInstrumentationConfig["dotnet"]) // set supported language instrumentation images in environment variable to be used for default instrumentation os.Setenv("AUTO_INSTRUMENTATION_JAVA", autoInstrumentationJava) diff --git a/pkg/instrumentation/defaultinstrumentation.go b/pkg/instrumentation/defaultinstrumentation.go index 9e800bd63..7a521e34a 100644 --- a/pkg/instrumentation/defaultinstrumentation.go +++ b/pkg/instrumentation/defaultinstrumentation.go @@ -26,6 +26,30 @@ const ( https = "https" ) +func getInstrumentationConfig(lang string) corev1.ResourceList { + instrumentationConfigCpu, _ := os.LookupEnv("AUTO_INSTRUMENTATION_LIMIT_CPU_" + lang) + instrumentationConfigMemory, _ := os.LookupEnv("AUTO_INSTRUMENTATION_LIMIT_MEMORY_" + lang) + + var instrumentationConfigLimits corev1.ResourceList + if instrumentationConfigCpu == "" && instrumentationConfigMemory == "" { + instrumentationConfigLimits = nil + } else if instrumentationConfigCpu == "" { + instrumentationConfigLimits = corev1.ResourceList{ + corev1.ResourceMemory: resource.MustParse(instrumentationConfigMemory), + } + } else if instrumentationConfigMemory == "" { + instrumentationConfigLimits = corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse(instrumentationConfigCpu), + } + } else { + instrumentationConfigLimits = corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse(instrumentationConfigCpu), + corev1.ResourceMemory: resource.MustParse(instrumentationConfigMemory), + } + } + return instrumentationConfigLimits +} + func getDefaultInstrumentation(agentConfig *adapters.CwaConfig, isWindowsPod bool) (*v1alpha1.Instrumentation, error) { javaInstrumentationImage, ok := os.LookupEnv("AUTO_INSTRUMENTATION_JAVA") if !ok { @@ -39,26 +63,6 @@ func getDefaultInstrumentation(agentConfig *adapters.CwaConfig, isWindowsPod boo if !ok { return nil, errors.New("unable to determine dotnet instrumentation image") } - autoInstrumentationConfigCpu, _ := os.LookupEnv("AUTO_INSTRUMENTATION_LIMIT_CPU") - autoInstrumentationConfigMemory, _ := os.LookupEnv("AUTO_INSTRUMENTATION_LIMIT_MEMORY") - - var autoInstrumentationConfigLimits corev1.ResourceList - if autoInstrumentationConfigCpu == "" && autoInstrumentationConfigMemory == "" { - autoInstrumentationConfigLimits = nil - } else if autoInstrumentationConfigCpu == "" { - autoInstrumentationConfigLimits = corev1.ResourceList{ - corev1.ResourceMemory: resource.MustParse(autoInstrumentationConfigMemory), - } - } else if autoInstrumentationConfigMemory == "" { - autoInstrumentationConfigLimits = corev1.ResourceList{ - corev1.ResourceCPU: resource.MustParse(autoInstrumentationConfigCpu), - } - } else { - autoInstrumentationConfigLimits = corev1.ResourceList{ - corev1.ResourceCPU: resource.MustParse(autoInstrumentationConfigCpu), - corev1.ResourceMemory: resource.MustParse(autoInstrumentationConfigMemory), - } - } cloudwatchAgentServiceEndpoint := "cloudwatch-agent.amazon-cloudwatch" if isWindowsPod { @@ -108,7 +112,7 @@ func getDefaultInstrumentation(agentConfig *adapters.CwaConfig, isWindowsPod boo {Name: "OTEL_LOGS_EXPORTER", Value: "none"}, }, Resources: corev1.ResourceRequirements{ - Limits: autoInstrumentationConfigLimits, + Limits: getInstrumentationConfig("JAVA"), }, }, Python: v1alpha1.Python{ @@ -128,7 +132,7 @@ func getDefaultInstrumentation(agentConfig *adapters.CwaConfig, isWindowsPod boo {Name: "OTEL_LOGS_EXPORTER", Value: "none"}, }, Resources: corev1.ResourceRequirements{ - Limits: autoInstrumentationConfigLimits, + Limits: getInstrumentationConfig("PYTHON"), }, }, DotNet: v1alpha1.DotNet{ @@ -148,7 +152,7 @@ func getDefaultInstrumentation(agentConfig *adapters.CwaConfig, isWindowsPod boo {Name: "OTEL_DOTNET_AUTO_PLUGINS", Value: "AWS.Distro.OpenTelemetry.AutoInstrumentation.Plugin, AWS.Distro.OpenTelemetry.AutoInstrumentation"}, }, Resources: corev1.ResourceRequirements{ - Limits: autoInstrumentationConfigLimits, + Limits: getInstrumentationConfig("DOTNET"), }, }, }, From 8aaa6350f6ec74ff0afae02c044bc11cb530082a Mon Sep 17 00:00:00 2001 From: musa-asad Date: Tue, 23 Jul 2024 19:36:53 -0400 Subject: [PATCH 06/20] Assume default values from helm chart and updated tests. --- pkg/instrumentation/defaultinstrumentation.go | 30 ++++++----------- .../defaultinstrumentation_test.go | 32 ++++++++++++------- 2 files changed, 30 insertions(+), 32 deletions(-) diff --git a/pkg/instrumentation/defaultinstrumentation.go b/pkg/instrumentation/defaultinstrumentation.go index 7a521e34a..7b8d821a1 100644 --- a/pkg/instrumentation/defaultinstrumentation.go +++ b/pkg/instrumentation/defaultinstrumentation.go @@ -26,26 +26,16 @@ const ( https = "https" ) -func getInstrumentationConfig(lang string) corev1.ResourceList { +func getInstrumentationConfigLimits(lang string) corev1.ResourceList { instrumentationConfigCpu, _ := os.LookupEnv("AUTO_INSTRUMENTATION_LIMIT_CPU_" + lang) instrumentationConfigMemory, _ := os.LookupEnv("AUTO_INSTRUMENTATION_LIMIT_MEMORY_" + lang) - var instrumentationConfigLimits corev1.ResourceList - if instrumentationConfigCpu == "" && instrumentationConfigMemory == "" { - instrumentationConfigLimits = nil - } else if instrumentationConfigCpu == "" { - instrumentationConfigLimits = corev1.ResourceList{ - corev1.ResourceMemory: resource.MustParse(instrumentationConfigMemory), - } - } else if instrumentationConfigMemory == "" { - instrumentationConfigLimits = corev1.ResourceList{ - corev1.ResourceCPU: resource.MustParse(instrumentationConfigCpu), - } - } else { - instrumentationConfigLimits = corev1.ResourceList{ - corev1.ResourceCPU: resource.MustParse(instrumentationConfigCpu), - corev1.ResourceMemory: resource.MustParse(instrumentationConfigMemory), - } + instrumentationConfigLimits := corev1.ResourceList{} + if instrumentationConfigCpu != "" { + instrumentationConfigLimits[corev1.ResourceCPU] = resource.MustParse(instrumentationConfigCpu) + } + if instrumentationConfigMemory != "" { + instrumentationConfigLimits[corev1.ResourceMemory] = resource.MustParse(instrumentationConfigMemory) } return instrumentationConfigLimits } @@ -112,7 +102,7 @@ func getDefaultInstrumentation(agentConfig *adapters.CwaConfig, isWindowsPod boo {Name: "OTEL_LOGS_EXPORTER", Value: "none"}, }, Resources: corev1.ResourceRequirements{ - Limits: getInstrumentationConfig("JAVA"), + Limits: getInstrumentationConfigLimits("JAVA"), }, }, Python: v1alpha1.Python{ @@ -132,7 +122,7 @@ func getDefaultInstrumentation(agentConfig *adapters.CwaConfig, isWindowsPod boo {Name: "OTEL_LOGS_EXPORTER", Value: "none"}, }, Resources: corev1.ResourceRequirements{ - Limits: getInstrumentationConfig("PYTHON"), + Limits: getInstrumentationConfigLimits("PYTHON"), }, }, DotNet: v1alpha1.DotNet{ @@ -152,7 +142,7 @@ func getDefaultInstrumentation(agentConfig *adapters.CwaConfig, isWindowsPod boo {Name: "OTEL_DOTNET_AUTO_PLUGINS", Value: "AWS.Distro.OpenTelemetry.AutoInstrumentation.Plugin, AWS.Distro.OpenTelemetry.AutoInstrumentation"}, }, Resources: corev1.ResourceRequirements{ - Limits: getInstrumentationConfig("DOTNET"), + Limits: getInstrumentationConfigLimits("DOTNET"), }, }, }, diff --git a/pkg/instrumentation/defaultinstrumentation_test.go b/pkg/instrumentation/defaultinstrumentation_test.go index 9001be5c1..7da7274c1 100644 --- a/pkg/instrumentation/defaultinstrumentation_test.go +++ b/pkg/instrumentation/defaultinstrumentation_test.go @@ -20,8 +20,12 @@ func Test_getDefaultInstrumentationLinux(t *testing.T) { os.Setenv("AUTO_INSTRUMENTATION_JAVA", defaultJavaInstrumentationImage) os.Setenv("AUTO_INSTRUMENTATION_PYTHON", defaultPythonInstrumentationImage) os.Setenv("AUTO_INSTRUMENTATION_DOTNET", defaultDotNetInstrumentationImage) - os.Setenv("AUTO_INSTRUMENTATION_LIMIT_CPU", "500m") - os.Setenv("AUTO_INSTRUMENTATION_LIMIT_MEMORY", "64Mi") + os.Setenv("AUTO_INSTRUMENTATION_LIMIT_CPU_JAVA", "500m") + os.Setenv("AUTO_INSTRUMENTATION_LIMIT_MEMORY_JAVA", "64Mi") + os.Setenv("AUTO_INSTRUMENTATION_LIMIT_CPU_PYTHON", "500m") + os.Setenv("AUTO_INSTRUMENTATION_LIMIT_MEMORY_PYTHON", "32Mi") + os.Setenv("AUTO_INSTRUMENTATION_LIMIT_CPU_DOTNET", "500m") + os.Setenv("AUTO_INSTRUMENTATION_LIMIT_MEMORY_DOTNET", "128Mi") httpInst := &v1alpha1.Instrumentation{ Status: v1alpha1.InstrumentationStatus{}, @@ -80,7 +84,7 @@ func Test_getDefaultInstrumentationLinux(t *testing.T) { Resources: corev1.ResourceRequirements{ Limits: corev1.ResourceList{ corev1.ResourceCPU: resource.MustParse("500m"), - corev1.ResourceMemory: resource.MustParse("64Mi"), + corev1.ResourceMemory: resource.MustParse("32Mi"), }, }, }, @@ -103,7 +107,7 @@ func Test_getDefaultInstrumentationLinux(t *testing.T) { Resources: corev1.ResourceRequirements{ Limits: corev1.ResourceList{ corev1.ResourceCPU: resource.MustParse("500m"), - corev1.ResourceMemory: resource.MustParse("64Mi"), + corev1.ResourceMemory: resource.MustParse("128Mi"), }, }, }, @@ -166,7 +170,7 @@ func Test_getDefaultInstrumentationLinux(t *testing.T) { Resources: corev1.ResourceRequirements{ Limits: corev1.ResourceList{ corev1.ResourceCPU: resource.MustParse("500m"), - corev1.ResourceMemory: resource.MustParse("64Mi"), + corev1.ResourceMemory: resource.MustParse("32Mi"), }, }, }, @@ -189,7 +193,7 @@ func Test_getDefaultInstrumentationLinux(t *testing.T) { Resources: corev1.ResourceRequirements{ Limits: corev1.ResourceList{ corev1.ResourceCPU: resource.MustParse("500m"), - corev1.ResourceMemory: resource.MustParse("64Mi"), + corev1.ResourceMemory: resource.MustParse("128Mi"), }, }, }, @@ -257,8 +261,12 @@ func Test_getDefaultInstrumentationWindows(t *testing.T) { os.Setenv("AUTO_INSTRUMENTATION_JAVA", defaultJavaInstrumentationImage) os.Setenv("AUTO_INSTRUMENTATION_PYTHON", defaultPythonInstrumentationImage) os.Setenv("AUTO_INSTRUMENTATION_DOTNET", defaultDotNetInstrumentationImage) - os.Setenv("AUTO_INSTRUMENTATION_LIMIT_CPU", "500m") - os.Setenv("AUTO_INSTRUMENTATION_LIMIT_MEMORY", "64Mi") + os.Setenv("AUTO_INSTRUMENTATION_LIMIT_CPU_JAVA", "500m") + os.Setenv("AUTO_INSTRUMENTATION_LIMIT_MEMORY_JAVA", "64Mi") + os.Setenv("AUTO_INSTRUMENTATION_LIMIT_CPU_PYTHON", "500m") + os.Setenv("AUTO_INSTRUMENTATION_LIMIT_MEMORY_PYTHON", "32Mi") + os.Setenv("AUTO_INSTRUMENTATION_LIMIT_CPU_DOTNET", "500m") + os.Setenv("AUTO_INSTRUMENTATION_LIMIT_MEMORY_DOTNET", "128Mi") httpInst := &v1alpha1.Instrumentation{ Status: v1alpha1.InstrumentationStatus{}, @@ -317,7 +325,7 @@ func Test_getDefaultInstrumentationWindows(t *testing.T) { Resources: corev1.ResourceRequirements{ Limits: corev1.ResourceList{ corev1.ResourceCPU: resource.MustParse("500m"), - corev1.ResourceMemory: resource.MustParse("64Mi"), + corev1.ResourceMemory: resource.MustParse("32Mi"), }, }, }, @@ -340,7 +348,7 @@ func Test_getDefaultInstrumentationWindows(t *testing.T) { Resources: corev1.ResourceRequirements{ Limits: corev1.ResourceList{ corev1.ResourceCPU: resource.MustParse("500m"), - corev1.ResourceMemory: resource.MustParse("64Mi"), + corev1.ResourceMemory: resource.MustParse("128Mi"), }, }, }, @@ -403,7 +411,7 @@ func Test_getDefaultInstrumentationWindows(t *testing.T) { Resources: corev1.ResourceRequirements{ Limits: corev1.ResourceList{ corev1.ResourceCPU: resource.MustParse("500m"), - corev1.ResourceMemory: resource.MustParse("64Mi"), + corev1.ResourceMemory: resource.MustParse("32Mi"), }, }, }, @@ -426,7 +434,7 @@ func Test_getDefaultInstrumentationWindows(t *testing.T) { Resources: corev1.ResourceRequirements{ Limits: corev1.ResourceList{ corev1.ResourceCPU: resource.MustParse("500m"), - corev1.ResourceMemory: resource.MustParse("64Mi"), + corev1.ResourceMemory: resource.MustParse("128Mi"), }, }, }, From a5978d2a73ac2b198e9424d86a7590f7f176bb52 Mon Sep 17 00:00:00 2001 From: musa-asad Date: Thu, 25 Jul 2024 02:12:51 -0400 Subject: [PATCH 07/20] Added requests. --- main.go | 33 +++++++++++++------ pkg/instrumentation/defaultinstrumentation.go | 23 +++++++------ 2 files changed, 36 insertions(+), 20 deletions(-) diff --git a/main.go b/main.go index faf1b7c64..538475372 100644 --- a/main.go +++ b/main.go @@ -81,9 +81,22 @@ func stringFlagOrEnv(p *string, name string, envName string, defaultValue string pflag.StringVar(p, name, defaultValue, usage) } -func setEnvLang(lang string, cfg map[string]string) { - os.Setenv("AUTO_INSTRUMENTATION_LIMIT_CPU_"+lang, cfg["cpu"]) - os.Setenv("AUTO_INSTRUMENTATION_LIMIT_MEMORY_"+lang, cfg["memory"]) +func setLangEnvVarsForResource(langStr string, resourceStr string, resource map[string]string) { + if cpu, ok := resource["cpu"]; ok { + os.Setenv("AUTO_INSTRUMENTATION_"+langStr+"_CPU_"+resourceStr, cpu) + } + if memory, ok := resource["memory"]; ok { + os.Setenv("AUTO_INSTRUMENTATION_"+langStr+"_MEM_"+resourceStr, memory) + } +} + +func setLangEnvVars(langStr string, cfg map[string]map[string]string) { + if limits, ok := cfg["limits"]; ok { + setLangEnvVarsForResource(langStr, "LIMIT", limits) + } + if requests, ok := cfg["requests"]; ok { + setLangEnvVarsForResource(langStr, "REQUEST", requests) + } } func main() { @@ -101,12 +114,12 @@ func main() { metricsAddr string probeAddr string pprofAddr string - autoInstrumentationConfigStr string agentImage string autoInstrumentationJava string autoInstrumentationPython string autoInstrumentationDotNet string autoAnnotationConfigStr string + autoInstrumentationConfigStr string webhookPort int tlsOpt tlsConfig dcgmExporterImage string @@ -116,25 +129,25 @@ func main() { pflag.StringVar(&metricsAddr, "metrics-addr", ":8080", "The address the metric endpoint binds to.") pflag.StringVar(&probeAddr, "health-probe-addr", ":8081", "The address the probe endpoint binds to.") pflag.StringVar(&pprofAddr, "pprof-addr", "", "The address to expose the pprof server. Default is empty string which disables the pprof server.") - pflag.StringVar(&autoInstrumentationConfigStr, "auto-instrumentation-config", "", "The configuration for auto-instrumentation.") stringFlagOrEnv(&agentImage, "agent-image", "RELATED_IMAGE_COLLECTOR", fmt.Sprintf("%s:%s", cloudwatchAgentImageRepository, v.AmazonCloudWatchAgent), "The default CloudWatch Agent image. This image is used when no image is specified in the CustomResource.") stringFlagOrEnv(&autoInstrumentationJava, "auto-instrumentation-java-image", "RELATED_IMAGE_AUTO_INSTRUMENTATION_JAVA", fmt.Sprintf("%s:%s", autoInstrumentationJavaImageRepository, v.AutoInstrumentationJava), "The default OpenTelemetry Java instrumentation image. This image is used when no image is specified in the CustomResource.") stringFlagOrEnv(&autoInstrumentationPython, "auto-instrumentation-python-image", "RELATED_IMAGE_AUTO_INSTRUMENTATION_PYTHON", fmt.Sprintf("%s:%s", autoInstrumentationPythonImageRepository, v.AutoInstrumentationPython), "The default OpenTelemetry Python instrumentation image. This image is used when no image is specified in the CustomResource.") stringFlagOrEnv(&autoInstrumentationDotNet, "auto-instrumentation-dotnet-image", "RELATED_IMAGE_AUTO_INSTRUMENTATION_DOTNET", fmt.Sprintf("%s:%s", autoInstrumentationDotNetImageRepository, v.AutoInstrumentationDotNet), "The default OpenTelemetry Dotnet instrumentation image. This image is used when no image is specified in the CustomResource.") stringFlagOrEnv(&autoAnnotationConfigStr, "auto-annotation-config", "AUTO_ANNOTATION_CONFIG", "", "The configuration for auto-annotation.") + pflag.StringVar(&autoInstrumentationConfigStr, "auto-instrumentation-config", "", "The configuration for auto-instrumentation.") stringFlagOrEnv(&dcgmExporterImage, "dcgm-exporter-image", "RELATED_IMAGE_DCGM_EXPORTER", fmt.Sprintf("%s:%s", dcgmExporterImageRepository, v.DcgmExporter), "The default DCGM Exporter image. This image is used when no image is specified in the CustomResource.") stringFlagOrEnv(&neuronMonitorImage, "neuron-monitor-image", "RELATED_IMAGE_NEURON_MONITOR", fmt.Sprintf("%s:%s", neuronMonitorImageRepository, v.NeuronMonitor), "The default Neuron monitor image. This image is used when no image is specified in the CustomResource.") pflag.Parse() // set instrumentation cpu and memory limits in environment variables to be used for default instrumentation - autoInstrumentationConfig := map[string]map[string]string{"java": {"cpu": "500m", "memory": "64Mi"}, "python": {"cpu": "500m", "memory": "32Mi"}, "dotnet": {"cpu": "500m", "memory": "128Mi"}} + autoInstrumentationConfig := map[string]map[string]map[string]string{"java": {"limits": {"cpu": "64Mi", "memory": "500m"}, "requests": {"cpu": "64Mi", "memory": "50m"}}, "python": {"limits": {"cpu": "32Mi", "memory": "500m"}, "requests": {"cpu": "32Mi", "memory": "50m"}}} err := json.Unmarshal([]byte(autoInstrumentationConfigStr), &autoInstrumentationConfig) if err != nil { - setupLog.Error(err, "Unable to unmarshal auto-instrumentation config, assuming default values") + setupLog.Info(fmt.Sprintf("Using default values: %v", autoInstrumentationConfig)) } - setEnvLang("JAVA", autoInstrumentationConfig["java"]) - setEnvLang("PYTHON", autoInstrumentationConfig["python"]) - setEnvLang("DOTNET", autoInstrumentationConfig["dotnet"]) + setLangEnvVars("JAVA", autoInstrumentationConfig["java"]) + setLangEnvVars("PYTHON", autoInstrumentationConfig["python"]) + setLangEnvVars("DOTNET", autoInstrumentationConfig["dotnet"]) // set supported language instrumentation images in environment variable to be used for default instrumentation os.Setenv("AUTO_INSTRUMENTATION_JAVA", autoInstrumentationJava) diff --git a/pkg/instrumentation/defaultinstrumentation.go b/pkg/instrumentation/defaultinstrumentation.go index 7b8d821a1..2c1496e82 100644 --- a/pkg/instrumentation/defaultinstrumentation.go +++ b/pkg/instrumentation/defaultinstrumentation.go @@ -26,18 +26,18 @@ const ( https = "https" ) -func getInstrumentationConfigLimits(lang string) corev1.ResourceList { - instrumentationConfigCpu, _ := os.LookupEnv("AUTO_INSTRUMENTATION_LIMIT_CPU_" + lang) - instrumentationConfigMemory, _ := os.LookupEnv("AUTO_INSTRUMENTATION_LIMIT_MEMORY_" + lang) +func getInstrumentationConfigForResource(langStr string, resourceStr string) corev1.ResourceList { + instrumentationConfigCpu, _ := os.LookupEnv("AUTO_INSTRUMENTATION_" + langStr + "_CPU_" + resourceStr) + instrumentationConfigMemory, _ := os.LookupEnv("AUTO_INSTRUMENTATION_" + langStr + "_MEM_" + resourceStr) - instrumentationConfigLimits := corev1.ResourceList{} + instrumentationConfigForResource := corev1.ResourceList{} if instrumentationConfigCpu != "" { - instrumentationConfigLimits[corev1.ResourceCPU] = resource.MustParse(instrumentationConfigCpu) + instrumentationConfigForResource[corev1.ResourceCPU] = resource.MustParse(instrumentationConfigCpu) } if instrumentationConfigMemory != "" { - instrumentationConfigLimits[corev1.ResourceMemory] = resource.MustParse(instrumentationConfigMemory) + instrumentationConfigForResource[corev1.ResourceMemory] = resource.MustParse(instrumentationConfigMemory) } - return instrumentationConfigLimits + return instrumentationConfigForResource } func getDefaultInstrumentation(agentConfig *adapters.CwaConfig, isWindowsPod bool) (*v1alpha1.Instrumentation, error) { @@ -102,7 +102,8 @@ func getDefaultInstrumentation(agentConfig *adapters.CwaConfig, isWindowsPod boo {Name: "OTEL_LOGS_EXPORTER", Value: "none"}, }, Resources: corev1.ResourceRequirements{ - Limits: getInstrumentationConfigLimits("JAVA"), + Limits: getInstrumentationConfigForResource("JAVA", "LIMIT"), + Requests: getInstrumentationConfigForResource("JAVA", "REQUEST"), }, }, Python: v1alpha1.Python{ @@ -122,7 +123,8 @@ func getDefaultInstrumentation(agentConfig *adapters.CwaConfig, isWindowsPod boo {Name: "OTEL_LOGS_EXPORTER", Value: "none"}, }, Resources: corev1.ResourceRequirements{ - Limits: getInstrumentationConfigLimits("PYTHON"), + Limits: getInstrumentationConfigForResource("PYTHON", "LIMIT"), + Requests: getInstrumentationConfigForResource("PYTHON", "REQUEST"), }, }, DotNet: v1alpha1.DotNet{ @@ -142,7 +144,8 @@ func getDefaultInstrumentation(agentConfig *adapters.CwaConfig, isWindowsPod boo {Name: "OTEL_DOTNET_AUTO_PLUGINS", Value: "AWS.Distro.OpenTelemetry.AutoInstrumentation.Plugin, AWS.Distro.OpenTelemetry.AutoInstrumentation"}, }, Resources: corev1.ResourceRequirements{ - Limits: getInstrumentationConfigLimits("DOTNET"), + Limits: getInstrumentationConfigForResource("DOTNET", "LIMIT"), + Requests: getInstrumentationConfigForResource("DOTNET", "REQUEST"), }, }, }, From 28833f35264ba9ff5798c2fba48a9b63c2bf78be Mon Sep 17 00:00:00 2001 From: musa-asad Date: Thu, 25 Jul 2024 02:50:17 -0400 Subject: [PATCH 08/20] Updated tests. --- .../defaultinstrumentation_test.go | 84 ++++++++++++++++--- 1 file changed, 72 insertions(+), 12 deletions(-) diff --git a/pkg/instrumentation/defaultinstrumentation_test.go b/pkg/instrumentation/defaultinstrumentation_test.go index 7da7274c1..e8e321d9c 100644 --- a/pkg/instrumentation/defaultinstrumentation_test.go +++ b/pkg/instrumentation/defaultinstrumentation_test.go @@ -20,12 +20,18 @@ func Test_getDefaultInstrumentationLinux(t *testing.T) { os.Setenv("AUTO_INSTRUMENTATION_JAVA", defaultJavaInstrumentationImage) os.Setenv("AUTO_INSTRUMENTATION_PYTHON", defaultPythonInstrumentationImage) os.Setenv("AUTO_INSTRUMENTATION_DOTNET", defaultDotNetInstrumentationImage) - os.Setenv("AUTO_INSTRUMENTATION_LIMIT_CPU_JAVA", "500m") - os.Setenv("AUTO_INSTRUMENTATION_LIMIT_MEMORY_JAVA", "64Mi") - os.Setenv("AUTO_INSTRUMENTATION_LIMIT_CPU_PYTHON", "500m") - os.Setenv("AUTO_INSTRUMENTATION_LIMIT_MEMORY_PYTHON", "32Mi") - os.Setenv("AUTO_INSTRUMENTATION_LIMIT_CPU_DOTNET", "500m") - os.Setenv("AUTO_INSTRUMENTATION_LIMIT_MEMORY_DOTNET", "128Mi") + os.Setenv("AUTO_INSTRUMENTATION_JAVA_CPU_LIMIT", "500m") + os.Setenv("AUTO_INSTRUMENTATION_JAVA_MEM_LIMIT", "64Mi") + os.Setenv("AUTO_INSTRUMENTATION_JAVA_CPU_REQUEST", "50m") + os.Setenv("AUTO_INSTRUMENTATION_JAVA_MEM_REQUEST", "64Mi") + os.Setenv("AUTO_INSTRUMENTATION_PYTHON_CPU_LIMIT", "500m") + os.Setenv("AUTO_INSTRUMENTATION_PYTHON_MEM_LIMIT", "32Mi") + os.Setenv("AUTO_INSTRUMENTATION_PYTHON_CPU_REQUEST", "50m") + os.Setenv("AUTO_INSTRUMENTATION_PYTHON_MEM_REQUEST", "32Mi") + os.Setenv("AUTO_INSTRUMENTATION_DOTNET_CPU_LIMIT", "500m") + os.Setenv("AUTO_INSTRUMENTATION_DOTNET_MEM_LIMIT", "128Mi") + os.Setenv("AUTO_INSTRUMENTATION_DOTNET_CPU_REQUEST", "50m") + os.Setenv("AUTO_INSTRUMENTATION_DOTNET_MEM_REQUEST", "128Mi") httpInst := &v1alpha1.Instrumentation{ Status: v1alpha1.InstrumentationStatus{}, @@ -63,6 +69,10 @@ func Test_getDefaultInstrumentationLinux(t *testing.T) { corev1.ResourceCPU: resource.MustParse("500m"), corev1.ResourceMemory: resource.MustParse("64Mi"), }, + Requests: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("50m"), + corev1.ResourceMemory: resource.MustParse("64Mi"), + }, }, }, Python: v1alpha1.Python{ @@ -86,6 +96,10 @@ func Test_getDefaultInstrumentationLinux(t *testing.T) { corev1.ResourceCPU: resource.MustParse("500m"), corev1.ResourceMemory: resource.MustParse("32Mi"), }, + Requests: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("50m"), + corev1.ResourceMemory: resource.MustParse("32Mi"), + }, }, }, DotNet: v1alpha1.DotNet{ @@ -109,6 +123,10 @@ func Test_getDefaultInstrumentationLinux(t *testing.T) { corev1.ResourceCPU: resource.MustParse("500m"), corev1.ResourceMemory: resource.MustParse("128Mi"), }, + Requests: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("50m"), + corev1.ResourceMemory: resource.MustParse("128Mi"), + }, }, }, }, @@ -149,6 +167,10 @@ func Test_getDefaultInstrumentationLinux(t *testing.T) { corev1.ResourceCPU: resource.MustParse("500m"), corev1.ResourceMemory: resource.MustParse("64Mi"), }, + Requests: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("50m"), + corev1.ResourceMemory: resource.MustParse("64Mi"), + }, }, }, Python: v1alpha1.Python{ @@ -172,6 +194,10 @@ func Test_getDefaultInstrumentationLinux(t *testing.T) { corev1.ResourceCPU: resource.MustParse("500m"), corev1.ResourceMemory: resource.MustParse("32Mi"), }, + Requests: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("50m"), + corev1.ResourceMemory: resource.MustParse("32Mi"), + }, }, }, DotNet: v1alpha1.DotNet{ @@ -195,6 +221,10 @@ func Test_getDefaultInstrumentationLinux(t *testing.T) { corev1.ResourceCPU: resource.MustParse("500m"), corev1.ResourceMemory: resource.MustParse("128Mi"), }, + Requests: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("50m"), + corev1.ResourceMemory: resource.MustParse("128Mi"), + }, }, }, }, @@ -261,12 +291,18 @@ func Test_getDefaultInstrumentationWindows(t *testing.T) { os.Setenv("AUTO_INSTRUMENTATION_JAVA", defaultJavaInstrumentationImage) os.Setenv("AUTO_INSTRUMENTATION_PYTHON", defaultPythonInstrumentationImage) os.Setenv("AUTO_INSTRUMENTATION_DOTNET", defaultDotNetInstrumentationImage) - os.Setenv("AUTO_INSTRUMENTATION_LIMIT_CPU_JAVA", "500m") - os.Setenv("AUTO_INSTRUMENTATION_LIMIT_MEMORY_JAVA", "64Mi") - os.Setenv("AUTO_INSTRUMENTATION_LIMIT_CPU_PYTHON", "500m") - os.Setenv("AUTO_INSTRUMENTATION_LIMIT_MEMORY_PYTHON", "32Mi") - os.Setenv("AUTO_INSTRUMENTATION_LIMIT_CPU_DOTNET", "500m") - os.Setenv("AUTO_INSTRUMENTATION_LIMIT_MEMORY_DOTNET", "128Mi") + os.Setenv("AUTO_INSTRUMENTATION_JAVA_CPU_LIMIT", "500m") + os.Setenv("AUTO_INSTRUMENTATION_JAVA_MEM_LIMIT", "64Mi") + os.Setenv("AUTO_INSTRUMENTATION_JAVA_CPU_REQUEST", "50m") + os.Setenv("AUTO_INSTRUMENTATION_JAVA_MEM_REQUEST", "64Mi") + os.Setenv("AUTO_INSTRUMENTATION_PYTHON_CPU_LIMIT", "500m") + os.Setenv("AUTO_INSTRUMENTATION_PYTHON_MEM_LIMIT", "32Mi") + os.Setenv("AUTO_INSTRUMENTATION_PYTHON_CPU_REQUEST", "50m") + os.Setenv("AUTO_INSTRUMENTATION_PYTHON_MEM_REQUEST", "32Mi") + os.Setenv("AUTO_INSTRUMENTATION_DOTNET_CPU_LIMIT", "500m") + os.Setenv("AUTO_INSTRUMENTATION_DOTNET_MEM_LIMIT", "128Mi") + os.Setenv("AUTO_INSTRUMENTATION_DOTNET_CPU_REQUEST", "50m") + os.Setenv("AUTO_INSTRUMENTATION_DOTNET_MEM_REQUEST", "128Mi") httpInst := &v1alpha1.Instrumentation{ Status: v1alpha1.InstrumentationStatus{}, @@ -304,6 +340,10 @@ func Test_getDefaultInstrumentationWindows(t *testing.T) { corev1.ResourceCPU: resource.MustParse("500m"), corev1.ResourceMemory: resource.MustParse("64Mi"), }, + Requests: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("50m"), + corev1.ResourceMemory: resource.MustParse("64Mi"), + }, }, }, Python: v1alpha1.Python{ @@ -327,6 +367,10 @@ func Test_getDefaultInstrumentationWindows(t *testing.T) { corev1.ResourceCPU: resource.MustParse("500m"), corev1.ResourceMemory: resource.MustParse("32Mi"), }, + Requests: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("50m"), + corev1.ResourceMemory: resource.MustParse("32Mi"), + }, }, }, DotNet: v1alpha1.DotNet{ @@ -350,6 +394,10 @@ func Test_getDefaultInstrumentationWindows(t *testing.T) { corev1.ResourceCPU: resource.MustParse("500m"), corev1.ResourceMemory: resource.MustParse("128Mi"), }, + Requests: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("50m"), + corev1.ResourceMemory: resource.MustParse("128Mi"), + }, }, }, }, @@ -390,6 +438,10 @@ func Test_getDefaultInstrumentationWindows(t *testing.T) { corev1.ResourceCPU: resource.MustParse("500m"), corev1.ResourceMemory: resource.MustParse("64Mi"), }, + Requests: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("50m"), + corev1.ResourceMemory: resource.MustParse("64Mi"), + }, }, }, Python: v1alpha1.Python{ @@ -413,6 +465,10 @@ func Test_getDefaultInstrumentationWindows(t *testing.T) { corev1.ResourceCPU: resource.MustParse("500m"), corev1.ResourceMemory: resource.MustParse("32Mi"), }, + Requests: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("50m"), + corev1.ResourceMemory: resource.MustParse("32Mi"), + }, }, }, DotNet: v1alpha1.DotNet{ @@ -436,6 +492,10 @@ func Test_getDefaultInstrumentationWindows(t *testing.T) { corev1.ResourceCPU: resource.MustParse("500m"), corev1.ResourceMemory: resource.MustParse("128Mi"), }, + Requests: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("50m"), + corev1.ResourceMemory: resource.MustParse("128Mi"), + }, }, }, }, From 4ac6133cb9ea03a50c3b6b15bdfef035013e5e18 Mon Sep 17 00:00:00 2001 From: musa-asad Date: Thu, 25 Jul 2024 03:49:21 -0400 Subject: [PATCH 09/20] Regular parse and fixed default config. --- main.go | 2 +- pkg/instrumentation/defaultinstrumentation.go | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/main.go b/main.go index 538475372..e87bc1fe4 100644 --- a/main.go +++ b/main.go @@ -140,7 +140,7 @@ func main() { pflag.Parse() // set instrumentation cpu and memory limits in environment variables to be used for default instrumentation - autoInstrumentationConfig := map[string]map[string]map[string]string{"java": {"limits": {"cpu": "64Mi", "memory": "500m"}, "requests": {"cpu": "64Mi", "memory": "50m"}}, "python": {"limits": {"cpu": "32Mi", "memory": "500m"}, "requests": {"cpu": "32Mi", "memory": "50m"}}} + autoInstrumentationConfig := map[string]map[string]map[string]string{"java": {"limits": {"cpu": "64Mi", "memory": "500m"}, "requests": {"cpu": "64Mi", "memory": "50m"}}, "python": {"limits": {"cpu": "32Mi", "memory": "500m"}, "requests": {"cpu": "32Mi", "memory": "50m"}}, "dotnet": {"limits": {"cpu": "128Mi", "memory": "500m"}, "requests": {"cpu": "128Mi", "memory": "50m"}}} err := json.Unmarshal([]byte(autoInstrumentationConfigStr), &autoInstrumentationConfig) if err != nil { setupLog.Info(fmt.Sprintf("Using default values: %v", autoInstrumentationConfig)) diff --git a/pkg/instrumentation/defaultinstrumentation.go b/pkg/instrumentation/defaultinstrumentation.go index 2c1496e82..97b91a072 100644 --- a/pkg/instrumentation/defaultinstrumentation.go +++ b/pkg/instrumentation/defaultinstrumentation.go @@ -31,11 +31,13 @@ func getInstrumentationConfigForResource(langStr string, resourceStr string) cor instrumentationConfigMemory, _ := os.LookupEnv("AUTO_INSTRUMENTATION_" + langStr + "_MEM_" + resourceStr) instrumentationConfigForResource := corev1.ResourceList{} - if instrumentationConfigCpu != "" { - instrumentationConfigForResource[corev1.ResourceCPU] = resource.MustParse(instrumentationConfigCpu) + instrumentationConfigCpuQuantity, err := resource.ParseQuantity(instrumentationConfigCpu) + if err == nil { + instrumentationConfigForResource[corev1.ResourceCPU] = instrumentationConfigCpuQuantity } - if instrumentationConfigMemory != "" { - instrumentationConfigForResource[corev1.ResourceMemory] = resource.MustParse(instrumentationConfigMemory) + instrumentationConfigMemoryQuantity, err := resource.ParseQuantity(instrumentationConfigMemory) + if err == nil { + instrumentationConfigForResource[corev1.ResourceMemory] = instrumentationConfigMemoryQuantity } return instrumentationConfigForResource } From 0ef0d331381b89eb94da0d092476e536c85d1aae Mon Sep 17 00:00:00 2001 From: musa-asad Date: Thu, 25 Jul 2024 04:11:24 -0400 Subject: [PATCH 10/20] Check languages. --- main.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index e87bc1fe4..bcfa9f059 100644 --- a/main.go +++ b/main.go @@ -145,9 +145,15 @@ func main() { if err != nil { setupLog.Info(fmt.Sprintf("Using default values: %v", autoInstrumentationConfig)) } - setLangEnvVars("JAVA", autoInstrumentationConfig["java"]) - setLangEnvVars("PYTHON", autoInstrumentationConfig["python"]) - setLangEnvVars("DOTNET", autoInstrumentationConfig["dotnet"]) + if javaVar, ok := autoInstrumentationConfig["java"]; ok { + setLangEnvVars("JAVA", javaVar) + } + if pythonVar, ok := autoInstrumentationConfig["python"]; ok { + setLangEnvVars("PYTHON", pythonVar) + } + if dotNetVar, ok := autoInstrumentationConfig["dotnet"]; ok { + setLangEnvVars("DOTNET", dotNetVar) + } // set supported language instrumentation images in environment variable to be used for default instrumentation os.Setenv("AUTO_INSTRUMENTATION_JAVA", autoInstrumentationJava) From de83a7857fe9cb822a370b2f538d8e22cc2d6d16 Mon Sep 17 00:00:00 2001 From: musa-asad Date: Thu, 25 Jul 2024 10:51:53 -0400 Subject: [PATCH 11/20] Debug --- .github/workflows/operator-integration-test.yml | 5 +++++ pkg/instrumentation/defaultinstrumentation.go | 3 ++- pkg/instrumentation/defaultinstrumentation_test.go | 3 ++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/.github/workflows/operator-integration-test.yml b/.github/workflows/operator-integration-test.yml index 463e9d0c3..528f2fbd0 100644 --- a/.github/workflows/operator-integration-test.yml +++ b/.github/workflows/operator-integration-test.yml @@ -188,14 +188,19 @@ jobs: kubectl describe pods -n default sleep 5 go test -v -run TestAllLanguagesDeployment ./integration-tests/manifests/annotations -timeout 30m + kubectl describe pods -n default sleep 5 go test -v -run TestJavaOnlyDeployment ./integration-tests/manifests/annotations -timeout 30m + kubectl describe pods -n default sleep 5 go test -v -run TestPythonOnlyDeployment ./integration-tests/manifests/annotations -timeout 30m + kubectl describe pods -n default sleep 5 go test -v -run TestDotNetOnlyDeployment ./integration-tests/manifests/annotations -timeout 30m + kubectl describe pods -n default sleep 5 go test -v -run TestAnnotationsOnMultipleResources ./integration-tests/manifests/annotations -timeout 30m + kubectl describe pods -n default DaemonsetAnnotationsTest: name: DaemonsetAnnotationsTest diff --git a/pkg/instrumentation/defaultinstrumentation.go b/pkg/instrumentation/defaultinstrumentation.go index 97b91a072..025057c8d 100644 --- a/pkg/instrumentation/defaultinstrumentation.go +++ b/pkg/instrumentation/defaultinstrumentation.go @@ -6,9 +6,10 @@ package instrumentation import ( "errors" "fmt" - "k8s.io/apimachinery/pkg/api/resource" "os" + "k8s.io/apimachinery/pkg/api/resource" + corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" diff --git a/pkg/instrumentation/defaultinstrumentation_test.go b/pkg/instrumentation/defaultinstrumentation_test.go index e8e321d9c..ebe5c3f3c 100644 --- a/pkg/instrumentation/defaultinstrumentation_test.go +++ b/pkg/instrumentation/defaultinstrumentation_test.go @@ -4,11 +4,12 @@ package instrumentation import ( - "k8s.io/apimachinery/pkg/api/resource" "os" "reflect" "testing" + "k8s.io/apimachinery/pkg/api/resource" + corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" From 7efb03f3125286ef99bcf7eebd1ee4ca2296520d Mon Sep 17 00:00:00 2001 From: musa-asad Date: Thu, 25 Jul 2024 11:04:25 -0400 Subject: [PATCH 12/20] Debug. --- .github/workflows/operator-integration-test.yml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/operator-integration-test.yml b/.github/workflows/operator-integration-test.yml index 528f2fbd0..a68beedeb 100644 --- a/.github/workflows/operator-integration-test.yml +++ b/.github/workflows/operator-integration-test.yml @@ -188,19 +188,15 @@ jobs: kubectl describe pods -n default sleep 5 go test -v -run TestAllLanguagesDeployment ./integration-tests/manifests/annotations -timeout 30m - kubectl describe pods -n default sleep 5 go test -v -run TestJavaOnlyDeployment ./integration-tests/manifests/annotations -timeout 30m - kubectl describe pods -n default sleep 5 go test -v -run TestPythonOnlyDeployment ./integration-tests/manifests/annotations -timeout 30m - kubectl describe pods -n default sleep 5 go test -v -run TestDotNetOnlyDeployment ./integration-tests/manifests/annotations -timeout 30m - kubectl describe pods -n default sleep 5 go test -v -run TestAnnotationsOnMultipleResources ./integration-tests/manifests/annotations -timeout 30m - kubectl describe pods -n default + kubectl describe pods DaemonsetAnnotationsTest: name: DaemonsetAnnotationsTest From 42b2d0e45a0d6e6366b2abb06e7059305ca76088 Mon Sep 17 00:00:00 2001 From: musa-asad Date: Thu, 25 Jul 2024 11:18:49 -0400 Subject: [PATCH 13/20] Reset. --- .github/workflows/operator-integration-test.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/operator-integration-test.yml b/.github/workflows/operator-integration-test.yml index a68beedeb..463e9d0c3 100644 --- a/.github/workflows/operator-integration-test.yml +++ b/.github/workflows/operator-integration-test.yml @@ -196,7 +196,6 @@ jobs: go test -v -run TestDotNetOnlyDeployment ./integration-tests/manifests/annotations -timeout 30m sleep 5 go test -v -run TestAnnotationsOnMultipleResources ./integration-tests/manifests/annotations -timeout 30m - kubectl describe pods DaemonsetAnnotationsTest: name: DaemonsetAnnotationsTest From f46459026b45888044fb934afd7e94d70f76d5c8 Mon Sep 17 00:00:00 2001 From: musa-asad Date: Thu, 25 Jul 2024 11:53:43 -0400 Subject: [PATCH 14/20] Increasing request to test. --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index 7ea55ddf0..8ae675a2d 100644 --- a/main.go +++ b/main.go @@ -140,7 +140,7 @@ func main() { pflag.Parse() // set instrumentation cpu and memory limits in environment variables to be used for default instrumentation - autoInstrumentationConfig := map[string]map[string]map[string]string{"java": {"limits": {"cpu": "64Mi", "memory": "500m"}, "requests": {"cpu": "64Mi", "memory": "50m"}}, "python": {"limits": {"cpu": "32Mi", "memory": "500m"}, "requests": {"cpu": "32Mi", "memory": "50m"}}, "dotnet": {"limits": {"cpu": "128Mi", "memory": "500m"}, "requests": {"cpu": "128Mi", "memory": "50m"}}} + autoInstrumentationConfig := map[string]map[string]map[string]string{"java": {"limits": {"cpu": "64Mi", "memory": "500m"}, "requests": {"cpu": "128Mi", "memory": "50m"}}, "python": {"limits": {"cpu": "32Mi", "memory": "500m"}, "requests": {"cpu": "128Mi", "memory": "50m"}}, "dotnet": {"limits": {"cpu": "128Mi", "memory": "500m"}, "requests": {"cpu": "128Mi", "memory": "50m"}}} err := json.Unmarshal([]byte(autoInstrumentationConfigStr), &autoInstrumentationConfig) if err != nil { setupLog.Info(fmt.Sprintf("Using default values: %v", autoInstrumentationConfig)) From aea17631c0c85cc01288f10dda2f728db7344a41 Mon Sep 17 00:00:00 2001 From: musa-asad Date: Thu, 25 Jul 2024 12:12:31 -0400 Subject: [PATCH 15/20] Increasing request to test. --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index 8ae675a2d..13079f800 100644 --- a/main.go +++ b/main.go @@ -140,7 +140,7 @@ func main() { pflag.Parse() // set instrumentation cpu and memory limits in environment variables to be used for default instrumentation - autoInstrumentationConfig := map[string]map[string]map[string]string{"java": {"limits": {"cpu": "64Mi", "memory": "500m"}, "requests": {"cpu": "128Mi", "memory": "50m"}}, "python": {"limits": {"cpu": "32Mi", "memory": "500m"}, "requests": {"cpu": "128Mi", "memory": "50m"}}, "dotnet": {"limits": {"cpu": "128Mi", "memory": "500m"}, "requests": {"cpu": "128Mi", "memory": "50m"}}} + autoInstrumentationConfig := map[string]map[string]map[string]string{"java": {"limits": {"cpu": "64Mi", "memory": "500m"}, "requests": {"cpu": "", "memory": "50m"}}, "python": {"limits": {"cpu": "32Mi", "memory": "500m"}, "requests": {"cpu": "", "memory": "50m"}}, "dotnet": {"limits": {"cpu": "128Mi", "memory": "500m"}, "requests": {"cpu": "", "memory": "50m"}}} err := json.Unmarshal([]byte(autoInstrumentationConfigStr), &autoInstrumentationConfig) if err != nil { setupLog.Info(fmt.Sprintf("Using default values: %v", autoInstrumentationConfig)) From ae8ee5af9f268bf44723f415fff3eca9fb473ea3 Mon Sep 17 00:00:00 2001 From: musa-asad Date: Thu, 25 Jul 2024 12:22:28 -0400 Subject: [PATCH 16/20] Increasing limit to test. --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index 13079f800..475799251 100644 --- a/main.go +++ b/main.go @@ -140,7 +140,7 @@ func main() { pflag.Parse() // set instrumentation cpu and memory limits in environment variables to be used for default instrumentation - autoInstrumentationConfig := map[string]map[string]map[string]string{"java": {"limits": {"cpu": "64Mi", "memory": "500m"}, "requests": {"cpu": "", "memory": "50m"}}, "python": {"limits": {"cpu": "32Mi", "memory": "500m"}, "requests": {"cpu": "", "memory": "50m"}}, "dotnet": {"limits": {"cpu": "128Mi", "memory": "500m"}, "requests": {"cpu": "", "memory": "50m"}}} + autoInstrumentationConfig := map[string]map[string]map[string]string{"java": {"limits": {"cpu": "", "memory": "500m"}, "requests": {"cpu": "", "memory": "50m"}}, "python": {"limits": {"cpu": "", "memory": "500m"}, "requests": {"cpu": "", "memory": "50m"}}, "dotnet": {"limits": {"cpu": "", "memory": "500m"}, "requests": {"cpu": "", "memory": "50m"}}} err := json.Unmarshal([]byte(autoInstrumentationConfigStr), &autoInstrumentationConfig) if err != nil { setupLog.Info(fmt.Sprintf("Using default values: %v", autoInstrumentationConfig)) From 96b8454dfe6d77c5ccd2d7b84c0715034fd90454 Mon Sep 17 00:00:00 2001 From: musa-asad Date: Thu, 25 Jul 2024 12:42:28 -0400 Subject: [PATCH 17/20] Reset defaults for testing. --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index 475799251..2a7fef754 100644 --- a/main.go +++ b/main.go @@ -140,7 +140,7 @@ func main() { pflag.Parse() // set instrumentation cpu and memory limits in environment variables to be used for default instrumentation - autoInstrumentationConfig := map[string]map[string]map[string]string{"java": {"limits": {"cpu": "", "memory": "500m"}, "requests": {"cpu": "", "memory": "50m"}}, "python": {"limits": {"cpu": "", "memory": "500m"}, "requests": {"cpu": "", "memory": "50m"}}, "dotnet": {"limits": {"cpu": "", "memory": "500m"}, "requests": {"cpu": "", "memory": "50m"}}} + autoInstrumentationConfig := map[string]map[string]map[string]string{"java": {"limits": {"cpu": "", "memory": ""}, "requests": {"cpu": "", "memory": ""}}, "python": {"limits": {"cpu": "", "memory": ""}, "requests": {"cpu": "", "memory": ""}}, "dotnet": {"limits": {"cpu": "", "memory": ""}, "requests": {"cpu": "", "memory": ""}}} err := json.Unmarshal([]byte(autoInstrumentationConfigStr), &autoInstrumentationConfig) if err != nil { setupLog.Info(fmt.Sprintf("Using default values: %v", autoInstrumentationConfig)) From 2a6268ca20211b61d43af6fa2e8d22372442bd30 Mon Sep 17 00:00:00 2001 From: musa-asad Date: Thu, 25 Jul 2024 13:47:05 -0400 Subject: [PATCH 18/20] Added defaults. --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index 2a7fef754..a84188e0a 100644 --- a/main.go +++ b/main.go @@ -140,7 +140,7 @@ func main() { pflag.Parse() // set instrumentation cpu and memory limits in environment variables to be used for default instrumentation - autoInstrumentationConfig := map[string]map[string]map[string]string{"java": {"limits": {"cpu": "", "memory": ""}, "requests": {"cpu": "", "memory": ""}}, "python": {"limits": {"cpu": "", "memory": ""}, "requests": {"cpu": "", "memory": ""}}, "dotnet": {"limits": {"cpu": "", "memory": ""}, "requests": {"cpu": "", "memory": ""}}} + 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"}}} err := json.Unmarshal([]byte(autoInstrumentationConfigStr), &autoInstrumentationConfig) if err != nil { setupLog.Info(fmt.Sprintf("Using default values: %v", autoInstrumentationConfig)) From 42cf9b1248c56b278d9e23155467eeb66d66febe Mon Sep 17 00:00:00 2001 From: musa-asad Date: Thu, 25 Jul 2024 15:24:05 -0400 Subject: [PATCH 19/20] Addressed nits. --- main.go | 2 +- pkg/instrumentation/defaultinstrumentation.go | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/main.go b/main.go index a84188e0a..dab3d66d8 100644 --- a/main.go +++ b/main.go @@ -139,7 +139,7 @@ func main() { stringFlagOrEnv(&neuronMonitorImage, "neuron-monitor-image", "RELATED_IMAGE_NEURON_MONITOR", fmt.Sprintf("%s:%s", neuronMonitorImageRepository, v.NeuronMonitor), "The default Neuron monitor image. This image is used when no image is specified in the CustomResource.") pflag.Parse() - // set instrumentation cpu and memory limits in environment variables to be used for default instrumentation + // set instrumentation cpu and memory limits in environment variables to be used for default instrumentation, which is received from the helm chart 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"}}} err := json.Unmarshal([]byte(autoInstrumentationConfigStr), &autoInstrumentationConfig) if err != nil { diff --git a/pkg/instrumentation/defaultinstrumentation.go b/pkg/instrumentation/defaultinstrumentation.go index 025057c8d..e9946148c 100644 --- a/pkg/instrumentation/defaultinstrumentation.go +++ b/pkg/instrumentation/defaultinstrumentation.go @@ -25,6 +25,12 @@ const ( http = "http" https = "https" + + java = "JAVA" + python = "PYTHON" + dotNet = "DOTNET" + limit = "LIMIT" + request = "REQUEST" ) func getInstrumentationConfigForResource(langStr string, resourceStr string) corev1.ResourceList { @@ -105,8 +111,8 @@ func getDefaultInstrumentation(agentConfig *adapters.CwaConfig, isWindowsPod boo {Name: "OTEL_LOGS_EXPORTER", Value: "none"}, }, Resources: corev1.ResourceRequirements{ - Limits: getInstrumentationConfigForResource("JAVA", "LIMIT"), - Requests: getInstrumentationConfigForResource("JAVA", "REQUEST"), + Limits: getInstrumentationConfigForResource(java, limit), + Requests: getInstrumentationConfigForResource(java, request), }, }, Python: v1alpha1.Python{ @@ -126,8 +132,8 @@ func getDefaultInstrumentation(agentConfig *adapters.CwaConfig, isWindowsPod boo {Name: "OTEL_LOGS_EXPORTER", Value: "none"}, }, Resources: corev1.ResourceRequirements{ - Limits: getInstrumentationConfigForResource("PYTHON", "LIMIT"), - Requests: getInstrumentationConfigForResource("PYTHON", "REQUEST"), + Limits: getInstrumentationConfigForResource(python, limit), + Requests: getInstrumentationConfigForResource(python, request), }, }, DotNet: v1alpha1.DotNet{ @@ -147,8 +153,8 @@ func getDefaultInstrumentation(agentConfig *adapters.CwaConfig, isWindowsPod boo {Name: "OTEL_DOTNET_AUTO_PLUGINS", Value: "AWS.Distro.OpenTelemetry.AutoInstrumentation.Plugin, AWS.Distro.OpenTelemetry.AutoInstrumentation"}, }, Resources: corev1.ResourceRequirements{ - Limits: getInstrumentationConfigForResource("DOTNET", "LIMIT"), - Requests: getInstrumentationConfigForResource("DOTNET", "REQUEST"), + Limits: getInstrumentationConfigForResource(dotNet, limit), + Requests: getInstrumentationConfigForResource(dotNet, request), }, }, }, From 9bdfa6cb3a2f194a1c779a00b48672c92b86560c Mon Sep 17 00:00:00 2001 From: musa-asad Date: Thu, 25 Jul 2024 15:36:19 -0400 Subject: [PATCH 20/20] Added link. --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index dab3d66d8..cf607e7bd 100644 --- a/main.go +++ b/main.go @@ -139,7 +139,7 @@ func main() { stringFlagOrEnv(&neuronMonitorImage, "neuron-monitor-image", "RELATED_IMAGE_NEURON_MONITOR", fmt.Sprintf("%s:%s", neuronMonitorImageRepository, v.NeuronMonitor), "The default Neuron monitor image. This image is used when no image is specified in the CustomResource.") pflag.Parse() - // set instrumentation cpu and memory limits in environment variables to be used for default instrumentation, which is received from the helm chart + // 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"}}} err := json.Unmarshal([]byte(autoInstrumentationConfigStr), &autoInstrumentationConfig) if err != nil {