Skip to content

Commit

Permalink
Ensure everything works in real life
Browse files Browse the repository at this point in the history
Signed-off-by: Adrian Cole <[email protected]>
  • Loading branch information
Adrian Cole committed Mar 12, 2024
1 parent 76c78a6 commit 89677c0
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 22 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ You can then run `helm search repo zipkin` to see the charts.
| ingress.path | string | `"/"` | |
| ingress.tls | list | `[]` | |
| nameOverride | string | `""` | |
| namespaceOverride | string | release namespace | Namespace to create the zipkin resources in |
| nodeSelector | object | `{}` | |
| podAnnotations."sidecar.istio.io/inject" | string | `"false"` | |
| podSecurityContext | object | `{}` | |
Expand All @@ -56,6 +57,7 @@ You can then run `helm search repo zipkin` to see the charts.
| serviceAccount.name | string | `""` | If not set and create is true, a name is generated using the fullname template |
| serviceAccount.psp | bool | `false` | |
| serviceMonitor.enabled | bool | `false` | Creates a ServiceMonitor to scrape /prometheus. Requires prometheus-operator |
| serviceMonitor.namespace | string | override or release namespace | Namespace to create the service monitor in |
| serviceMonitor.labels | object | `{}` | Additional metadata labels |
| serviceMonitor.interval | string | Prometheus global scrape interval | How often to scrape /prometheus. e.g. '5s' |
| serviceMonitor.scrapeTimeout | string | Prometheus global scrape timeout | Timeout for scraping metrics. e.g. '10s' |
Expand Down
39 changes: 34 additions & 5 deletions charts/zipkin/ci/helmfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,42 @@ releases:
namespace: ci-monitoring
createNamespace: true
chart: prometheus-community/kube-prometheus-stack
# Reduce size of this test stack by disabling dependencies we don't use.
values:
- alertmanager:
- prometheusOperator:
enabled: true
prometheus:
enabled: true
prometheusSpec:
# Allow any namespace and any values
serviceMonitorNamespaceSelector:
any: true
serviceMonitorSelector:
any: true
serviceMonitorSelectorNilUsesHelmValues: false
# Disable anything else, like multi-container grafana pods.
defaultRules:
enabled: false
- grafana:
alertmanager:
enabled: false
- nodeExporter:
kubeApiServer:
enabled: false
- kubeletService:
kubelet:
enabled: false
kubeControllerManager:
enabled: false
coreDns:
enabled: false
kubeDns:
enabled: false
kubeEtcd:
enabled: false
kubeScheduler:
enabled: false
kubeProxy:
enabled: false
kubeStateMetrics:
enabled: false
nodeExporter:
enabled: false
grafana:
enabled: false
3 changes: 2 additions & 1 deletion charts/zipkin/ci/serviceMonitor-values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
serviceMonitor:
enabled: true
interval: 1s
scrapeTimeout: 2s
scrapeTimeout: 1s
namespace: ci-monitoring
20 changes: 13 additions & 7 deletions charts/zipkin/templates/servicemonitor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,32 @@ apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: {{ include "zipkin.fullname" . }}
{{- if .Values.serviceMonitor.namespace }}
namespace: {{ .Values.serviceMonitor.namespace }}
{{- else }}
namespace: {{ include "zipkin.namespace" . }}
{{- end }}
labels:
{{- include "zipkin.labels" . | nindent 4 }}
{{- if .Values.serviceMonitor.labels }}
{{- (toYaml .Values.serviceMonitor.labels | nindent 4) }}
{{- end }}
spec:
jobLabel: {{ include "zipkin.fullname" . }}
namespaceSelector:
matchNames:
- {{ include "zipkin.namespace" . }}
endpoints:
- port: http-query
path: '/prometheus'
{{- if .Values.serviceMonitor.interval }}
interval: {{ .Values.serviceMonitor.interval }}
scheme: http
{{- with .Values.serviceMonitor.interval }}
interval: {{ . }}
{{- end }}
{{- if .Values.serviceMonitor.scrapeTimeout }}
scrapeTimeout: {{ .Values.serviceMonitor.scrapeTimeout }}
{{- with .Values.serviceMonitor.scrapeTimeout }}
scrapeTimeout: {{ . }}
{{- end }}
selector:
matchLabels:
{{- include "zipkin.selectorLabels" . | nindent 8 }}
namespaceSelector:
matchNames:
- {{ include "zipkin.namespace" . }}
{{- end }}
28 changes: 21 additions & 7 deletions charts/zipkin/templates/tests/test-connection.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ apiVersion: v1
kind: Pod
metadata:
name: "{{ include "zipkin.fullname" . }}-test-connection"
labels:
{{- include "zipkin.labels" . | nindent 4 }}
labels: {} # we don't need any labels in the test pod!
annotations:
"helm.sh/hook": test
spec:
Expand Down Expand Up @@ -39,6 +38,16 @@ spec:
command: [ '/bin/sh', '-c' ]
# Get an arbitrary API endpoint using the ClusterIP and service port
args: [ 'wget -q --spider --header "b3: cafebabecafebabe-cafebabecafebabe-1" http://{{ include "zipkin.fullname" . }}:{{ .Values.service.port }}/api/v2/services' ]
- name: get-api2
image: "ghcr.io/openzipkin/alpine:3.19.1"
command: [ '/bin/sh', '-c' ]
# Get an arbitrary API endpoint using the ClusterIP and service port
args: [ 'wget -q --spider --header "b3: cafebabecafebabe-cafebabecafebabe-1" http://{{ include "zipkin.fullname" . }}:{{ .Values.service.port }}/api/v2/services' ]
- name: get-api3
image: "ghcr.io/openzipkin/alpine:3.19.1"
command: [ '/bin/sh', '-c' ]
# Get an arbitrary API endpoint using the ClusterIP and service port
args: [ 'wget -q --spider --header "b3: cafebabecafebabe-cafebabecafebabe-1" http://{{ include "zipkin.fullname" . }}:{{ .Values.service.port }}/api/v2/services' ]
{{- if .Values.zipkin.selfTracing.enabled }}
- name: get-self-trace
image: 'ghcr.io/openzipkin/alpine:3.19.1'
Expand All @@ -47,13 +56,18 @@ spec:
args: [ 'sleep 3 && wget -q --spider http://{{ include "zipkin.fullname" . }}:{{ .Values.service.port }}/api/v2/trace/cafebabecafebabe' ]
{{- end }}
{{- if .Values.serviceMonitor.enabled }}
# This verifies prometheus scraped the zipkin service on the correct
# endpoint, by reading an actual statistic.
# See https://prometheus.io/docs/prometheus/latest/querying/api/
- name: get-prometheus-query
image: 'ghcr.io/openzipkin/alpine:3.19.1'
command: [ '/bin/sh', '-c' ]
# If using a service monitor, wait for the scrape interval and check for a statistic.
# This uses prometheus-operated in the ci-monitoring namespace, from helmfile.yaml.
# Note: The query API returns HTTP 200 on empty, so we grep to ensure something returned.
# See https://prometheus.io/docs/prometheus/latest/querying/api/
args: [ 'sleep 5 && wget -q -O - http://prometheus-operated.ci-monitoring.svc.cluster.local:9090/api/v1/query?query=http_server_requests_seconds_max | grep zipkin' ]
# Note: The below commands use the Prometheus API, which returns HTTP 200
# even on empty. Rather than install jq, we use grep to ensure a result.
#
# We use a sleep loop despite the scrape delay of only 1s. This is due to
# an up to one-minute read-back delay between adding the service monitor,
# and being visibility as a prometheus target in kube-prometheus-stack.
args: [ 'until (wget -q -O - http://prometheus-operated.{{ .Values.serviceMonitor.namespace }}.svc.cluster.local:9090/api/v1/query?query=http_server_requests_seconds_max|grep zipkin); do sleep 3; done' ]
{{- end }}
restartPolicy: Never
3 changes: 3 additions & 0 deletions charts/zipkin/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@
"labels": {
"type": "object"
},
"namespace": {
"type": "string"
},
"scrapeTimeout": {
"type": "string"
}
Expand Down
7 changes: 5 additions & 2 deletions charts/zipkin/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,14 @@ service:

serviceMonitor:
# Creates a ServiceMonitor to scrape /prometheus
# You must have the prometheus-operator installed to set this to true
enabled: false
labels: {}
# Namespace to create the service monitor in
namespace: ""
# interval: 10s
# scrapeTimeout: 10s
# Add any labels required by your prometheus spec serviceMonitorSelector
labels: {}
# release: prometheus

ingress:
enabled: false
Expand Down

0 comments on commit 89677c0

Please sign in to comment.