Skip to content

Commit 38af08e

Browse files
authored
fix(k8s): Migrate Grafana dashboards (#2638)
Just like #2634, #2621 and #2628 but this time completely untested.
1 parent f128789 commit 38af08e

File tree

4 files changed

+15
-32
lines changed

4 files changed

+15
-32
lines changed

plugins/source/k8s/dashboards/grafana/asset_inventory.json

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@
123123
"group": [],
124124
"metricColumn": "none",
125125
"rawQuery": true,
126-
"rawSql": "select count(*) from k8s_resources where context in (${contexts}) and cq_table in (${cq_tables}) ;",
126+
"rawSql": "select count(*) from k8s_resources where context in (${contexts}) and _cq_table in (${cq_tables}) ;",
127127
"refId": "A"
128128
}
129129
],
@@ -183,7 +183,7 @@
183183
"group": [],
184184
"metricColumn": "none",
185185
"rawQuery": true,
186-
"rawSql": "select context, count(*) from k8s_resources where cq_table in (${cq_tables}) group by context order by count desc;",
186+
"rawSql": "select context, count(*) from k8s_resources where _cq_table in (${cq_tables}) group by context order by count desc;",
187187
"refId": "A"
188188
}
189189
],
@@ -219,19 +219,7 @@
219219
{
220220
"matcher": {
221221
"id": "byName",
222-
"options": "cq_meta"
223-
},
224-
"properties": [
225-
{
226-
"id": "custom.width",
227-
"value": 392
228-
}
229-
]
230-
},
231-
{
232-
"matcher": {
233-
"id": "byName",
234-
"options": "cq_table"
222+
"options": "_cq_table"
235223
},
236224
"properties": [
237225
{
@@ -255,7 +243,7 @@
255243
{
256244
"matcher": {
257245
"id": "byName",
258-
"options": "fetch_date"
246+
"options": "_cq_sync_time"
259247
},
260248
"properties": [
261249
{
@@ -267,7 +255,7 @@
267255
{
268256
"matcher": {
269257
"id": "byName",
270-
"options": "cq_id"
258+
"options": "_cq_id"
271259
},
272260
"properties": [
273261
{
@@ -307,7 +295,7 @@
307295
"group": [],
308296
"metricColumn": "none",
309297
"rawQuery": true,
310-
"rawSql": "select cq_id, cq_table, context, uid, fetch_date from k8s_resources where context in (${contexts}) and cq_table in (${cq_tables}) ;",
298+
"rawSql": "select _cq_id, _cq_table, context, uid, _cq_sync_time from k8s_resources where context in (${contexts}) and _cq_table in (${cq_tables}) ;",
311299
"refId": "A",
312300
"select": [
313301
[
@@ -380,7 +368,7 @@
380368
"group": [],
381369
"metricColumn": "none",
382370
"rawQuery": true,
383-
"rawSql": "select cq_table, count(*) from k8s_resources where context in (${contexts}) group by cq_table order by count desc;",
371+
"rawSql": "select _cq_table, count(*) from k8s_resources where context in (${contexts}) group by _cq_table order by count desc;",
384372
"refId": "A"
385373
}
386374
],
@@ -414,13 +402,13 @@
414402
},
415403
{
416404
"current": {},
417-
"definition": "select distinct(cq_table) from k8s_resources;",
405+
"definition": "select distinct(_cq_table) from k8s_resources;",
418406
"hide": 0,
419407
"includeAll": true,
420408
"multi": true,
421409
"name": "cq_tables",
422410
"options": [],
423-
"query": "select distinct(cq_table) from k8s_resources;",
411+
"query": "select distinct(_cq_table) from k8s_resources;",
424412
"refresh": 1,
425413
"regex": "",
426414
"skipUrlSync": false,

plugins/source/k8s/dashboards/grafana/compliance.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@
200200
"type": "postgres",
201201
"uid": "${DS_POSTGRESQL}"
202202
},
203-
"description": "Time since the most recent CloudQuery fetch happened.",
203+
"description": "Time since the most recent CloudQuery sync happened.",
204204
"fieldConfig": {
205205
"defaults": {
206206
"color": {
@@ -254,11 +254,11 @@
254254
"group": [],
255255
"metricColumn": "none",
256256
"rawQuery": true,
257-
"rawSql": "SELECT (cq_meta::JSONB->>'last_updated')::TIMESTAMP WITH TIME ZONE AS time, 1 FROM k8s_core_pods ORDER BY time DESC LIMIT 1;",
257+
"rawSql": "SELECT _cq_sync_time AS time, 1 FROM k8s_core_pods ORDER BY time DESC LIMIT 1;",
258258
"refId": "A"
259259
}
260260
],
261-
"title": "Last Fetch",
261+
"title": "Last Sync",
262262
"type": "stat"
263263
},
264264
{

plugins/source/k8s/views/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ This directory contains useful aggregated views that you can create against the
44

55
Those views are also tests in CI to make sure it works with the latest schema.
66

7-
For dashboard examples that reuse those views take a look at [https://github.com/cloudquery/dashboards](https://github.com/cloudquery/dashboards).
7+
For dashboard examples that reuse those views take a look at [../dashboards](../dashboards).

plugins/source/k8s/views/resource.sql

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,10 @@ BEGIN
1919
strSQL = strSQL || ' UNION ALL ';
2020
END IF;
2121
-- create an SQL query to select from table and transform it into our resources view schema
22-
strSQL = strSQL || format('SELECT cq_id, cq_meta, %L AS cq_table, context, uid,
23-
COALESCE(%s, (cq_meta->>''last_updated'')::timestamp) AS fetch_date
24-
FROM %s',
25-
tbl,
26-
CASE WHEN EXISTS (SELECT 1 FROM information_schema.columns WHERE column_name='fetch_date' AND table_name=tbl) THEN 'fetch_date' ELSE 'NULL::timestamp' END,
27-
tbl);
22+
strSQL = strSQL || format('SELECT _cq_id, _cq_source_name, _cq_sync_time, %L AS cq_table, context, uid FROM %s', tbl, tbl);
2823
END LOOP;
2924
IF strSQL = ''::TEXT THEN
30-
RAISE EXCEPTION 'No tables found with UID and CONTEXT columns. Run a fetch first and try again.';
25+
RAISE EXCEPTION 'No tables found with UID and CONTEXT columns. Run a sync first and try again.';
3126
ELSE
3227
EXECUTE FORMAT('CREATE VIEW k8s_resources AS (%s)', strSQL);
3328
END IF;

0 commit comments

Comments
 (0)