Skip to content

Commit

Permalink
Merge pull request #80 from qclaogui:mixin-multiple-mode
Browse files Browse the repository at this point in the history
Issue-76: Monitoring Mixins support for multiple modes
  • Loading branch information
qclaogui authored Mar 30, 2024
2 parents e6ae98a + 7e138a9 commit b3ef824
Show file tree
Hide file tree
Showing 21 changed files with 2,680 additions and 2,609 deletions.
32 changes: 24 additions & 8 deletions monitoring-mixins/agent-flow-mixin/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,25 @@ fmt: ## Format the mixin files
update: $(JB) ## update mixin
$(JB) update

define build_mixin_func
$(eval $@_MIXIN_OUTPUT = $(1))
@mkdir -p "${$@_MIXIN_OUTPUT}"; \
find "${$@_MIXIN_OUTPUT}" ! -name "kustomization.yaml" ! -name "prometheus-alerts.yaml" ! -name "prometheus-rules.yaml" -type f -delete
@$(MIXTOOL) generate all --output-alerts "${$@_MIXIN_OUTPUT}/alerts.yaml" --output-rules "${$@_MIXIN_OUTPUT}/rules.yaml" --directory "${$@_MIXIN_OUTPUT}/dashboards_out" "${$@_MIXIN_OUTPUT}.libsonnet"
# @../../tools/check-rules.sh "${$@_MIXIN_OUTPUT}/rules.yaml" 20
@mv ${$@_MIXIN_OUTPUT}/alerts.yaml ${$@_MIXIN_OUTPUT}/${CURRENT_DIR}-alerts.yaml
@mv ${$@_MIXIN_OUTPUT}/rules.yaml ${$@_MIXIN_OUTPUT}/${CURRENT_DIR}-rules.yaml
endef


.PHONY: build
build: $(MIXTOOL) ## Generates the mixin files
@mkdir -p "$(MIXIN_OUT_PATH)"; \
find "$(MIXIN_OUT_PATH)" ! -name "kustomization.yaml" ! -name "prometheus-alerts.yaml" ! -name "prometheus-rules.yaml" -type f -delete
@$(MIXTOOL) generate all --output-alerts "$(MIXIN_OUT_PATH)/alerts.yaml" --output-rules "$(MIXIN_OUT_PATH)/rules.yaml" --directory "$(MIXIN_OUT_PATH)/dashboards_out" "mixin.libsonnet"
# @../../tools/check-rules.sh "$(MIXIN_OUT_PATH)/rules.yaml" 20
@mv $(MIXIN_OUT_PATH)/alerts.yaml $(MIXIN_OUT_PATH)/${CURRENT_DIR}-alerts.yaml
@mv $(MIXIN_OUT_PATH)/rules.yaml $(MIXIN_OUT_PATH)/${CURRENT_DIR}-rules.yaml
$(foreach mixin,$(MIXIN_OUT_PATH),$(call build_mixin_func, $(mixin)))

.PHONY: check
check: $(MIXTOOL) build fmt manifests ## Build, fmt and check the mixin files
check: $(MIXTOOL) build fmt ## Build, fmt and check the mixin files
@../../tools/find-diff-or-untracked.sh . "$(MIXIN_OUT_PATH)" || (echo "Please build and fmt mixin by running 'make build fmt'" && false); \
# $(JB) install && \
# jb install && \
# $(MIXTOOL) lint mixin.libsonnet

##@ Dashboards & k8s
Expand All @@ -38,6 +44,16 @@ check: $(MIXTOOL) build fmt manifests ## Build, fmt and check the mixin files
manifests: $(KUSTOMIZE) build ## Generates dashboards for k8s
$(KUSTOMIZE) build deploy > deploy/manifests/k8s-all-in-one.yaml

# NOTE: dashboards_out has been deprecated, please use build instead
dashboards_out:
@mkdir -p deploy/dashboards_out deploy/manifests
jsonnet -J vendor -e '(import "mixin.libsonnet").grafanaDashboards' -m deploy/dashboards_out

prom_alerts.yaml:
jsonnet -J vendor -S -e 'std.manifestYamlDoc((import "mixin.libsonnet").prometheusAlerts)' > deploy/$@

prom_rules.yaml:
jsonnet -J vendor -S -e 'std.manifestYamlDoc((import "mixin.libsonnet").prometheusRules)' > deploy/$@

##@ General

Expand Down
4 changes: 4 additions & 0 deletions monitoring-mixins/agent-flow-mixin/deploy.libsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(import 'mixin.libsonnet') + {
// Config overrides
prometheusRules: {},
}
6 changes: 1 addition & 5 deletions monitoring-mixins/agent-flow-mixin/mixin.libsonnet
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
local mixin = import 'agent-flow-mixin/mixin.libsonnet';

