Skip to content

Commit

Permalink
feat(canary): add prometheus push metrics (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
JossWhittle authored Dec 18, 2023
1 parent a180a06 commit 49b6e15
Show file tree
Hide file tree
Showing 14 changed files with 561 additions and 141 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/flake8.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ jobs:

- name: run flake8
run: |
flake8 --max-complexity 10 --ignore E501 src
flake8 --max-complexity 10 --ignore E501,C901 src
11 changes: 11 additions & 0 deletions charts/canary/charts/crds/crds/http-monitor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,22 @@ spec:
properties:
url:
type: string
description: Url to poll over http(s).
proxy:
type: object
properties:
url:
type: string
description: Url to a http proxy to use when polling the target url. Null inherits the controllers default, empty string explicitly disables proxy.
interval:
type: integer #seconds
status:
type: integer
default: 200
required:
- url
- interval
- status
scope: Namespaced
names:
plural: canaryhttpmonitors
Expand Down
10 changes: 0 additions & 10 deletions charts/canary/templates/_helpers/common.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,6 @@ The list of `env` vars for canary pods
EXAMPLE USAGE: {{ include "canary.env" (dict "Release" .Release "Values" .Values "extraEnv" $extraEnv) }}
*/}}
{{- define "canary.env" }}
{{- /* user-defined (global) */ -}}
{{- if .Values.canary.extraEnv }}
{{ toYaml .Values.canary.extraEnv }}
{{- end }}

{{- /* user-defined */ -}}
{{- if .extraEnv }}
{{ toYaml .extraEnv }}
Expand All @@ -117,11 +112,6 @@ The list of `envFrom` vars for canary pods
EXAMPLE USAGE: {{ include "canary.envFrom" (dict "Release" .Release "Values" .Values "extraEnvFrom" $extraEnvFrom) }}
*/}}
{{- define "canary.envFrom" }}
{{- /* user-defined (global) */ -}}
{{- if .Values.canary.extraEnvFrom }}
{{ toYaml .Values.canary.extraEnvFrom }}
{{- end }}

{{- /* user-defined */ -}}
{{- if .extraEnvFrom }}
{{ toYaml .extraEnvFrom }}
Expand Down
93 changes: 93 additions & 0 deletions charts/canary/templates/controller/daemonset.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
{{- if and .Values.controller.enabled (eq .Values.controller.mode "daemonset") }}
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: {{ include "canary.fullname" . }}-controller
namespace: {{ .Release.Namespace }}

