-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add custom prometheus metrics (#129)
- Loading branch information
Showing
13 changed files
with
214 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{{- if .Values.metrics.enabled }} | ||
apiVersion: monitoring.coreos.com/v1 | ||
kind: ServiceMonitor | ||
metadata: | ||
name: {{ include "sops-secrets-operator.fullname" . }}-mentrics-monitor | ||
labels: | ||
{{ include "sops-secrets-operator.labels" . | indent 4 }} | ||
spec: | ||
endpoints: | ||
- path: /metrics | ||
port: https | ||
scheme: https | ||
bearerTokenFile: /var/run/secrets/kubernetes.io/serviceaccount/token | ||
tlsConfig: | ||
insecureSkipVerify: true | ||
selector: | ||
matchLabels: | ||
app.kubernetes.io/name: {{ include "sops-secrets-operator.name" . }} | ||
app.kubernetes.io/instance: {{ .Release.Name }} | ||
{{- end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
suite: operator prometheus monitor tests | ||
templates: | ||
- monitor.yaml | ||
|
||
tests: | ||
|
||
- it: should not render any ServiceMonitor documents | ||
release: | ||
name: sops | ||
namespace: sops | ||
asserts: | ||
- hasDocuments: | ||
count: 0 | ||
|
||
- it: should set correct kind and apiVersion, one document and selector | ||
release: | ||
name: sops | ||
namespace: sops | ||
set: | ||
metrics: | ||
enabled: true | ||
asserts: | ||
- isKind: | ||
of: ServiceMonitor | ||
- isAPIVersion: | ||
of: monitoring.coreos.com/v1 | ||
- hasDocuments: | ||
count: 1 | ||
- equal: | ||
path: spec.selector.matchLabels | ||
value: | ||
app.kubernetes.io/instance: sops | ||
app.kubernetes.io/name: sops-secrets-operator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */ | ||
|
||
// these metrics are introduced for learning purposes, these have almost no real value | ||
|
||
package controllers | ||
|
||
import ( | ||
"github.com/prometheus/client_golang/prometheus" | ||
"sigs.k8s.io/controller-runtime/pkg/metrics" | ||
) | ||
|
||
var ( | ||
sopsSecretsReconciliations = prometheus.NewCounter( | ||
prometheus.CounterOpts{ | ||
Name: "sopssecrets_reconcilation_successes_total", | ||
Help: "Number of SopsSecrets reconciliations", | ||
}, | ||
) | ||
|
||
sopsSecretsReconciliationFailures = prometheus.NewCounter( | ||
prometheus.CounterOpts{ | ||
Name: "sopssecrets_reconcilation_failures_total", | ||
Help: "Number of SopsSecrets reconcoliation failures", | ||
}, | ||
) | ||
|
||
sopsSecretsReconciliationsSuspended = prometheus.NewCounter( | ||
prometheus.CounterOpts{ | ||
Name: "sopssecrets_reconcilation_suspends_total", | ||
Help: "Number of SopsSecrets reconciliations suspends", | ||
}, | ||
) | ||
) | ||
|
||
func init() { | ||
// Register custom metrics with the global prometheus registry | ||
metrics.Registry.MustRegister( | ||
sopsSecretsReconciliations, | ||
sopsSecretsReconciliationFailures, | ||
sopsSecretsReconciliationsSuspended, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.