Level 4 : Deep Insights for the Recipe application
It is about monitoring and alerting the recipe application.
By default, controller-runtime builds a global prometheus registry and publishes a collection of performance metrics for each controller.
We can search for the metrics exported from the namespace where the project is running. Use this: {namespace="devconf-operator-system"} as the input to the search box in Prometheus.
You can also publish additional metrics with custom collectors by using the global registry from controller-runtime/pkg/metrics.
One way to achieve this is to declare your collectors as global variables and then register them using init() in the controller’s package.
1. Enable the Metrics by uncommenting the following line in the file config/default/kustomization.yaml.
Doing this creates the ServiceMonitor resource which enables exporting the metrics.
[PROMETHEUS] To enable prometheus monitor, uncomment all sections with 'PROMETHEUS'.
- ../prometheus
2. Under the “controller” directory, we implement a new function and let's call it internal/controller/metrics.go
Use our provided a patch to generate the code listed in 1,2 and 3 above
$ patch --strip=1 < ${WORKSHOP_REPO}/workshop/level_4/patches/0001-add_metrics.patch$ patch --strip=1 < ${WORKSHOP_REPO}/workshop/level_4/patches/0002-docker-to-podman.patch$ make docker-build docker-push IMG=quay.io/rocrisp/recipe_operator:3.0.0Note: Select Golang from docker.io/library/golang:1.20
$ make deploy IMG=quay.io/rocrisp/recipe_operator:3.0.0Allow the service monitor of the Operator to be scraped by the Prometheus instance of the OpenShift Container Platform cluster.
oc apply -f config/prometheus/role.yaml
oc apply -f config/prometheus/rolebinding.yamlLabels the devconf-operator-system namespace to scrape for metrics, which enables OpenShift cluster monitoring for that namespace
$ oc label namespace devconf-operator-system openshift.io/cluster-monitoring="true"
$ oc get namespace devconf-operator-system --show-labelsFor reference, https://docs.openshift.com/container-platform/4.15/operators/operator_sdk/osdk-monitoring-prometheus.html