labels:
app: {{ include "canary.labels.app" . }}
component: controller
chart: {{ include "canary.labels.chart" . }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
{{- range $key, $value := .Values.controller.labels }}
{{ $key }}: {{ $value | quote }}
{{- end }}
annotations:
{{- range $key, $value := .Values.controller.annotations }}
{{ $key }}: {{ $value | quote }}
{{- end }}

spec:

selector:
matchLabels:
app: {{ include "canary.labels.app" . }}
component: controller
release: {{ .Release.Name }}

updateStrategy:
{{- if eq .Values.controller.daemonset.updateStrategy "RollingUpdate" }}
rollingUpdate:
maxUnavailable: {{ .Values.controller.daemonset.maxUnavailable }}
{{- end }}
type: {{ .Values.controller.daemonset.updateStrategy }}

template:
metadata:
labels:
app: {{ include "canary.labels.app" . }}
component: controller
chart: {{ include "canary.labels.chart" . }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
{{- range $key, $value := .Values.controller.labels }}
{{ $key }}: {{ $value | quote }}
{{- end }}
annotations:
{{- range $key, $value := .Values.controller.podAnnotations }}
{{ $key }}: {{ $value | quote }}
{{- end }}
{{- range $key, $value := .Values.controller.annotations }}
{{ $key }}: {{ $value | quote }}
{{- end }}

spec:

restartPolicy: Always
serviceAccountName: canaryhttpmonitor

tolerations: {{ toYaml .Values.controller.tolerations | nindent 8 }}
nodeSelector: {{ toYaml .Values.controller.nodeSelector | nindent 8 }}
affinity: {{ toYaml .Values.controller.affinity | nindent 8 }}
terminationGracePeriodSeconds: {{ .Values.controller.terminationGracePeriod }}

containers:
- name: controller
{{- include "canary.image" (dict "image" .Values.controller.image) | indent 10 }}

ports:
- containerPort: 8080

envFrom:
{{- include "canary.envFrom" (dict "Release" .Release "Values" .Values "extraEnv" .Values.controller.extraEnvFrom) | indent 12 }}
env:
# Make the controller aware of where it is in the cluster
- name: CANARY_K8S_NODE_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
- name: CANARY_K8S_POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: CANARY_K8S_POD_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: CANARY_K8S_RELEASE_NAME
value: {{ .Release.Name }}
{{- include "canary.env" (dict "Release" .Release "Values" .Values "extraEnv" .Values.controller.extraEnv) | indent 12 }}

{{- end }}
53 changes: 50 additions & 3 deletions charts/canary/templates/controller/deployment.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- if .Values.controller.enabled }}
{{- if and .Values.controller.enabled (eq .Values.controller.mode "deployment") }}
apiVersion: apps/v1
kind: Deployment
metadata:
Expand All @@ -11,9 +11,16 @@ metadata:
chart: {{ include "canary.labels.chart" . }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
{{- range $key, $value := .Values.controller.labels }}
{{ $key }}: {{ $value | quote }}
{{- end }}
annotations:
{{- range $key, $value := .Values.controller.annotations }}
{{ $key }}: {{ $value | quote }}
{{- end }}

spec:
replicas: 1
replicas: {{ .Values.controller.deployment.replicas }}

selector:
matchLabels:
Expand All @@ -26,15 +33,55 @@ spec:
labels:
app: {{ include "canary.labels.app" . }}
component: controller
chart: {{ include "canary.labels.chart" . }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
{{- range $key, $value := .Values.controller.labels }}
{{ $key }}: {{ $value | quote }}
{{- end }}
annotations:
{{- range $key, $value := .Values.controller.podAnnotations }}
{{ $key }}: {{ $value | quote }}
{{- end }}
{{- range $key, $value := .Values.controller.annotations }}
{{ $key }}: {{ $value | quote }}
{{- end }}

spec:

restartPolicy: Always
serviceAccountName: canaryhttpmonitor

tolerations: {{ toYaml .Values.controller.tolerations | nindent 8 }}
nodeSelector: {{ toYaml .Values.controller.nodeSelector | nindent 8 }}
affinity: {{ toYaml .Values.controller.affinity | nindent 8 }}
terminationGracePeriodSeconds: {{ .Values.controller.terminationGracePeriod }}

containers:
- name: controller
{{- include "canary.image" (dict "image" .Values.controller.image) | indent 10 }}

serviceAccountName: canaryhttpmonitor
ports:
- containerPort: 8080

envFrom:
{{ include "canary.envFrom" (dict "extraEnv" .Values.controller.extraEnvFrom) | indent 12 }}
env:
# Make the controller aware of where it is in the cluster
- name: CANARY_K8S_NODE_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
- name: CANARY_K8S_POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: CANARY_K8S_POD_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: CANARY_K8S_RELEASE_NAME
value: {{ .Release.Name }}
{{- include "canary.env" (dict "extraEnv" .Values.controller.extraEnv) | indent 12 }}

{{- end }}
10 changes: 6 additions & 4 deletions charts/canary/templates/monitors/example-monitor.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
{{- if .Values.monitor.example.enabled }}
apiVersion: "canary.ukserp.ac.uk/v1"
kind: CanaryHTTPMonitor
metadata:
name: github
name: github-canary
namespace: {{ .Release.Namespace }}
spec:
url: https://api.github.com/octocat
interval: 30 #seconds

url: https://github.com/SwanseaUniversityMedical/Canary
interval: 60 #seconds
status: 200
{{- end }}
28 changes: 28 additions & 0 deletions charts/canary/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,38 @@ crds:
controller:
enabled: true

tolerations: []
nodeSelector: {}
affinity: {}
terminationGracePeriod: 15

labels: {}
annotations: {}
extraEnv: []
extraEnvFrom: []

podAnnotations:
prometheus.io/scrape: "true"
prometheus.io/path: /metrics
prometheus.io/port: "8080"

mode: deployment

deployment:
replicas: 1

daemonset:
updateStrategy: RollingUpdate
maxUnavailable: 1

image:
repository: harbor.ukserp.ac.uk/canary/canary
tag: 1.5.0
pullPolicy: IfNotPresent
pullSecret: ""
uid: 1001
gid: 1001

monitor:
example:
enabled: false
Loading

0 comments on commit 49b6e15

Please sign in to comment.