diff --git a/library/common/templates/class/_cnpgPooler.tpl b/library/common/templates/class/_cnpgPooler.tpl index 5707e008..ce241e39 100644 --- a/library/common/templates/class/_cnpgPooler.tpl +++ b/library/common/templates/class/_cnpgPooler.tpl @@ -28,19 +28,5 @@ spec: parameters: max_client_conn: "1000" default_pool_size: "10" -{{- if $values.monitoring }} -{{- if $values.monitoring.enablePodMonitor }} ---- -apiVersion: monitoring.coreos.com/v1 -kind: PodMonitor -metadata: - name: {{ printf "%v-%v" $cnpgClusterName $values.pooler.type }} -spec: - selector: - matchLabels: - cnpg.io/poolerName: {{ printf "%v-%v" $cnpgClusterName $values.pooler.type }} - podMetricsEndpoints: - - port: metrics -{{- end }} -{{- end }} + {{- end -}} diff --git a/library/common/templates/lib/cnpg/_poolerMetrics.tpl b/library/common/templates/lib/cnpg/_poolerMetrics.tpl new file mode 100644 index 00000000..f1b7152e --- /dev/null +++ b/library/common/templates/lib/cnpg/_poolerMetrics.tpl @@ -0,0 +1,9 @@ +{{- define "tc.v1.common.lib.cnpg.metrics.pooler" -}} +enabled: true +type: "podmonitor" +selector: + matchLabels: + cnpg.io/poolerName: {{ .poolerName }} +endpoints: +- port: metrics +{{- end }} diff --git a/library/common/templates/lib/util/_primary_metrics.tpl b/library/common/templates/lib/util/_primary_metrics.tpl index 3c4b8c5e..f0853992 100644 --- a/library/common/templates/lib/util/_primary_metrics.tpl +++ b/library/common/templates/lib/util/_primary_metrics.tpl @@ -24,10 +24,6 @@ {{- if not $result -}} {{- if eq (len $enabledMetrics) 1 -}} {{- $result = keys $enabledMetrics | mustFirst -}} - {{- else -}} - {{- if $enabledMetrics -}} - {{- fail "At least one Metric must be set as primary" -}} - {{- end -}} {{- end -}} {{- end -}} {{- $result -}} diff --git a/library/common/templates/spawner/_cnpg.tpl b/library/common/templates/spawner/_cnpg.tpl index 0c319fbf..90bc0fd5 100644 --- a/library/common/templates/spawner/_cnpg.tpl +++ b/library/common/templates/spawner/_cnpg.tpl @@ -72,6 +72,19 @@ {{- $_ := set $cnpgValues.creds "host" $host }} {{- $_ := set $cnpgValues.creds "jdbc" $jdbc }} + + {{- if $cnpgValues.monitoring }} + {{- if $cnpgValues.monitoring.enablePodMonitor }} + {{- $poolermetrics := include "tc.v1.common.lib.cnpg.metrics.pooler" (dict "poolerName" ( printf "%s-rw" $cnpgValues.name) ) | fromYaml -}} + + {{- $_ := set $.Values.metrics ( printf "cnpg-%s-rw" $cnpgValues.shortName ) $poolermetrics }} + {{- if $cnpgValues.acceptRO }} + {{- $poolermetricsRO := include "tc.v1.common.lib.cnpg.metrics.pooler" (dict "poolerName" ( printf "%s-ro" $cnpgValues.name) ) | fromYaml -}} + {{- $_ := set $.Values.metrics ( printf "cnpg-%s-ro" $cnpgValues.shortName ) $poolermetricsRO }} + {{- end }} + {{- end }} + {{- end }} + {{- end -}} {{- end -}} {{- end -}}