Skip to content

Commit

Permalink
Mixins: Align schema with other mixins (thanos-io#2619)
Browse files Browse the repository at this point in the history
* mixin/thanos: align mixin schema with other mixins

- promote default.libsonnet to main config file
- include config.libsonnet in mixin.libsonnet
- include jsonnetfile.json
- allow generating directly from mixin/thanos directory

Signed-off-by: paulfantom <[email protected]>

* mixin: move one directory higher

Signed-off-by: paulfantom <[email protected]>
  • Loading branch information
paulfantom authored May 18, 2020
1 parent 334a41b commit 11c75ae
Show file tree
Hide file tree
Showing 43 changed files with 32 additions and 52 deletions.
13 changes: 6 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ PROMTOOL ?= $(GOBIN)/promtool-$(PROMTOOL_VERSION)
# systems gsed won't be installed, so will use sed as expected.
SED ?= $(shell which gsed 2>/dev/null || which sed)

MIXIN_ROOT ?= mixin
THANOS_MIXIN ?= mixin/thanos
THANOS_MIXIN ?= mixin
JSONNET_VENDOR_DIR ?= mixin/vendor

WEB_DIR ?= website
Expand Down Expand Up @@ -404,20 +403,20 @@ examples/tmp:
$(JSONNET) -J ${JSONNET_VENDOR_DIR} -m examples/tmp/ ${THANOS_MIXIN}/separated_alerts.jsonnet | xargs -I{} sh -c 'cat {} | $(GOJSONTOYAML) > {}.yaml; rm -f {}' -- {}

.PHONY: examples/dashboards # to keep examples/dashboards/dashboards.md.
examples/dashboards: $(JSONNET) ${THANOS_MIXIN}/mixin.libsonnet ${THANOS_MIXIN}/defaults.libsonnet ${THANOS_MIXIN}/dashboards/*
examples/dashboards: $(JSONNET) ${THANOS_MIXIN}/mixin.libsonnet ${THANOS_MIXIN}/config.libsonnet ${THANOS_MIXIN}/dashboards/*
-rm -rf examples/dashboards/*.json
$(JSONNET) -J ${JSONNET_VENDOR_DIR} -m examples/dashboards ${THANOS_MIXIN}/dashboards.jsonnet

examples/alerts/alerts.yaml: $(JSONNET) $(GOJSONTOYAML) ${THANOS_MIXIN}/mixin.libsonnet ${THANOS_MIXIN}/defaults.libsonnet ${THANOS_MIXIN}/alerts/*
examples/alerts/alerts.yaml: $(JSONNET) $(GOJSONTOYAML) ${THANOS_MIXIN}/mixin.libsonnet ${THANOS_MIXIN}/config.libsonnet ${THANOS_MIXIN}/alerts/*
$(JSONNET) ${THANOS_MIXIN}/alerts.jsonnet | $(GOJSONTOYAML) > $@

examples/alerts/rules.yaml: $(JSONNET) $(GOJSONTOYAML) ${THANOS_MIXIN}/mixin.libsonnet ${THANOS_MIXIN}/defaults.libsonnet ${THANOS_MIXIN}/rules/*
examples/alerts/rules.yaml: $(JSONNET) $(GOJSONTOYAML) ${THANOS_MIXIN}/mixin.libsonnet ${THANOS_MIXIN}/config.libsonnet ${THANOS_MIXIN}/rules/*
$(JSONNET) ${THANOS_MIXIN}/rules.jsonnet | $(GOJSONTOYAML) > $@

.PHONY: jsonnet-vendor
jsonnet-vendor: $(JSONNET_BUNDLER) $(MIXIN_ROOT)/jsonnetfile.json $(MIXIN_ROOT)/jsonnetfile.lock.json
jsonnet-vendor: $(JSONNET_BUNDLER) $(THANOS_MIXIN)/jsonnetfile.json $(THANOS_MIXIN)/jsonnetfile.lock.json
rm -rf ${JSONNET_VENDOR_DIR}
cd ${MIXIN_ROOT} && $(JSONNET_BUNDLER) install
cd ${THANOS_MIXIN} && $(JSONNET_BUNDLER) install

JSONNETFMT_CMD := $(JSONNETFMT) -n 2 --max-blank-lines 2 --string-style s --comment-style s

Expand Down
4 changes: 2 additions & 2 deletions mixin/thanos/README.md → mixin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ $ jb update

#### Configure

This project is intended to be used as a library. You can extend and customize dashboards and alerting rules by creating for own generators, such as the generators ([alerts.jsonnet](alerts.jsonnet) and [dashboards.jsonnet](dashboards.jsonnet)) that are use to create [examples](../../examples). Default parameters are collected in [defaults.libsonnet](defaults.libsonnet), feel free to modify and generate your own definitons.
This project is intended to be used as a library. You can extend and customize dashboards and alerting rules by creating for own generators, such as the generators ([alerts.jsonnet](alerts.jsonnet) and [dashboards.jsonnet](dashboards.jsonnet)) that are use to create [examples](../../examples). Default parameters are collected in [config.libsonnet](config.libsonnet), feel free to modify and generate your own definitons.

[embedmd]:# (defaults.libsonnet)
[embedmd]:# (config.libsonnet)
```libsonnet
{
query+:: {
Expand Down
3 changes: 3 additions & 0 deletions mixin/alerts.jsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(
import 'mixin.libsonnet'
).prometheusAlerts
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
9 changes: 9 additions & 0 deletions mixin/dashboards.jsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
local dashboards =
(
import 'mixin.libsonnet'
).grafanaDashboards;

{
[name]: dashboards[name]
for name in std.objectFields(dashboards)
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
9 changes: 0 additions & 9 deletions mixin/jsonnetfile.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,6 @@
}
},
"version": "master"
},
{
"source": {
"local": {
"directory": "thanos"
}
},
"version": ".",
"name": "thanos-mixin"
}
],
"legacyImports": true
Expand Down
9 changes: 0 additions & 9 deletions mixin/jsonnetfile.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,6 @@
},
"version": "f4c59f64f80442f871a06c91edf74d014b82acaf",
"sum": "ELsYwK+kGdzX1mee2Yy+/b2mdO4Y503BOCDkFzwmGbE="
},
{
"source": {
"local": {
"directory": "thanos"
}
},
"version": "",
"name": "thanos-mixin"
}
],
"legacyImports": false
Expand Down
File renamed without changes.
3 changes: 2 additions & 1 deletion mixin/thanos/mixin.libsonnet → mixin/mixin.libsonnet
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
(import 'dashboards/dashboards.libsonnet') +
(import 'alerts/alerts.libsonnet') +
(import 'rules/rules.libsonnet')
(import 'rules/rules.libsonnet') +
(import 'config.libsonnet')
3 changes: 3 additions & 0 deletions mixin/rules.jsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(
import 'mixin.libsonnet'
).prometheusRules
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
7 changes: 7 additions & 0 deletions mixin/separated_alerts.jsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
[group.name]: group
for group in
(
import 'mixin.libsonnet'
).prometheusAlerts.groups
}
4 changes: 0 additions & 4 deletions mixin/thanos/alerts.jsonnet

This file was deleted.

9 changes: 0 additions & 9 deletions mixin/thanos/dashboards.jsonnet

This file was deleted.

4 changes: 0 additions & 4 deletions mixin/thanos/rules.jsonnet

This file was deleted.

7 changes: 0 additions & 7 deletions mixin/thanos/separated_alerts.jsonnet

This file was deleted.

0 comments on commit 11c75ae

Please sign in to comment.