Skip to content

Allow for HA/custom database configuration within gitlab.rb

DanielP requested to merge feature-custom-database into master

What does this MR do?

This change will allow customers to configure their own database for Grafana within the gitlab.rb. This will also allow customers that choose to configure an HA GitLab setup to leverage an existing database for Grafana. This will also allow the customer to use an existing application node rather then needing to create a separate monitoring node as long as they move the database somewhere else like a cloud providers database solution(ex: AWS RDS)

How was this tested?

This was tested with a customer by following the following steps:

Grafana on GitLab Multi-node setup

By default GitLab Grafana does not work (unable to login) on multi-node architecture. This is mainly due to that fact that each node uses its own grafana datastore. We are going to use existing GitLab postgresql RDS instance with a dedicated database for grafana. WIP:

Prerequisites

  • Postgres instance
  • Two or more GitLab app instances

Configure Databse

Login to Postgres database with your dba credentials and create the grafana database and user.

CREATE DATABASE grafanadb;
CREATE USER grafana WITH encrypted PASSWORD 'password';
GRANT ALL PRIVILEGES ON DATABASE grafanadb TO grafana;

Configure grafana template on all GitLab Nodes

Gitlab does not support the grafana [database] parameter out of the box. You will need to modify the following gem to enable grafana database parameters with gitlab.rb.

  • Create a backup of this file first before modifying

/opt/gitlab/embedded/cookbooks/monitoring/templates/grafana_ini.erb

<% if !@db_type.nil? && !@db_database.nil? -%>
type = <%=@db_type%>
host = <%=@db_host%>:<%=@db_port%>
name = <%=@db_database%>
user = <%=@db_username%>
password = """<%=@db_password%>"""
<% end -%>

Configure GitLab Nodes

Add grafana db parameters to gitlab.rb

/etc/gtilab/gitlab.rb

grafana['db_type'] = "postgres"
grafana['db_database'] = "grafanadb"
grafana['db_username'] = "grafana"
grafana['db_password'] = "password"
grafana['db_host'] = "hostname.example.com"
grafana['db_port'] = 5432

End result

Run gitlab-ctl reconfigure Check that grafana.in to see if database parameters got mapped correctly by Omnibus.

/var/opt/gitlab/grafana/grafana.ini

type = postgres
host = hostname.example.com:5432
name = grafanadb
user = grafana
password = """password"""

The customer was able to round robin between multiple application nodes and connect to Grafana without needing to setup a dedicated monitoring node. After this change has been made, I can update the documentation with instructions on doing this.

Related issues

Checklist

See Definition of done.

For anything in this list which will not be completed, please provide a reason in the MR discussion

Required

  • Merge Request Title, and Description are up to date, accurate, and descriptive
  • MR targeting the appropriate branch
  • MR has a green pipeline on GitLab.com
  • Pipeline is green on dev.gitlab.org if the change is touching anything besides documentation or internal cookbooks
  • trigger-package has a green pipeline running against latest commit

Expected (please provide an explanation if not completing)

  • Test plan indicating conditions for success has been posted and passes
  • Documentation created/updated
  • Tests added
  • Integration tests added to GitLab QA
  • Equivalent MR/issue for the GitLab Chart opened

Merge request reports