Skip to content

Commit

Permalink
feat(metrics): add prometheus endpoint (#147)
Browse files Browse the repository at this point in the history
Co-authored-by: Fabio Bonelli 
Co-authored-by: Nicola Squartini
  • Loading branch information
LorenzoS92 authored Oct 12, 2022
1 parent ebc5993 commit 5880e05
Show file tree
Hide file tree
Showing 6 changed files with 484 additions and 4 deletions.
6 changes: 6 additions & 0 deletions charts/developers-italia-api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ The API of Developers Italia
| serviceAccount.annotations | object | `{}` | |
| serviceAccount.create | bool | `true` | |
| serviceAccount.name | string | `""` | |
| serviceMonitor.additionalLabels | object | `{}` | |
| serviceMonitor.enabled | bool | `false` | Create ServiceMonitor resource (requires corresponding Prometheus Operator CRD installed). |
| serviceMonitor.interval | string | `nil` | Interval at which metrics should be scraped (uses Prometheus default if unspecified, details [here](https://prometheus-operator.dev/docs/operator/api/#monitoring.coreos.com/v1.Endpoint)) |
| serviceMonitor.jobLabel | string | `nil` | Defaults to the name of the Kubernetes service (details [here](https://prometheus-operator.dev/docs/operator/api/#monitoring.coreos.com/v1.ServiceMonitor)). |
| serviceMonitor.scrapeTimeout | string | `nil` | Timeout after which the scrape is ended (uses Prometheus default if unspecified, details [here](https://prometheus-operator.dev/docs/operator/api/#monitoring.coreos.com/v1.Endpoint)). |
| serviceMonitor.targetLabels | list | `[]` | |
| tolerations | list | `[]` | |
| useExistingSecret | string | `nil` | Name of existing Kubernetes secret containing keys 'databaseDSN' and 'pasetoKey'. If not provided, a secret will be generated using values from 'databaseDSN' and 'pasetoKey'. |

Expand Down
35 changes: 35 additions & 0 deletions charts/developers-italia-api/templates/servicemonitor.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{{- if .Values.serviceMonitor.enabled -}}
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: {{ include "developers-italia-api.fullname" . }}
labels:
{{- include "developers-italia-api.labels" . | nindent 4 }}
{{- if .Values.serviceMonitor.additionalLabels }}
{{- toYaml .Values.serviceMonitor.additionalLabels | nindent 4 }}
{{- end }}
spec:
endpoints:
- port: http
{{- if .Values.serviceMonitor.interval }}
interval: {{ .Values.serviceMonitor.interval }}
{{- end }}
{{- if .Values.serviceMonitor.scrapeTimeout }}
scrapeTimeout: {{ .Values.serviceMonitor.scrapeTimeout }}
{{- end }}
{{- if .Values.serviceMonitor.jobLabel }}
jobLabel: {{ .Values.serviceMonitor.jobLabel | quote }}
{{- end }}
namespaceSelector:
matchNames:
- {{ .Release.Namespace }}
{{- if .Values.serviceMonitor.targetLabels }}
targetLabels:
{{- range .Values.serviceMonitor.targetLabels }}
- {{ . }}
{{- end }}
{{- end }}
selector:
matchLabels:
{{- include "developers-italia-api.selectorLabels" . | nindent 6 }}
{{- end }}
12 changes: 12 additions & 0 deletions charts/developers-italia-api/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,15 @@ databaseDSN: ""

# -- Base64 encoded Paseto Key.
pasetoKey: ""

serviceMonitor:
# -- Create ServiceMonitor resource (requires corresponding Prometheus Operator CRD installed).
enabled: false
additionalLabels: {}
# -- (string) Defaults to the name of the Kubernetes service (details [here](https://prometheus-operator.dev/docs/operator/api/#monitoring.coreos.com/v1.ServiceMonitor)).
jobLabel:
# -- (string) Interval at which metrics should be scraped (uses Prometheus default if unspecified, details [here](https://prometheus-operator.dev/docs/operator/api/#monitoring.coreos.com/v1.Endpoint))
interval:
# -- (string) Timeout after which the scrape is ended (uses Prometheus default if unspecified, details [here](https://prometheus-operator.dev/docs/operator/api/#monitoring.coreos.com/v1.Endpoint)).
scrapeTimeout:
targetLabels: []
17 changes: 15 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,32 @@ require (
github.com/go-playground/validator/v10 v10.11.0
github.com/go-testfixtures/testfixtures/v3 v3.8.0
github.com/gofiber/contrib/paseto v0.0.0-20220621082844-83549332c36e
github.com/gofiber/fiber/v2 v2.34.1
github.com/gofiber/fiber/v2 v2.36.0
github.com/jackc/pgerrcode v0.0.0-20220416144525-469b46aa5efa
github.com/stretchr/testify v1.7.5
gorm.io/driver/postgres v1.3.7
gorm.io/driver/sqlite v1.3.4
gorm.io/gorm v1.23.6
)

require golang.org/x/exp v0.0.0-20220827204233-334a2380cb91
require (
github.com/ansrivas/fiberprometheus/v2 v2.4.1
golang.org/x/exp v0.0.0-20220827204233-334a2380cb91
)

require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/gofiber/adaptor/v2 v2.1.25 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/mattn/go-sqlite3 v1.14.13 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/prometheus/client_golang v1.12.2 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.32.1 // indirect
github.com/prometheus/procfs v0.7.3 // indirect
golang.org/x/net v0.0.0-20220722155237-a158d28d115b // indirect
google.golang.org/protobuf v1.26.0 // indirect
)

require (
Expand Down
Loading

0 comments on commit 5880e05

Please sign in to comment.