{"user":"aerogearcatalog","name":"metrics-apb","namespace":"aerogearcatalog","repository_type":"image","status":1,"status_description":"active","description":"Prometheus \u0026 Grafana with auth on OpenShift","is_private":false,"is_automated":true,"star_count":2,"pull_count":861800,"last_updated":"2019-04-12T09:30:37.466136Z","last_modified":"2024-10-16T13:48:34.145251Z","date_registered":"2018-01-10T09:53:08.795384Z","collaborator_count":0,"affiliation":null,"hub_user":"aerogearcatalog","has_starred":false,"full_description":"# Metrics APB\n\n[![](https://img.shields.io/docker/automated/jrottenberg/ffmpeg.svg)](https://hub.docker.com/r/aerogearcatalog/metrics-apb/)\n[![Docker Stars](https://img.shields.io/docker/stars/aerogearcatalog/metrics-apb.svg)](https://registry.hub.docker.com/v2/repositories/aerogearcatalog/metrics-apb/stars/count/)\n[![Docker pulls](https://img.shields.io/docker/pulls/aerogearcatalog/metrics-apb.svg)](https://registry.hub.docker.com/v2/repositories/aerogearcatalog/metrics-apb/)\n[![License](https://img.shields.io/:license-Apache2-blue.svg)](http://www.apache.org/licenses/LICENSE-2.0)\n\n## Testing\n\nIf you want to test the changes made to this repo, you can do it by simply running `apb test`\nThe test does the following:\n1. Builds the APB \n1. Creates the project in currently targeted OpenShift instance\n1. Runs the `provision` role\n1. Runs the `test-provision` role which checks that\n    * Grafana and Prometheus routes are accessible\n    * we're getting successful response from OpenShift auth proxy server\n1. Runs `deprovision` role\n1. Runs `deprovision-test` role which checks that all objects (routes, pods, services) were deprovisioned successfully\n\nIf the test ends successfully, you should see the message `Pod phase Succeeded without returning test results` in your console output.\n\nFor more information about testing of APBs, check [ansible-playbook-bundle documentation](https://github.com/ansibleplaybookbundle/ansible-playbook-bundle/blob/master/docs/getting_started.md#test)\n\n## How auto-discovery of services work\n\nSee the inline comments [here](roles/provision-metrics-apb/templates/prometheus-config-map.yml.j2) and the\nexample config from Prometheus [here](https://github.com/prometheus/prometheus/blob/master/documentation/examples/prometheus-kubernetes.yml).\n\n## How to Add a New Dashboard while Provisioning a Service\n\nGrafana picks up any dashboard JSON files that are placed inside the `grafana-dashboards-configmap`. This section describes how to add a new dashboard into the `grafana-dashboards-configmap` from inside an APB. The APB that provisions the service should also be responsible for adding the dashboard.\n\nA reusable Ansible role for adding JSON files to a Config Map has been created: https://github.com/aerogear/oc-patch-file-to-configmap-role. The sections below demostrate how to use the role.\n\n#### requirements.yml\nUnder the `playbooks` directory create a file `requirements.yml`:\n\n```yaml\n- src: https://github.com/aerogear/oc-patch-file-to-configmap-role\n  version: master\n  name: oc-patch-file-to-configmap\n```\n\nThis file defines the `oc-patch-file-to-configmap` role as a dependency. \n\n#### Modify Dockerfile\nThe next step is to modify the default `Dockerfile`. The default APB Dockerfile usually has a list of commands like this:\n\n```\nCOPY playbooks /opt/apb/actions\nCOPY roles /opt/ansible/roles\nCOPY vars /opt/ansible/vars\nRUN chmod -R g=u /opt/{ansible,apb}\nUSER apb\n```\n\nAdd the following line **before** the `RUN chmod -R g=u /opt/{ansible,apb}` command:\n\n\n```\nRUN ansible-galaxy install -r /opt/apb/actions/requirements.yml -p /opt/ansible/roles\n```\n\nThis command uses the `ansible-galaxy` CLI tool to install dependencies in `requirements.yml` into the appropriate roles directory. This means when `apb build` is run, the `oc-patch-file-to-configmap` role is installed into the APB image.\n\n#### Usage\n\nIt is recommended to use the `oc-patch-file-to-configmap` role directly within the role being used to provision the service (e.g. `provision-keycloak-apb`). The role directory structure should be similar to this:\n\n```bash\n├── defaults\n│   └── main.yml\n├── files\n│   ├── ... # role specific files\n├── tasks\n│   └── main.yml\n└── templates\n    ├── ... # role specific templates\n```\n\nFirst, place the dashboard json file underneath the `files` directory. e.g. `files/keycloak-dashboard.json`\n\nNext, add the following variables to `defaults/main.yml`\n\n```yaml\n# Dashboard config\ndashboards_configmap: grafana-dashboards-configmap # this should not change\ndashboard_filename: keycloak-dashboard.json # name the file will have inside the config map\ndashboard_file_contents: \"{{ lookup('file','../files/keycloak-dashboard.json') }}\" # Contents of the dashboard file\n```\n\n**Note** the `dashboard_filename` is the name the file will have inside the Config Map. **This name should not clash with another service.** If a file with the same name already exists in the Config Map, it will be overwritten.\n\nLastly, add the following into `tasks/main.yml`\n\n```yaml\n- include_role:\n    name: oc-patch-file-to-configmap\n  vars:\n    file_contents: \"{{ dashboard_file_contents }}\"\n    filename: \"{{ dashboard_filename }}\"\n    configmap: \"{{ dashboards_configmap }}\"\n    namespace: \"{{ namespace }}\"\n```\n\nThis instructs Ansible to execute the role, passing in the appropriate variables.\n\n**Note** If the usage of this role is still not clear, take a look at the usage in the [Keycloak APB](https://github.com/aerogearcatalog/keycloak-apb).\n","permissions":{"read":true,"write":false,"admin":false},"media_types":["application/vnd.docker.container.image.v1+json"],"content_types":["image"],"categories":[],"immutable_tags_settings":{"enabled":false,"rules":[".*"]},"storage_size":2039523041,"source":null}