mixin {
prometheusRules: {},
}
import 'agent-flow-mixin/mixin.libsonnet'
39 changes: 27 additions & 12 deletions monitoring-mixins/go-runtime-mixin/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,27 @@ CURRENT_DIR = $(notdir $(shell pwd))
fmt: ## Format the mixin files
@find . -type f -name '*.libsonnet' | xargs -n 1 -- $(JSONNET_FMT) -i

.PHONY: update
update: $(JB) ## update mixin
$(JB) update

define build_mixin_func
$(eval $@_MIXIN_OUTPUT = $(1))
@mkdir -p "${$@_MIXIN_OUTPUT}"; \
find "${$@_MIXIN_OUTPUT}" ! -name "kustomization.yaml" ! -name "prometheus-alerts.yaml" ! -name "prometheus-rules.yaml" -type f -delete
@$(MIXTOOL) generate all --output-alerts "${$@_MIXIN_OUTPUT}/alerts.yaml" --output-rules "${$@_MIXIN_OUTPUT}/rules.yaml" --directory "${$@_MIXIN_OUTPUT}/dashboards_out" "${$@_MIXIN_OUTPUT}.libsonnet"
# @../../tools/check-rules.sh "${$@_MIXIN_OUTPUT}/rules.yaml" 20
@mv ${$@_MIXIN_OUTPUT}/alerts.yaml ${$@_MIXIN_OUTPUT}/${CURRENT_DIR}-alerts.yaml
@mv ${$@_MIXIN_OUTPUT}/rules.yaml ${$@_MIXIN_OUTPUT}/${CURRENT_DIR}-rules.yaml
endef


.PHONY: build
build: $(MIXTOOL) ## Generates the mixin files
@mkdir -p "$(MIXIN_OUT_PATH)"; \
find "$(MIXIN_OUT_PATH)" ! -name "kustomization.yaml" ! -name "prometheus-alerts.yaml" ! -name "prometheus-rules.yaml" -type f -delete
@$(MIXTOOL) generate all --output-alerts "$(MIXIN_OUT_PATH)/alerts.yaml" --output-rules "$(MIXIN_OUT_PATH)/rules.yaml" --directory "$(MIXIN_OUT_PATH)/dashboards_out" "mixin.libsonnet"
# @../../tools/check-rules.sh "$(MIXIN_OUT_PATH)/rules.yaml" 20
@mv $(MIXIN_OUT_PATH)/alerts.yaml $(MIXIN_OUT_PATH)/${CURRENT_DIR}-alerts.yaml
@mv $(MIXIN_OUT_PATH)/rules.yaml $(MIXIN_OUT_PATH)/${CURRENT_DIR}-rules.yaml
$(foreach mixin,$(MIXIN_OUT_PATH),$(call build_mixin_func, $(mixin)))

.PHONY: check
check: build fmt manifests## Build, fmt and check the mixin files
check: $(MIXTOOL) build fmt ## Build, fmt and check the mixin files
@../../tools/find-diff-or-untracked.sh . "$(MIXIN_OUT_PATH)" || (echo "Please build and fmt mixin by running 'make build fmt'" && false); \
# jb install && \
# $(MIXTOOL) lint mixin.libsonnet
Expand All @@ -34,11 +44,16 @@ check: build fmt manifests## Build, fmt and check the mixin files
manifests: $(KUSTOMIZE) build ## Generates dashboards for k8s
$(KUSTOMIZE) build deploy > deploy/manifests/k8s-all-in-one.yaml

rules_load: ## Load rules and alerts to monitoring system
mimirtool rules load --id=anonymous --address=http://localhost:9009 deploy/rules.yaml
mimirtool rules load --id=anonymous --address=http://localhost:9009 deploy/alerts.yaml
mimirtool alertmanager --id=anonymous --address=http://localhost:9009 load deploy/alertmanager.yaml deploy/default.tmpl
mimirtool alertmanager --id=anonymous --address=http://localhost:9009 get
# NOTE: dashboards_out has been deprecated, please use build instead
dashboards_out:
@mkdir -p deploy/dashboards_out deploy/manifests
jsonnet -J vendor -e '(import "mixin.libsonnet").grafanaDashboards' -m deploy/dashboards_out

prom_alerts.yaml:
jsonnet -J vendor -S -e 'std.manifestYamlDoc((import "mixin.libsonnet").prometheusAlerts)' > deploy/$@

prom_rules.yaml:
jsonnet -J vendor -S -e 'std.manifestYamlDoc((import "mixin.libsonnet").prometheusRules)' > deploy/$@

##@ General

