From 1af912f96df35394d603166862ce51b244dca736 Mon Sep 17 00:00:00 2001 From: Daniel Schulze Date: Tue, 21 Jun 2022 14:23:17 +0200 Subject: [PATCH 1/5] get opentelemetry sidecar running --- .../nginx-configuration/annotations.md | 16 ++ .../nginx-configuration/configmap.md | 10 ++ images/opentelemetry/rootfs/Dockerfile | 2 +- images/opentelemetry/rootfs/init_module.sh | 7 +- .../ingress/annotations/opentelemetry/main.go | 75 ++++++++ .../annotations/opentelemetry/main_test.go | 160 ++++++++++++++++++ internal/ingress/controller/config/config.go | 7 + .../ingress/controller/template/template.go | 18 ++ rootfs/Dockerfile | 2 - rootfs/Dockerfile.chroot | 1 - rootfs/etc/nginx/template/nginx.tmpl | 8 + 11 files changed, 300 insertions(+), 6 deletions(-) create mode 100644 internal/ingress/annotations/opentelemetry/main.go create mode 100644 internal/ingress/annotations/opentelemetry/main_test.go diff --git a/docs/user-guide/nginx-configuration/annotations.md b/docs/user-guide/nginx-configuration/annotations.md index 0c65bd0c88..4caa910199 100755 --- a/docs/user-guide/nginx-configuration/annotations.md +++ b/docs/user-guide/nginx-configuration/annotations.md @@ -806,6 +806,22 @@ sometimes need to be overridden to enable it or disable it for a specific ingres nginx.ingress.kubernetes.io/opentracing-trust-incoming-span: "true" ``` +### Enable Opentelemetry + +Opentelemetry can be enabled or disabled globally through the ConfigMap + +```yaml +nginx.ingress.kubernetes.io/enable-opentelemetry: "true" +``` + +### Opentelemetry config + +Opentelemetry config + +```yaml +nginx.ingress.kubernetes.io/opentelemetry-config: "/conf/otel-nginx.toml" +``` + ### X-Forwarded-Prefix Header To add the non-standard `X-Forwarded-Prefix` header to the upstream request with a string value, the following annotation can be used: diff --git a/docs/user-guide/nginx-configuration/configmap.md b/docs/user-guide/nginx-configuration/configmap.md index 270dd1c62a..d93eb815b3 100755 --- a/docs/user-guide/nginx-configuration/configmap.md +++ b/docs/user-guide/nginx-configuration/configmap.md @@ -130,6 +130,8 @@ The following table shows a configuration option's name, type, and the default v |[enable-opentracing](#enable-opentracing)|bool|"false"| |[opentracing-operation-name](#opentracing-operation-name)|string|""| |[opentracing-location-operation-name](#opentracing-location-operation-name)|string|""| +|[enable-opentelemetry](#enable-opentelemetry)|bool|"false"| +|[opentelemetry-config](#opentelemetry-config)|string|`Mandatory`| |[zipkin-collector-host](#zipkin-collector-host)|string|""| |[zipkin-collector-port](#zipkin-collector-port)|int|9411| |[zipkin-service-name](#zipkin-service-name)|string|"nginx"| @@ -896,6 +898,14 @@ Specifies a custom name for the location span. _**default:**_ is empty For example, set to "HTTP $request_method $uri". +## enable-opentelemetry + +Enables the nginx Opentelemetry extension. _**default:**_ is disabled + +## opentelemetry-config + +Opentelemetry exporters, processors, etc config. Mandatory + ## zipkin-collector-host Specifies the host to use when uploading traces. It must be a valid URL. diff --git a/images/opentelemetry/rootfs/Dockerfile b/images/opentelemetry/rootfs/Dockerfile index 91832fa55f..ae6ddacbd6 100644 --- a/images/opentelemetry/rootfs/Dockerfile +++ b/images/opentelemetry/rootfs/Dockerfile @@ -42,4 +42,4 @@ RUN bash /opt/third_party/build.sh -n FROM alpine:3.14.6 COPY --from=base /opt/third_party/init_module.sh /usr/local/bin/init_module.sh COPY --from=nginx /etc/nginx/modules /etc/nginx/modules -COPY --from=nginx /opt/third_party/install/lib /etc/nginx/modules +COPY --from=nginx /opt/third_party/install/lib /usr/lib diff --git a/images/opentelemetry/rootfs/init_module.sh b/images/opentelemetry/rootfs/init_module.sh index bac5e64aac..961352ee41 100755 --- a/images/opentelemetry/rootfs/init_module.sh +++ b/images/opentelemetry/rootfs/init_module.sh @@ -18,5 +18,8 @@ set -o errexit set -o nounset set -o pipefail -mkdir -p /modules_mount/etc/nginx/modules -cp -R /etc/nginx/modules /modules_mount/etc/nginx/modules +for path in /etc/nginx/modules /usr/lib; +do + mkdir -p /modules_mount${path} + cp -R $path/* /modules_mount${path}/; +done diff --git a/internal/ingress/annotations/opentelemetry/main.go b/internal/ingress/annotations/opentelemetry/main.go new file mode 100644 index 0000000000..a3823f1e91 --- /dev/null +++ b/internal/ingress/annotations/opentelemetry/main.go @@ -0,0 +1,75 @@ +/* +Copyright 2019 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package opentelemetry + +import ( + networking "k8s.io/api/networking/v1" + "k8s.io/klog/v2" + + "k8s.io/ingress-nginx/internal/ingress/annotations/parser" + "k8s.io/ingress-nginx/internal/ingress/resolver" +) + +type opentelemetry struct { + r resolver.Resolver +} + +// Config contains the configuration to be used in the Ingress +type Config struct { + OpenTelemetryEnabled bool `json:"enabled"` + OpenTelemetryConfig string `json:"config"` +} + +// Equal tests for equality between two Config types +func (bd1 *Config) Equal(bd2 *Config) bool { + + if bd1.OpenTelemetryEnabled != bd2.OpenTelemetryEnabled { + return false + } + + if bd1.OpenTelemetryConfig != bd2.OpenTelemetryConfig { + return false + } + + return true +} + + +func NewParser(r resolver.Resolver) parser.IngressAnnotation { + return opentelemetry{r} +} + +// Parse parses the annotations to look for opentelemetry configurations +func (c opentelemetry) Parse(ing *networking.Ingress) (interface{}, error) { + var err error + config := &Config{} + + config.OpenTelemetryEnabled, err = parser.GetBoolAnnotation("enable-opentelemetry", ing) + if err != nil { + config.OpenTelemetryEnabled = false + } + + if config.OpenTelemetryEnabled { + config.OpenTelemetryConfig, err = parser.GetStringAnnotation("opentelemetry-config", ing) + if err != nil { + klog.Errorf("OpenTelementry config file (opentelemetry_config) must be set - %v.", err) + return nil, err + } + } + + return config, nil +} diff --git a/internal/ingress/annotations/opentelemetry/main_test.go b/internal/ingress/annotations/opentelemetry/main_test.go new file mode 100644 index 0000000000..e7c6f58c54 --- /dev/null +++ b/internal/ingress/annotations/opentelemetry/main_test.go @@ -0,0 +1,160 @@ +/* +Copyright 2019 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package opentelemetry + +import ( + "testing" + + api "k8s.io/api/core/v1" + networking "k8s.io/api/networking/v1" + meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/ingress-nginx/internal/ingress/annotations/parser" + "k8s.io/ingress-nginx/internal/ingress/resolver" +) + +func buildIngress() *networking.Ingress { + defaultBackend := networking.IngressBackend{ + Service: &networking.IngressServiceBackend{ + Name: "default-backend", + Port: networking.ServiceBackendPort{ + Number: 80, + }, + }, + } + + return &networking.Ingress{ + ObjectMeta: meta_v1.ObjectMeta{ + Name: "foo", + Namespace: api.NamespaceDefault, + }, + Spec: networking.IngressSpec{ + DefaultBackend: &networking.IngressBackend{ + Service: &networking.IngressServiceBackend{ + Name: "default-backend", + Port: networking.ServiceBackendPort{ + Number: 80, + }, + }, + }, + Rules: []networking.IngressRule{ + { + Host: "foo.bar.com", + IngressRuleValue: networking.IngressRuleValue{ + HTTP: &networking.HTTPIngressRuleValue{ + Paths: []networking.HTTPIngressPath{ + { + Path: "/foo", + Backend: defaultBackend, + }, + }, + }, + }, + }, + }, + }, + } +} + +func TestIngressAnnotationOpentelemetrySetTrue(t *testing.T) { + ing := buildIngress() + + data := map[string]string{} + data[parser.GetAnnotationWithPrefix("enable-opentelemetry")] = "true" + data[parser.GetAnnotationWithPrefix("opentelemetry-config")] = "/conf/otel-nginx.toml" + ing.SetAnnotations(data) + + val, _ := NewParser(&resolver.Mock{}).Parse(ing) + openTelemetry, ok := val.(*Config) + if !ok { + t.Errorf("expected a Config type") + } + + if !openTelemetry.OpenTelemetryEnabled { + t.Errorf("expected annotation value to be true, got false") + } + + if openTelemetry.OpenTelemetryConfig != "/conf/otel-nginx.toml" { + t.Errorf("expected %s but returned %s", "/conf/otel-nginx.toml" ,openTelemetry.OpenTelemetryConfig) + } +} + +func TestIngressAnnotationOpentelemetrySetFalse(t *testing.T) { + ing := buildIngress() + + // Test with explicitly set to false + data := map[string]string{} + data[parser.GetAnnotationWithPrefix("enable-opentelemetry")] = "false" + ing.SetAnnotations(data) + + val, _ := NewParser(&resolver.Mock{}).Parse(ing) + openTelemetry, ok := val.(*Config) + if !ok { + t.Errorf("expected a Config type") + } + + if openTelemetry.OpenTelemetryEnabled { + t.Errorf("expected annotation value to be false, got true") + } +} + +func TestIngressAnnotationOpentelemetryConfigUnset(t *testing.T) { + ing := buildIngress() + + data := map[string]string{} + data[parser.GetAnnotationWithPrefix("enable-opentelemetry")] = "true" + ing.SetAnnotations(data) + + val, _ := NewParser(&resolver.Mock{}).Parse(ing) + _, ok := val.(*Config) + if ok { + t.Errorf("expected no Config type") + } +} + +func TestIngressAnnotationOpentelemetryConfigEmpty(t *testing.T) { + ing := buildIngress() + + data := map[string]string{} + data[parser.GetAnnotationWithPrefix("enable-opentelemetry")] = "true" + data[parser.GetAnnotationWithPrefix("opentelemetry-config")] = "" + ing.SetAnnotations(data) + + val, _ := NewParser(&resolver.Mock{}).Parse(ing) + _, ok := val.(*Config) + if ok { + t.Errorf("expected no Config type") + } + +} + +func TestIngressAnnotationOpentelemetryUnset(t *testing.T) { + ing := buildIngress() + + // Test with no annotation specified + data := map[string]string{} + ing.SetAnnotations(data) + + val, _ := NewParser(&resolver.Mock{}).Parse(ing) + openTelemetry, ok := val.(*Config) + if !ok { + t.Errorf("expected a Config type") + } + + if openTelemetry.OpenTelemetryEnabled { + t.Errorf("expected annotation value to be false, got true") + } +} diff --git a/internal/ingress/controller/config/config.go b/internal/ingress/controller/config/config.go index 07f9d957aa..d99122158c 100644 --- a/internal/ingress/controller/config/config.go +++ b/internal/ingress/controller/config/config.go @@ -559,6 +559,13 @@ type Configuration struct { // Default: true OpentracingTrustIncomingSpan bool `json:"opentracing-trust-incoming-span"` + // EnableOpentelemetry enables the nginx Opentelemetry extension + // By default this is disabled + EnableOpentelemetry bool `json:"enable-opentelemetry"` + + // OpentelemetryConfig sets the opentelemetry config file + OpentelemetryConfig string `json:"opentelemetry-config"` + // ZipkinCollectorHost specifies the host to use when uploading traces ZipkinCollectorHost string `json:"zipkin-collector-host"` diff --git a/internal/ingress/controller/template/template.go b/internal/ingress/controller/template/template.go index a331c196af..c89704f634 100644 --- a/internal/ingress/controller/template/template.go +++ b/internal/ingress/controller/template/template.go @@ -275,6 +275,7 @@ var ( "buildHTTPSListener": buildHTTPSListener, "buildOpentracingForLocation": buildOpentracingForLocation, "shouldLoadOpentracingModule": shouldLoadOpentracingModule, + "shouldLoadOpentelemetryModule": shouldLoadOpentelemetryModule, "buildModSecurityForLocation": buildModSecurityForLocation, "buildMirrorLocations": buildMirrorLocations, "shouldLoadAuthDigestModule": shouldLoadAuthDigestModule, @@ -1605,6 +1606,23 @@ func shouldLoadOpentracingModule(c interface{}, s interface{}) bool { return false } +// shouldLoadOpentelemetryModule determines whether or not the Opentelemetry module needs to be loaded. +// It checks if `enable-opentelemetry` is set in the ConfigMap. +func shouldLoadOpentelemetryModule(c interface{}, s interface{}) bool { + cfg, ok := c.(config.Configuration) + if !ok { + klog.Errorf("expected a 'config.Configuration' type but %T was returned", c) + return false + } + + if cfg.EnableOpentelemetry { + return true + } + + return false + +} + func buildModSecurityForLocation(cfg config.Configuration, location *ingress.Location) string { isMSEnabledInLoc := location.ModSecurity.Enable isMSEnableSetInLoc := location.ModSecurity.EnableSet diff --git a/rootfs/Dockerfile b/rootfs/Dockerfile index 0bf9a03043..1eab94c580 100644 --- a/rootfs/Dockerfile +++ b/rootfs/Dockerfile @@ -31,8 +31,6 @@ LABEL org.opencontainers.image.revision="${COMMIT_SHA}" LABEL build_id="${BUILD_ID}" -ENV LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/modules_mount/etc/nginx/modules/modules - WORKDIR /etc/nginx RUN apk update \ diff --git a/rootfs/Dockerfile.chroot b/rootfs/Dockerfile.chroot index 04adccf8aa..5ea3ce8356 100644 --- a/rootfs/Dockerfile.chroot +++ b/rootfs/Dockerfile.chroot @@ -44,7 +44,6 @@ LABEL build_id="${BUILD_ID}" ENV LUA_PATH="/usr/local/share/luajit-2.1.0-beta3/?.lua;/usr/local/share/lua/5.1/?.lua;/usr/local/lib/lua/?.lua;;" ENV LUA_CPATH="/usr/local/lib/lua/?/?.so;/usr/local/lib/lua/?.so;;" ENV PATH=$PATH:/usr/local/luajit/bin:/usr/local/nginx/sbin:/usr/local/nginx/bin -ENV LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/modules_mount/etc/nginx/modules/modules RUN apk update \ && apk upgrade \ diff --git a/rootfs/etc/nginx/template/nginx.tmpl b/rootfs/etc/nginx/template/nginx.tmpl index 561278b6fb..879aa170dc 100755 --- a/rootfs/etc/nginx/template/nginx.tmpl +++ b/rootfs/etc/nginx/template/nginx.tmpl @@ -37,6 +37,10 @@ load_module /etc/nginx/modules/ngx_http_modsecurity_module.so; load_module /etc/nginx/modules/ngx_http_opentracing_module.so; {{ end }} +{{ if (shouldLoadOpentelemetryModule $cfg $servers) }} +load_module /modules_mount/etc/nginx/modules/otel_ngx_module.so; +{{ end }} + daemon off; worker_processes {{ $cfg.WorkerProcesses }}; @@ -64,6 +68,10 @@ events { } http { + {{ if (shouldLoadOpentelemetryModule $cfg $servers) }} + opentelemetry_config {{ $cfg.OpentelemetryConfig }}; + {{ end }} + lua_package_path "/etc/nginx/lua/?.lua;;"; {{ buildLuaSharedDictionaries $cfg $servers }} From b4c20592342a76ee97635e304c96580ff6924929 Mon Sep 17 00:00:00 2001 From: Daniel Schulze Date: Wed, 22 Jun 2022 13:06:36 +0200 Subject: [PATCH 2/5] add otel library path adaption to root Dockerfiles --- rootfs/Dockerfile | 4 ++++ rootfs/Dockerfile.chroot | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/rootfs/Dockerfile b/rootfs/Dockerfile index 1eab94c580..02f83849b4 100644 --- a/rootfs/Dockerfile +++ b/rootfs/Dockerfile @@ -31,6 +31,10 @@ LABEL org.opencontainers.image.revision="${COMMIT_SHA}" LABEL build_id="${BUILD_ID}" +# enable sidecar / init cotnainer library path +# extra modules should use /modules_mount//lib, which should be added here +RUN echo "/lib:/usr/lib:/usr/local/lib:/modules_mount/otel/lib" > /etc/ld-musl-x86_64.path + WORKDIR /etc/nginx RUN apk update \ diff --git a/rootfs/Dockerfile.chroot b/rootfs/Dockerfile.chroot index 5ea3ce8356..cd9eab13ac 100644 --- a/rootfs/Dockerfile.chroot +++ b/rootfs/Dockerfile.chroot @@ -45,6 +45,10 @@ ENV LUA_PATH="/usr/local/share/luajit-2.1.0-beta3/?.lua;/usr/local/share/lua/5.1 ENV LUA_CPATH="/usr/local/lib/lua/?/?.so;/usr/local/lib/lua/?.so;;" ENV PATH=$PATH:/usr/local/luajit/bin:/usr/local/nginx/sbin:/usr/local/nginx/bin +# enable sidecar / init cotnainer library path +# extra modules should use /modules_mount//lib, which should be added here +RUN echo "/lib:/usr/lib:/usr/local/lib:/modules_mount/otel/lib" > /etc/ld-musl-x86_64.path + RUN apk update \ && apk upgrade \ && apk add -U --no-cache \ From ece1be0920e7e372a40c742cb597ddccbfa5829c Mon Sep 17 00:00:00 2001 From: Daniel Schulze Date: Thu, 23 Jun 2022 22:13:17 +0200 Subject: [PATCH 3/5] use otel specific library path --- docs/user-guide/nginx-configuration/configmap.md | 3 ++- images/opentelemetry/rootfs/Dockerfile | 2 +- images/opentelemetry/rootfs/init_module.sh | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/docs/user-guide/nginx-configuration/configmap.md b/docs/user-guide/nginx-configuration/configmap.md index d93eb815b3..4ced53fc14 100755 --- a/docs/user-guide/nginx-configuration/configmap.md +++ b/docs/user-guide/nginx-configuration/configmap.md @@ -904,7 +904,8 @@ Enables the nginx Opentelemetry extension. _**default:**_ is disabled ## opentelemetry-config -Opentelemetry exporters, processors, etc config. Mandatory +Opentelemetry exporters, processors, etc config. Mandatory, if enable-opentelemetry is enabled +For more details see docs/user-guide/third-party-addons/opentelemetry.md ## zipkin-collector-host diff --git a/images/opentelemetry/rootfs/Dockerfile b/images/opentelemetry/rootfs/Dockerfile index ae6ddacbd6..cfcae7c678 100644 --- a/images/opentelemetry/rootfs/Dockerfile +++ b/images/opentelemetry/rootfs/Dockerfile @@ -42,4 +42,4 @@ RUN bash /opt/third_party/build.sh -n FROM alpine:3.14.6 COPY --from=base /opt/third_party/init_module.sh /usr/local/bin/init_module.sh COPY --from=nginx /etc/nginx/modules /etc/nginx/modules -COPY --from=nginx /opt/third_party/install/lib /usr/lib +COPY --from=nginx /opt/third_party/install/lib /otel/lib diff --git a/images/opentelemetry/rootfs/init_module.sh b/images/opentelemetry/rootfs/init_module.sh index 961352ee41..438d997da1 100755 --- a/images/opentelemetry/rootfs/init_module.sh +++ b/images/opentelemetry/rootfs/init_module.sh @@ -18,7 +18,7 @@ set -o errexit set -o nounset set -o pipefail -for path in /etc/nginx/modules /usr/lib; +for path in /etc/nginx/modules /otel/lib; do mkdir -p /modules_mount${path} cp -R $path/* /modules_mount${path}/; From 122de9eed8545a36209240e1e4ca0d361e1f2e6a Mon Sep 17 00:00:00 2001 From: Daniel Schulze Date: Fri, 24 Jun 2022 00:22:45 +0200 Subject: [PATCH 4/5] add otel sidecar usage documentation --- .../third-party-addons/opentelemetry.md | 126 ++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 docs/user-guide/third-party-addons/opentelemetry.md diff --git a/docs/user-guide/third-party-addons/opentelemetry.md b/docs/user-guide/third-party-addons/opentelemetry.md new file mode 100644 index 0000000000..9445904419 --- /dev/null +++ b/docs/user-guide/third-party-addons/opentelemetry.md @@ -0,0 +1,126 @@ +# OpenTelemetry sidecar + +Enables distributed tracing using [OpenTelemetry](https://opentelemetry.io/). + +Using the OpenTelemetry sidecar enables the OpenTelemetry nginx module [OpenTelemetry nginx module](https://github.com/open-telemetry/opentelemetry-cpp-contrib/tree/main/instrumentation/nginx) for the NGINX ingress controller. +By default this feature is disabled. + +## Usage + +To enable the OpenTelemetry nginx module, the sidecar must be activated and configured. + +### Enable sidecar + +The OpenTelemetry sidecar load the OpenTelemetry module into the ingress-nginx container. +To enable the sidecar use the [helm chart](https://github.com/kubernetes/ingress-nginx/tree/main/charts/ingress-nginx): +``` + extraModules: + - name: opentelemetry + image: registry.k8s.io/ingress-nginx/opentelemetry +``` + + +Otherwise add to the controller deployment configuration: +``` +spec: + template: + spec: + containers: + volumeMounts: + - name: modules + mountPath: /modules_mount + initContainers: + - name: opentelemetry + image: registry.k8s.io/ingress-nginx/opentelemetry + command: ['sh', '-c', '/usr/local/bin/init_module.sh'] + volumeMounts: + - name: modules + mountPath: /modules_mount + volumes: + - name: modules + emptyDir: {} +``` + +### enable module + +To enable the Opentelemetry nginx module add to the configuration ConfigMap: +``` +data: + enable-opentelemetry: "true" +``` + +The [OpenTelemetry C++ library](https://github.com/open-telemetry/opentelemetry-cpp), base of the OpenTelemetry nginx module, requires a configuration file for processor and exporter configuration. The configuration file is `mandatory`. +``` +data: + opentelemetry-config: /conf/otel-nginx.toml +``` + +#### module configuration +The module configuration for processors and exporters can be added by an additional ConfigMap: +``` +{ + "kind": "ConfigMap", + "apiVersion": "v1", + "metadata": { + "name": "nginx-otel", + "namespace": "ingress-nginx", + "creationTimestamp": null + }, + "data": { + "otel-nginx.toml": "exporter = \"otlp\"\nprocessor = \"batch\"\n\n[exporters.otlp]\n# Alternatively the OTEL_EXPORTER_OTLP_ENDPOINT environment variable can also be used.\nhost = \"localhost\"\nport = 4317\n\n[processors.batch]\nmax_queue_size = 2048\nschedule_delay_millis = 5000\nmax_export_batch_size = 512\n\n[service]\nname = \"nginx-proxy\" # Opentelemetry resource name\n\n[sampler]\nname = \"AlwaysOn\" # Also: AlwaysOff, TraceIdRatioBased\nratio = 0.1\nparent_based = false\n" + } +} +``` +Currently this ConfigMap must be added manually. +The configuration here is equal to [OpenTelemetry C++ usage description](https://github.com/open-telemetry/opentelemetry-cpp-contrib/tree/main/instrumentation/nginx#usage) + +Additionally the `otel-nginx.toml` file must be mounted to the ingress-nginx container +``` +spec: + template: + spec: + containers: + volumeMounts: + - name: otel-nginx + readOnly: true + mountPath: /conf + volumes: + - name: otel-nginx + configMap: + name: nginx-otel + items: + - key: otel-nginx.toml + path: otel-nginx.toml +``` + +### nginx configuration +The OpenTelemetry nginx module provides several [nginx directives](https://github.com/open-telemetry/opentelemetry-cpp-contrib/tree/main/instrumentation/nginx#nginx-directives). + +`Comming soon.` + +### helm chart + +The easiest way to activate the sidecar is to use the [helm chart](https://github.com/kubernetes/ingress-nginx/tree/main/charts/ingress-nginx). The values.yaml file have to contain + +``` + extraModules: + - name: opentelemetry + image: registry.k8s.io/ingress-nginx/opentelemetry:v20220415-controller-v1.2.0-beta.0-2-g81c2afd97@sha256:ce61e2cf0b347dffebb2dcbf57c33891d2217c1bad9c0959c878e5be671ef941 + + config: + enable-opentelemetry: true + opentelemetry-config: "/conf/otel-nginx.toml" + + extraVolumeMounts: + - name: otel-nginx + readOnly: true + mountPath: /conf + + extraVolumes: + - name: otel-nginx + configMap: + name: nginx-otel +``` + +## Collector +As OpenTelemetry collector use for example [OpenTelemetry Collector Helm Chart](https://github.com/open-telemetry/opentelemetry-helm-charts/tree/main/charts/opentelemetry-collector) \ No newline at end of file From 800381bb37e485b6a5bdb78fbf3e0dc52410687b Mon Sep 17 00:00:00 2001 From: Daniel Schulze Date: Fri, 24 Jun 2022 15:34:32 +0200 Subject: [PATCH 5/5] cleanup --- rootfs/Dockerfile.chroot | 1 - 1 file changed, 1 deletion(-) diff --git a/rootfs/Dockerfile.chroot b/rootfs/Dockerfile.chroot index dd6e36fa06..10a3356796 100644 --- a/rootfs/Dockerfile.chroot +++ b/rootfs/Dockerfile.chroot @@ -45,7 +45,6 @@ ENV LUA_PATH="/usr/local/share/luajit-2.1.0-beta3/?.lua;/usr/local/share/lua/5.1 ENV LUA_CPATH="/usr/local/lib/lua/?/?.so;/usr/local/lib/lua/?.so;;" ENV PATH=$PATH:/usr/local/luajit/bin:/usr/local/nginx/sbin:/usr/local/nginx/bin - RUN apk update \ && apk upgrade \ && apk add -U --no-cache \