This document contains guidelines and references for configuring services in the Konflux clusters to be monitored and graphed.
For a service to be monitored, it needs to instrument Prometheus metrics, or have an external service that will poll it and generate metrics on its behalf.
For reference, see Writing Exporters
Prometheus needs to be able to reach the service in order to scrape the metrics it generates. Check out this example of a metrics-exporting service.
Service Monitors (ServiceMonitors) are Kubernetes custom resources that the Prometheus operator uses for creating scraping configurations for Prometheus pods. Consequently, Creating a Service Monitor creates a new target for Prometheus to collect metrics from.
Copy and modify this example for adding the Service Monitor declaration.
Ideally, the Service Monitor should be defined inside the component repository and then referenced by the infra-deployment component's configurations.
Namespace: the Service Monitor should be defined under the same namespace as the
service it monitors. Same goes for the namespaces for the rest of the resources
defined for the Service Monitor. Namely, service, servicemonitor and the
servicemonitor's serviceaccount and secret.
ClusterRole and ClusterRoleBinding: make sure you edit the cluster role and cluster role binding definitions so their names are unique.
ServiceMonitor: Verify the validity of the Service Monitor's selector. For example,
if it's matching a label, make sure you specify your app's label appropriately (e.g.
app: my-app, control-plane: controller-manager).
IMPORTANT: make sure your service's namespace does NOT contain label
openshift.io/cluster-monitoring: 'true'. Otherwise, it will not be monitored by the user workload Prometheus instance.
Grafana datasources contain the connection settings to the Prometheus instances.
A single
datasource (Thanos querier),
appstudio-datasource is defined and it lets us query metrics from the Platform and
User Workload Monitoring Prometheus.
To use this default datasource any definition of a datasource in the dashboard json file
should be removed or a templating should be used.
A dashboard is a set of one or more panels organized and arranged into one or more rows. It visualizes results from multiple data sources simultaneously. New dashboards can be added through the user interface, preconfigured in the infra-deployments repository, or imported from other projects.
-
Create a dashboard for your team's view of your service's Service Level Indicators (After navigating to your folder + Create Dashboard).
Note: Creating a new dashboard manually is available only for development environment. You may copy and edit the
exampledashboard json instead, and test the new dashboard on the staging and production environments. Theexampledashboard json definition can be found here -
Add tiles to the dashboard to track your initial set of service level indicators. If the servicemonitor was added correctly to the stage Prometheus datasource, it will show up in the query list when you edit a tile.
-
Export the dashboard definition in JSON format: At the top of the screen, select the icon with 3 dots and click
Share dashboard or panel-->Export-->Save to file.
Follow the next steps to define a dashboard in your team's repository:
-
The dashboard should be located in the team’s repository, so no change in
infra-deploymentsis required.The recommended structure is:
├── grafana │ ├── dashboards │ │ └── <teams_dashboard>.json │ ├── <GrafanaDashboard resource file> │ └── kustomization.yamlFor example:
├── grafana │ ├── dashboards │ │ └── example-dashboard.json │ ├── dashboard.yaml │ └── kustomization.yaml -
Create a folder in your team's repository to maintain the dashboard configuration (e.g. grafana)
-
Edit the dashboard json file:
To pick the default predefined datasource, edit the dashboard json file and remove
datasourcefrom it. For example:"datasource": { "type": "prometheus", "uid": "PF224BEF3374A25F8" }
Alternatively it is possible to use templating to select a datasource. For example:
"templating": { "list": [ { "current": { "selected": true, "text": "Prometheus", "value": "Prometheus" }, "hide": 0, "includeAll": false, "multi": false, "name": "datasource", "options": [], "query": "prometheus", "queryValue": "", "refresh": 1, "regex": ".*-(appstudio)-.*", "skipUrlSync": false, "type": "datasource" } ] },
In this example, the dashboard will use
Prometheusdatasource, with ability to use other datasource that containsappstudioin the name. -
Add the dashboard json file to the folder you created.
-
Create a
kustomization.yamlfile to generate a config map from the dashboard json, and to add theGrafanaDashboardresource file (dashboard.yaml). For example:kind: Kustomization apiVersion: kustomize.config.k8s.io/v1beta1 namespace: example configMapGenerator: - name: grafana-dashboard-example files: - dashboards/example-dashboard.json resources: - dashboard.yaml
-
Create the
GrafanaDashboardresource file that uses the config map to create the dashboard:apiVersion: grafana.integreatly.org/v1beta1 kind: GrafanaDashboard metadata: name: grafana-dashboard-example labels: app: appstudio-grafana spec: instanceSelector: matchLabels: dashboards: "appstudio-grafana" configMapRef: name: grafana-dashboard-example key: example-dashboard.json
-
Push the code to the team's repository.
Check out this example o11y PR for creating a dashboard in the team's repository.
Follow these steps to add a dashboard to the infra-deployments repository:
-
Create a team folder under
components/monitoring/grafana/base/<team_name>. -
Create a
kustomization.yamlfile and add the dashboard you created as a resource by using the commit sha as ref. For example:apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization resources: - https://github.com/redhat-appstudio/o11y/grafana/?ref=82bec1c488250ae32d458c77755e432329be1b45
-
Add your team's folder to the base kustomization file to automatically add it to future deployments.
-
Push the code to the
infra-deploymentsrepository.
Follow the next steps to verify and check your dashboard after merging the configurations:
-
Open the Grafana UI.
-
Click the
Manageoption in theDashboardsmenu. -
Verify that your team’s dashboard is located under
appstudio-grafanafolder.