diff --git a/config/custom-environment-variables.json b/config/custom-environment-variables.json index 0987c24..bab0f6d 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 8741ee3..764b5fd 100644 --- a/helm/templates/_helpers.tpl +++ b/helm/templates/_helpers.tpl @@ -104,24 +104,35 @@ Returns the cloud provider image pull secret name from global if exists or from {{- end -}} {{/* -Returns if tracing is enabled 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 "raster-catalog-manager.tracingEnabled" -}} -{{- if .Values.global.tracing.enabled }} - {{- .Values.global.tracing.enabled -}} -{{- else -}} - {{- .Values.env.tracing.enabled -}} +{{- define "raster-catalog-manager.tracingUrl" -}} +{{- 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 "raster-catalog-manager.tracingUrl" -}} -{{- if .Values.global.tracing.url }} - {{- .Values.global.tracing.url -}} -{{- else if .Values.cloudProvider -}} - {{- .Values.env.tracing.url -}} +{{- define "raster-catalog-manager.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 "raster-catalog-manager.otelResourceAttributes" .resourceAttributes }} +*/}} +{{- define "raster-catalog-manager.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 a7c934e..f52a5be 100644 --- a/helm/templates/_tplValues.tpl +++ b/helm/templates/_tplValues.tpl @@ -60,7 +60,3 @@ Custom definitions {{- define "common.fs.merged" -}} {{- include "common.tplvalues.merge" ( dict "values" ( list .Values.storage.fs .Values.global.storage.fs ) "context" . ) }} {{- end -}} - -{{- define "common.openTelemetryOptions.merged" -}} -{{- include "common.tplvalues.merge" ( dict "values" ( list .Values.env.openTelemetryOptions .Values.global.openTelemetryOptions ) "context" . ) }} -{{- end -}} diff --git a/helm/templates/configmap.yaml b/helm/templates/configmap.yaml index e3c4a95..9b9b072 100644 --- a/helm/templates/configmap.yaml +++ b/helm/templates/configmap.yaml @@ -1,8 +1,9 @@ {{- $chartName := include "raster-catalog-manager.name" . -}} {{- $configmapName := include "configmap.fullname" . }} +{{- $server := .Values.server -}} +{{- $telemetry := .Values.telemetry -}} {{- $tracingUrl := include "raster-catalog-manager.tracingUrl" . -}} -{{- $tracingEnabled := include "raster-catalog-manager.tracingEnabled" . -}} -{{- $openTelemetryOptions := (include "common.openTelemetryOptions.merged" .) | fromYaml }} +{{- $opentelemetryLoggingUrl := include "raster-catalog-manager.opentelemetryLoggingUrl" . -}} {{- $db := (include "common.db.merged" .) | fromYaml }} {{- if .Values.enabled -}} apiVersion: v1 @@ -10,33 +11,39 @@ 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 }} - TELEMETRY_TRACING_ENABLED: {{ $tracingEnabled | quote }} - {{ if $tracingEnabled }} - TELEMETRY_TRACING_URL: {{ $tracingUrl }} - {{ end }} - OPENTELEMETRY_LOGGING_ENABLED: {{ $openTelemetryOptions.enabled | quote }} - {{ if $openTelemetryOptions.enabled }} - OPENTELEMETRY_LOGGING_URL: {{ $openTelemetryOptions.url }} - {{ if $openTelemetryOptions.resourceAttributes }} - OPENTELEMETRY_RESOURCE_ATTRIBUTES: {{ $openTelemetryOptions.resourceAttributes | toJson | quote }} - {{ end }} - {{ end }} - DB_HOST: {{ $db.host }} - DB_PORT: {{ $db.port | quote }} - DB_NAME: {{ $db.name }} + {{- 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 }} + OTLP_LOGGER_ENDPOINT_URL: {{ $opentelemetryLoggingUrl | quote }} + {{- if .resourceAttributes }} + OTEL_RESOURCE_ATTRIBUTES: {{ include "raster-catalog-manager.otelResourceAttributes" .resourceAttributes | quote }} + {{- end }} + {{- end }} + {{- end }} + TELEMETRY_TRACING_ENABLED: {{ .tracing.enabled | quote }} + {{- if .tracing.enabled }} + TELEMETRY_TRACING_URL: {{ $tracingUrl | quote }} + {{- end }} + {{- end }} + DB_HOST: {{ $db.host | quote }} + DB_PORT: {{ $db.port | quote }} + DB_NAME: {{ $db.name | quote }} DB_SSL_ENABLE: {{ $db.sslEnabled | quote }} - DB_SSL_CA: {{ .Values.db.sslMountPath }}/{{ .Values.db.caFile }} - DB_SSL_KEY: {{ .Values.db.sslMountPath }}/{{ .Values.db.caKey }} - DB_SSL_CERT: {{ .Values.db.sslMountPath }}/{{ .Values.db.certFile }} - DB_SCHEMA: {{ $db.schema }} + DB_SSL_CA: {{ printf "%s/%s" .Values.db.sslMountPath .Values.db.caFile | quote }} + DB_SSL_KEY: {{ printf "%s/%s" .Values.db.sslMountPath .Values.db.caKey | quote }} + DB_SSL_CERT: {{ printf "%s/%s" .Values.db.sslMountPath .Values.db.certFile | quote }} + DB_SCHEMA: {{ $db.schema | quote }} DB_LOGGING: {{ $db.logging | quote }} - PGAPPNAME: {{ $chartName }} + PGAPPNAME: {{ $chartName | quote }} {{- with .Values.configManagement }} - CONFIG_NAME: {{ .name| quote }} + CONFIG_NAME: {{ .name | quote }} CONFIG_VERSION: {{ .version | quote }} CONFIG_OFFLINE_MODE: {{ .offlineMode | quote }} CONFIG_SERVER_URL: {{ .serverUrl | quote }} diff --git a/helm/templates/deployment.yaml b/helm/templates/deployment.yaml index 397da9e..d92f455 100644 --- a/helm/templates/deployment.yaml +++ b/helm/templates/deployment.yaml @@ -6,6 +6,7 @@ {{- $cloudProviderDockerRegistryUrl := include "raster-catalog-manager.cloudProviderDockerRegistryUrl" . -}} {{- $cloudProviderImagePullSecretName := include "raster-catalog-manager.cloudProviderImagePullSecretName" . -}} {{- $imageTag := include "raster-catalog-manager.tag" . -}} +{{- $server := .Values.server -}} {{- $db := (include "common.db.merged" .) | fromYaml }} {{- $postgresSecretName := ternary $db.secrets.externalSecretName (printf "%s%s" .Release.Name "-postgres-secret") $db.secrets.useExternal -}} @@ -69,7 +70,7 @@ spec: fieldRef: fieldPath: metadata.uid - name: SERVER_PORT - value: {{ .Values.env.targetPort | quote }} + value: {{ $server.targetPort | quote }} {{- if .Values.global.ca.secretName }} - name: REQUESTS_CA_BUNDLE value: {{ printf "%s/%s" .Values.global.ca.path .Values.global.ca.key | quote }} @@ -91,13 +92,13 @@ spec: name: {{ $configmapName }} ports: - name: http - containerPort: {{ .Values.env.targetPort }} - protocol: {{ .Values.env.protocol }} + containerPort: {{ $server.targetPort }} + protocol: {{ $server.protocol }} livenessProbe: initialDelaySeconds: {{ .Values.initialDelaySeconds }} httpGet: path: /liveness - port: {{ .Values.env.targetPort }} + port: {{ $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 c1b6a36..59fc053 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 914b677..7397ed9 100644 --- a/helm/templates/service.yaml +++ b/helm/templates/service.yaml @@ -2,6 +2,7 @@ {{- $chartName := include "raster-catalog-manager.name" . -}} {{- $cloudProviderFlavor := include "raster-catalog-manager.cloudProviderFlavor" . -}} {{- $serviceName := include "service.fullname" . -}} +{{- $server := .Values.server -}} {{- if .Values.enabled -}} apiVersion: v1 kind: Service @@ -18,9 +19,9 @@ spec: type: NodePort {{- end }} ports: - - port: {{ .Values.env.port }} - targetPort: {{ .Values.env.targetPort }} - protocol: {{ .Values.env.protocol }} + - port: {{ $server.port }} + targetPort: {{ $server.targetPort }} + protocol: {{ $server.protocol }} name: http {{- if eq $cloudProviderFlavor "minikube" }} nodePort: {{ .Values.nodePort }} diff --git a/helm/values.yaml b/helm/values.yaml index b43232e..a43aeb5 100644 --- a/helm/values.yaml +++ b/helm/values.yaml @@ -1,7 +1,9 @@ global: cloudProvider: {} - tracing: {} - openTelemetryOptions: {} + telemetry: + tracing: {} + logger: + opentelemetryOptions: {} environment: "" db: host: "" @@ -67,26 +69,32 @@ image: podAnnotations: {} configManagement: - offlineMode: false + offlineMode: true name: 'raster-catalog-manager' version: 'latest' serverUrl: 'http://localhost:8080/api' -env: +server: port: 80 targetPort: 8080 protocol: TCP - logLevel: warn - logPrettyPrintEnabled: false responseCompressionEnabled: true - requestPayloadLimit: 1mb + requestPayloadLimit: 5mb + +telemetry: + logger: + level: info + 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: false + enabled: true url: http://localhost:55681/v1/traces - openTelemetryOptions: - enabled: false - url: '' - resourceAttributes: {} resources: enabled: false diff --git a/src/containerConfig.ts b/src/containerConfig.ts index a90048c..508f3f0 100644 --- a/src/containerConfig.ts +++ b/src/containerConfig.ts @@ -19,7 +19,7 @@ export const registerExternalValues = async (options?: RegisterOptions): Promise const loggerConfig = configInstance.get('telemetry.logger'); - 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();