Skip to content

Commit a03217e

Browse files
authored
feat: support scraping metrics by prometheus(#36) (#37)
1 parent 4546ec1 commit a03217e

File tree

5 files changed

+84
-9
lines changed

5 files changed

+84
-9
lines changed

charts/gbox/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apiVersion: v2
22
name: gbox
33
description: GBox Helm chart for Kubernetes. GBox is a reverse proxy in front of any GraphQL server for caching, securing and monitoring.
44
type: application
5-
version: 1.0.3
5+
version: 1.0.4
66
appVersion: "v1.0.5"
77
sources:
88
- https://github.com/gbox-proxy/gbox

charts/gbox/README.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# GBox Chart for Kubernetes
22

3-
![Version: 1.0.3](https://img.shields.io/badge/Version-1.0.3-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: v1.0.5](https://img.shields.io/badge/AppVersion-v1.0.5-informational?style=flat-square)
3+
![Version: 1.0.4](https://img.shields.io/badge/Version-1.0.4-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: v1.0.5](https://img.shields.io/badge/AppVersion-v1.0.5-informational?style=flat-square)
44

55
GBox Helm chart for Kubernetes. GBox is a reverse proxy in front of any GraphQL server for caching, securing and monitoring.
66

@@ -50,15 +50,21 @@ To install the chart with the release name `my-release`, run the following comma
5050
| ingress.annotations | object | `{}` | Annotations to be added to the ingress. |
5151
| ingress.className | string | `""` | Ingress [class name](https://kubernetes.io/docs/concepts/services-networking/ingress/#ingress-class). |
5252
| ingress.enabled | bool | `false` | Enable [ingress](https://kubernetes.io/docs/concepts/services-networking/ingress/). |
53-
| ingress.hosts[0].host | string | `"chart-example.local"` | |
54-
| ingress.hosts[0].paths[0].path | string | `"/"` | |
55-
| ingress.hosts[0].paths[0].pathType | string | `"ImplementationSpecific"` | |
53+
| ingress.hosts | list | See [values.yaml](values.yaml). | Ingress host configuration. |
5654
| ingress.tls | list | See [values.yaml](values.yaml). | Ingress TLS configuration. |
5755
| metrics.enabled | bool | `true` | Whether enable Prometheus metric endpoint or not |
5856
| metrics.path | string | `"/metrics"` | Url path of metric endpoint. |
57+
| metrics.serviceMonitor.additionalLabels | object | `{}` | Additional labels that can be used so ServiceMonitor resource(s) can be discovered by Prometheus |
58+
| metrics.serviceMonitor.enabled | bool | `false` | Create ServiceMonitor resource(s) for scraping metrics using PrometheusOperator. When enabled @param metrics.enabled must be set to true |
59+
| metrics.serviceMonitor.honorLabels | bool | `false` | Specify honorLabels parameter to add the scrape endpoint |
60+
| metrics.serviceMonitor.interval | string | `"30s"` | The interval at which metrics should be scraped |
61+
| metrics.serviceMonitor.metricRelabelings | list | `[]` | Metrics RelabelConfigs to apply to samples before ingestion. |
62+
| metrics.serviceMonitor.namespace | string | `""` | The namespace in which the ServiceMonitor will be created |
63+
| metrics.serviceMonitor.relabellings | list | `[]` | |
64+
| metrics.serviceMonitor.scrapeTimeout | string | `""` | The timeout after which the scrape is ended |
5965
| nameOverride | string | `""` | A name in place of the chart name for `app:` labels. |
6066
| nodeSelector | object | `{}` | [Node selector](https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/#nodeselector) configuration. |
61-
| podAnnotations | object | `{}` | Annotations to be added to pods. |
67+
| podAnnotations | object | See [values.yaml](values.yaml). | Annotations to be added to pods. |
6268
| podSecurityContext | object | `{}` | Pod [security context](https://kubernetes.io/docs/tasks/configure-pod-container/security-context/#set-the-security-context-for-a-pod). See the [API reference](https://kubernetes.io/docs/reference/kubernetes-api/workload-resources/pod-v1/#security-context) for details. |
6369
| redis.architecture | string | `"standalone"` | Set Redis architecture standalone or replication. |
6470
| redis.auth.password | string | `"!ChangeMe!"` | |

charts/gbox/templates/deployment.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ spec:
1313
{{- include "gbox.selectorLabels" . | nindent 6 }}
1414
template:
1515
metadata:
16-
{{- with .Values.podAnnotations }}
16+
{{- if .Values.podAnnotations }}
1717
annotations:
18-
{{- toYaml . | nindent 8 }}
18+
{{- tpl (toYaml .Values.podAnnotations) . | nindent 8 }}
1919
{{- end }}
2020
labels:
2121
{{- include "gbox.selectorLabels" . | nindent 8 }}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{{- if and .Values.metrics.enabled .Values.metrics.serviceMonitor.enabled }}
2+
apiVersion: monitoring.coreos.com/v1
3+
kind: ServiceMonitor
4+
metadata:
5+
name: {{ include "gbox.fullname" . }}
6+
{{- if .Values.metrics.serviceMonitor.namespace }}
7+
namespace: {{ .Values.metrics.serviceMonitor.namespace }}
8+
{{- else }}
9+
namespace: {{ .Release.Namespace | quote }}
10+
{{- end }}
11+
labels: {{- include "gbox.labels" . | nindent 4 }}
12+
{{- if .Values.metrics.serviceMonitor.additionalLabels }}
13+
{{- include .Values.metrics.serviceMonitor.additionalLabels . | nindent 4 }}
14+
{{- end }}
15+
spec:
16+
endpoints:
17+
- port: http
18+
path: {{ .Values.metrics.path }}
19+
{{- if .Values.metrics.serviceMonitor.interval }}
20+
interval: {{ .Values.metrics.serviceMonitor.interval }}
21+
{{- end }}
22+
{{- if .Values.metrics.serviceMonitor.scrapeTimeout }}
23+
scrapeTimeout: {{ .Values.metrics.serviceMonitor.scrapeTimeout }}
24+
{{- end }}
25+
{{- if .Values.metrics.serviceMonitor.honorLabels }}
26+
honorLabels: {{ .Values.metrics.serviceMonitor.honorLabels }}
27+
{{- end }}
28+
{{- if .Values.metrics.serviceMonitor.relabellings }}
29+
relabelings: {{- toYaml .Values.metrics.serviceMonitor.relabellings | nindent 6 }}
30+
{{- end }}
31+
{{- if .Values.metrics.serviceMonitor.metricRelabelings }}
32+
metricRelabelings: {{- toYaml .Values.metrics.serviceMonitor.metricRelabelings | nindent 6 }}
33+
{{- end }}
34+
namespaceSelector:
35+
matchNames:
36+
- {{ .Release.Namespace }}
37+
selector:
38+
matchLabels: {{- include "gbox.selectorLabels" . | nindent 6 }}
39+
{{- end }}

charts/gbox/values.yaml

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ serviceAccount:
2525
name: ""
2626

2727
# -- Annotations to be added to pods.
28-
podAnnotations: {}
28+
# @default -- See [values.yaml](values.yaml).
29+
podAnnotations:
30+
prometheus.io/scrape: "true"
31+
prometheus.io/port: "80"
32+
prometheus.io/path: "{{ .Values.metrics.path }}"
2933

3034
# -- Pod [security context](https://kubernetes.io/docs/tasks/configure-pod-container/security-context/#set-the-security-context-for-a-pod).
3135
# See the [API reference](https://kubernetes.io/docs/reference/kubernetes-api/workload-resources/pod-v1/#security-context) for details.
@@ -195,3 +199,29 @@ metrics:
195199

196200
# -- Url path of metric endpoint.
197201
path: /metrics
202+
203+
# Prometheus Service Monitor
204+
serviceMonitor:
205+
# -- Create ServiceMonitor resource(s) for scraping metrics using PrometheusOperator. When enabled @param metrics.enabled must be set to true
206+
enabled: false
207+
208+
# -- The namespace in which the ServiceMonitor will be created
209+
namespace: ""
210+
211+
# -- The interval at which metrics should be scraped
212+
interval: 30s
213+
214+
# -- The timeout after which the scrape is ended
215+
scrapeTimeout: ""
216+
217+
# -- Metrics RelabelConfigs to apply to samples before scraping.
218+
relabellings: []
219+
220+
# -- Metrics RelabelConfigs to apply to samples before ingestion.
221+
metricRelabelings: []
222+
223+
# -- Specify honorLabels parameter to add the scrape endpoint
224+
honorLabels: false
225+
226+
# -- Additional labels that can be used so ServiceMonitor resource(s) can be discovered by Prometheus
227+
additionalLabels: {}

0 commit comments

Comments
 (0)