From eb14a7c887484caae20092a580dbe70665544ebd Mon Sep 17 00:00:00 2001 From: Camila Macedo <7708031+camilamacedo86@users.noreply.github.com> Date: Mon, 23 Dec 2024 19:37:42 +0000 Subject: [PATCH] (doc): Add a doc as a guidance to help users know how to consume the metrics and integrate it with other solutions --- docs/draft/howto/consuming-metrics.md | 294 ++++++++++++++++++++++++++ 1 file changed, 294 insertions(+) create mode 100644 docs/draft/howto/consuming-metrics.md diff --git a/docs/draft/howto/consuming-metrics.md b/docs/draft/howto/consuming-metrics.md new file mode 100644 index 000000000..9fba46241 --- /dev/null +++ b/docs/draft/howto/consuming-metrics.md @@ -0,0 +1,294 @@ +# Consuming Metrics + +!!! warning +Metrics endpoints and ports are available as an alpha release and are subject to change in future versions. +The following procedure is provided as an example for testing purposes. Do not depend on alpha features in production clusters. + +Operator-Controller and CatalogD are configured to export metrics by default. The metrics are exposed on the `/metrics` endpoint of the respective services. + +The metrics are secured by [RBAC policies][rbac-k8s-docs], requiring appropriate permissions for access. +By default, they are exposed over HTTPS, necessitating valid certificates for integration with services like Prometheus. +The following sections cover enabling metrics, validating access, and integrating with the [Prometheus Operator][prometheus-operator]. + +Below, you will learn how to enable the metrics, validate access, and integrate with [Prometheus Operator][prometheus-operator]. + +--- + +## Operator-Controller Metrics + +### Step 1: Enable Access + +To enable access to the Operator-Controller metrics, create a `ClusterRoleBinding` to +allow the Operator-Controller service account to access the metrics. + +```shell +kubectl create clusterrolebinding operator-controller-metrics-binding \ + --clusterrole=operator-controller-metrics-reader \ + --serviceaccount=olmv1-system:operator-controller-controller-manager +``` + +### Step 2: Validate Access Manually + +#### Create a Token and Extract Certificates + +Generate a token for the service account and extract the required certificates: + +```shell +TOKEN=$(kubectl create token operator-controller-controller-manager -n olmv1-system) +echo $TOKEN +``` + +#### Deploy a Pod to Consume Metrics + +Ensure that the Pod is deployed in a namespace labeled to enforce restricted permissions. Apply the following: + +```shell +kubectl apply -f - <" \ +https://operator-controller-service.olmv1-system.svc.cluster.local:8443/metrics +``` + +Validate using certificates and token: + +```shell +curl -v --cacert /tmp/cert/ca.crt --cert /tmp/cert/tls.crt --key /tmp/cert/tls.key \ +-H "Authorization: Bearer " \ +https://operator-controller-service.olmv1-system.svc.cluster.local:8443/metrics +``` + +--- + +## CatalogD Metrics + +### Step 1: Enable Access + +To enable access to the CatalogD metrics, create a `ClusterRoleBinding` for the CatalogD service account: + +```shell +kubectl create clusterrolebinding catalogd-metrics-binding \ + --clusterrole=catalogd-metrics-reader \ + --serviceaccount=olmv1-system:catalogd-controller-manager +``` + +### Step 2: Validate Access Manually + +#### Create a Token and Extract Certificates + +Generate a token and get the required certificates: + +```shell +TOKEN=$(kubectl create token catalogd-controller-manager -n olmv1-system) +echo $TOKEN +``` + +#### Deploy a Pod to Consume Metrics + +From the shell use the `TOKEN` value obtained above to check the metrics: + +```shell +OLM_SECRET=$(kubectl get secret -n olmv1-system -o jsonpath="{.items[*].metadata.name}" | tr ' ' '\n' | grep '^catalogd-service-cert') +echo $OLM_SECRET +``` + +```shell +kubectl apply -f - <" \ +https://catalogd-service.olmv1-system.svc.cluster.local:7443/metrics +``` + +Validate using certificates and token: + +```shell +curl -v --cacert /tmp/cert/ca.crt --cert /tmp/cert/tls.crt --key /tmp/cert/tls.key \ +-H "Authorization: Bearer " \ +https://catalogd-service.olmv1-system.svc.cluster.local:7443/metrics +``` + +--- + +## Enabling Integration with Prometheus + +If using [Prometheus Operator][prometheus-operator], create a `ServiceMonitor` to scrape metrics: + +!!! note +The following manifests are provided as examples. You may need to configure certain settings, such as `serviceMonitorSelector`, +to ensure that metrics are properly scraped. This will depend on how Prometheus is configured and, for example, the namespace +where the `ServiceMonitor` is applied. + +### For Operator-Controller + +```shell +kubectl apply -f - <