diff --git a/cdviz-grafana/dashboards/cdevents-activity.json b/cdviz-grafana/dashboards/cdevents-activity.json new file mode 100644 index 0000000..3dc2b40 --- /dev/null +++ b/cdviz-grafana/dashboards/cdevents-activity.json @@ -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": "" +} diff --git a/charts/cdviz-collector/Chart.yaml b/charts/cdviz-collector/Chart.yaml index d09ad3c..6d6f18f 100644 --- a/charts/cdviz-collector/Chart.yaml +++ b/charts/cdviz-collector/Chart.yaml @@ -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 diff --git a/charts/cdviz-grafana/.helmignore b/charts/cdviz-grafana/.helmignore new file mode 100644 index 0000000..0e8a0eb --- /dev/null +++ b/charts/cdviz-grafana/.helmignore @@ -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/ diff --git a/charts/cdviz-grafana/Chart.yaml b/charts/cdviz-grafana/Chart.yaml new file mode 100644 index 0000000..897e112 --- /dev/null +++ b/charts/cdviz-grafana/Chart.yaml @@ -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 diff --git a/charts/cdviz-grafana/grafana-dashboards b/charts/cdviz-grafana/grafana-dashboards new file mode 120000 index 0000000..5b83062 --- /dev/null +++ b/charts/cdviz-grafana/grafana-dashboards @@ -0,0 +1 @@ +../../cdviz-grafana/dashboards/ \ No newline at end of file diff --git a/charts/cdviz-grafana/templates/_helpers.tpl b/charts/cdviz-grafana/templates/_helpers.tpl new file mode 100644 index 0000000..534b7f4 --- /dev/null +++ b/charts/cdviz-grafana/templates/_helpers.tpl @@ -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 }} diff --git a/charts/cdviz/templates/grafana-dashboards.yaml b/charts/cdviz-grafana/templates/grafana-dashboards.yaml similarity index 61% rename from charts/cdviz/templates/grafana-dashboards.yaml rename to charts/cdviz-grafana/templates/grafana-dashboards.yaml index 833b344..eeed5fa 100644 --- a/charts/cdviz/templates/grafana-dashboards.yaml +++ b/charts/cdviz-grafana/templates/grafana-dashboards.yaml @@ -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 -}} diff --git a/charts/cdviz-grafana/templates/grafana-datasources.yaml b/charts/cdviz-grafana/templates/grafana-datasources.yaml new file mode 100644 index 0000000..fa9ac9d --- /dev/null +++ b/charts/cdviz-grafana/templates/grafana-datasources.yaml @@ -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 -}} diff --git a/charts/cdviz-grafana/values.yaml b/charts/cdviz-grafana/values.yaml new file mode 100644 index 0000000..536293b --- /dev/null +++ b/charts/cdviz-grafana/values.yaml @@ -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" diff --git a/charts/cdviz/Chart.yaml b/charts/cdviz/Chart.yaml index 39ee415..d761fe6 100644 --- a/charts/cdviz/Chart.yaml +++ b/charts/cdviz/Chart.yaml @@ -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 @@ -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 diff --git a/charts/cdviz/templates/grafana-datasources.yaml b/charts/cdviz/templates/grafana-datasources.yaml deleted file mode 100644 index 925d9e3..0000000 --- a/charts/cdviz/templates/grafana-datasources.yaml +++ /dev/null @@ -1,28 +0,0 @@ -{{- if .Values.grafanaAssets.enabled -}} -apiVersion: v1 -kind: ConfigMap -metadata: - name: "{{ include "my.fullname" $ }}-grafana-datasources" - labels: - grafana_datasource: "1" - {{- include "my.labels" . | nindent 4 }} -data: - {{ include "my.fullname" $ }}-grafana-datasource-postgresql.yaml: |- - apiVersion: 1 - datasources: - - name: {{ include "my.fullname" $ }}-postgres - 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 -{{- end -}} diff --git a/charts/cdviz/values.yaml b/charts/cdviz/values.yaml index 5a1cfe5..32eaa04 100644 --- a/charts/cdviz/values.yaml +++ b/charts/cdviz/values.yaml @@ -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, @@ -57,4 +57,3 @@ grafana: env: GF_AUTH_ANONYMOUS_ENABLED: "true" GF_AUTH_ANONYMOUS_ORG_ROLE: Admin - diff --git a/justfile b/justfile index 86035fe..3f00afc 100644 --- a/justfile +++ b/justfile @@ -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"