Skip to content

Commit

Permalink
Updates in k8s-stack (#657)
Browse files Browse the repository at this point in the history
- Bump version of `grafana` helm-chart to `6.59.*`
- Bump version of `prometheus-node-exporter` helm-chart to `4.23.*`
- Bump version of `kube-state-metrics` helm-chart to `0.59.*`
- Update alerting rules
- Update grafana dashboards
- Add `make` commands `sync-rules` and `sync-dashboards`
  • Loading branch information
Amper authored Sep 12, 2023
1 parent e59ec53 commit 7bb3fa6
Show file tree
Hide file tree
Showing 37 changed files with 5,064 additions and 1,500 deletions.
25 changes: 23 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
URL=https://victoriametrics.github.io/helm-charts/
HELM_IMAGE = alpine/helm:3.11.3
HELM_IMAGE = alpine/helm:3.12.3
HELM_DOCS_IMAGE = jnorwood/helm-docs:v1.11.0
PYTHON_IMAGE = python:3.11.5-alpine3.18
CT_IMAGE = quay.io/helmpack/chart-testing:v3.7.1
KNOWN_TARGETS=helm
HELM?=helm-docker
Expand Down Expand Up @@ -122,9 +123,29 @@ init:
# CMD="repo index --url ${URL} --merge index.yaml ." $(MAKE) $(HELM)

gen-docs:
docker run --rm --name helm-docs \
docker run --rm \
--user $(shell id -u):$(shell id -g) \
--mount type=bind,src="$(shell pwd)",dst=/helm-charts \
-w /helm-charts \
$(HELM_DOCS_IMAGE) \
helm-docs

# Synchronize alerting rules in charts/victoria-metrics-k8s-stack/templates/rules
sync-rules:
docker run --rm \
--user $(shell id -u):$(shell id -g) \
--mount type=bind,src="$(shell pwd)/charts/victoria-metrics-k8s-stack",dst=/k8s-stack \
-w /k8s-stack/hack/ \
$(PYTHON_IMAGE) sh -c "\
pip3 install --no-cache-dir --no-build-isolation -r requirements.txt --user && python3 sync_rules.py \
"

# Synchronize grafana dashboards in charts/victoria-metrics-k8s-stack/templates/grafana/dashboards
sync-dashboards:
docker run --rm \
--user $(shell id -u):$(shell id -g) \
--mount type=bind,src="$(shell pwd)/charts/victoria-metrics-k8s-stack",dst=/k8s-stack \
-w /k8s-stack/hack/ \
$(PYTHON_IMAGE) sh -c "\
pip3 install --no-cache-dir --no-build-isolation -r requirements.txt --user && python3 sync_grafana_dashboards.py \
"
8 changes: 7 additions & 1 deletion charts/victoria-metrics-k8s-stack/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@

## Next release

- TODO
- Bump version of `grafana` helm-chart to `6.59.*`
- Bump version of `prometheus-node-exporter` helm-chart to `4.23.*`
- Bump version of `kube-state-metrics` helm-chart to `0.59.*`
- Update alerting rules
- Update grafana dashboards
- Add `make` commands `sync-rules` and `sync-dashboards`
- Add support of VictoriaMetrics datasource

## 0.17.8

Expand Down
10 changes: 5 additions & 5 deletions charts/victoria-metrics-k8s-stack/Chart.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ dependencies:
version: 0.27.0
- name: kube-state-metrics
repository: https://prometheus-community.github.io/helm-charts
version: 4.24.0
version: 5.12.1
- name: prometheus-node-exporter
repository: https://prometheus-community.github.io/helm-charts
version: 4.7.1
version: 4.23.0
- name: grafana
repository: https://grafana.github.io/helm-charts
version: 6.44.11
version: 6.59.4
- name: crds
repository: ""
version: 0.0.0
digest: sha256:e9c79348c0413d1156c97acd8fdcbe87db6c4d2f60e1ee3b807c144dbb25cfd7
generated: "2023-09-11T12:02:20.612859+02:00"
digest: sha256:f11c8971aa12b3097718ef2cac11430f4cbb33a293f25f1b85f32d1285e67a05
generated: "2023-09-12T11:52:30.436711+02:00"
8 changes: 4 additions & 4 deletions charts/victoria-metrics-k8s-stack/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: v2
name: victoria-metrics-k8s-stack
description: Kubernetes monitoring on VictoriaMetrics stack. Includes VictoriaMetrics Operator, Grafana dashboards, ServiceScrapes and VMRules
type: application
version: 0.17.8
version: 0.18.0
appVersion: v1.93.4
sources:
- https://github.com/VictoriaMetrics/helm-charts
Expand Down Expand Up @@ -37,15 +37,15 @@ dependencies:
repository: https://victoriametrics.github.io/helm-charts
condition: victoria-metrics-operator.enabled
- name: kube-state-metrics
version: "4.24.*"
version: "5.12.*"
repository: https://prometheus-community.github.io/helm-charts
condition: kube-state-metrics.enabled
- name: prometheus-node-exporter
version: "4.7.*"
version: "4.23.*"
repository: https://prometheus-community.github.io/helm-charts
condition: prometheus-node-exporter.enabled
- name: grafana
version: "6.44.*"
version: "6.59.*"
repository: https://grafana.github.io/helm-charts
condition: grafana.enabled
- name: crds
Expand Down
4 changes: 3 additions & 1 deletion charts/victoria-metrics-k8s-stack/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Helm Chart For Victoria Metrics kubernetes monitoring stack.

![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![Version: 0.17.8](https://img.shields.io/badge/Version-0.17.8-informational?style=flat-square)
![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![Version: 0.18.0](https://img.shields.io/badge/Version-0.18.0-informational?style=flat-square)
[![Artifact Hub](https://img.shields.io/endpoint?url=https://artifacthub.io/badge/repository/victoriametrics)](https://artifacthub.io/packages/helm/victoriametrics/victoria-logs-k8s-stack)

Kubernetes monitoring on VictoriaMetrics stack. Includes VictoriaMetrics Operator, Grafana dashboards, ServiceScrapes and VMRules
Expand Down Expand Up @@ -396,6 +396,7 @@ Change the values according to the need of the environment in ``victoria-metrics
| grafana.dashboards.default.nodeexporter.gnetId | int | `1860` | |
| grafana.dashboards.default.nodeexporter.revision | int | `22` | |
| grafana.defaultDashboardsTimezone | string | `"utc"` | |
| grafana.defaultDatasourceType | string | `"prometheus"` | |
| grafana.enabled | bool | `true` | |
| grafana.forceDeployDatasource | bool | `false` | |
| grafana.ingress.annotations | object | `{}` | |
Expand All @@ -412,6 +413,7 @@ Change the values according to the need of the environment in ``victoria-metrics
| grafana.sidecar.dashboards.multicluster | bool | `false` | |
| grafana.sidecar.datasources.createVMReplicasDatasources | bool | `false` | |
| grafana.sidecar.datasources.enabled | bool | `true` | |
| grafana.sidecar.datasources.initDatasources | bool | `true` | |
| grafana.sidecar.datasources.jsonData | object | `{}` | |
| grafana.vmServiceScrape.enabled | bool | `true` | |
| grafana.vmServiceScrape.spec | object | `{}` | |
Expand Down
54 changes: 25 additions & 29 deletions charts/victoria-metrics-k8s-stack/RELEASE_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,35 @@
2. Apply changes via `helm dependency update`
3. Update image tag in chart values:

<div class="with-copy" markdown="1">

```console
cd hack
python3 sync_rules.py
python3 sync_grafana_dashboards.py
```
</div>

<div class="with-copy" markdown="1">

```console
make sync-rules
make sync-dashboards
```
</div>
4. Bump version of the victoria-metrics-k8s-stack [Chart.yml](https://github.com/VictoriaMetrics/helm-charts/blob/master/charts/victoria-metrics-k8s-stack/Chart.yaml)
5. Run linter:

<div class="with-copy" markdown="1">

```console
make lint
```

</div>

<div class="with-copy" markdown="1">
```console
make lint
```
</div>
6. Render templates locally to check for errors:

<div class="with-copy" markdown="1">

```console
helm template vm-k8s-stack ./charts/victoria-metrics-k8s-stack --output-dir out --values ./values.yaml --debug
```

</div>

<div class="with-copy" markdown="1">
```console
helm template vm-k8s-stack ./charts/victoria-metrics-k8s-stack --output-dir out --values ./charts/victoria-metrics-k8s-stack/values.yaml --debug
```
</div>
7. Test updated chart by installing it to your kubernetes cluster.
8. Update docs with
```console
helm-docs
```
```console
helm-docs
```
9. Commit the changes and send a [PR](https://github.com/VictoriaMetrics/helm-charts/pulls)
1 change: 1 addition & 0 deletions charts/victoria-metrics-k8s-stack/hack/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
Cython<3.0
PyYAML==6.0
requests==2.31.0
38 changes: 29 additions & 9 deletions charts/victoria-metrics-k8s-stack/hack/sync_grafana_dashboards.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,31 +169,48 @@ def yaml_str_repr(struct, indent=2):
return text


def replace_ds_type_in_panel(panel):
if 'datasource' in panel:
if 'type' in panel['datasource']:
panel['datasource']['type'] = '__VM_DEFAULT_DATASOURCE__'
for target in panel.get('targets', []):
if 'datasource' in target:
if 'type' in target['datasource']:
target['datasource']['type'] = '__VM_DEFAULT_DATASOURCE__'

def patch_dashboards_json(content):
try:
content_struct = json.loads(content)

## multicluster
overwrite_list = []
for variable in content_struct['templating']['list']:
if variable['name'] == 'cluster':
variable['hide'] = ':multicluster:'
overwrite_list.append(variable)
if 'templating' in content_struct:
for variable in content_struct['templating'].get('list', []):
if variable.get('name', '') == 'cluster':
variable['hide'] = ':multicluster:'
if variable.get('type', '') == 'datasource' and variable.get('query', '') == 'prometheus':
variable['query'] = '__VM_DEFAULT_DATASOURCE__'
overwrite_list.append(variable)
content_struct['templating']['list'] = overwrite_list

## make dashboards readonly
content_struct['editable'] = False

## add common tag
content_struct['tags'].append('vm-k8s-stack')
if 'tags' in content_struct:
content_struct['tags'].append('vm-k8s-stack')

## fix drilldown links. see https://github.com/kubernetes-monitoring/kubernetes-mixin/issues/659
for row in content_struct['rows']:
for panel in row['panels']:
for row in content_struct.get('rows', []):
for panel in row.get('panels', []):
replace_ds_type_in_panel(panel)
for style in panel.get('styles', []):
if 'linkUrl' in style and style['linkUrl'].startswith('./d'):
style['linkUrl'] = style['linkUrl'].replace('./d', '/d')

for panel in content_struct.get('panels', []):
replace_ds_type_in_panel(panel)

content_array = []
original_content_lines = content.split('\n')
for i, line in enumerate(json.dumps(content_struct, indent=4).split('\n')):
Expand All @@ -220,8 +237,8 @@ def patch_dashboards_json(content):
'\{\{ if .Values.grafana.sidecar.dashboards.multicluster \}\}0\{\{ else \}\}2\{\{ end \}\}',
content[multicluster + 15:]
))
except (ValueError, KeyError):
pass
except (ValueError, KeyError) as err:
print("Cannot update dashboard content: ", err)

return content

Expand Down Expand Up @@ -254,6 +271,9 @@ def write_group_to_file(resource_name, content, url, destination):
# footer
lines += '{{- end }}'

# replace placeholders with datasource type variable
lines = lines.replace("__VM_DEFAULT_DATASOURCE__", '{{ default \"prometheus\" .Values.grafana.defaultDatasourceType }}')

filename = resource_name + '.yaml'
new_filename = "%s/%s" % (destination, filename)

Expand Down
24 changes: 24 additions & 0 deletions charts/victoria-metrics-k8s-stack/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -240,3 +240,27 @@ vmselect:
{{ define "victoria-metrics-k8s-stack.VMClusterSpec"}}
{{ tpl (deepCopy .Values.vmcluster.spec | mergeOverwrite ( include "vmselectSpec" . | fromYaml) | toYaml) . }}
{{- end }}

{{/*
VictoriaMetrics Datasource
*/}}
{{ define "victoria-metrics-k8s-stack.VMDataSource"}}
{{- $vmDSPluginEnabled := false }}
{{- if .Values.grafana.plugins }}
{{- range $value := .Values.grafana.plugins }}
{{- if (contains "victoriametrics-datasource" $value) }}
{{- $vmDSPluginEnabled = true }}
{{- end }}
{{- end }}
{{- end }}
{{- $vmAllowUnsigned := contains "victoriametrics-datasource" (dig "grafana.ini" "plugins" "allow_loading_unsigned_plugins" "" .Values.grafana) }}
{{- if (and $vmDSPluginEnabled $vmAllowUnsigned) }}
- name: VictoriaMetrics (DS)
type: victoriametrics-datasource
{{- $readEndpoint:= (include "victoria-metrics-k8s-stack.vmReadEndpoint" . | fromYaml) }}
url: {{ $readEndpoint.url }}
access: proxy
isDefault: false
jsonData: {{ toYaml .Values.grafana.sidecar.datasources.jsonData | nindent 8 }}
{{- end }}
{{- end }}
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ data:
"options": [
],
"query": "prometheus",
"query": "{{ default "prometheus" .Values.grafana.defaultDatasourceType }}",
"refresh": 1,
"regex": "",
"type": "datasource"
Expand Down
Loading

0 comments on commit 7bb3fa6

Please sign in to comment.