Skip to content

Commit

Permalink
Merge pull request #8 from adinhodovic/update-linting
Browse files Browse the repository at this point in the history
style: Update dashboard linter and rules
  • Loading branch information
adinhodovic authored Dec 7, 2023
2 parents 5d361bb + 7d0f10a commit 458b29d
Show file tree
Hide file tree
Showing 12 changed files with 663 additions and 134 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
branches:
- main
env:
golang-version: '1.17'
golang-version: "1.21"
jobs:
generate:
runs-on: ubuntu-latest
Expand Down
31 changes: 27 additions & 4 deletions .lint
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
---
exclusions:
template-job-rule:
panel-job-instance-rule:
target-rate-interval-rule:
panel-datasource-rule:
template-instance-rule:
reason: We don't use instances.
panel-datasource-rule:
reason: Using a datasource for each panel.
panel-title-description-rule:
reason: TODO(adinhodovic)
target-rate-interval-rule:
reason: Intented 2 week range.
entries:
- dashboard: Django / Overview
panel: Cache Hitrate [30m]
- dashboard: Django / Overview
panel: Top Database Errors (1w)
- dashboard: Django / Requests / Overview
panel: Top Templates (1w)
- dashboard: Django / Requests / Overview
panel: Top Responses By View (1w)
- dashboard: Django / Requests / Overview
panel: Top Responses By Type (1w)
- dashboard: Django / Requests / By View
panel: Success Rate (non 4xx-5xx responses) [1w]
- dashboard: Django / Requests / By View
panel: Average Request Latency (P95) [1w]
- dashboard: Django / Requests / By View
panel: Average Request Latency (P50) [1w]
target-instance-rule:
12 changes: 3 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,9 @@ alerts-lint: $(PROMTOOL_BIN) prometheus_alerts.yaml # prometheus_rules.yaml
# @$(PROMTOOL_BIN) check rules prometheus_rules.yaml
@$(PROMTOOL_BIN) check rules prometheus_alerts.yaml

$(OUT_DIR)/.lint: $(OUT_DIR)
@cp .lint $@

