Skip to content

Allow configurable resource requests and limits received by helm chart. #196

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand All @@ -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)
Expand Down
28 changes: 28 additions & 0 deletions pkg/instrumentation/defaultinstrumentation.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
package instrumentation

import (
"encoding/json"
"errors"
"fmt"
"k8s.io/apimachinery/pkg/api/resource"
"os"

corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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
Expand Down
Loading