From b13cb6bdbc2467beb18a21fb22900baa49885ae7 Mon Sep 17 00:00:00 2001
From: Dmitry Paramonov <asmatic075@gmail.com>
Date: Thu, 10 Oct 2024 10:28:04 +0300
Subject: [PATCH] fix: Set up grafana datasource and apply small fixes

---
 grafana/docker-compose.yml                            |  1 +
 grafana/grafana_data/.gitkeep                         |  0
 grafana/provisioning/datasources/datasource.yml       |  9 +++++++++
 prometheus/{prometheus_data => config}/prometheus.yml |  9 ++-------
 prometheus/docker-compose.yml                         | 10 ++++++----
 5 files changed, 18 insertions(+), 11 deletions(-)
 delete mode 100644 grafana/grafana_data/.gitkeep
 create mode 100644 grafana/provisioning/datasources/datasource.yml
 rename prometheus/{prometheus_data => config}/prometheus.yml (69%)

diff --git a/grafana/docker-compose.yml b/grafana/docker-compose.yml
index 62976cc6b..86723774c 100644
--- a/grafana/docker-compose.yml
+++ b/grafana/docker-compose.yml
@@ -11,6 +11,7 @@ services:
       - 3000:3000
     volumes:
       - grafana_data:/var/lib/grafana
+      - ./provisioning:/etc/grafana/provisioning
     profiles:
       - multi-tenant
 
diff --git a/grafana/grafana_data/.gitkeep b/grafana/grafana_data/.gitkeep
deleted file mode 100644
index e69de29bb..000000000
diff --git a/grafana/provisioning/datasources/datasource.yml b/grafana/provisioning/datasources/datasource.yml
new file mode 100644
index 000000000..8341f7670
--- /dev/null
+++ b/grafana/provisioning/datasources/datasource.yml
@@ -0,0 +1,9 @@
+datasources:
+-  access: 'proxy'
+   editable: true
+   is_default: true
+   name: 'agents-api'
+   org_id: 1
+   type: 'prometheus'
+   url: 'http://prometheus:9090'
+   version: 1           
diff --git a/prometheus/prometheus_data/prometheus.yml b/prometheus/config/prometheus.yml
similarity index 69%
rename from prometheus/prometheus_data/prometheus.yml
rename to prometheus/config/prometheus.yml
index a2d6194c0..e556a2c53 100644
--- a/prometheus/prometheus_data/prometheus.yml
+++ b/prometheus/config/prometheus.yml
@@ -12,7 +12,7 @@ alerting:
     static_configs:
     - targets: []
 scrape_configs:
-- job_name: prometheus
+- job_name: agents-api
   honor_timestamps: true
   scrape_interval: 15s
   scrape_timeout: 10s
@@ -21,9 +21,4 @@ scrape_configs:
   follow_redirects: true
   static_configs:
   - targets:
-    - localhost:9090
-- job_name: 'fastapi'
-  scrape_interval: 10s
-  metrics_path: /metrics
-  static_configs:
-    - targets: ['http://agents-api-multi-tenant:8080']
+    - agents-api-multi-tenant:8080
diff --git a/prometheus/docker-compose.yml b/prometheus/docker-compose.yml
index f12462785..f3c53d966 100644
--- a/prometheus/docker-compose.yml
+++ b/prometheus/docker-compose.yml
@@ -6,12 +6,10 @@ services:
     container_name: prometheus
     profiles:
       - multi-tenant
-    
-    ports:
-      - 11000:9090
 
     volumes:
-      - ./prometheus_data/prometheus.yml:/etc/prometheus/prometheus.yml
+      - ./config/prometheus.yml:/etc/prometheus/prometheus.yml
+      - prometheus_data:/prometheus
     
     depends_on:
       agents-api-multi-tenant:
@@ -19,3 +17,7 @@ services:
     
     command:
       - '--config.file=/etc/prometheus/prometheus.yml'
+
+volumes:
+  prometheus_data:
+    external: true