Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds (Prometheus) ServiceMonitor integration #16

Merged
merged 7 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,11 @@ jobs:
uses: helm/kind-action@v1
if: steps.list-changed.outputs.changed == 'true'

- name: Setup helmfile
uses: mamezou-tech/[email protected]

- name: Install prometheus
run: helmfile -f charts/zipkin/ci/helmfile.yaml sync

- name: Run chart-testing (install)
run: ct install
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ You can then run `helm search repo zipkin` to see the charts.
| serviceAccount.create | bool | `true` | |
| 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.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' |
| tolerations | list | `[]` | |
| zipkin.discovery.eureka.serviceUrl | string | no default | v2 endpoint of Eureka, e.g. `https://eureka-prod/eureka/v2` |
| zipkin.discovery.eureka.app | string | `"zipkin"` | The application this instance registers to |
Expand Down
24 changes: 24 additions & 0 deletions charts/zipkin/ci/helmfile.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
# install via `helmfile -f charts/zipkin/ci/helmfile.yaml sync`
repositories:
- name: prometheus-community
url: https://prometheus-community.github.io/helm-charts

# Prometheus is too much to configure manually in a test yaml. We need the CRD

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in a test yaml so we use helm.

Maybe, I wasn't quite sure what the intention is of this comment, made a guess

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good guess

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, rewrote!

# servicemonitors.monitoring.coreos.com as well as Prometheus, deployed as the
# service named "prometheus-operated" in our test namespace "ci-monitoring"
releases:
- name: prometheus-stack
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:
enabled: false
- grafana:
enabled: false
- nodeExporter:
enabled: false
- kubeletService:
enabled: false
5 changes: 5 additions & 0 deletions charts/zipkin/ci/serviceMonitor-values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
serviceMonitor:
enabled: true
interval: 1s
scrapeTimeout: 2s
41 changes: 41 additions & 0 deletions charts/zipkin/templates/servicemonitor.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{{- /*
Copyright 2024 The OpenZipkin Authors
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: later we can switch everything to SPDX, so I didn't do it in this PR


Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License
is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or implied. See the License for the specific language governing permissions and limitations under
the License.
*/}}
{{- if .Values.serviceMonitor.enabled -}}
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: {{ include "zipkin.fullname" . }}
namespace: {{ include "zipkin.namespace" . }}
labels:
{{- include "zipkin.labels" . | nindent 4 }}
{{- if .Values.serviceMonitor.labels }}
{{- (toYaml .Values.serviceMonitor.labels | nindent 4) }}
{{- end }}
spec:
endpoints:
- port: http-query
path: '/prometheus'
{{- if .Values.serviceMonitor.interval }}
interval: {{ .Values.serviceMonitor.interval }}
{{- end }}
{{- if .Values.serviceMonitor.scrapeTimeout }}
scrapeTimeout: {{ .Values.serviceMonitor.scrapeTimeout }}
{{- end }}
selector:
matchLabels:
{{- include "zipkin.selectorLabels" . | nindent 8 }}
namespaceSelector:
matchNames:
- {{ include "zipkin.namespace" . }}
{{- end }}
10 changes: 10 additions & 0 deletions charts/zipkin/templates/tests/test-connection.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,15 @@ spec:
command: [ '/bin/sh', '-c' ]
# If self-tracing, sleep for the trace to process. Then, get it by the constant ID passed above.
args: [ 'sleep 3 && wget -q --spider http://{{ include "zipkin.fullname" . }}:{{ .Values.service.port }}/api/v2/trace/cafebabecafebabe' ]
{{- end }}
{{- if .Values.serviceMonitor.enabled }}
- 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' ]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can take out the '|grep zipkin' temporarily here to see that the query works, but no data is returned. You might also want to check '/api/v1/targets?scrapePool=zipkin'

{{- end }}
restartPolicy: Never
17 changes: 17 additions & 0 deletions charts/zipkin/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,23 @@
}
}
},
"serviceMonitor": {
"type": "object",
"properties": {
"enabled": {
"type": "boolean"
},
"interval": {
"type": "string"
},
"labels": {
"type": "object"
},
"scrapeTimeout": {
"type": "string"
}
}
},
"tolerations": {
"type": "array"
},
Expand Down
8 changes: 8 additions & 0 deletions charts/zipkin/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ service:
type: ClusterIP
port: 9411

serviceMonitor:
# Creates a ServiceMonitor to scrape /prometheus
# You must have the prometheus-operator installed to set this to true
enabled: false
labels: {}
# interval: 10s
# scrapeTimeout: 10s

ingress:
enabled: false
annotations:
Expand Down
Loading