Skip to content

Commit

Permalink
feat: support scraping metrics by prometheus(#36) (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
Phu96 authored May 12, 2022
1 parent 4546ec1 commit a03217e
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 9 deletions.
2 changes: 1 addition & 1 deletion charts/gbox/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: v2
name: gbox
description: GBox Helm chart for Kubernetes. GBox is a reverse proxy in front of any GraphQL server for caching, securing and monitoring.
type: application
version: 1.0.3
version: 1.0.4
appVersion: "v1.0.5"
sources:
- https://github.com/gbox-proxy/gbox
Expand Down
16 changes: 11 additions & 5 deletions charts/gbox/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# GBox Chart for Kubernetes

![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)
![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)

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

Expand Down Expand Up @@ -50,15 +50,21 @@ To install the chart with the release name `my-release`, run the following comma
| ingress.annotations | object | `{}` | Annotations to be added to the ingress. |
| ingress.className | string | `""` | Ingress [class name](https://kubernetes.io/docs/concepts/services-networking/ingress/#ingress-class). |
| ingress.enabled | bool | `false` | Enable [ingress](https://kubernetes.io/docs/concepts/services-networking/ingress/). |
| ingress.hosts[0].host | string | `"chart-example.local"` | |
| ingress.hosts[0].paths[0].path | string | `"/"` | |
| ingress.hosts[0].paths[0].pathType | string | `"ImplementationSpecific"` | |
| ingress.hosts | list | See [values.yaml](values.yaml). | Ingress host configuration. |
| ingress.tls | list | See [values.yaml](values.yaml). | Ingress TLS configuration. |
| metrics.enabled | bool | `true` | Whether enable Prometheus metric endpoint or not |
| metrics.path | string | `"/metrics"` | Url path of metric endpoint. |
| metrics.serviceMonitor.additionalLabels | object | `{}` | Additional labels that can be used so ServiceMonitor resource(s) can be discovered by Prometheus |
| metrics.serviceMonitor.enabled | bool | `false` | Create ServiceMonitor resource(s) for scraping metrics using PrometheusOperator. When enabled @param metrics.enabled must be set to true |
| metrics.serviceMonitor.honorLabels | bool | `false` | Specify honorLabels parameter to add the scrape endpoint |
| metrics.serviceMonitor.interval | string | `"30s"` | The interval at which metrics should be scraped |
| metrics.serviceMonitor.metricRelabelings | list | `[]` | Metrics RelabelConfigs to apply to samples before ingestion. |
| metrics.serviceMonitor.namespace | string | `""` | The namespace in which the ServiceMonitor will be created |
| metrics.serviceMonitor.relabellings | list | `[]` | |
| metrics.serviceMonitor.scrapeTimeout | string | `""` | The timeout after which the scrape is ended |
| nameOverride | string | `""` | A name in place of the chart name for `app:` labels. |
| nodeSelector | object | `{}` | [Node selector](https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/#nodeselector) configuration. |
| podAnnotations | object | `{}` | Annotations to be added to pods. |
| podAnnotations | object | See [values.yaml](values.yaml). | Annotations to be added to pods. |
| 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. |
| redis.architecture | string | `"standalone"` | Set Redis architecture standalone or replication. |
| redis.auth.password | string | `"!ChangeMe!"` | |
Expand Down
4 changes: 2 additions & 2 deletions charts/gbox/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ spec:
{{- include "gbox.selectorLabels" . | nindent 6 }}
template:
metadata:
{{- with .Values.podAnnotations }}
{{- if .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- tpl (toYaml .Values.podAnnotations) . | nindent 8 }}
{{- end }}
labels:
{{- include "gbox.selectorLabels" . | nindent 8 }}
Expand Down
39 changes: 39 additions & 0 deletions charts/gbox/templates/servicemonitor.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{{- if and .Values.metrics.enabled .Values.metrics.serviceMonitor.enabled }}
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: {{ include "gbox.fullname" . }}
{{- if .Values.metrics.serviceMonitor.namespace }}
namespace: {{ .Values.metrics.serviceMonitor.namespace }}
{{- else }}
namespace: {{ .Release.Namespace | quote }}
{{- end }}
labels: {{- include "gbox.labels" . | nindent 4 }}
{{- if .Values.metrics.serviceMonitor.additionalLabels }}
{{- include .Values.metrics.serviceMonitor.additionalLabels . | nindent 4 }}
{{- end }}
spec:
endpoints:
- port: http
path: {{ .Values.metrics.path }}
{{- if .Values.metrics.serviceMonitor.interval }}
interval: {{ .Values.metrics.serviceMonitor.interval }}
{{- end }}
{{- if .Values.metrics.serviceMonitor.scrapeTimeout }}
scrapeTimeout: {{ .Values.metrics.serviceMonitor.scrapeTimeout }}
{{- end }}
{{- if .Values.metrics.serviceMonitor.honorLabels }}
honorLabels: {{ .Values.metrics.serviceMonitor.honorLabels }}
{{- end }}
{{- if .Values.metrics.serviceMonitor.relabellings }}
relabelings: {{- toYaml .Values.metrics.serviceMonitor.relabellings | nindent 6 }}
{{- end }}
{{- if .Values.metrics.serviceMonitor.metricRelabelings }}
metricRelabelings: {{- toYaml .Values.metrics.serviceMonitor.metricRelabelings | nindent 6 }}
{{- end }}
namespaceSelector:
matchNames:
- {{ .Release.Namespace }}
selector:
matchLabels: {{- include "gbox.selectorLabels" . | nindent 6 }}
{{- end }}
32 changes: 31 additions & 1 deletion charts/gbox/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ serviceAccount:
name: ""

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

# -- 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.
Expand Down Expand Up @@ -195,3 +199,29 @@ metrics:

# -- Url path of metric endpoint.
path: /metrics

# Prometheus Service Monitor
serviceMonitor:
# -- Create ServiceMonitor resource(s) for scraping metrics using PrometheusOperator. When enabled @param metrics.enabled must be set to true
enabled: false

# -- The namespace in which the ServiceMonitor will be created
namespace: ""

# -- The interval at which metrics should be scraped
interval: 30s

# -- The timeout after which the scrape is ended
scrapeTimeout: ""

# -- Metrics RelabelConfigs to apply to samples before scraping.
relabellings: []

# -- Metrics RelabelConfigs to apply to samples before ingestion.
metricRelabelings: []

# -- Specify honorLabels parameter to add the scrape endpoint
honorLabels: false

# -- Additional labels that can be used so ServiceMonitor resource(s) can be discovered by Prometheus
additionalLabels: {}

0 comments on commit a03217e

Please sign in to comment.