diff --git a/helm/templates/_helpers.tpl b/helm/templates/_helpers.tpl index da7d776..6e7aafa 100644 --- a/helm/templates/_helpers.tpl +++ b/helm/templates/_helpers.tpl @@ -96,23 +96,36 @@ 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 "ts-server-boilerplate.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 "ts-server-boilerplate.metricsUrl" -}} -{{- if .Values.global.metrics.url }} - {{- .Values.global.metrics.url -}} -{{- else -}} - {{- .Values.env.metrics.url -}} +{{- define "ts-server-boilerplate.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 "ts-server-boilerplate.otelResourceAttributes" .resourceAttributes }} +*/}} +{{- define "ts-server-boilerplate.otelResourceAttributes" -}} +{{- $attributes := list }} +{{- range $key, $value := . }} +{{- $attributes = append $attributes (printf "%s=%s" $key (toString $value)) }} +{{- end }} +{{- join "," $attributes }} +{{- end -}} + diff --git a/helm/templates/configmap.yaml b/helm/templates/configmap.yaml index 187f013..0cd9c61 100644 --- a/helm/templates/configmap.yaml +++ b/helm/templates/configmap.yaml @@ -1,26 +1,37 @@ +{{- $server := .Values.server -}} +{{- $telemetry := .Values.telemetry -}} {{- $tracingUrl := include "ts-server-boilerplate.tracingUrl" . -}} -{{- $metricsUrl := include "ts-server-boilerplate.metricsUrl" . -}} +{{- $opentelemetryLoggingUrl := include "ts-server-boilerplate.opentelemetryLoggingUrl" . -}} {{- if .Values.enabled -}} apiVersion: v1 kind: ConfigMap metadata: name: {{ include "ts-server-boilerplate.fullname" . }} 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 }} - {{ if .Values.env.tracing.enabled }} + {{- 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 }} + {{- if .enabled }} + OPENTELEMETRY_LOGGING_ENABLED: 'true' + OTLP_LOGGER_ENDPOINT_URL: {{ $opentelemetryLoggingUrl | quote }} + {{- if .resourceAttributes }} + OTEL_RESOURCE_ATTRIBUTES: {{ include "ts-server-boilerplate.otelResourceAttributes" .resourceAttributes | quote }} + {{- end }} + {{- end }} + {{- end }} + {{- if .tracing.enabled }} TELEMETRY_TRACING_ENABLED: 'true' - TELEMETRY_TRACING_URL: {{ $tracingUrl }} - {{ end }} - {{ if .Values.env.metrics.enabled }} - TELEMETRY_METRICS_ENABLED: 'true' - TELEMETRY_METRICS_URL: {{ $metricsUrl }} - {{ end }} + TELEMETRY_TRACING_URL: {{ $tracingUrl | quote }} + {{- end }} + {{- end }} npm_config_cache: /tmp/ {{- 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 862cff4..29e8bee 100644 --- a/helm/templates/deployment.yaml +++ b/helm/templates/deployment.yaml @@ -4,6 +4,7 @@ {{- $cloudProviderDockerRegistryUrl := include "ts-server-boilerplate.cloudProviderDockerRegistryUrl" . -}} {{- $cloudProviderImagePullSecretName := include "ts-server-boilerplate.cloudProviderImagePullSecretName" . -}} {{- $imageTag := include "ts-server-boilerplate.tag" . -}} +{{- $server := .Values.server -}} {{- if .Values.enabled -}} apiVersion: apps/v1 kind: Deployment @@ -72,7 +73,7 @@ spec: fieldRef: fieldPath: metadata.uid - name: SERVER_PORT - value: {{ .Values.env.targetPort | quote }} + value: {{ $server.targetPort | quote }} {{- if .Values.caSecretName }} - name: REQUESTS_CA_BUNDLE value: {{ printf "%s/%s" .Values.caPath .Values.caKey | quote }} @@ -87,8 +88,8 @@ spec: name: {{ include "ts-server-boilerplate.fullname" . }} 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 }} @@ -96,7 +97,7 @@ spec: failureThreshold: {{ .Values.livenessProbe.failureThreshold }} httpGet: path: {{ .Values.livenessProbe.path }} - port: {{ .Values.env.targetPort }} + port: {{ $server.targetPort }} {{- end }} {{- if .Values.readinessProbe.enabled }} readinessProbe: @@ -105,7 +106,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 7a9c7ce..a4ef613 100644 --- a/helm/templates/ingress.yaml +++ b/helm/templates/ingress.yaml @@ -1,7 +1,7 @@ {{- if and (.Values.enabled) (.Values.ingress.enabled) -}} {{- $fullName := include "ts-server-boilerplate.fullname" . -}} {{- $serviceName := $fullName -}} -{{- $servicePort := .Values.env.port -}} +{{- $servicePort := .Values.server.port -}} {{- $ingressPath := .Values.ingress.path -}} {{- $ingressPathType := default "Prefix" .Values.ingress.pathType -}} {{- $extraPaths := .Values.ingress.extraPaths -}} diff --git a/helm/templates/service.yaml b/helm/templates/service.yaml index f69c44c..1e235e7 100644 --- a/helm/templates/service.yaml +++ b/helm/templates/service.yaml @@ -1,6 +1,7 @@ {{- $releaseName := .Release.Name -}} {{- $chartName := include "ts-server-boilerplate.name" . -}} {{- $cloudProviderFlavor := include "ts-server-boilerplate.cloudProviderFlavor" . -}} +{{- $server := .Values.server -}} {{- if .Values.enabled -}} apiVersion: v1 kind: Service @@ -16,9 +17,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 e7d34d9..f982729 100644 --- a/helm/values.yaml +++ b/helm/values.yaml @@ -1,7 +1,9 @@ global: cloudProvider: {} - tracing: {} - metrics: {} + telemetry: + tracing: {} + logger: + opentelemetryOptions: {} mclabels: component: backend @@ -69,20 +71,27 @@ image: # tag: 'latest' pullPolicy: IfNotPresent -env: +server: port: 8080 targetPort: 8080 protocol: TCP - logLevel: info - logPrettyPrintEnabled: false responseCompressionEnabled: true requestPayloadLimit: 1mb + +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/trace - metrics: - enabled: false - url: http://localhost:55681/v1/metrics resources: enabled: true