Bläddra i källkod

Write graphite tag integration test

Nick Babcock 6 år sedan
förälder
incheckning
433b9186db

+ 17 - 0
OhmGraphite.Test/GraphiteTest.cs

@@ -21,5 +21,22 @@ namespace OhmGraphite.Test
             var content = await resp.Content.ReadAsStringAsync();
             Assert.Contains("ohm.my-pc.intelcpu.0.temperature.cpucore.1", content);
         }
+
+        [Fact, Trait("Category", "integration")]
+        public async void InsertTagGraphiteTest()
+        {
+            var writer = new GraphiteWriter("graphite", 2003, "my-pc", tags: true);
+            await writer.ReportMetrics(DateTime.Now, TestSensorCreator.Values());
+
+            // wait for carbon to sync to disk
+            Thread.Sleep(TimeSpan.FromSeconds(2));
+            var client = new HttpClient();
+            var resp = await client.GetAsync("http://graphite/render?format=csv&target=seriesByTag('sensor_type=Temperature','hardware_type=CPU')");
+            Assert.True(resp.IsSuccessStatusCode);
+            var content = await resp.Content.ReadAsStringAsync();
+            Assert.Contains("host=my-pc", content);
+            Assert.Contains("app=ohm", content);
+            Assert.Contains("sensor_type=Temperature", content);
+        }
     }
 }

+ 2 - 0
ci/Dockerfile.graphite

@@ -0,0 +1,2 @@
+FROM graphiteapp/graphite-statsd
+COPY local_settings.py /opt/graphite/webapp/graphite/

+ 0 - 0
Dockerfile.tests → ci/Dockerfile.tests


+ 1 - 1
Dockerfile.timescale → ci/Dockerfile.timescale

@@ -1,3 +1,3 @@
 FROM timescale/timescaledb:0.12.1-pg10
-COPY assets/setup-docker.sh /docker-entrypoint-initdb.d/.
+COPY ci/setup-docker.sh /docker-entrypoint-initdb.d/.
 COPY assets/schema.sql /sql/schema.sql

+ 16 - 0
ci/local_settings.py

@@ -0,0 +1,16 @@
+TAGDB_REDIS_HOST = 'redis'
+TAGDB_REDIS_PORT = 6379
+TAGDB_REDIS_DB = 0
+
+### FROM GRAPHITE DOCKER
+
+import os
+
+LOG_DIR = '/var/log/graphite'
+SECRET_KEY = '$(date +%s | sha256sum | base64 | head -c 64)'
+
+if (os.getenv("MEMCACHE_HOST") is not None):
+    MEMCACHE_HOSTS = os.getenv("MEMCACHE_HOST").split(",")
+
+if (os.getenv("DEFAULT_CACHE_DURATION") is not None):
+    DEFAULT_CACHE_DURATION = int(os.getenv("CACHE_DURATION"))

+ 0 - 0
assets/setup-docker.sh → ci/setup-docker.sh


+ 0 - 0
assets/wait-for-it.sh → ci/wait-for-it.sh


+ 13 - 4
docker-compose.yml

@@ -1,15 +1,24 @@
 version: '3'
 services:
+  redis:
+    image: redis:alpine
   graphite:
-    image: graphiteapp/graphite-statsd
+    build:
+      dockerfile: Dockerfile.graphite
+      context: ci
+    depends_on:
+      - redis
   timescale:
     build:
-      dockerfile: Dockerfile.timescale
+      dockerfile: ci/Dockerfile.timescale
       context: .
     environment:
       POSTGRES_PASSWORD: 123456
   app:
     build:
-      dockerfile: Dockerfile.tests
+      dockerfile: ci/Dockerfile.tests
       context: .
-    command: ./assets/wait-for-it.sh timescale:5432 -- ./assets/wait-for-it.sh graphite:80 -- mono /root/.nuget/packages/xunit.runner.console/2.4.0/tools/net461/xunit.console.exe OhmGraphite.Test/bin/Debug/net461/OhmGraphite.Test.dll
+    depends_on:
+      - timescale
+      - graphite
+    command: ./ci/wait-for-it.sh timescale:5432 -- ./ci/wait-for-it.sh graphite:80 -- mono /root/.nuget/packages/xunit.runner.console/2.4.0/tools/net461/xunit.console.exe OhmGraphite.Test/bin/Debug/net461/OhmGraphite.Test.dll