From 1c38aa212ece68be785a35c4b93e91066fa60ea6 Mon Sep 17 00:00:00 2001 From: Ian Fijolek Date: Fri, 29 Jul 2022 13:02:22 -0700 Subject: [PATCH] Add mysql database storage to Grafana --- nomad/databases/mysql.tf | 6 +++ nomad/metrics/grafana.nomad | 85 +++++++++++++++++++++++++++++++++++-- 2 files changed, 87 insertions(+), 4 deletions(-) diff --git a/nomad/databases/mysql.tf b/nomad/databases/mysql.tf index 1fe86c9..591783e 100644 --- a/nomad/databases/mysql.tf +++ b/nomad/databases/mysql.tf @@ -42,6 +42,12 @@ resource "consul_config_entry" "mysql_intents" { Precedence = 9 Type = "consul" }, + { + Action = "allow" + Name = "grafana" + Precedence = 9 + Type = "consul" + }, ] }) } diff --git a/nomad/metrics/grafana.nomad b/nomad/metrics/grafana.nomad index c2f6a9b..c06d302 100644 --- a/nomad/metrics/grafana.nomad +++ b/nomad/metrics/grafana.nomad @@ -38,6 +38,11 @@ job "grafana" { destination_name = "loki" local_bind_port = 3100 } + + upstreams { + destination_name = "mysql-server" + local_bind_port = 6060 + } } } @@ -62,6 +67,70 @@ job "grafana" { ] } + task "grafana-bootstrap" { + driver = "docker" + + lifecycle { + hook = "prestart" + sidecar = false + } + + config { + image = "mysql:8" + args = [ + "/bin/bash", + "-c", + "/usr/bin/mysql --defaults-extra-file=/task/my.cnf < /task/bootstrap.sql", + ] + + mount { + type = "bind" + source = "local/" + target = "/task/" + } + } + + vault { + policies = [ + "access-tables", + "nomad-task", + ] + } + + template { + data = <