.PHONY: dashboards-lint
dashboards-lint: $(GRAFANA_DASHBOARD_LINTER_BIN) $(OUT_DIR)/.lint
# Replace rates var with $$__rate_interval to make dashboard-linter happy.
@sed -i -e 's/1w/$$__rate_interval/g' $(OUT_DIR)/*.json
@find $(OUT_DIR) -name '*.json' -print0 | xargs -n 1 -0 $(GRAFANA_DASHBOARD_LINTER_BIN) lint --strict
dashboards-lint: $(GRAFANA_DASHBOARD_LINTER_BIN)
@find $(OUT_DIR) -name '*.json' -print0 | xargs -n 1 -0 $(GRAFANA_DASHBOARD_LINTER_BIN) lint --strict --config .lint


.PHONY: clean
Expand All @@ -74,5 +69,4 @@ $(BIN_DIR):

$(TOOLING): $(BIN_DIR)
@echo Installing tools from hack/tools.go
@cd scripts && go list -mod=mod -tags tools -f '{{ range .Imports }}{{ printf "%s\n" .}}{{end}}' ./ | xargs -tI % go build -mod=mod -o $(BIN_DIR) %

@cd scripts && go list -e -mod=mod -tags tools -f '{{ range .Imports }}{{ printf "%s\n" .}}{{end}}' ./ | xargs -tI % go build -mod=mod -o $(BIN_DIR) %
16 changes: 10 additions & 6 deletions dashboards/django-overview.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ local tsOverride = tsStandardOptions.override;

// Table
local tbOptions = tablePanel.options;
local tbStandardOptions = tablePanel.standardOptions;
local tbQueryOptions = tablePanel.queryOptions;

{
Expand All @@ -39,7 +40,7 @@ local tbQueryOptions = tablePanel.queryOptions;
'datasource',
'prometheus',
) +
datasource.generalOptions.withLabel('Data Source'),
datasource.generalOptions.withLabel('Data source'),

local namespaceVariable =
query.new(
Expand All @@ -63,8 +64,8 @@ local tbQueryOptions = tablePanel.queryOptions;
query.withDatasourceFromVariable(datasourceVariable) +
query.withSort(1) +
query.generalOptions.withLabel('Job') +
query.selectionOptions.withMulti(false) +
query.selectionOptions.withIncludeAll(false) +
query.selectionOptions.withMulti(true) +
query.selectionOptions.withIncludeAll(true, '.+') +
query.refresh.onLoad() +
query.refresh.onTime(),

Expand All @@ -82,7 +83,7 @@ local tbQueryOptions = tablePanel.queryOptions;
namespace=~"$namespace",
job=~"$job",
view!~"%(djangoIgnoredViews)s",
}[2m]
}[$__rate_interval]
)
), 0.001
)
Expand Down Expand Up @@ -371,7 +372,7 @@ local tbQueryOptions = tablePanel.queryOptions;
max (
django_migrations_applied_total {
namespace="$namespace",
job="$job"
job=~"$job"
}
) by (namespace, job)
||| % $._config,
Expand All @@ -386,6 +387,7 @@ local tbQueryOptions = tablePanel.queryOptions;
migrationsAppliedQuery,
)
) +
stStandardOptions.withUnit('short') +
stOptions.reduceOptions.withCalcs(['lastNotNull']) +
stStandardOptions.thresholds.withSteps([
stStandardOptions.threshold.step.withValue(0) +
Expand All @@ -396,7 +398,7 @@ local tbQueryOptions = tablePanel.queryOptions;
max (
django_migrations_unapplied_total {
namespace="$namespace",
job="$job"
job=~"$job"
}
) by (namespace, job)
||| % $._config,
Expand All @@ -411,6 +413,7 @@ local tbQueryOptions = tablePanel.queryOptions;
migrationsUnAppliedQuery,
)
) +
stStandardOptions.withUnit('short') +
stOptions.reduceOptions.withCalcs(['lastNotNull']) +
stStandardOptions.thresholds.withSteps([
stStandardOptions.threshold.step.withValue(0) +
Expand Down Expand Up @@ -438,6 +441,7 @@ local tbQueryOptions = tablePanel.queryOptions;
tablePanel.new(
'Top Database Errors (1w)',
) +
tbStandardOptions.withUnit('short') +
tbOptions.withSortBy(
tbOptions.sortBy.withDisplayName('Type')
) +
Expand Down
7 changes: 4 additions & 3 deletions dashboards/django-requests-by-view.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ local tsOverride = tsStandardOptions.override;
'datasource',
'prometheus',
) +
datasource.generalOptions.withLabel('Data Source'),
datasource.generalOptions.withLabel('Data source'),

local namespaceVariable =
query.new(
Expand All @@ -58,8 +58,8 @@ local tsOverride = tsStandardOptions.override;
query.withDatasourceFromVariable(datasourceVariable) +
query.withSort(1) +
query.generalOptions.withLabel('Job') +
query.selectionOptions.withMulti(false) +
query.selectionOptions.withIncludeAll(false) +
query.selectionOptions.withMulti(true) +
query.selectionOptions.withIncludeAll(true, '.+') +
query.refresh.onLoad() +
query.refresh.onTime(),

Expand Down Expand Up @@ -166,6 +166,7 @@ local tsOverride = tsStandardOptions.override;
requestHttpExceptionsQuery,
)
) +
stStandardOptions.withUnit('short') +
stOptions.reduceOptions.withCalcs(['lastNotNull']) +
stStandardOptions.thresholds.withSteps([
stStandardOptions.threshold.step.withValue(1) +
Expand Down
8 changes: 4 additions & 4 deletions dashboards/django-requests-overview.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ local tbOverride = tbStandardOptions.override;
'datasource',
'prometheus',
) +
datasource.generalOptions.withLabel('Data Source'),
datasource.generalOptions.withLabel('Data source'),

local namespaceVariable =
query.new(
Expand All @@ -66,8 +66,8 @@ local tbOverride = tbStandardOptions.override;
query.withDatasourceFromVariable(datasourceVariable) +
query.withSort(1) +
query.generalOptions.withLabel('Job') +
query.selectionOptions.withMulti(false) +
query.selectionOptions.withIncludeAll(false) +
query.selectionOptions.withMulti(true) +
query.selectionOptions.withIncludeAll(true, '.+') +
query.refresh.onLoad() +
query.refresh.onTime(),

Expand Down Expand Up @@ -117,7 +117,7 @@ local tbOverride = tbStandardOptions.override;
view=~"$view",
view!~"%(djangoIgnoredViews)s",
method=~"$method"
}[2m]
}[$__rate_interval]
)
), 0.001
)
Expand Down
5 changes: 0 additions & 5 deletions dashboards_out/.lint

This file was deleted.

24 changes: 16 additions & 8 deletions dashboards_out/django-overview.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"type": "prometheus",
"uid": "$datasource"
},
"expr": "round(\n sum(\n rate(\n django_http_requests_total_by_view_transport_method_total{\n namespace=~\"$namespace\",\n job=~\"$job\",\n view!~\"<unnamed view>|health_check:health_check_home|prometheus-django-metrics\",\n }[2m]\n )\n ), 0.001\n)\n"
"expr": "round(\n sum(\n rate(\n django_http_requests_total_by_view_transport_method_total{\n namespace=~\"$namespace\",\n job=~\"$job\",\n view!~\"<unnamed view>|health_check:health_check_home|prometheus-django-metrics\",\n }[$__rate_interval]\n )\n ), 0.001\n)\n"
}
],
"title": "Request Volume",
Expand Down Expand Up @@ -340,7 +340,8 @@
"value": 0
}
]
}
},
"unit": "short"
}
},
"gridPos": {
Expand All @@ -364,7 +365,7 @@
"type": "prometheus",
"uid": "$datasource"
},
"expr": "max (\n django_migrations_applied_total {\n namespace=\"$namespace\",\n job=\"$job\"\n }\n) by (namespace, job)\n"
"expr": "max (\n django_migrations_applied_total {\n namespace=\"$namespace\",\n job=~\"$job\"\n }\n) by (namespace, job)\n"
}
],
"title": "Migrations Applied",
Expand All @@ -388,7 +389,8 @@
"value": 0.10000000000000001
}
]
}
},
"unit": "short"
}
},
"gridPos": {
Expand All @@ -412,7 +414,7 @@
"type": "prometheus",
"uid": "$datasource"
},
"expr": "max (\n django_migrations_unapplied_total {\n namespace=\"$namespace\",\n job=\"$job\"\n }\n) by (namespace, job)\n"
"expr": "max (\n django_migrations_unapplied_total {\n namespace=\"$namespace\",\n job=~\"$job\"\n }\n) by (namespace, job)\n"
}
],
"title": "Migrations Unapplied",
Expand All @@ -423,6 +425,11 @@
"type": "datasource",
"uid": "-- Mixed --"
},
"fieldConfig": {
"defaults": {
"unit": "short"
}
},
"gridPos": {
"h": 9,
"w": 12,
Expand Down Expand Up @@ -686,7 +693,7 @@
"templating": {
"list": [
{
"label": "Data Source",
"label": "Data source",
"name": "datasource",
"query": "prometheus",
"type": "datasource"
Expand All @@ -706,13 +713,14 @@
"type": "query"
},
{
"allValue": ".+",
"datasource": {
"type": "prometheus",
"uid": "${datasource}"
},
"includeAll": false,
"includeAll": true,
"label": "Job",
"multi": false,
"multi": true,
"name": "job",
"query": "label_values(django_http_responses_total_by_status_view_method_total{namespace=~\"$namespace\"}, job)",
"refresh": 2,
Expand Down
10 changes: 6 additions & 4 deletions dashboards_out/django-requests-by-view.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@
"value": 100
}
]
}
},
"unit": "short"
}
},
"gridPos": {
Expand Down Expand Up @@ -596,7 +597,7 @@
"templating": {
"list": [
{
"label": "Data Source",
"label": "Data source",
"name": "datasource",
"query": "prometheus",
"type": "datasource"
Expand All @@ -616,13 +617,14 @@
"type": "query"
},
{
"allValue": ".+",
"datasource": {
"type": "prometheus",
"uid": "${datasource}"
},
"includeAll": false,
"includeAll": true,
"label": "Job",
"multi": false,
"multi": true,
"name": "job",
"query": "label_values(django_http_responses_total_by_status_view_method_total{namespace=~\"$namespace\"}, job)",
"refresh": 2,
Expand Down
9 changes: 5 additions & 4 deletions dashboards_out/django-requests-overview.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"type": "prometheus",
"uid": "$datasource"
},
"expr": "round(\n sum(\n rate(\n django_http_requests_total_by_view_transport_method_total{\n namespace=~\"$namespace\",\n job=~\"$job\",\n view=~\"$view\",\n view!~\"<unnamed view>|health_check:health_check_home|prometheus-django-metrics\",\n method=~\"$method\"\n }[2m]\n )\n ), 0.001\n)\n"
"expr": "round(\n sum(\n rate(\n django_http_requests_total_by_view_transport_method_total{\n namespace=~\"$namespace\",\n job=~\"$job\",\n view=~\"$view\",\n view!~\"<unnamed view>|health_check:health_check_home|prometheus-django-metrics\",\n method=~\"$method\"\n }[$__rate_interval]\n )\n ), 0.001\n)\n"
}
],
"title": "Request Volume",
Expand Down Expand Up @@ -1032,7 +1032,7 @@
"templating": {
"list": [
{
"label": "Data Source",
"label": "Data source",
"name": "datasource",
"query": "prometheus",
"type": "datasource"
Expand All @@ -1052,13 +1052,14 @@
"type": "query"
},
{
"allValue": ".+",
"datasource": {
"type": "prometheus",
"uid": "${datasource}"
},
"includeAll": false,
"includeAll": true,
"label": "Job",
"multi": false,
"multi": true,
"name": "job",
"query": "label_values(django_http_responses_total_by_status_view_method_total{namespace=~\"$namespace\"}, job)",
"refresh": 2,
Expand Down
Loading

0 comments on commit 458b29d

Please sign in to comment.