Expand Down
3 changes: 3 additions & 0 deletions monitoring-mixins/go-runtime-mixin/deploy.libsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(import 'mixin.libsonnet') + {
// Config overrides
}
37 changes: 23 additions & 14 deletions monitoring-mixins/kubernetes-mixin/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,25 @@ fmt: ## Format the mixin files
update: $(JB) ## update mixin
$(JB) update

define build_mixin_func
$(eval $@_MIXIN_OUTPUT = $(1))
@mkdir -p "${$@_MIXIN_OUTPUT}"; \
find "${$@_MIXIN_OUTPUT}" ! -name "kustomization.yaml" ! -name "prometheus-alerts.yaml" ! -name "prometheus-rules.yaml" -type f -delete
@$(MIXTOOL) generate all --output-alerts "${$@_MIXIN_OUTPUT}/alerts.yaml" --output-rules "${$@_MIXIN_OUTPUT}/rules.yaml" --directory "${$@_MIXIN_OUTPUT}/dashboards_out" "${$@_MIXIN_OUTPUT}.libsonnet"
@../../tools/check-rules.sh "${$@_MIXIN_OUTPUT}/rules.yaml" 20
@mv ${$@_MIXIN_OUTPUT}/alerts.yaml ${$@_MIXIN_OUTPUT}/${CURRENT_DIR}-alerts.yaml
@mv ${$@_MIXIN_OUTPUT}/rules.yaml ${$@_MIXIN_OUTPUT}/${CURRENT_DIR}-rules.yaml
endef


.PHONY: build
build: $(MIXTOOL) ## Generates the mixin files
@mkdir -p "$(MIXIN_OUT_PATH)"; \
find "$(MIXIN_OUT_PATH)" ! -name "kustomization.yaml" ! -name "prometheus-alerts.yaml" ! -name "prometheus-rules.yaml" -type f -delete
@$(MIXTOOL) generate all --output-alerts "$(MIXIN_OUT_PATH)/alerts.yaml" --output-rules "$(MIXIN_OUT_PATH)/rules.yaml" --directory "$(MIXIN_OUT_PATH)/dashboards_out" "mixin.libsonnet"
@../../tools/check-rules.sh "$(MIXIN_OUT_PATH)/rules.yaml" 20
@mv $(MIXIN_OUT_PATH)/alerts.yaml $(MIXIN_OUT_PATH)/${CURRENT_DIR}-alerts.yaml
@mv $(MIXIN_OUT_PATH)/rules.yaml $(MIXIN_OUT_PATH)/${CURRENT_DIR}-rules.yaml
$(foreach mixin,$(MIXIN_OUT_PATH),$(call build_mixin_func, $(mixin)))

.PHONY: check
check: build fmt ## Build, fmt and check the mixin files
check: $(MIXTOOL) build fmt ## Build, fmt and check the mixin files
@../../tools/find-diff-or-untracked.sh . "$(MIXIN_OUT_PATH)" || (echo "Please build and fmt mixin by running 'make build fmt'" && false); \
# $(JB) install && \
# jb install && \
# $(MIXTOOL) lint mixin.libsonnet

##@ Dashboards & k8s
Expand All @@ -38,13 +44,16 @@ check: build fmt ## Build, fmt and check the mixin files
manifests: $(KUSTOMIZE) build ## Generates dashboards for k8s
$(KUSTOMIZE) build deploy > deploy/manifests/k8s-all-in-one.yaml

# NOTE: dashboards_out has been deprecated, please use build instead
dashboards_out:
@mkdir -p deploy/dashboards_out deploy/manifests
jsonnet -J vendor -e '(import "mixin.libsonnet").grafanaDashboards' -m deploy/dashboards_out

prom_alerts.yaml:
jsonnet -J vendor -S -e 'std.manifestYamlDoc((import "mixin.libsonnet").prometheusAlerts)' > deploy/$@

rules_load: ## Load rules and alerts to monitoring system
mimirtool rules load --id=anonymous --address=http://localhost:9009 deploy/rules.yaml
mimirtool rules load --id=anonymous --address=http://localhost:9009 deploy/alerts.yaml
mimirtool alertmanager --id=anonymous --address=http://localhost:9009 load deploy/alertmanager.yaml deploy/default.tmpl
mimirtool alertmanager --id=anonymous --address=http://localhost:9009 get
mimirtool alertmanager --id=anonymous --address=http://localhost:9009 delete
prom_rules.yaml:
jsonnet -J vendor -S -e 'std.manifestYamlDoc((import "mixin.libsonnet").prometheusRules)' > deploy/$@

##@ General

