Skip to content

Commit

Permalink
feat: Migrate to new Grafonnet lib (#15)
Browse files Browse the repository at this point in the history
* feat: Migrate to new Graffonet lib

* feat: progress

* feat: progress

* feat: progress

* style: Lint and fix
  • Loading branch information
adinhodovic committed Feb 15, 2024
1 parent b3e389d commit fbe228a
Show file tree
Hide file tree
Showing 15 changed files with 2,700 additions and 2,250 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---
name: CI
name: ci
on:
push:
branches:
Expand All @@ -8,7 +7,7 @@ on:
branches:
- main
env:
golang-version: '1.17'
golang-version: "1.21"
jobs:
generate:
runs-on: ubuntu-latest
Expand Down
13 changes: 10 additions & 3 deletions .lint
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
---
exclusions:
template-job-rule:
panel-job-instance-rule:
target-rate-interval-rule:
template-job-rule:
reason: Jobs are not set to multi in our case.
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-instance-rule:
6 changes: 2 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ $(OUT_DIR)/.lint: $(OUT_DIR)
.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
@sed -i -e 's/\[$$error_codes\]\.\*/500/g' $(OUT_DIR)/*.json
@find $(OUT_DIR) -name '*.json' -print0 | xargs -n 1 -0 $(GRAFANA_DASHBOARD_LINTER_BIN) lint --strict
@find $(OUT_DIR) -name '*.json' -print0 | xargs -n 1 -0 $(GRAFANA_DASHBOARD_LINTER_BIN) lint --strict --config .lint


.PHONY: clean
Expand All @@ -75,5 +73,5 @@ $(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) %

4 changes: 2 additions & 2 deletions alerts/alerts.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
annotations: {
summary: 'Nginx high HTTP 4xx error rate.',
description: 'More than %(ingressNginx4xxThreshold)s%% HTTP requests with status 4xx for {{ $labels.exported_namespace }}/{{ $labels.ingress }} the past %(ingressNginx4xxInterval)s.' % $._config,
dashboard_url: $._config.dashboardUrl,
dashboard_url: $._config.overviewDashboardUrl + '?var-exported_namespace={{ $labels.exported_namespace }}&var-ingress={{ $labels.ingress }}',
},
},
{
Expand All @@ -28,7 +28,7 @@
annotations: {
summary: 'Nginx high HTTP 5xx error rate.',
description: 'More than %(ingressNginx5xxThreshold)s%% HTTP requests with status 5xx for {{ $labels.exported_namespace }}/{{ $labels.ingress }} the past %(ingressNginx5xxInterval)s.' % $._config,
dashboard_url: $._config.dashboardUrl,
dashboard_url: $._config.overviewDashboardUrl + '?var-exported_namespace={{ $labels.exported_namespace }}&var-ingress={{ $labels.ingress }}',
},
labels: {
severity: $._config.ingressNginx5xxSeverity,
Expand Down
48 changes: 42 additions & 6 deletions config.libsonnet
Original file line number Diff line number Diff line change
@@ -1,19 +1,55 @@
local g = import 'github.com/grafana/grafonnet/gen/grafonnet-latest/main.libsonnet';
local annotation = g.dashboard.annotation;

{
_config+:: {
// Bypasses grafana.com/dashboards validator
bypassDashboardValidation: {
__inputs: [],
__requires: [],
},

// Selectors are inserted between {} in Prometheus queries.
ingressNginxSelector: 'job="ingress-nginx-controller-metrics"',
ingressNginxSelector: 'job=~"ingress-nginx-controller-metrics"',

grafanaUrl: 'https://grafana.com',
overviewDashboardUid: 'ingress-nginx-overview-12mk4klgjweg',
dashboardLabelQueryParams: 'var-exported_namespace={{ $labels.exported_namespace }}&var-ingress={{ $labels.ingress }}',
dashboardUrl: '%s/d/%s/nginx-ingress-controller?%s' % [self.grafanaUrl, self.overviewDashboardUid, self.dashboardLabelQueryParams],
requestHandlingPerformanceDashboardUid: 'ingress-nginx-request-jqkwfdqwd',
tags: ['nginx', 'ingress-nginx'],

overviewDashboardUid: 'ingress-nginx-overview-12mk',
requestHandlingPerformanceDashboardUid: 'ingress-nginx-request-handling-jqkw',

overviewDashboardUrl: '%s/d/%s/ingress-nginx-overview' % [self.grafanaUrl, self.overviewDashboardUid],
requestHandlingPerformanceDashboardUrl: '%s/d/%s/fix tis' % [
self.grafanaUrl,
self.requestHandlingPerformanceDashboardUid,
], // TODO: fix this

tags: ['ingress-nginx', 'ingress-nginx-mixin'],

ignoredIngresses: '',
ingressNginx4xxSeverity: 'info',
ingressNginx4xxInterval: '5m',
ingressNginx4xxThreshold: '5', // percent
ingressNginx5xxSeverity: 'warning',
ingressNginx5xxInterval: '5m',
ingressNginx5xxThreshold: '5', // percent

// Custom annotations to display in graphs
annotation: {
enabled: false,
name: 'Custom Annotation',
datasource: '-- Grafana --',
iconColor: 'green',
tags: [],
},

customAnnotation:: if $._config.annotation.enabled then
annotation.withName($._config.annotation.name) +
annotation.withIconColor($._config.annotation.iconColor) +
annotation.withHide(false) +
annotation.datasource.withUid($._config.annotation.datasource) +
annotation.target.withMatchAny(true) +
annotation.target.withTags($._config.annotation.tags) +
annotation.target.withType('tags')
else {},
},
}
Loading

0 comments on commit fbe228a

Please sign in to comment.