Skip to content

Commit

Permalink
Nginx Instrumentation crd (#1853)
Browse files Browse the repository at this point in the history
* Nginx Instrumentation crd

* Nginx Instruemtnation crd

* chloggen

* typos

* make generate crd

* make bundle - crd

* make bundle - versions

* default resources

* consts for resource settings

* rename resource consts

* rename resource consts
  • Loading branch information
chrlic authored Jun 27, 2023
1 parent 574f282 commit 3b26276
Show file tree
Hide file tree
Showing 7 changed files with 1,326 additions and 13 deletions.
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"`

// 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
37 changes: 29 additions & 8 deletions apis/v1alpha1/instrumentation_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,23 @@ 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_"
)

// log is for logging in this package.
var instrumentationlog = logf.Log.WithName("instrumentation-resource")

var initContainerDefaultLimitResources = corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("500m"),
corev1.ResourceMemory: resource.MustParse("128Mi"),
}
var initContainerDefaultRequestedResources = corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("1m"),
corev1.ResourceMemory: resource.MustParse("128Mi"),
}

func (r *Instrumentation) SetupWebhookWithManager(mgr ctrl.Manager) error {
return ctrl.NewWebhookManagedBy(mgr).
For(r).
Expand Down Expand Up @@ -153,23 +163,31 @@ func (r *Instrumentation) Default() {
}
}
if r.Spec.ApacheHttpd.Resources.Limits == nil {
r.Spec.ApacheHttpd.Resources.Limits = corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("500m"),
corev1.ResourceMemory: resource.MustParse("128Mi"),
}
r.Spec.ApacheHttpd.Resources.Limits = initContainerDefaultLimitResources
}
if r.Spec.ApacheHttpd.Resources.Requests == nil {
r.Spec.ApacheHttpd.Resources.Requests = corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("1m"),
corev1.ResourceMemory: resource.MustParse("128Mi"),
}
r.Spec.ApacheHttpd.Resources.Requests = initContainerDefaultRequestedResources
}
if r.Spec.ApacheHttpd.Version == "" {
r.Spec.ApacheHttpd.Version = "2.4"
}
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 = initContainerDefaultLimitResources
}
if r.Spec.Nginx.Resources.Requests == nil {
r.Spec.Nginx.Resources.Requests = initContainerDefaultRequestedResources
}
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 +293,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.

Loading

0 comments on commit 3b26276

Please sign in to comment.