Expand Down
23 changes: 23 additions & 0 deletions monitoring-mixins/kubernetes-mixin/deploy.libsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
(import "mixin.libsonnet") +{
// Config overrides
_config+:: {
cadvisorSelector: 'job="integrations/kubernetes/cadvisor"',
kubeletSelector: 'job="integrations/kubernetes/kubelet"',
kubeStateMetricsSelector: 'job="integrations/kubernetes/kube-state-metrics"',
nodeExporterSelector: 'job="integrations/node_exporter"',
kubeSchedulerSelector: 'job="kube-scheduler"',
kubeControllerManagerSelector: 'job="kube-controller-manager"',
kubeApiserverSelector: 'job="integrations/kubernetes/apiserver"',
kubeProxySelector: 'job="kube-proxy"',

grafanaK8s+:: {
dashboardNamePrefix: 'Mixin / ',
dashboardTags: ['kubernetes', 'infrastucture'],
},

// Opt-in to multiCluster dashboards by overriding this and the clusterLabel.
showMultiCluster: true,
// Default datasource name
datasourceName: 'Metrics',
},
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"options": {
"content": "The SLO (service level objective) and other metrics displayed on this dashboard are for informational purposes only."
},
"pluginVersion": "v10.2.0",
"pluginVersion": "v10.4.0",
"title": "Notice",
"type": "text"
},
Expand All @@ -41,7 +41,7 @@
},
"id": 2,
"interval": "1m",
"pluginVersion": "v10.2.0",
"pluginVersion": "v10.4.0",
"targets": [
{
"datasource": {
Expand Down Expand Up @@ -87,7 +87,7 @@
"mode": "single"
}
},
"pluginVersion": "v10.2.0",
"pluginVersion": "v10.4.0",
"targets": [
{
"datasource": {
Expand Down Expand Up @@ -121,7 +121,7 @@
},
"id": 4,
"interval": "1m",
"pluginVersion": "v10.2.0",
"pluginVersion": "v10.4.0",
"targets": [
{
"datasource": {
Expand Down Expand Up @@ -219,7 +219,7 @@
"mode": "single"
}
},
"pluginVersion": "v10.2.0",
"pluginVersion": "v10.4.0",
"targets": [
{
"datasource": {
Expand Down Expand Up @@ -263,7 +263,7 @@
"mode": "single"
}
},
"pluginVersion": "v10.2.0",
"pluginVersion": "v10.4.0",
"targets": [
{
"datasource": {
Expand Down Expand Up @@ -306,7 +306,7 @@
"mode": "single"
}
},
"pluginVersion": "v10.2.0",
"pluginVersion": "v10.4.0",
"targets": [
{
"datasource": {
Expand Down Expand Up @@ -340,7 +340,7 @@
},
"id": 8,
"interval": "1m",
"pluginVersion": "v10.2.0",
"pluginVersion": "v10.4.0",
"targets": [
{
"datasource": {
Expand Down Expand Up @@ -438,7 +438,7 @@
"mode": "single"
}
},
"pluginVersion": "v10.2.0",
"pluginVersion": "v10.4.0",
"targets": [
{
"datasource": {
Expand Down Expand Up @@ -482,7 +482,7 @@
"mode": "single"
}
},
"pluginVersion": "v10.2.0",
"pluginVersion": "v10.4.0",
"targets": [
{
"datasource": {
Expand Down Expand Up @@ -525,7 +525,7 @@
"mode": "single"
}
},
"pluginVersion": "v10.2.0",
"pluginVersion": "v10.4.0",
"targets": [
{
"datasource": {
Expand Down Expand Up @@ -568,7 +568,7 @@
"mode": "single"
}
},
"pluginVersion": "v10.2.0",
"pluginVersion": "v10.4.0",
"targets": [
{
"datasource": {
Expand Down Expand Up @@ -611,7 +611,7 @@
"mode": "single"
}
},
"pluginVersion": "v10.2.0",
"pluginVersion": "v10.4.0",
"targets": [
{
"datasource": {
Expand Down Expand Up @@ -657,7 +657,7 @@
"mode": "single"
}
},
"pluginVersion": "v10.2.0",
"pluginVersion": "v10.4.0",
"targets": [
{
"datasource": {
Expand Down Expand Up @@ -699,7 +699,7 @@
"mode": "single"
}
},
"pluginVersion": "v10.2.0",
"pluginVersion": "v10.4.0",
"targets": [
{
"datasource": {
Expand Down Expand Up @@ -742,7 +742,7 @@
"mode": "single"
}
},
"pluginVersion": "v10.2.0",
"pluginVersion": "v10.4.0",
"targets": [
{
"datasource": {
Expand Down Expand Up @@ -784,7 +784,7 @@
"mode": "single"
}
},
"pluginVersion": "v10.2.0",
"pluginVersion": "v10.4.0",
"targets": [
{
"datasource": {
Expand Down
Loading

0 comments on commit b3ef824

Please sign in to comment.