Skip to content

build(ansible): add options to install grafana and dashboards #5589

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ansible/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ will only install Kafka when setting up the ecosystem.
| full_install | bool | yes | enables full ecosystem installation |
| install_kafka | bool | `{{ full_install }}` | installs Strimzi Kafka Operator |
| install_prometheus | bool | `{{ full_install }}` | installs Prometheus Operator |
| install_grafana | bool | `{{ full_install }}` | installs Grafana Operator |
| install_certmanager | bool | `{{ full_install }}` | installs Cert Manager |
| install_jaeger | bool | `{{ full_install }}` | installs Jaeger |
| install_opentelemetry | bool | `{{ full_install }}` | installs OpenTelemetry |
Expand Down
2 changes: 2 additions & 0 deletions ansible/playbooks/setup-ecosystem.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
full_install: yes

install_prometheus: "{{ full_install }}"
install_grafana: "{{ full_install }}"
install_kafka: "{{ full_install }}"
install_certmanager: "{{ full_install }}"
install_jaeger: "{{ full_install }}"
install_opentelemetry: "{{ full_install }}"

configure_prometheus: "{{ install_prometheus }}"
configure_grafana: "{{ install_grafana }}"
configure_kafka: "{{ install_kafka }}"
configure_jaeger: "{{ install_jaeger }}"
configure_opentelemetry: "{{ install_opentelemetry }}"
Expand Down
19 changes: 19 additions & 0 deletions ansible/playbooks/vars/default.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
---
# Default credentials.
# These credentials are used as defaults for:
# - the grafana install, when configured
#
# For grafana, once the cluster is up and running, you may fetch the randomly generated password
# by running (change `seldon-monitoring` to the value of the seldon_monitoring_namespace
# variable):
#
# kubectl get secret --namespace seldon-monitoring grafana -o jsonpath="{.data.admin-password}" | base64 --decode ; echo
#

# Overwrite by passing sd_user and/or sd_password variables when running the playbook
seldon_admin_user: "admin"
seldon_random_gen_password: "{{ lookup('password', '/dev/null chars=digits length=6') }}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How to fetch the randomly generated password?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is printed during the playbook run. If that is missed, one may run kubectl get secret --namespace seldon-monitoring grafana -o jsonpath="{.data.admin-password}" | base64 --decode ; echo to get the current password from k8s

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a comment on how to get the password beyond the first run of the playbook


# Seldon Configuration
seldon_mesh_namespace: seldon-mesh

Expand All @@ -9,7 +24,11 @@ seldon_core_v2_type_svc_type: LoadBalancer
seldon_core_v2_scheduler_svc_type: LoadBalancer

# Prometheus Operator Configuration
seldon_monitoring_prometheus_name_generated: seldon-monitoring-prometheus
seldon_monitoring_prometheus_url: "http://{{ seldon_monitoring_prometheus_name_generated }}.{{ seldon_monitoring_namespace }}:9090"
seldon_monitoring_namespace: seldon-monitoring
# Grafana
seldon_monitoring_grafana_web_ui_port: 3000

# Strimzi Kafka Configuration
strimzi_kafka_operator_namespace: "{{ seldon_mesh_namespace }}"
Expand Down
2 changes: 2 additions & 0 deletions ansible/roles/ecosystem/defaults/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ seldon_mesh_namespace: seldon-mesh

# Installation on/off flags
install_prometheus: true
install_grafana: false
install_kafka: true
install_certmanager: true
install_jaeger: true
install_opentelemetry: true

# Configuration on/off flags
configure_prometheus: "{{ install_prometheus }}"
configure_grafana: "{{ install_grafana }}"
enable_kraft: "{{ install_kafka }}"
configure_kafka: "{{ install_kafka }}"
configure_jaeger: "{{ install_jaeger }}"
Expand Down
15 changes: 15 additions & 0 deletions ansible/roles/ecosystem/tasks/grafana.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
- name: Set default user
ansible.builtin.set_fact:
sd_user: "{{ seldon_admin_user }}"
when: sd_user is not defined

- name: Set default password
ansible.builtin.set_fact:
sd_password: "{{ seldon_random_gen_password }}"
when: sd_password is not defined

- name: "Install Grafana instance"
include_role:
name: grafana
when: install_grafana | bool
3 changes: 3 additions & 0 deletions ansible/roles/ecosystem/tasks/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
- name: Install and configure Prometheus Operator
import_tasks: prometheus.yaml

- name: Install and configure Grafana
import_tasks: grafana.yaml

- name: Install and configure Strimzi Kafka
import_tasks: kafka.yaml

Expand Down
7 changes: 7 additions & 0 deletions ansible/roles/grafana/defaults/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
grafana_chart_version: 7.3.9
grafana_app_version: 10.4.2

grafana_preloaded_dashboards:
- name: mms
json: "{{ lookup('file', playbook_dir + '/../../prometheus/dashboards/provisioning/seldon.json') }}"
26 changes: 26 additions & 0 deletions ansible/roles/grafana/tasks/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
- name: Create a k8s namespace
kubernetes.core.k8s:
name: "{{ seldon_monitoring_namespace }}"
api_version: v1
kind: Namespace
state: present

- name: Install Grafana
kubernetes.core.helm:
name: grafana
namespace: "{{ seldon_monitoring_namespace }}"
chart_ref: "grafana"
chart_version: "{{ grafana_chart_version }}"
chart_repo_url: "https://grafana.github.io/helm-charts"
wait: true
values: "{{ lookup('ansible.builtin.template', '../templates/values.yaml.j2') | from_yaml }}"

- name: Grafana config and login details
ansible.builtin.debug:
msg:
- Grafana installed in the cluster.
- To view the webapp, access it via the generated ingress URL, or run
- "kubectl port-forward -n {{ seldon_monitoring_namespace }} svc/grafana {{ seldon_monitoring_grafana_web_ui_port }}:80"
- in a terminal, and visit http://localhost:{{ seldon_monitoring_grafana_web_ui_port }} in your browser.
- Login with {{ sd_user }}/{{ sd_password }}.
68 changes: 68 additions & 0 deletions ansible/roles/grafana/templates/values.yaml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
---
apiVersion: 1

adminUser: "{{ sd_user }}"
adminPassword: "{{ sd_password }}"

grafana.ini:
paths:
data: /var/lib/grafana/
logs: /var/log/grafana
plugins: /var/lib/grafana/plugins
provisioning: /etc/grafana/provisioning
analytics:
check_for_updates: false
log:
mode: console
grafana_net:
url: https://grafana.net
server:
protocol: http
http_port: "{{ seldon_monitoring_grafana_web_ui_port }}"
domain: "''"
serve_from_sub_path: false

persistence:
type: pvc
enabled: true
accessModes:
- ReadWriteOnce
size: 10Gi
finalizers:
- kubernetes.io/pvc-protection
extraPvcLabels: {}

datasources:
datasources.yaml:
apiVersion: 1
datasources:
- name: Prometheus
type: prometheus
url: "{{ seldon_monitoring_prometheus_url }}"
access: proxy
isDefault: true

dashboardProviders:
dashboardproviders.yaml:
apiVersion: 1
providers:
- name: 'default'
orgId: 1
folder: ''
type: file
disableDeletion: false
allowUiUpdates: true
editable: true
options:
path: /var/lib/grafana/dashboards/default

dashboards:
default:
{% for dashboard in grafana_preloaded_dashboards | default([]) -%}
{{ dashboard.name }}:
json: |-
{{ dashboard.json | to_nice_json(indent=2) | indent(8) }}
datasource:
- name: DS_PROMETHEUS
value: Prometheus
{% endfor -%}
Loading