Skip to content
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

Nginx Instrumentation crd #1853

Merged
merged 13 commits into from
Jun 27, 2023
16 changes: 16 additions & 0 deletions .chloggen/1853-nginx-crd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: new_component

# The name of the component, or a single word describing the area of concern, (e.g. operator, target allocator, github action)
component: operator

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Instrumentation crd for Nginx auto-instrumentation.

# One or more tracking issues related to the change
issues: [1853]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:
35 changes: 34 additions & 1 deletion apis/v1alpha1/instrumentation_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,13 @@ type InstrumentationSpec struct {
// +optional
Go Go `json:"go,omitempty"`

// Apache defines configuration for Apache HTTPD auto-instrumentation.
// ApacheHttpd defines configuration for Apache HTTPD auto-instrumentation.
// +optional
ApacheHttpd ApacheHttpd `json:"apacheHttpd,omitempty"`

// Nginx defines configuration for Nginx auto-instrumentation.
// +optional
Nginx Nginx `json:"nginx,omitempty"`
}

// Resource defines the configuration for the resource attributes, as defined by the OpenTelemetry specification.
Expand Down Expand Up @@ -218,6 +222,35 @@ type ApacheHttpd struct {
// Needed only if different from default "/usr/local/apache2/conf"
// +optional
ConfigPath string `json:"configPath,omitempty"`

// Resources describes the compute resource requirements.
// +optional
Resources corev1.ResourceRequirements `json:"resourceRequirements,omitempty"`
}

// Nginx defines Nginx SDK and instrumentation configuration.
type Nginx struct {
// Image is a container image with Nginx SDK and auto-instrumentation.
// +optional
Image string `json:"image,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there already image for nginx instrumentation?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah it's here #1852

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For Nginx autoinstrumentation, default image with the instrumentation libraries is the same as for Apache Httpd - autoinstrumentation-apache-httpd


// Env defines Nginx specific env vars. There are four layers for env vars' definitions and
// the precedence order is: `original container env vars` > `language specific env vars` > `common env vars` > `instrument spec configs' vars`.
// If the former var had been defined, then the other vars would be ignored.
// +optional
Env []corev1.EnvVar `json:"env,omitempty"`

// Attrs defines Nginx agent specific attributes. The precedence order is:
// `agent default attributes` > `instrument spec attributes` .
// Attributes are documented at https://github.com/open-telemetry/opentelemetry-cpp-contrib/tree/main/instrumentation/otel-webserver-module
// +optional
Attrs []corev1.EnvVar `json:"attrs,omitempty"`

// Location of Nginx configuration file.
// Needed only if different from default "/etx/nginx/nginx.conf"
// +optional
ConfigFile string `json:"configFile,omitempty"`

// Resources describes the compute resource requirements.
// +optional
Resources corev1.ResourceRequirements `json:"resourceRequirements,omitempty"`
Expand Down
24 changes: 24 additions & 0 deletions apis/v1alpha1/instrumentation_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const (
AnnotationDefaultAutoInstrumentationDotNet = "instrumentation.opentelemetry.io/default-auto-instrumentation-dotnet-image"
AnnotationDefaultAutoInstrumentationGo = "instrumentation.opentelemetry.io/default-auto-instrumentation-go-image"
AnnotationDefaultAutoInstrumentationApacheHttpd = "instrumentation.opentelemetry.io/default-auto-instrumentation-apache-httpd-image"
AnnotationDefaultAutoInstrumentationNginx = "instrumentation.opentelemetry.io/default-auto-instrumentation-nginx-image"
envPrefix = "OTEL_"
envSplunkPrefix = "SPLUNK_"
)
Expand Down Expand Up @@ -170,6 +171,26 @@ func (r *Instrumentation) Default() {
if r.Spec.ApacheHttpd.ConfigPath == "" {
r.Spec.ApacheHttpd.ConfigPath = "/usr/local/apache2/conf"
}
if r.Spec.Nginx.Image == "" {
if val, ok := r.Annotations[AnnotationDefaultAutoInstrumentationNginx]; ok {
r.Spec.Nginx.Image = val
}
}
if r.Spec.Nginx.Resources.Limits == nil {
r.Spec.Nginx.Resources.Limits = corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("500m"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should extract these to a constant and reuse for others.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

corev1.ResourceMemory: resource.MustParse("128Mi"),
}
}
if r.Spec.Nginx.Resources.Requests == nil {
r.Spec.Nginx.Resources.Requests = corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("1m"),
corev1.ResourceMemory: resource.MustParse("128Mi"),
}
}
if r.Spec.Nginx.ConfigFile == "" {
r.Spec.Nginx.ConfigFile = "/etc/nginx/nginx.conf"
}
}

// +kubebuilder:webhook:verbs=create;update,path=/validate-opentelemetry-io-v1alpha1-instrumentation,mutating=false,failurePolicy=fail,groups=opentelemetry.io,resources=instrumentations,versions=v1alpha1,name=vinstrumentationcreateupdate.kb.io,sideEffects=none,admissionReviewVersions=v1
Expand Down Expand Up @@ -275,6 +296,9 @@ func (r *Instrumentation) validate() error {
if err := r.validateEnv(r.Spec.ApacheHttpd.Env); err != nil {
return err
}
if err := r.validateEnv(r.Spec.Nginx.Env); err != nil {
return err
}

return nil
}
Expand Down
31 changes: 31 additions & 0 deletions apis/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ metadata:
categories: Logging & Tracing
certified: "false"
containerImage: ghcr.io/open-telemetry/opentelemetry-operator/opentelemetry-operator
createdAt: "2023-06-08T08:15:18Z"
createdAt: "2023-06-18T11:41:05Z"
description: Provides the OpenTelemetry components, including the Collector
operators.operatorframework.io/builder: operator-sdk-v1.27.0
operators.operatorframework.io/project_layout: go.kubebuilder.io/v3
Expand Down
Loading