Skip to content

Commit

Permalink
CRD defs for Apache HTTPD Autoinstrumentation (open-telemetry#1305)
Browse files Browse the repository at this point in the history
* CRD defs for Apache HTTPD Autoinstrumentation

* Generated resources for Apache Httpd CRD defs

* Generated bundle for Apache Httpd CRD

* Fixed version for "make bundle"

* Makefile and version update

* Chngnd repo user to open-telemetry for make bundle

* Reverted changes in kustomization.yaml

* Reverted changes in kustomization.yaml

* Reverted chnages in kustomization.yaml

* Apache HTTPD - Link to attributes doc

* make bundle sync

* ./.chloggen yaml added for open-telemetry#1305

* Version fix
  • Loading branch information
chrlic authored Feb 2, 2023
1 parent 80a5b0d commit e0be22a
Show file tree
Hide file tree
Showing 10 changed files with 1,163 additions and 10 deletions.
16 changes: 16 additions & 0 deletions .chloggen/1305-apache-httpd-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: enhancement

# 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: This PR adds CRD for Apache HTTPD auto-instrumentation

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

# (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:
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ AUTO_INSTRUMENTATION_JAVA_VERSION ?= "$(shell grep -v '\#' versions.txt | grep a
AUTO_INSTRUMENTATION_NODEJS_VERSION ?= "$(shell grep -v '\#' versions.txt | grep autoinstrumentation-nodejs | awk -F= '{print $$2}')"
AUTO_INSTRUMENTATION_PYTHON_VERSION ?= "$(shell grep -v '\#' versions.txt | grep autoinstrumentation-python | awk -F= '{print $$2}')"
AUTO_INSTRUMENTATION_DOTNET_VERSION ?= "$(shell grep -v '\#' versions.txt | grep autoinstrumentation-dotnet | awk -F= '{print $$2}')"
AUTO_INSTRUMENTATION_APACHE_HTTPD_VERSION ?= "$(shell grep -v '\#' versions.txt | grep autoinstrumentation-apache-httpd | awk -F= '{print $$2}')"
LD_FLAGS ?= "-X ${VERSION_PKG}.version=${VERSION} -X ${VERSION_PKG}.buildDate=${VERSION_DATE} -X ${VERSION_PKG}.otelCol=${OTELCOL_VERSION} -X ${VERSION_PKG}.targetAllocator=${TARGETALLOCATOR_VERSION} -X ${VERSION_PKG}.autoInstrumentationJava=${AUTO_INSTRUMENTATION_JAVA_VERSION} -X ${VERSION_PKG}.autoInstrumentationNodeJS=${AUTO_INSTRUMENTATION_NODEJS_VERSION} -X ${VERSION_PKG}.autoInstrumentationPython=${AUTO_INSTRUMENTATION_PYTHON_VERSION} -X ${VERSION_PKG}.autoInstrumentationDotNet=${AUTO_INSTRUMENTATION_DOTNET_VERSION}"
ARCH ?= $(shell go env GOARCH)

Expand Down
31 changes: 31 additions & 0 deletions apis/v1alpha1/instrumentation_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ type InstrumentationSpec struct {
// DotNet defines configuration for DotNet auto-instrumentation.
// +optional
DotNet DotNet `json:"dotnet,omitempty"`

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

// Resource defines the configuration for the resource attributes, as defined by the OpenTelemetry specification.
Expand Down Expand Up @@ -145,6 +149,33 @@ type DotNet struct {
Env []corev1.EnvVar `json:"env,omitempty"`
}

type ApacheHttpd struct {
// Image is a container image with Apache SDK and auto-instrumentation.
// +optional
Image string `json:"image,omitempty"`

// Env defines Apache HTTPD 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 Apache HTTPD agent specific attributes. The precedence 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"`

// Apache HTTPD server version. One of 2.4 or 2.2. Default is 2.4
// +optional
Version string `json:"version,omitempty"`

// Location of Apache HTTPD server configuration.
// Needed only if different from default "/usr/local/apache2/conf"
// +optional
ConfigPath string `json:"configPath,omitempty"`
}

// InstrumentationStatus defines status of the instrumentation.
type InstrumentationStatus struct {
}
Expand Down
27 changes: 21 additions & 6 deletions apis/v1alpha1/instrumentation_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ import (
)

const (
AnnotationDefaultAutoInstrumentationJava = "instrumentation.opentelemetry.io/default-auto-instrumentation-java-image"
AnnotationDefaultAutoInstrumentationNodeJS = "instrumentation.opentelemetry.io/default-auto-instrumentation-nodejs-image"
AnnotationDefaultAutoInstrumentationPython = "instrumentation.opentelemetry.io/default-auto-instrumentation-python-image"
AnnotationDefaultAutoInstrumentationDotNet = "instrumentation.opentelemetry.io/default-auto-instrumentation-dotnet-image"
envPrefix = "OTEL_"
envSplunkPrefix = "SPLUNK_"
AnnotationDefaultAutoInstrumentationJava = "instrumentation.opentelemetry.io/default-auto-instrumentation-java-image"
AnnotationDefaultAutoInstrumentationNodeJS = "instrumentation.opentelemetry.io/default-auto-instrumentation-nodejs-image"
AnnotationDefaultAutoInstrumentationPython = "instrumentation.opentelemetry.io/default-auto-instrumentation-python-image"
AnnotationDefaultAutoInstrumentationDotNet = "instrumentation.opentelemetry.io/default-auto-instrumentation-dotnet-image"
AnnotationDefaultAutoInstrumentationApacheHttpd = "instrumentation.opentelemetry.io/default-auto-instrumentation-apache-httpd-image"
envPrefix = "OTEL_"
envSplunkPrefix = "SPLUNK_"
)

// log is for logging in this package.
Expand Down Expand Up @@ -78,6 +79,17 @@ func (r *Instrumentation) Default() {
r.Spec.DotNet.Image = val
}
}
if r.Spec.ApacheHttpd.Image == "" {
if val, ok := r.Annotations[AnnotationDefaultAutoInstrumentationApacheHttpd]; ok {
r.Spec.ApacheHttpd.Image = val
}
}
if r.Spec.ApacheHttpd.Version == "" {
r.Spec.ApacheHttpd.Version = "2.4"
}
if r.Spec.ApacheHttpd.ConfigPath == "" {
r.Spec.ApacheHttpd.ConfigPath = "/usr/local/apache2/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 @@ -134,6 +146,9 @@ func (r *Instrumentation) validate() error {
if err := r.validateEnv(r.Spec.DotNet.Env); err != nil {
return err
}
if err := r.validateEnv(r.Spec.ApacheHttpd.Env); err != nil {
return err
}

return nil
}
Expand Down
10 changes: 6 additions & 4 deletions apis/v1alpha1/instrumentation_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ func TestInstrumentationDefaultingWebhook(t *testing.T) {
inst := &Instrumentation{
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
AnnotationDefaultAutoInstrumentationJava: "java-img:1",
AnnotationDefaultAutoInstrumentationNodeJS: "nodejs-img:1",
AnnotationDefaultAutoInstrumentationPython: "python-img:1",
AnnotationDefaultAutoInstrumentationDotNet: "dotnet-img:1",
AnnotationDefaultAutoInstrumentationJava: "java-img:1",
AnnotationDefaultAutoInstrumentationNodeJS: "nodejs-img:1",
AnnotationDefaultAutoInstrumentationPython: "python-img:1",
AnnotationDefaultAutoInstrumentationDotNet: "dotnet-img:1",
AnnotationDefaultAutoInstrumentationApacheHttpd: "apache-httpd-img:1",
},
},
}
Expand All @@ -37,6 +38,7 @@ func TestInstrumentationDefaultingWebhook(t *testing.T) {
assert.Equal(t, "nodejs-img:1", inst.Spec.NodeJS.Image)
assert.Equal(t, "python-img:1", inst.Spec.Python.Image)
assert.Equal(t, "dotnet-img:1", inst.Spec.DotNet.Image)
assert.Equal(t, "apache-httpd-img:1", inst.Spec.ApacheHttpd.Image)
}

func TestInstrumentationValidatingWebhook(t *testing.T) {
Expand Down
30 changes: 30 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 e0be22a

Please sign in to comment.