diff --git a/config/custom-environment-variables.json b/config/custom-environment-variables.json index d7cc900..292aa75 100644 --- a/config/custom-environment-variables.json +++ b/config/custom-environment-variables.json @@ -17,11 +17,8 @@ "__name": "OPENTELEMETRY_LOGGING_ENABLED", "__format": "boolean" }, - "url": "OPENTELEMETRY_LOGGING_URL", - "resourceAttributes": { - "__name": "OPENTELEMETRY_RESOURCE_ATTRIBUTES", - "__format": "json" - } + "url": "OTLP_LOGGER_ENDPOINT_URL", + "resourceAttributes": "OTEL_RESOURCE_ATTRIBUTES" } }, "tracing": { diff --git a/helm/templates/_helpers.tpl b/helm/templates/_helpers.tpl index 2e45948..f19d5a8 100644 --- a/helm/templates/_helpers.tpl +++ b/helm/templates/_helpers.tpl @@ -103,23 +103,35 @@ Returns the cloud provider image pull secret name from global if exists or from {{- end -}} {{/* -Returns the tracing url from global if exists or from the chart's values +Returns the tracing url from global if set, otherwise from the chart's values */}} {{- define "mapproxy-api.tracingUrl" -}} -{{- if .Values.global.tracing.url }} - {{- .Values.global.tracing.url -}} -{{- else if .Values.cloudProvider -}} - {{- .Values.env.tracing.url -}} +{{- if .Values.global.telemetry.tracing.url }} + {{- .Values.global.telemetry.tracing.url -}} +{{- else if .Values.telemetry.tracing.url -}} + {{- .Values.telemetry.tracing.url -}} {{- end -}} {{- end -}} {{/* -Returns the tracing url from global if exists or from the chart's values +Returns the opentelemetry logging url from global if set, otherwise from the chart's values */}} -{{- define "mapproxy-api.metricsUrl" -}} -{{- if .Values.global.metrics.url }} - {{- .Values.global.metrics.url -}} -{{- else -}} - {{- .Values.env.metrics.url -}} +{{- define "mapproxy-api.opentelemetryLoggingUrl" -}} +{{- if .Values.global.telemetry.logger.opentelemetryOptions.url }} + {{- .Values.global.telemetry.logger.opentelemetryOptions.url -}} +{{- else if .Values.telemetry.logger.opentelemetryOptions.url -}} + {{- .Values.telemetry.logger.opentelemetryOptions.url -}} {{- end -}} {{- end -}} + +{{/* +Renders a map of resource attributes as key=value,key=value for OTEL_RESOURCE_ATTRIBUTES. +Usage: {{ include "mapproxy-api.otelResourceAttributes" .resourceAttributes }} +*/}} +{{- define "mapproxy-api.otelResourceAttributes" -}} +{{- $attributes := list }} +{{- range $key, $value := . }} +{{- $attributes = append $attributes (printf "%s=%s" $key (toString $value)) }} +{{- end }} +{{- join "," $attributes }} +{{- end -}} diff --git a/helm/templates/_tplValues.tpl b/helm/templates/_tplValues.tpl index 947cd70..3fd1543 100644 --- a/helm/templates/_tplValues.tpl +++ b/helm/templates/_tplValues.tpl @@ -61,14 +61,6 @@ Custom definitions {{- include "common.tplvalues.merge" ( dict "values" ( list .Values.storage.fs .Values.global.storage.fs ) "context" . ) }} {{- end -}} -{{- define "common.tracing.merged" -}} -{{- include "common.tplvalues.merge" ( dict "values" ( list .Values.tracing .Values.global.tracing ) "context" . ) }} -{{- end -}} - -{{- define "common.openTelemetryOptions.merged" -}} -{{- include "common.tplvalues.merge" ( dict "values" ( list .Values.env.openTelemetryOptions .Values.global.openTelemetryOptions ) "context" . ) }} -{{- end -}} - {{- define "common.redis.merged" -}} {{- include "common.tplvalues.merge" ( dict "values" ( list .Values.redis .Values.global.redis ) "context" . ) }} {{- end -}} diff --git a/helm/templates/configmap.yaml b/helm/templates/configmap.yaml index b5fe212..0688678 100644 --- a/helm/templates/configmap.yaml +++ b/helm/templates/configmap.yaml @@ -1,8 +1,10 @@ {{- $chartName := include "mapproxy-api.name" . -}} {{- $configmapName := include "configmap.fullname" . }} {{- $storage := (include "common.storage.merged" .) | fromYaml }} -{{- $tracing := (include "common.tracing.merged" .) | fromYaml }} -{{- $openTelemetryOptions := (include "common.openTelemetryOptions.merged" .) | fromYaml }} +{{- $server := .Values.server -}} +{{- $telemetry := .Values.telemetry -}} +{{- $tracingUrl := include "mapproxy-api.tracingUrl" . -}} +{{- $opentelemetryLoggingUrl := include "mapproxy-api.opentelemetryLoggingUrl" . -}} {{- $redis := (include "common.redis.merged" .) | fromYaml }} {{- if .Values.enabled -}} @@ -11,21 +13,27 @@ kind: ConfigMap metadata: name: {{ $configmapName }} data: - REQUEST_PAYLOAD_LIMIT: {{ .Values.env.requestPayloadLimit | quote }} - RESPONSE_COMPRESSION_ENABLED: {{ .Values.env.responseCompressionEnabled | quote }} - LOG_LEVEL: {{ .Values.env.logLevel | quote }} - LOG_PRETTY_PRINT_ENABLED: {{ .Values.env.logPrettyPrintEnabled | quote }} - {{- with $openTelemetryOptions }} + {{- with $server }} + REQUEST_PAYLOAD_LIMIT: {{ .requestPayloadLimit | quote }} + RESPONSE_COMPRESSION_ENABLED: {{ .responseCompressionEnabled | quote }} + {{- end }} + {{- with $telemetry }} + LOG_LEVEL: {{ .logger.level | quote }} + LOG_PRETTY_PRINT_ENABLED: {{ .logger.prettyPrint | quote }} + {{- with .logger.opentelemetryOptions }} OPENTELEMETRY_LOGGING_ENABLED: {{ .enabled | quote }} - {{ if .enabled }} - OPENTELEMETRY_LOGGING_URL: {{ .url | quote }} - OPENTELEMETRY_RESOURCE_ATTRIBUTES: {{ .resourceAttributes | toJson | quote }} + {{- if .enabled }} + OTLP_LOGGER_ENDPOINT_URL: {{ $opentelemetryLoggingUrl | quote }} + {{- if .resourceAttributes }} + OTEL_RESOURCE_ATTRIBUTES: {{ include "mapproxy-api.otelResourceAttributes" .resourceAttributes | quote }} + {{- end }} + {{- end }} + {{- end }} + TELEMETRY_TRACING_ENABLED: {{ .tracing.enabled | quote }} + {{- if .tracing.enabled }} + TELEMETRY_TRACING_URL: {{ $tracingUrl | quote }} {{- end }} {{- end }} - TELEMETRY_TRACING_ENABLED: {{ $tracing.enabled | quote }} - {{ if $tracing.enabled }} - TELEMETRY_TRACING_URL: {{ $tracing.url }} - {{ end }} MAPPROXY_CONFIG_PROVIDER: {{ quote $storage.mapproxyConfigProvider }} MAPPROXY_CACHE_GRIDS: {{ quote .Values.env.mapproxyCache.grids }} MAPPROXY_CACHE_UPSCALE_TILES: {{ quote .Values.env.mapproxyCache.upscaleTiles }} diff --git a/helm/templates/deployment.yaml b/helm/templates/deployment.yaml index c233360..422ac53 100644 --- a/helm/templates/deployment.yaml +++ b/helm/templates/deployment.yaml @@ -59,6 +59,7 @@ spec: - name: {{ $chartName }} {{- with .Values.image }} image: {{ $cloudProviderDockerRegistryUrl }}{{ .repository }}:{{ $imageTag }} + imagePullPolicy: {{ .pullPolicy | default "IfNotPresent" }} {{- end }} volumeMounts: {{- if .Values.global.ca.secretName }} @@ -84,7 +85,7 @@ spec: {{- end }} env: - name: SERVER_PORT - value: {{ .Values.env.targetPort | quote }} + value: {{ .Values.server.targetPort | quote }} - name: K8S_POD_UID valueFrom: fieldRef: @@ -140,13 +141,13 @@ spec: name: {{ $configmapName }} ports: - name: http - containerPort: {{ .Values.env.targetPort }} - protocol: {{ .Values.env.protocol }} + containerPort: {{ .Values.server.targetPort }} + protocol: {{ .Values.server.protocol }} livenessProbe: initialDelaySeconds: {{ .Values.initialDelaySeconds }} httpGet: path: /liveness - port: {{ .Values.env.targetPort }} + port: {{ .Values.server.targetPort }} {{- if .Values.resources.enabled }} resources: {{- toYaml .Values.resources.value | nindent 12 }} diff --git a/helm/templates/ingress.yaml b/helm/templates/ingress.yaml index 968f524..ab011aa 100644 --- a/helm/templates/ingress.yaml +++ b/helm/templates/ingress.yaml @@ -39,6 +39,6 @@ spec: service: name: {{ $serviceName }} port: - number: {{ .Values.env.port }} + number: {{ .Values.server.port }} host: {{ $ingressHost }} {{- end -}} diff --git a/helm/templates/service.yaml b/helm/templates/service.yaml index 46c3779..8de630e 100644 --- a/helm/templates/service.yaml +++ b/helm/templates/service.yaml @@ -18,9 +18,9 @@ spec: type: NodePort {{- end }} ports: - - port: {{ .Values.env.port }} - targetPort: {{ .Values.env.targetPort }} - protocol: {{ .Values.env.protocol }} + - port: {{ .Values.server.port }} + targetPort: {{ .Values.server.targetPort }} + protocol: {{ .Values.server.protocol }} name: http {{- if eq $cloudProviderFlavor "minikube" }} nodePort: {{ .Values.nodePort }} diff --git a/helm/values.yaml b/helm/values.yaml index 8a63c5d..93ca8f9 100644 --- a/helm/values.yaml +++ b/helm/values.yaml @@ -1,7 +1,9 @@ global: cloudProvider: {} - tracing: {} - openTelemetryOptions: {} + telemetry: + tracing: {} + logger: + opentelemetryOptions: {} environment: "" storage: mapproxyConfigProvider: "" # -> 'DB' | 'FS' | 'S3' @@ -59,6 +61,7 @@ cloudProvider: image: repository: mapproxy-api tag: 'latest' + pullPolicy: IfNotPresent storage: mapproxyConfigProvider: "" # -> 'DB' | 'FS' | 'S3' @@ -78,40 +81,48 @@ db: name: "" port: 5432 sslEnabled: false - schema: "" + schema: "MapproxyConfig" dbRejectUnauthorized: false secrets: useExternal: false externalSecretName: "" configManagement: - offlineMode: false + offlineMode: true name: 'mapproxy-api' version: 'latest' serverUrl: 'http://localhost:8080/api' -tracing: - enabled: false - url: '' - # add pod annotations - # example: - # podAnnotations: - # annotation1: annotation-value-1 - # annotation2: annotation-value-2 +# add pod annotations +# example: +# podAnnotations: +# annotation1: annotation-value-1 +# annotation2: annotation-value-2 podAnnotations: {} -env: +server: port: 80 targetPort: 8080 protocol: TCP - logLevel: warn - logPrettyPrintEnabled: false - openTelemetryOptions: - enabled: false - url: '' - resourceAttributes: {} responseCompressionEnabled: true requestPayloadLimit: 1mb + +telemetry: + logger: + level: warn + prettyPrint: false + opentelemetryOptions: + enabled: true + url: http://localhost:4317 + # Rendered as OTEL_RESOURCE_ATTRIBUTES in "key=value,key=value" format + # resourceAttributes: + # service.namespace: namespace + # deployment.environment: dev + tracing: + enabled: true + url: http://localhost:55681/v1/traces + +env: mapproxyCache: grids: WorldCRS84 upscaleTiles: 18 diff --git a/src/containerConfig.ts b/src/containerConfig.ts index 9e7efba..27659b0 100644 --- a/src/containerConfig.ts +++ b/src/containerConfig.ts @@ -26,7 +26,7 @@ export const registerExternalValues = async (options?: RegisterOptions): Promise const mapproxyConfig = configInstance.get('mapproxy') as IMapProxyConfig; const redisConfig = configInstance.get('redis') as IRedisConfig; - const logger = await jsLogger({ ...loggerConfig, prettyPrint: loggerConfig.prettyPrint, mixin: getOtelMixin() }); + const logger = await jsLogger({ ...loggerConfig, mixin: getOtelMixin() }); const tracer = trace.getTracer(SERVICE_NAME); const metricsRegistry = new Registry();