diff --git a/config/custom-environment-variables.json b/config/custom-environment-variables.json index e527ae7..7544482 100644 --- a/config/custom-environment-variables.json +++ b/config/custom-environment-variables.json @@ -15,11 +15,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 dd09bc5..efb6f2c 100644 --- a/helm/templates/_helpers.tpl +++ b/helm/templates/_helpers.tpl @@ -106,3 +106,37 @@ Returns the cloud provider image pull secret name from global if exists or from {{- .Values.cloudProvider.imagePullSecretName -}} {{- end -}} {{- end -}} + +{{/* +Returns the tracing url from global if set, otherwise from the chart's values +*/}} +{{- define "job-tracker.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 opentelemetry logging url from global if set, otherwise from the chart's values +*/}} +{{- define "job-tracker.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 "job-tracker.otelResourceAttributes" .resourceAttributes }} +*/}} +{{- define "job-tracker.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 b10930c..0e4536c 100644 --- a/helm/templates/_tplValues.tpl +++ b/helm/templates/_tplValues.tpl @@ -53,14 +53,6 @@ Custom definitions {{- include "common.tplvalues.merge" ( dict "values" ( list .Values.jobDefinitions .Values.global.jobDefinitions ) "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 -}} - {{/* Returns a yaml array of all the tasks types from jobDefinitions that has suspendJobOnFail: true */}} diff --git a/helm/templates/configmap.yaml b/helm/templates/configmap.yaml index cb9dfea..5841030 100644 --- a/helm/templates/configmap.yaml +++ b/helm/templates/configmap.yaml @@ -2,30 +2,37 @@ {{- $jobDefinitions := (include "common.jobDefinitions.merged" .) | fromYaml }} {{- $suspendingTaskTypes := include "suspendingTaskTypes" . }} {{- $serviceUrls := (include "common.serviceUrls.merged" .) | fromYaml }} -{{- $queue := .Values.env.queue }} -{{- $tracing := (include "common.tracing.merged" .) | fromYaml }} -{{- $openTelemetryOptions := (include "common.openTelemetryOptions.merged" .) | fromYaml }} +{{- $server := .Values.server -}} +{{- $telemetry := .Values.telemetry -}} +{{- $tracingUrl := include "job-tracker.tracingUrl" . -}} +{{- $opentelemetryLoggingUrl := include "job-tracker.opentelemetryLoggingUrl" . -}} {{- if .Values.enabled -}} apiVersion: v1 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 "job-tracker.otelResourceAttributes" .resourceAttributes | quote }} + {{- end }} + {{- end }} + {{- end }} + TELEMETRY_TRACING_ENABLED: {{ .tracing.enabled | quote }} + {{- if .tracing.enabled }} + TELEMETRY_TRACING_URL: {{ $tracingUrl | quote }} {{- end }} {{- end }} - {{ if $tracing.enabled }} - TELEMETRY_TRACING_ENABLED: 'true' - TELEMETRY_TRACING_URL: {{ $tracing.url }} - {{ end }} npm_config_cache: /tmp/ JOB_MANAGER_BASE_URL: {{ $serviceUrls.jobManager | quote }} JOB_DEFINITIONS_JOB_NEW: {{ $jobDefinitions.jobs.new.type | quote }} diff --git a/helm/templates/deployment.yaml b/helm/templates/deployment.yaml index c57f39b..116ae06 100644 --- a/helm/templates/deployment.yaml +++ b/helm/templates/deployment.yaml @@ -6,6 +6,7 @@ {{- $cloudProviderDockerRegistryUrl := include "job-tracker.cloudProviderDockerRegistryUrl" . -}} {{- $cloudProviderImagePullSecretName := include "job-tracker.cloudProviderImagePullSecretName" . -}} {{- $imageTag := include "job-tracker.tag" . -}} +{{- $server := .Values.server -}} {{- if .Values.enabled -}} apiVersion: apps/v1 kind: Deployment @@ -71,7 +72,7 @@ spec: {{- end }} env: - name: SERVER_PORT - value: {{ .Values.env.targetPort | quote }} + value: {{ $server.targetPort | quote }} - name: K8S_POD_UID valueFrom: fieldRef: @@ -90,8 +91,8 @@ spec: name: {{ $configmapName }} ports: - name: http - containerPort: {{ .Values.env.targetPort }} - protocol: {{ .Values.env.protocol }} + containerPort: {{ $server.targetPort }} + protocol: {{ $server.protocol }} {{- if .Values.livenessProbe.enabled }} livenessProbe: initialDelaySeconds: {{ .Values.livenessProbe.initialDelaySeconds }} @@ -99,7 +100,7 @@ spec: failureThreshold: {{ .Values.livenessProbe.failureThreshold }} httpGet: path: {{ .Values.livenessProbe.path }} - port: {{ .Values.env.targetPort }} + port: {{ $server.targetPort }} {{- end }} {{- if .Values.readinessProbe.enabled }} readinessProbe: @@ -108,7 +109,7 @@ spec: failureThreshold: {{ .Values.readinessProbe.failureThreshold }} httpGet: path: {{ .Values.readinessProbe.path }} - port: {{ .Values.env.targetPort }} + port: {{ $server.targetPort }} {{- end }} {{- if .Values.resources.enabled }} resources: diff --git a/helm/templates/ingress.yaml b/helm/templates/ingress.yaml index 59800c6..981472f 100644 --- a/helm/templates/ingress.yaml +++ b/helm/templates/ingress.yaml @@ -32,6 +32,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 8e0c78d..49c4aed 100644 --- a/helm/templates/service.yaml +++ b/helm/templates/service.yaml @@ -2,6 +2,7 @@ {{- $chartName := include "job-tracker.name" . -}} {{- $cloudProviderFlavor := include "job-tracker.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 36a3138..0971fc9 100644 --- a/helm/values.yaml +++ b/helm/values.yaml @@ -1,10 +1,12 @@ global: cloudProvider: {} - tracing: {} + telemetry: + tracing: {} + logger: + opentelemetryOptions: {} environment: '' jobDefinitions: {} serviceUrls: {} - openTelemetryOptions: {} ca: secretName: '' path: '/usr/local/share/ca-certificates' @@ -64,12 +66,8 @@ cloudProvider: imagePullSecretName: '' flavor: openshift -tracing: - enabled: false - url: '' - configManagement: - offlineMode: false + offlineMode: true name: 'job-tracker' version: 'latest' serverUrl: 'http://localhost:8080/api' @@ -137,21 +135,28 @@ taskFlowManager: deleteLayerTasksFlow: - delete - tiles-deletion -env: + +server: port: 80 targetPort: 8080 protocol: TCP - logLevel: info - logPrettyPrintEnabled: false - openTelemetryOptions: - enabled: false - url: '' - resourceAttributes: {} responseCompressionEnabled: true requestPayloadLimit: 1mb - queue: - dequeueIntervalMs: 3000 - heartbeatIntervalMs: 3000 + +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: true + url: http://localhost:55681/v1/traces resources: enabled: false diff --git a/src/containerConfig.ts b/src/containerConfig.ts index 5f2cbb3..78d6941 100644 --- a/src/containerConfig.ts +++ b/src/containerConfig.ts @@ -41,7 +41,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();