Skip to content

Commit

Permalink
📦 moves grafana assets as part of cdviz-grafana
Browse files Browse the repository at this point in the history
  • Loading branch information
davidB committed Feb 1, 2024
1 parent ea92032 commit e02a510
Show file tree
Hide file tree
Showing 13 changed files with 252 additions and 39 deletions.
99 changes: 99 additions & 0 deletions cdviz-grafana/dashboards/cdevents-activity.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
{
"annotations": {
"list": [
{
"builtIn": 1,
"datasource": {
"type": "grafana",
"uid": "-- Grafana --"
},
"enable": true,
"hide": true,
"iconColor": "rgba(0, 211, 255, 1)",
"name": "Annotations & Alerts",
"type": "dashboard"
}
]
},
"description": "",
"editable": true,
"fiscalYearStartMonth": 0,
"graphTooltip": 0,
"id": 1,
"links": [],
"liveNow": false,
"panels": [
{
"datasource": {
"type": "postgres",
"uid": "P3ABDE63318046581"
},
"gridPos": {
"h": 8,
"w": 24,
"x": 0,
"y": 0
},
"id": 1,
"options": {
"dedupStrategy": "none",
"enableLogDetails": true,
"prettifyLogMessage": false,
"showCommonLabels": true,
"showLabels": false,
"showTime": true,
"sortOrder": "Descending",
"wrapLogMessage": true
},
"pluginVersion": "10.2.2",
"targets": [
{
"datasource": {
"type": "postgres",
"uid": "P3ABDE63318046581"
},
"editorMode": "code",
"format": "table",
"rawQuery": true,
"rawSql": "SELECT \"timestamp\",\n \"payload\"\nFROM \"cdevents_lake\"\nWHERE $__timeFilter(timestamp) \nORDER BY \"timestamp\" DESC",
"refId": "A",
"sql": {
"columns": [
{
"parameters": [],
"type": "function"
}
],
"groupBy": [
{
"property": {
"type": "string"
},
"type": "groupBy"
}
],
"limit": 50
}
}
],
"title": "Events Logs",
"type": "logs"
}
],
"refresh": "",
"schemaVersion": 38,
"tags": [],
"templating": {
"list": []
},
"time": {
"from": "now-6h",
"to": "now"
},
"timepicker": {},
"timezone": "",
"title": "cdevents activity",
"uid": "a6eeda5f-2550-438c-9477-8ed28ab50ce6",
"version": 1,
"weekStart": ""
}
4 changes: 2 additions & 2 deletions charts/cdviz-collector/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ apiVersion: v2
name: cdviz-collector
description: A Helm chart for Kubernetes
type: application
version: 0.2.0 # TODO Change this to a version number on release
appVersion: "0.1.0" # TODO Change this to a version number on release
version: 0.1.0 # TODO Change this to a version number on release
appVersion: 0.1.0 # TODO Change this to a version number on release
23 changes: 23 additions & 0 deletions charts/cdviz-grafana/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
6 changes: 6 additions & 0 deletions charts/cdviz-grafana/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: v2
name: cdviz-grafana
description: cdviz's grafana resources (dashboards, datasources, ...)
type: application
version: 0.1.0 # TODO Change this to a version number on release
appVersion: 0.1.0 # TODO Change this to a version number on release
1 change: 1 addition & 0 deletions charts/cdviz-grafana/grafana-dashboards
62 changes: 62 additions & 0 deletions charts/cdviz-grafana/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "my.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "my.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "my.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "my.labels" -}}
helm.sh/chart: {{ include "my.chart" . }}
{{ include "my.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "my.selectorLabels" -}}
app.kubernetes.io/name: {{ include "my.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "my.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "my.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
{{- if .Values.grafanaAssets.enabled -}}
{{- if .Values.dashboards.enabled -}}
{{- $files := .Files.Glob "grafana-dashboards/*.{yaml,json}" }}
{{- if $files }}
---
apiVersion: v1
kind: ConfigMap
metadata:
name: "{{ include "my.fullname" $ }}-grafana-dashboards"
name: "{{ include "my.fullname" $ }}-dashboards"
labels:
grafana_dashboard: "1"
{{- toYaml .Values.dashboards.annotations | nindent 4}}
{{- include "my.labels" $ | nindent 4 }}
data:
{{- range $path, $fileContents := $files }}
{{ include "my.fullname" $ }}-{{ base $path }}: |-
{{ $.Files.Get $path | nindent 4 }}
{{ tpl ($.Files.Get $path) $ | nindent 4 }}
{{- end }}
{{- end }}
{{- end -}}
17 changes: 17 additions & 0 deletions charts/cdviz-grafana/templates/grafana-datasources.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{{- if (and .Values.datasources.enabled .Values.datasources.definitions) -}}
apiVersion: v1
kind: ConfigMap
metadata:
name: "{{ include "my.fullname" $ }}-datasources"
labels:
{{- toYaml .Values.datasources.annotations | nindent 4}}
{{- include "my.labels" . | nindent 4 }}
data:
{{ include "my.fullname" $ }}-datasources.yaml: |-
apiVersion: 1
datasources:
{{- range $name, $def := .Values.datasources.definitions }}
- name: {{ $name }}
{{- tpl (toYaml $def ) $ | nindent 8 }}
{{- end }}
{{- end -}}
26 changes: 26 additions & 0 deletions charts/cdviz-grafana/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
datasources:
enabled: true
annotations:
grafana_datasource: "1"
definitions:
cdviz:
# same syntax than on grafana datasources provisionner
type: postgres
url: '$POSTGRES_HOST'
user: '$POSTGRES_USER_CDVIZ_READER' # from env var (injected via secrets)
secureJsonData:
password: '$POSTGRES_PASSWORD_CDVIZ_READER'
jsonData:
database: '$POSTGRES_DB'
sslmode: 'disable' # disable/require/verify-ca/verify-full
maxOpenConns: 10 # Grafana v5.4+
maxIdleConns: 10 # Grafana v5.4+
maxIdleConnsAuto: true # Grafana v9.5.1+
connMaxLifetime: 14400 # Grafana v5.4+
postgresVersion: 1000
timescaledb: false

dashboards:
enabled: true
annotations:
grafana_dashboard: "1"
10 changes: 7 additions & 3 deletions charts/cdviz/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ apiVersion: v2
name: cdviz
description: A Helm chart for Kubernetes
type: application
version: 0.2.0 # TODO Change this to a version number on release
appVersion: "0.1.0" # TODO Change this to a version number on release
version: 0.1.0 # TODO Change this to a version number on release
appVersion: 0.1.0 # TODO Change this to a version number on release

dependencies:
- name: postgresql
Expand All @@ -16,5 +16,9 @@ dependencies:
repository: https://grafana.github.io/helm-charts
condition: grafana.enabled
- name: cdviz-collector
version: 0.2.0
version: 0.1.0
repository: file://../cdviz-collector
- name: cdviz-grafana
version: 0.1.0
repository: file://../cdviz-grafana
condition: cdviz-grafana.enabled
28 changes: 0 additions & 28 deletions charts/cdviz/templates/grafana-datasources.yaml

This file was deleted.

3 changes: 1 addition & 2 deletions charts/cdviz/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ postgresql:
userPasswordKey: POSTGRES_PASSWORD

# cdviz provides optional dashboards, datasources,... for grafana as configmaps loadable by sidecars.
grafanaAssets:
cdviz-grafana:
enabled: true

# The following sections is used to configure a grafana instance as part of the chart,
Expand All @@ -57,4 +57,3 @@ grafana:
env:
GF_AUTH_ANONYMOUS_ENABLED: "true"
GF_AUTH_ANONYMOUS_ORG_ROLE: Admin

4 changes: 4 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ k8s_create:
k8s_dev:
skaffold dev --port-forward

k8s_delete_cdviz:
helm delete cdviz -n cdviz --cascade foreground || true
kubectl delete namespace cdviz

k8s_delete:
# k3d cluster delete "$CLUSTER_NAME"
# kind delete cluster --name "$CLUSTER_NAME"
Expand Down

0 comments on commit e02a510

Please sign in to comment.