From d0f324fb755ae022b52e7b481c3cf39fe8d168de Mon Sep 17 00:00:00 2001 From: Jimi Dodd-o Date: Wed, 6 Dec 2023 15:59:47 -0500 Subject: [PATCH 1/2] Prom exporter release (#277) * Prom exporter release * Dont overwrite app version * Silly * Overwritable items standardize * Add top level readme info * Update helm chart * Rename * Rename * paste issue * Dont need ns * correct api url * Try and install server first * Force install maybe * Oops * Separate out prefect server install * Try the default namespace --- .../prometheus-prefect-exporter-ct.yaml | 6 + .../prometheus-exporter-release.yaml | 94 ++++++ ...etheus-prefect.exporter-lint-and-test.yaml | 47 +++ README.md | 4 + charts/prometheus-prefect-exporter/Chart.yaml | 19 ++ charts/prometheus-prefect-exporter/README.md | 87 +++++ .../README.md.gotmpl | 51 +++ .../templates/NOTES.txt | 22 ++ .../templates/_helpers.tpl | 62 ++++ .../templates/deployment.yaml | 84 +++++ .../templates/hpa.yaml | 28 ++ .../templates/pdb.yaml | 13 + .../templates/prometheusrule.yaml | 17 + .../templates/service.yaml | 15 + .../templates/serviceaccount.yaml | 12 + .../templates/servicemonitor.yaml | 25 ++ .../templates/tests/test-connection.yaml | 17 + .../values.schema.json | 316 ++++++++++++++++++ .../prometheus-prefect-exporter/values.yaml | 205 ++++++++++++ 19 files changed, 1124 insertions(+) create mode 100644 .github/linters/prometheus-prefect-exporter-ct.yaml create mode 100644 .github/workflows/prometheus-exporter-release.yaml create mode 100644 .github/workflows/prometheus-prefect.exporter-lint-and-test.yaml create mode 100644 charts/prometheus-prefect-exporter/Chart.yaml create mode 100644 charts/prometheus-prefect-exporter/README.md create mode 100644 charts/prometheus-prefect-exporter/README.md.gotmpl create mode 100644 charts/prometheus-prefect-exporter/templates/NOTES.txt create mode 100644 charts/prometheus-prefect-exporter/templates/_helpers.tpl create mode 100644 charts/prometheus-prefect-exporter/templates/deployment.yaml create mode 100644 charts/prometheus-prefect-exporter/templates/hpa.yaml create mode 100644 charts/prometheus-prefect-exporter/templates/pdb.yaml create mode 100644 charts/prometheus-prefect-exporter/templates/prometheusrule.yaml create mode 100644 charts/prometheus-prefect-exporter/templates/service.yaml create mode 100644 charts/prometheus-prefect-exporter/templates/serviceaccount.yaml create mode 100644 charts/prometheus-prefect-exporter/templates/servicemonitor.yaml create mode 100644 charts/prometheus-prefect-exporter/templates/tests/test-connection.yaml create mode 100644 charts/prometheus-prefect-exporter/values.schema.json create mode 100644 charts/prometheus-prefect-exporter/values.yaml diff --git a/.github/linters/prometheus-prefect-exporter-ct.yaml b/.github/linters/prometheus-prefect-exporter-ct.yaml new file mode 100644 index 00000000..bed704db --- /dev/null +++ b/.github/linters/prometheus-prefect-exporter-ct.yaml @@ -0,0 +1,6 @@ +# See https://github.com/helm/chart-testing#configuration +charts: + - charts/prometheus-prefect-exporter +helm-extra-args: --timeout 600s +namespace: default +release-label: prefect diff --git a/.github/workflows/prometheus-exporter-release.yaml b/.github/workflows/prometheus-exporter-release.yaml new file mode 100644 index 00000000..74a54ae6 --- /dev/null +++ b/.github/workflows/prometheus-exporter-release.yaml @@ -0,0 +1,94 @@ +name: Release Prometheus Prefect Exporter Helm Chart + +"on": + push: + tags: + # prefect-prometheus-exporter-2023.9.1, but not prefect-prometheus-exporter-2023.09.01 + # prefect-prometheus-exporter-2023.11.5, but not prefect-prometheus-exporter-2023.11.05 + # https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#filter-pattern-cheat-sheet + - 'prefect-prometheus-exporter-2[0-9][2-9][3-9].1?[0-9].[1-3]?[0-9]' + +jobs: + release: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Get the version tags + id: get_version + run: | + # Enable pipefail so git command failures do not result in null versions downstream + set -x + export "FULL_RELEASE=$(echo $GITHUB_REF | cut -d / -f 3)" + echo "RELEASE_VERSION=$(echo $FULL_RELEASE | cut -d - -f 4)" >> $GITHUB_OUTPUT + echo "PROMETHEUS_PREFECT_EXPORTER_VERSION=$(\ + git ls-remote --tags --refs --sort="v:refname" \ + https://github.com/PrefectHQ/prometheus-prefect-exporter | tail -n1 | sed 's/.*\///' \ + )" >> $GITHUB_OUTPUT + + - name: Copy Artifact Hub metadata + run: | + mkdir -p /tmp/chart + cp artifacthub-repo.yml /tmp/chart + + - name: Configure Git + run: | + git config user.name "$GITHUB_ACTOR" + git config user.email "$GITHUB_ACTOR@users.noreply.github.com" + + - name: Set up Helm + uses: azure/setup-helm@v3.5 + + - name: Prepare GPG key for signing + run: | + gpg_dir=/tmp/.gpg + mkdir "$gpg_dir" + keyring="$gpg_dir/secring.gpg" + base64 -d <<< "$GPG_KEYRING_BASE64" > "$keyring" + passphrase_file="$gpg_dir/passphrase" + echo "$GPG_PASSPHRASE" > "$passphrase_file" + echo "SIGN_PASSPHRASE_FILE=$passphrase_file" >> "$GITHUB_ENV" + echo "SIGN_KEYRING=$keyring" >> "$GITHUB_ENV" + env: + GPG_KEYRING_BASE64: "${{ secrets.GPG_KEYRING_BASE64 }}" + GPG_PASSPHRASE: "${{ secrets.GPG_PASSPHRASE }}" + + - name: Package Prometheus Exporter helm chart + run: | + mkdir -p /tmp/chart + cd charts + # Update the prefect version tag in values.yaml + sed -i "s/tag:.*$/tag: $PROMETHEUS_PREFECT_EXPORTER_VERSION/g" prometheus-prefect-exporter/values.yaml + helm package prometheus-prefect-exporter \ + --destination /tmp/chart \ + --dependency-update \ + --version $RELEASE_VERSION \ + --app-version $PROMETHEUS_PREFECT_EXPORTER_VERSION \ + --sign --key 'jamie@prefect.io' \ + --keyring $SIGN_KEYRING \ + --passphrase-file $SIGN_PASSPHRASE_FILE + env: + RELEASE_VERSION: ${{ steps.get_version.outputs.RELEASE_VERSION }} + PROMETHEUS_PREFECT_EXPORTER_VERSION: ${{ steps.get_version.outputs.PROMETHEUS_PREFECT_EXPORTER_VERSION }} + SIGN_KEYRING: ${{ env.SIGN_KEYRING }} + SIGN_PASSPHRASE_FILE: ${{ env.SIGN_PASSPHRASE_FILE }} + + - name: Update chart index + run: | + git stash # Stash changes to the values.yaml so checkout doesn't complain + git checkout gh-pages + helm repo index /tmp/chart --url https://prefecthq.github.io/prefect-helm/charts --merge ./index.yaml + + - name: Commit and push + run: | + cp /tmp/chart/artifacthub-repo.yml . + cp /tmp/chart/index.yaml . + cp /tmp/chart/prometheus-prefect-exporter-$RELEASE_VERSION.* ./charts + git add ./artifacthub-repo.yml ./index.yaml prometheus-prefect-exporter-$RELEASE_VERSION.* + git commit -m "Release $RELEASE_VERSION" + git push origin gh-pages + env: + RELEASE_VERSION: ${{ steps.get_version.outputs.RELEASE_VERSION }} diff --git a/.github/workflows/prometheus-prefect.exporter-lint-and-test.yaml b/.github/workflows/prometheus-prefect.exporter-lint-and-test.yaml new file mode 100644 index 00000000..fa33f1f8 --- /dev/null +++ b/.github/workflows/prometheus-prefect.exporter-lint-and-test.yaml @@ -0,0 +1,47 @@ +name: Lint and Test Prometheus Prefect Exporter Chart + +"on": + pull_request: + paths: + - .github/workflows/prometheus-prefect-exporter-lint-and-test.yaml + - .github/linters/prometheus-prefect-exporter-ct.yaml + - charts/prometheus-prefect-exporter/** + +jobs: + lint_test: + name: "lint-test (${{ matrix.kubernetes }})" + runs-on: ubuntu-latest + strategy: + matrix: + kubernetes: + - "1.25.8" + - "1.26.3" + - "1.27.0" + fail-fast: false + + steps: + - name: Checkout Code + uses: actions/checkout@v4 + + - name: Set up Helm + uses: azure/setup-helm@v3.5 + + - name: Set up chart-testing + uses: helm/chart-testing-action@v2.6.1 + + - name: Run chart-testing (lint) + run: ct lint --config .github/linters/prometheus-prefect-exporter-ct.yaml + + - name: Create kind cluster + uses: helm/kind-action@v1.8.0 + with: + node_image: "kindest/node:v${{ matrix.kubernetes }}" + + - name: Install Prefect Server + run: | + helm dependency build ./charts/prefect-server/ + helm install prefect-server -n default ./charts/prefect-server/ --set=postgresql.auth.password=TESTING + + - name: Run chart-testing (install) + run: | + ct install --config .github/linters/prometheus-prefect-exporter-ct.yaml --helm-extra-set-args "--set=prefectApiUrl=http://prefect-server.default.svc.cluster.local:4200/api" diff --git a/README.md b/README.md index 271a4ee2..8e46e22f 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,10 @@ It is possible for multiple agent processes to be started for a single work pool [Prefect server](https://docs.prefect.io/latest/guides/host/) is a self-hosted open source backend that makes it easy to observe and orchestrate your Prefect flows. It is an alternative to using the hosted [Prefect Cloud](https://docs.prefect.io/latest/cloud/) platform. Prefect Cloud provides additional features including automations and user management. +## [Prometheus Prefect Exporter](charts/prometheus-prefect-exporter/) + +The Prometheus Prefect Exporter is a tool to pull relevant Prefect metrics from a hosted Prefect Server instance + ## Usage [Helm](https://helm.sh) must be installed to use the charts. diff --git a/charts/prometheus-prefect-exporter/Chart.yaml b/charts/prometheus-prefect-exporter/Chart.yaml new file mode 100644 index 00000000..ff0b1962 --- /dev/null +++ b/charts/prometheus-prefect-exporter/Chart.yaml @@ -0,0 +1,19 @@ +apiVersion: v2 +appVersion: "latest" +description: A Helm chart to deploy Prometheus Prefect Exporter +home: https://github.com/PrefectHQ +keywords: + - prometheus-prefect-exporter +maintainers: + - name: jamiezieziula + email: jamie@prefect.io + - name: jimid27 + email: jimi@prefect.io + - name: parkedwards + email: edward@prefect.io +name: prometheus-prefect-exporter +sources: + - https://github.com/PrefectHQ/prefect-helm +type: application +# This version is never actually shipped. github actions will package add the appropriate version at build-time +version: 0.0.0 diff --git a/charts/prometheus-prefect-exporter/README.md b/charts/prometheus-prefect-exporter/README.md new file mode 100644 index 00000000..295ebb48 --- /dev/null +++ b/charts/prometheus-prefect-exporter/README.md @@ -0,0 +1,87 @@ +# prometheus-prefect-exporter + +## Overview + +This chart deploys a [Prometheus Exporter](https://github.com/PrefectHQ/prometheus-prefect-exporter) for Prefect Server, providing relevant metrics from your deployed Prefect Server instance. +Shoutout to @ialejandro for the original work on this chart! + +## Installing the Chart + +### Prerequisites + +1. Add the Prefect Helm repository to your Helm client: + + ```bash + helm repo add prefect https://prefecthq.github.io/prefect-helm + helm repo update + ``` + +2. Deploy a Prefect Server instance using the [Prefect Server Helm chart](https://github.com/PrefectHQ/prefect-helm/tree/main/charts/prefect-server) + +### Install the Prefect Exporter chart + +1. Configure the Prefect exporter values as needed + Create a `values.yaml` file to customize the Prometheus Prefect Exporter configuration. + +2. Install the chart + ```bash + helm install prometheus-prefect-exporter prefect/prometheus-prefect-exporter --namespace= -f values.yaml + ``` + +3. Verify the deployment + + Check the status of your Prometheus Prefect Exporter deployment: + + ```bash + kubectl get pods -n prefect + + NAME READY STATUS RESTARTS AGE + prometheus-prefect-exporter-76vxqnq 1/1 Running 0 25m + ``` + + You should see the Prometheus Prefect Exporter pod running + +## Maintainers + +| Name | Email | Url | +| ---- | ------ | --- | +| jamiezieziula | | | +| jimid27 | | | +| parkedwards | | | + +## Values + +| Key | Type | Default | Description | +|-----|------|---------|-------------| +| affinity | object | `{}` | Affinity for pod assignment | +| autoscaling | object | `{"enabled":false,"maxReplicas":100,"minReplicas":1,"targetCPUUtilizationPercentage":80}` | Autoscaling with CPU or memory utilization percentage | +| env | object | `{}` | Environment variables to configure application | +| fullnameOverride | string | `""` | String to fully override prometheus-prefect-exporter.fullname template | +| image | object | `{"pullPolicy":"IfNotPresent","repository":"prefecthq/prometheus-prefect-exporter","tag":"1.0.0"}` | Image registry | +| imagePullSecrets | list | `[]` | Global Docker registry secret names as an array | +| ingress | object | `{"annotations":{},"className":"","enabled":false,"hosts":[{"host":"chart-example.local","paths":[{"path":"/","pathType":"ImplementationSpecific"}]}],"tls":[]}` | Ingress configuration to expose app | +| livenessProbe | bool | `false` | Enable livenessProbe | +| nameOverride | string | `""` | String to partially override prometheus-prefect-exporter.fullname template (will maintain the release name) | +| nodeSelector | object | `{}` | Node labels for pod assignment | +| podAnnotations | object | `{}` | Pod annotations | +| podDisruptionBudget | object | `{}` | Limits the number of Pods of a replicated application that are down simultaneously from voluntary disruptions | +| podSecurityContext | object | `{}` | To specify security settings for a Pod | +| prefectApiUrl | string | `"http://prefect-server.prefect.svc.cluster.local:4200"` | Prefect API URL to connect to for metrics | +| prometheusRule.additionalLabels | object | `{}` | | +| prometheusRule.enabled | bool | `false` | | +| prometheusRule.rules | list | `[]` | | +| readinessProbe | bool | `false` | Enable readinessProbe | +| replicaCount | int | `1` | Number of replicas | +| resources | object | `{}` | The resources limits and requested | +| securityContext | object | `{}` | Defines privilege and access control settings for a Pod or Container | +| service | object | `{"port":80,"targetPort":8000,"type":"ClusterIP"}` | Kubernetes servide to expose Pod | +| service.port | int | `80` | Kubernetes Service port | +| service.targetPort | int | `8000` | Pod expose port | +| service.type | string | `"ClusterIP"` | Kubernetes Service type. Allowed values: NodePort, LoadBalancer or ClusterIP | +| serviceAccount | object | `{"annotations":{},"create":true,"name":""}` | Enable creation of ServiceAccount | +| serviceMonitor | object | `{"enabled":false,"interval":"30s","metricRelabelings":[],"relabelings":[],"scrapeTimeout":"10s"}` | Enable ServiceMonitor to get metrics ref: https://github.com/prometheus-operator/prometheus-operator/blob/main/Documentation/api.md#servicemonitor | +| serviceMonitor.enabled | bool | `false` | Enable or disable | +| tolerations | list | `[]` | Tolerations for pod assignment | + +---------------------------------------------- +Autogenerated from chart metadata using [helm-docs v1.11.3](https://github.com/norwoodj/helm-docs/releases/v1.11.3) diff --git a/charts/prometheus-prefect-exporter/README.md.gotmpl b/charts/prometheus-prefect-exporter/README.md.gotmpl new file mode 100644 index 00000000..22f90966 --- /dev/null +++ b/charts/prometheus-prefect-exporter/README.md.gotmpl @@ -0,0 +1,51 @@ +{{ template "chart.header" . }} + +## Overview + +This chart deploys a [Prometheus Exporter](https://github.com/PrefectHQ/prometheus-prefect-exporter) for Prefect Server, providing relevant metrics from your deployed Prefect Server instance. +Shoutout to @ialejandro for the original work on this chart! + +## Installing the Chart + +### Prerequisites + +1. Add the Prefect Helm repository to your Helm client: + + ```bash + helm repo add prefect https://prefecthq.github.io/prefect-helm + helm repo update + ``` + +2. Deploy a Prefect Server instance using the [Prefect Server Helm chart](https://github.com/PrefectHQ/prefect-helm/tree/main/charts/prefect-server) + +### Install the Prefect Exporter chart + +1. Configure the Prefect exporter values as needed + Create a `values.yaml` file to customize the Prometheus Prefect Exporter configuration. + +2. Install the chart + ```bash + helm install prometheus-prefect-exporter prefect/prometheus-prefect-exporter --namespace= -f values.yaml + ``` + +3. Verify the deployment + + Check the status of your Prometheus Prefect Exporter deployment: + + ```bash + kubectl get pods -n prefect + + NAME READY STATUS RESTARTS AGE + prometheus-prefect-exporter-76vxqnq 1/1 Running 0 25m + ``` + + You should see the Prometheus Prefect Exporter pod running + + +{{ template "chart.maintainersSection" . }} + +{{ template "chart.requirementsSection" . }} + +{{ template "chart.valuesSection" . }} + +{{ template "helm-docs.versionFooter" . }} diff --git a/charts/prometheus-prefect-exporter/templates/NOTES.txt b/charts/prometheus-prefect-exporter/templates/NOTES.txt new file mode 100644 index 00000000..a0436f04 --- /dev/null +++ b/charts/prometheus-prefect-exporter/templates/NOTES.txt @@ -0,0 +1,22 @@ +1. Get the application URL by running these commands: +{{- if .Values.ingress.enabled }} +{{- range $host := .Values.ingress.hosts }} + {{- range .paths }} + http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }} + {{- end }} +{{- end }} +{{- else if contains "NodePort" .Values.service.type }} + export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "prometheus-prefect-exporter.fullname" . }}) + export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}") + echo http://$NODE_IP:$NODE_PORT +{{- else if contains "LoadBalancer" .Values.service.type }} + NOTE: It may take a few minutes for the LoadBalancer IP to be available. + You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "prometheus-prefect-exporter.fullname" . }}' + export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "prometheus-prefect-exporter.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}") + echo http://$SERVICE_IP:{{ .Values.service.port }} +{{- else if contains "ClusterIP" .Values.service.type }} + export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "prometheus-prefect-exporter.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}") + export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}") + echo "Visit http://127.0.0.1:8080 to use your application" + kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT +{{- end }} diff --git a/charts/prometheus-prefect-exporter/templates/_helpers.tpl b/charts/prometheus-prefect-exporter/templates/_helpers.tpl new file mode 100644 index 00000000..837e8bd3 --- /dev/null +++ b/charts/prometheus-prefect-exporter/templates/_helpers.tpl @@ -0,0 +1,62 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "prometheus-prefect-exporter.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 "prometheus-prefect-exporter.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 "prometheus-prefect-exporter.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "prometheus-prefect-exporter.labels" -}} +helm.sh/chart: {{ include "prometheus-prefect-exporter.chart" . }} +{{ include "prometheus-prefect-exporter.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "prometheus-prefect-exporter.selectorLabels" -}} +app.kubernetes.io/name: {{ include "prometheus-prefect-exporter.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "prometheus-prefect-exporter.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "prometheus-prefect-exporter.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/charts/prometheus-prefect-exporter/templates/deployment.yaml b/charts/prometheus-prefect-exporter/templates/deployment.yaml new file mode 100644 index 00000000..66cd7564 --- /dev/null +++ b/charts/prometheus-prefect-exporter/templates/deployment.yaml @@ -0,0 +1,84 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "prometheus-prefect-exporter.fullname" . }} + labels: + {{- include "prometheus-prefect-exporter.labels" . | nindent 4 }} +spec: + {{- if not .Values.autoscaling.enabled }} + replicas: {{ .Values.replicaCount }} + {{- end }} + selector: + matchLabels: + {{- include "prometheus-prefect-exporter.selectorLabels" . | nindent 6 }} + template: + metadata: + {{- with .Values.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "prometheus-prefect-exporter.selectorLabels" . | nindent 8 }} + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- if .Values.serviceAccount.useServiceAccount }} + serviceAccountName: {{ .Values.serviceAccount.useServiceAccount }} + {{ else }} + serviceAccountName: {{ include "prometheus-prefect-exporter.serviceAccountName" . }} + {{- end }} + securityContext: + {{- toYaml .Values.podSecurityContext | nindent 8 }} + containers: + - name: {{ .Chart.Name }} + securityContext: + {{- toYaml .Values.securityContext | nindent 12 }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + args: + {{- if .Values.containerArgs }} + {{- range .Values.containerArgs }} + - {{ . | quote }} + {{- end }} + {{- end }} + ports: + - name: http + containerPort: {{ .Values.service.targetPort | default .Values.service.port }} + protocol: TCP + {{- if .Values.livenessProbe }} + livenessProbe: + httpGet: + path: / + port: http + {{- end }} + {{- if .Values.readinessProbe }} + readinessProbe: + httpGet: + path: / + port: http + {{- end }} + env: + - name: PREFECT_API_URL + value: {{ .Values.prefectApiUrl }} + {{- if .Values.env }} + {{- range $key, $value := .Values.env }} + - name: {{ $key | upper }} + value: {{ $value | quote }} + {{- end }} + {{- end }} + resources: + {{- toYaml .Values.resources | nindent 12 }} + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} diff --git a/charts/prometheus-prefect-exporter/templates/hpa.yaml b/charts/prometheus-prefect-exporter/templates/hpa.yaml new file mode 100644 index 00000000..5b1f48da --- /dev/null +++ b/charts/prometheus-prefect-exporter/templates/hpa.yaml @@ -0,0 +1,28 @@ +{{- if .Values.autoscaling.enabled }} +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: {{ include "prometheus-prefect-exporter.fullname" . }} + labels: + {{- include "prometheus-prefect-exporter.labels" . | nindent 4 }} +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: {{ include "prometheus-prefect-exporter.fullname" . }} + minReplicas: {{ .Values.autoscaling.minReplicas }} + maxReplicas: {{ .Values.autoscaling.maxReplicas }} + metrics: + {{- if .Values.autoscaling.targetCPUUtilizationPercentage }} + - type: Resource + resource: + name: cpu + targetAverageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }} + {{- end }} + {{- if .Values.autoscaling.targetMemoryUtilizationPercentage }} + - type: Resource + resource: + name: memory + targetAverageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }} + {{- end }} +{{- end }} diff --git a/charts/prometheus-prefect-exporter/templates/pdb.yaml b/charts/prometheus-prefect-exporter/templates/pdb.yaml new file mode 100644 index 00000000..63fbf058 --- /dev/null +++ b/charts/prometheus-prefect-exporter/templates/pdb.yaml @@ -0,0 +1,13 @@ +{{- if .Values.podDisruptionBudget -}} +apiVersion: policy/v1 +kind: PodDisruptionBudget +metadata: + name: {{ template "prometheus-prefect-exporter.fullname" . }} + labels: + {{- include "prometheus-prefect-exporter.labels" . | nindent 4 }} +spec: + selector: + matchLabels: + {{- include "prometheus-prefect-exporter.selectorLabels" . | nindent 6 }} +{{ toYaml .Values.podDisruptionBudget | indent 2 }} +{{- end }} diff --git a/charts/prometheus-prefect-exporter/templates/prometheusrule.yaml b/charts/prometheus-prefect-exporter/templates/prometheusrule.yaml new file mode 100644 index 00000000..f31d3eb2 --- /dev/null +++ b/charts/prometheus-prefect-exporter/templates/prometheusrule.yaml @@ -0,0 +1,17 @@ +{{- if .Values.prometheusRule.enabled }} +apiVersion: monitoring.coreos.com/v1 +kind: PrometheusRule +metadata: + name: {{ template "prometheus-prefect-exporter.fullname" . }} + labels: + {{- include "prometheus-prefect-exporter.labels" . | nindent 4 }} + {{- with .Values.prometheusRule.additionalLabels -}} +{{- toYaml . | nindent 4 -}} + {{- end }} +spec: + {{- with .Values.prometheusRule.rules }} + groups: + - name: {{ template "prometheus-prefect-exporter.name" $ }} + rules: {{ toYaml . | nindent 8 }} + {{- end }} +{{- end }} diff --git a/charts/prometheus-prefect-exporter/templates/service.yaml b/charts/prometheus-prefect-exporter/templates/service.yaml new file mode 100644 index 00000000..49f110ac --- /dev/null +++ b/charts/prometheus-prefect-exporter/templates/service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "prometheus-prefect-exporter.fullname" . }} + labels: + {{- include "prometheus-prefect-exporter.labels" . | nindent 4 }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: {{ .Values.service.targetPort | default .Values.service.port }} + protocol: TCP + name: http + selector: + {{- include "prometheus-prefect-exporter.selectorLabels" . | nindent 4 }} diff --git a/charts/prometheus-prefect-exporter/templates/serviceaccount.yaml b/charts/prometheus-prefect-exporter/templates/serviceaccount.yaml new file mode 100644 index 00000000..24287b2f --- /dev/null +++ b/charts/prometheus-prefect-exporter/templates/serviceaccount.yaml @@ -0,0 +1,12 @@ +{{- if .Values.serviceAccount.create -}} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "prometheus-prefect-exporter.serviceAccountName" . }} + labels: + {{- include "prometheus-prefect-exporter.labels" . | nindent 4 }} + {{- with .Values.serviceAccount.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +{{- end }} diff --git a/charts/prometheus-prefect-exporter/templates/servicemonitor.yaml b/charts/prometheus-prefect-exporter/templates/servicemonitor.yaml new file mode 100644 index 00000000..e8c8543d --- /dev/null +++ b/charts/prometheus-prefect-exporter/templates/servicemonitor.yaml @@ -0,0 +1,25 @@ +{{- if .Values.serviceMonitor.enabled }} +apiVersion: monitoring.coreos.com/v1 +kind: ServiceMonitor +metadata: + name: {{ include "prometheus-prefect-exporter.fullname" . }} + labels: + {{- include "prometheus-prefect-exporter.labels" . | nindent 4 }} +spec: + jobLabel: "{{ .Release.Name }}" + selector: + matchLabels: + {{- include "prometheus-prefect-exporter.selectorLabels" . | nindent 8 }} + endpoints: + - port: http + interval: {{ .Values.serviceMonitor.interval | quote }} + scrapeTimeout: {{ .Values.serviceMonitor.scrapeTimeout | quote }} + {{- if .Values.serviceMonitor.metricRelabelings }} + metricRelabelings: + {{- toYaml .Values.serviceMonitor.metricRelabelings | nindent 4 }} + {{- end }} + {{- if .Values.serviceMonitor.relabelings }} + relabelings: + {{- toYaml .Values.serviceMonitor.relabelings | nindent 4 }} + {{- end }} +{{- end -}} diff --git a/charts/prometheus-prefect-exporter/templates/tests/test-connection.yaml b/charts/prometheus-prefect-exporter/templates/tests/test-connection.yaml new file mode 100644 index 00000000..e3d2a407 --- /dev/null +++ b/charts/prometheus-prefect-exporter/templates/tests/test-connection.yaml @@ -0,0 +1,17 @@ +{{- if .Values.testConnection }} +apiVersion: v1 +kind: Pod +metadata: + name: "{{ include "prometheus-prefect-exporter.fullname" . }}-test-connection" + labels: + {{- include "prometheus-prefect-exporter.labels" . | nindent 4 }} + annotations: + "helm.sh/hook": test +spec: + containers: + - name: wget + image: busybox + command: ['wget'] + args: ['{{ include "prometheus-prefect-exporter.fullname" . }}:{{ .Values.service.targetPort | default .Values.service.port }}'] + restartPolicy: Never +{{- end }} \ No newline at end of file diff --git a/charts/prometheus-prefect-exporter/values.schema.json b/charts/prometheus-prefect-exporter/values.schema.json new file mode 100644 index 00000000..e688d382 --- /dev/null +++ b/charts/prometheus-prefect-exporter/values.schema.json @@ -0,0 +1,316 @@ +{ + "$schema": "http://json-schema.org/schema#", + "type": "object", + "additionalProperties": false, + "properties": { + "replicaCount" : { + "type": "integer", + "title": "Replica Count", + "description": "Number of replicas to deploy", + "form": true + }, + "image": { + "type": "object", + "title": "Image", + "description": "Image to deploy", + "form": true, + "properties": { + "repository": { + "type": "string", + "title": "Repository", + "description": "Image repository", + "form": true + }, + "tag": { + "type": "string", + "title": "Tag", + "description": "Image tag", + "form": true + }, + "pullPolicy": { + "type": "string", + "title": "Pull Policy", + "description": "Image pull policy", + "form": true + } + } + }, + "nameOverride": { + "type": "string", + "title": "Name Override", + "description": "Override the name of the chart", + "form": true + }, + "fullnameOverride": { + "type": "string", + "title": "Fullname Override", + "description": "Override the fullname of the chart", + "form": true + }, + "imagePullSecrets": { + "type": "array", + "title": "Image Pull Secrets", + "description": "Image pull secrets", + "form": true + }, + "serviceAccount": { + "type": "object", + "title": "Service Account", + "description": "Service account", + "form": true, + "properties": { + "create": { + "type": "boolean", + "title": "Create", + "description": "Create service account", + "form": true + }, + "annotations": { + "type": "object", + "title": "Annotations", + "description": "Service account annotations", + "form": true + }, + "name": { + "type": "string", + "title": "Name", + "description": "Service account name", + "form": true + } + } + }, + "prefectApiUrl": { + "type": "string", + "title": "Prefect API URL", + "description": "Prefect API URL", + "form": true + }, + "env": { + "type": "object", + "title": "Environment Variables", + "description": "Environment variables", + "form": true + }, + "podDisruptionBudget": { + "type": "object", + "title": "Pod Disruption Budget", + "description": "Pod disruption budget", + "form": true + }, + "podAnnotations": { + "type": "object", + "title": "Pod Annotations", + "description": "Pod annotations", + "form": true + }, + "podSecurityContext": { + "type": "object", + "title": "Pod Security Context", + "description": "Pod security context", + "form": true + }, + "securityContext": { + "type": "object", + "title": "Security Context", + "description": "Security context", + "form": true + }, + "service": { + "type": "object", + "additionalProperties": true, + "title": "Service", + "description": "Service", + "form": true, + "properties": { + "type": { + "type": "string", + "title": "Type", + "description": "Service type", + "form": true + }, + "port": { + "type": "integer", + "title": "Port", + "description": "Service port", + "form": true + }, + "targetPort": { + "type": "integer", + "title": "Target Port", + "description": "Service target port", + "form": true + } + } + }, + "serviceMonitor": { + "type": "object", + "title": "Service Monitor", + "description": "Service monitor", + "form": true, + "properties": { + "enabled": { + "type": "boolean", + "title": "Enabled", + "description": "Enable service monitor", + "form": true + }, + "interval": { + "type": "string", + "title": "Interval", + "description": "Service monitor interval", + "form": true + }, + "scrapeTimeout": { + "type": "string", + "title": "Timeout", + "description": "Service monitor timeout", + "form": true + }, + "metricRelabelings" : { + "type": "array", + "title": "Metric Relabelings", + "description": "Service monitor metric relabelings", + "form": true + }, + "relabelings" : { + "type": "array", + "title": "Relabelings", + "description": "Service monitor relabelings", + "form": true + } + } + }, + "prometheusRule": { + "type": "object", + "title": "Prometheus Rule", + "description": "Prometheus rule", + "form": true, + "properties": { + "enabled": { + "type": "boolean", + "title": "Enabled", + "description": "Enable prometheus rule", + "form": true + }, + "additionalLabels": { + "type": "object", + "title": "Additional Labels", + "description": "Prometheus rule additional labels", + "form": true + }, + "rules": { + "type": "array", + "title": "Rules", + "description": "Prometheus rule rules", + "form": true + } + } + }, + "livenessProbe": { + "type": "boolean", + "title": "Liveness Probe", + "description": "Enable liveness probe", + "form": true + }, + "readinessProbe": { + "type": "boolean", + "title": "Readiness Probe", + "description": "Enable readiness probe", + "form": true + }, + "ingress": { + "type": "object", + "title": "Ingress", + "description": "Ingress", + "form": true, + "properties": { + "enabled": { + "type": "boolean", + "title": "Enabled", + "description": "Enable ingress", + "form": true + }, + "className": { + "type": "string", + "title": "Class Name", + "description": "Ingress class name", + "form": true + }, + "annotations": { + "type": "object", + "title": "Annotations", + "description": "Ingress annotations", + "form": true + }, + "hosts": { + "type": "array", + "title": "Hosts", + "description": "Ingress hosts", + "form": true + }, + "tls": { + "type": "array", + "title": "TLS", + "description": "Ingress TLS", + "form": true + } + } + }, + "resources": { + "type": "object", + "title": "Resources", + "description": "Resources", + "form": true + }, + "autoscaling": { + "type": "object", + "title": "Autoscaling", + "description": "Autoscaling", + "form": true, + "properties": { + "enabled": { + "type": "boolean", + "title": "Enabled", + "description": "Enable autoscaling", + "form": true + }, + "minReplicas": { + "type": "integer", + "title": "Min Replicas", + "description": "Autoscaling min replicas", + "form": true + }, + "maxReplicas": { + "type": "integer", + "title": "Max Replicas", + "description": "Autoscaling max replicas", + "form": true + }, + "targetCPUUtilizationPercentage": { + "type": "integer", + "title": "Target CPU Utilization Percentage", + "description": "Autoscaling target CPU utilization percentage", + "form": true + } + } + }, + "nodeSelector": { + "type": "object", + "title": "Node Selector", + "description": "Node selector", + "form": true + }, + "tolerations": { + "type": "array", + "title": "Tolerations", + "description": "Tolerations", + "form": true + }, + "affinity": { + "type": "object", + "title": "Affinity", + "description": "Affinity", + "form": true + } + } +} \ No newline at end of file diff --git a/charts/prometheus-prefect-exporter/values.yaml b/charts/prometheus-prefect-exporter/values.yaml new file mode 100644 index 00000000..09a1c5ac --- /dev/null +++ b/charts/prometheus-prefect-exporter/values.yaml @@ -0,0 +1,205 @@ +# -- Number of replicas +replicaCount: 1 + +# -- Image registry +image: + repository: prefecthq/prometheus-prefect-exporter + pullPolicy: IfNotPresent + # Overrides the image tag whose default is the chart appVersion. + tag: 1.0.0 + +# -- String to partially override prometheus-prefect-exporter.fullname template (will maintain the release name) +nameOverride: "" + +# -- String to fully override prometheus-prefect-exporter.fullname template +fullnameOverride: "" + +# -- Global Docker registry secret names as an array +imagePullSecrets: [] + +# -- Enable creation of ServiceAccount +serviceAccount: + # Specifies whether a service account should be created + create: true + # Annotations to add to the service account + annotations: {} + # The name of the service account to use. + # If not set and create is true, a name is generated using the fullname template + name: "" + +# -- Prefect API URL to connect to for metrics +prefectApiUrl: http://prefect-server.prefect.svc.cluster.local:4200/api +# -- Environment variables to configure application +env: {} + # Plain vars + # foo: bar + # my_env: my_value + +# -- Limits the number of Pods of a replicated application that are down simultaneously from voluntary disruptions +podDisruptionBudget: {} + # maxUnavailable: 0 + +# -- Pod annotations +podAnnotations: {} + +# -- To specify security settings for a Pod +podSecurityContext: {} + # fsGroup: 2000 + +# -- Defines privilege and access control settings for a Pod or Container +securityContext: {} + # capabilities: + # drop: + # - ALL + # readOnlyRootFilesystem: true + # runAsNonRoot: true + # runAsUser: 1000 + +# -- Kubernetes servide to expose Pod +service: + # -- Kubernetes Service type. Allowed values: NodePort, LoadBalancer or ClusterIP + type: ClusterIP + # -- Kubernetes Service port + port: 80 + # -- Pod expose port + targetPort: 8000 + +# -- Enable ServiceMonitor to get metrics +# ref: https://github.com/prometheus-operator/prometheus-operator/blob/main/Documentation/api.md#servicemonitor +serviceMonitor: + # -- Enable or disable + enabled: false + interval: 30s + scrapeTimeout: 10s + metricRelabelings: [] + relabelings: [] + +## -- Custom PrometheusRules to be defined +# ref: https://github.com/coreos/prometheus-operator#customresourcedefinitions +prometheusRule: + enabled: false + additionalLabels: {} + rules: [] + # - alert: PrefectServerDown + # expr: sum by (pod, namespace) (kube_pod_info{namespace="prefect", pod=~"prefect-server.*"}) == 0 + # for: 0m + # labels: + # severity: critical + # annotations: + # summary: Flow Run {{ $labels.flow_name }} {{ $labels.state_name }} (Flow {{ $labels.flow_name }}) + # description: "Flow Run failed or crashed\n VALUE = {{ $value }}\n LABELS = {{ $labels }}" + + # - alert: PrefectDeploymentsAllPaused + # expr: (count by (namespace) (prefect_info_deployment) == bool count by (namespace) (prefect_info_deployment{is_schedule_active="False"})) == 1 + # for: 0m + # labels: + # severity: warning + # annotations: + # summary: All deployments are paused + # description: "All deployments are paused\n VALUE = {{ $value }}\n LABELS = {{ $labels }}" + + # - alert: PrefectAgentWorkersNotRunning + # expr: sum(kube_deployment_status_replicas{deployment=~".*agent|.*worker"}) == 0 + # for: 0m + # labels: + # severity: critical + # annotations: + # summary: All agent and worker are not running + # description: "All agent and worker are not running\n VALUE = {{ $value }}\n LABELS = {{ $labels }}" + + # - alert: PrefectWorkPoolNotAllow + # expr: prefect_work_pools_total == 0 + # for: 0m + # labels: + # severity: critical + # annotations: + # summary: Worker pool not allowed + # description: "Worker pool not allowed\n VALUE = {{ $value }}\n LABELS = {{ $labels }}" + + # - alert: PrefectWorkPoolsAllPaused + # expr: (count by (namespace) (prefect_work_pools_total) == bool count by (namespace) (prefect_info_work_pools{is_paused="True"})) == 1 + # for: 0m + # labels: + # severity: warning + # annotations: + # summary: All work pools are paused + # description: "All work pools are paused\n VALUE = {{ $value }}\n LABELS = {{ $labels }}" + + # - alert: PrefectWorkQueueNotAllow + # expr: prefect_work_queues_total == 0 + # for: 0m + # labels: + # severity: critical + # annotations: + # summary: Worker queue not allowed + # description: "Worker queue not allowed\n VALUE = {{ $value }}\n LABELS = {{ $labels }}" + + # - alert: PrefectWorkQueuesAllPaused + # expr: (count by (namespace) (prefect_work_queues_total) == bool count by (namespace) (prefect_info_work_queues{is_paused="True"})) == 1 + # for: 0m + # labels: + # severity: warning + # annotations: + # summary: All work queues are paused + # description: "All work queues are paused\n VALUE = {{ $value }}\n LABELS = {{ $labels }}" + + # - alert: PrefectFlowRunCrashedOrFailed + # expr: group by (flow_name, flow_run_name, namespace) (count_over_time(prefect_info_flow_runs{state_name=~"Failed|Crashed"}[1m])) + # for: 0m + # labels: + # severity: critical + # annotations: + # summary: Flow Run {{ $labels.flow_name }} {{ $labels.state_name }} (Flow {{ $labels.flow_name }}) + # description: "Flow Run failed or crashed\n VALUE = {{ $value }}\n LABELS = {{ $labels }}" + + +# -- Enable livenessProbe +livenessProbe: false +# -- Enable readinessProbe +readinessProbe: false +# -- Ingress configuration to expose app +ingress: + enabled: false + className: "" + annotations: {} + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + hosts: + - host: chart-example.local + paths: + - path: / + pathType: ImplementationSpecific + tls: [] + # - secretName: chart-example-tls + # hosts: + # - chart-example.local + +# -- The resources limits and requested +resources: {} + # We usually recommend not to specify default resources and to leave this as a conscious + # choice for the user. This also increases chances charts run on environments with little + # resources, such as Minikube. If you do want to specify resources, uncomment the following + # lines, adjust them as necessary, and remove the curly braces after 'resources:'. + # limits: + # cpu: 100m + # memory: 128Mi + # requests: + # cpu: 100m + # memory: 128Mi + +# -- Autoscaling with CPU or memory utilization percentage +autoscaling: + enabled: false + minReplicas: 1 + maxReplicas: 100 + targetCPUUtilizationPercentage: 80 + # targetMemoryUtilizationPercentage: 80 + +# -- Node labels for pod assignment +nodeSelector: {} + +# -- Tolerations for pod assignment +tolerations: [] + +# -- Affinity for pod assignment +affinity: {} From 576d1459484db7aacc3faa150e0f6129065a97bb Mon Sep 17 00:00:00 2001 From: Jimi Dodd-o Date: Thu, 7 Dec 2023 14:16:18 -0500 Subject: [PATCH 2/2] Fix: commit req and file name for prometheus-prefect-exporter release (#278) Fix commit req and file name --- .github/workflows/prometheus-exporter-release.yaml | 2 +- ...test.yaml => prometheus-prefect-exporter-lint-and-test.yaml} | 0 charts/prometheus-prefect-exporter/README.md | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) rename .github/workflows/{prometheus-prefect.exporter-lint-and-test.yaml => prometheus-prefect-exporter-lint-and-test.yaml} (100%) diff --git a/.github/workflows/prometheus-exporter-release.yaml b/.github/workflows/prometheus-exporter-release.yaml index 74a54ae6..cc67722c 100644 --- a/.github/workflows/prometheus-exporter-release.yaml +++ b/.github/workflows/prometheus-exporter-release.yaml @@ -87,7 +87,7 @@ jobs: cp /tmp/chart/artifacthub-repo.yml . cp /tmp/chart/index.yaml . cp /tmp/chart/prometheus-prefect-exporter-$RELEASE_VERSION.* ./charts - git add ./artifacthub-repo.yml ./index.yaml prometheus-prefect-exporter-$RELEASE_VERSION.* + git add ./artifacthub-repo.yml ./index.yaml ./charts/prometheus-prefect-exporter-$RELEASE_VERSION.* git commit -m "Release $RELEASE_VERSION" git push origin gh-pages env: diff --git a/.github/workflows/prometheus-prefect.exporter-lint-and-test.yaml b/.github/workflows/prometheus-prefect-exporter-lint-and-test.yaml similarity index 100% rename from .github/workflows/prometheus-prefect.exporter-lint-and-test.yaml rename to .github/workflows/prometheus-prefect-exporter-lint-and-test.yaml diff --git a/charts/prometheus-prefect-exporter/README.md b/charts/prometheus-prefect-exporter/README.md index 295ebb48..882984e3 100644 --- a/charts/prometheus-prefect-exporter/README.md +++ b/charts/prometheus-prefect-exporter/README.md @@ -3,7 +3,7 @@ ## Overview This chart deploys a [Prometheus Exporter](https://github.com/PrefectHQ/prometheus-prefect-exporter) for Prefect Server, providing relevant metrics from your deployed Prefect Server instance. -Shoutout to @ialejandro for the original work on this chart! +Shoutout to [@ialejandro](https://github.com/ialejandro) for the original work on this chart! ## Installing the Chart