Skip to content

Commit

Permalink
feat: Provide capability to scrape Prometheus metrics in Promitor Res…
Browse files Browse the repository at this point in the history
…ource Discovery (promitor#60)
  • Loading branch information
tomkerkhove authored Aug 18, 2021
1 parent cf6d70e commit d0ab503
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 2 deletions.
7 changes: 7 additions & 0 deletions promitor-agent-resource-discovery/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ their default values.
| `azureAuthentication.identity.id` | Id of the Azure AD entity to authenticate with | |
| `azureAuthentication.identity.key` | Secret of the Azure AD entity to authenticate with, when using mode `ServicePrincipal` (default) or `UserAssignedManagedIdentity` | |
| `azureAuthentication.identity.binding` | Aad Pod Identity name, when using `UserAssignedManagedIdentity` or `SystemAssignedManagedIdentity` as mode | |
| `prometheus.enabled` | Indication whether or not metrics should be exposed as a Prometheus scraping endpoint | `true`|
| `prometheus.enableServiceDiscovery` | Indication whether or not service discovery with annotations should be enabled ([docs](https://github.com/helm/charts/tree/master/stable/prometheus#scraping-pod-metrics-via-annotations)) | `true` |
| `prometheus.serviceMonitor.enabled` | Indication whether or not to create a ServiceMonitor object for [Prometheus Operator](https://github.com/prometheus-operator/prometheus-operator#customresourcedefinitions) | `false` |
| `prometheus.serviceMonitor.namespace` | The namespace where the ServiceMonitor should be created | |
| `prometheus.serviceMonitor.labels` | Labels for the ServiceMonitor | `{}` |
| `prometheus.serviceMonitor.interval` | How often Prometheus should scrape | `60s` |
| `prometheus.serviceMonitor.timeout` | Timeout for the scraping operation | `10s` |
| `cache.enabled` | Indication whether or not discovered resources should be cached in-memory to avoid Azure throttling | `true` |
| `cache.durationInMinutes` | Amount of minutes to cache discovered resources | `5` |
| `telemetry.applicationInsights.enabled` | Indication whether or not to send telemetry to Azure Application Insights | `false` |
Expand Down
9 changes: 7 additions & 2 deletions promitor-agent-resource-discovery/templates/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,21 @@ metadata:
namespace: {{ .Release.Namespace }}
labels:
{{- include "promitor-agent-resource-discovery.labels" . | nindent 4 }}
{{- if .Values.service.loadBalancer.enabled }}
{{- if or (.Values.service.loadBalancer.azure.dnsPrefix) (.Values.service.loadBalancer.azure.exposeInternally) }}
{{- if or (.Values.service.loadBalancer.enabled) (.Values.prometheus.enableServiceDiscovery) }}
annotations:
{{- if or (.Values.service.loadBalancer.azure.dnsPrefix) (.Values.service.loadBalancer.azure.exposeInternally) }}
{{- if .Values.service.loadBalancer.azure.dnsPrefix }}
service.beta.kubernetes.io/azure-dns-label-name: {{ .Values.service.loadBalancer.azure.dnsPrefix }}
{{- end }}
{{- if .Values.service.loadBalancer.azure.exposeInternally }}
service.beta.kubernetes.io/azure-load-balancer-internal: "true"
{{- end }}
{{- end }}
{{- if .Values.prometheus.enableServiceDiscovery }}
prometheus.io/scrape: "true"
prometheus.io/path: /metrics
prometheus.io/port: {{ .Values.service.targetPort | quote }}
{{- end }}
{{- end }}
spec:
{{- if .Values.service.loadBalancer.enabled }}
Expand Down
30 changes: 30 additions & 0 deletions promitor-agent-resource-discovery/templates/servicemonitor.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{{- if and ( .Values.prometheus.serviceMonitor.enabled ) (.Values.prometheus.enabled ) }}
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
labels:
{{- include "promitor-agent-resource-discovery.labels" . | nindent 4 }}
{{- if .Values.prometheus.serviceMonitor.labels }}
{{ toYaml .Values.prometheus.serviceMonitor.labels | indent 4 }}
{{- end }}
name: {{ template "promitor-agent-resource-discovery.fullname" . }}
{{- if .Values.prometheus.serviceMonitor.namespace }}
namespace: {{ .Values.prometheus.serviceMonitor.namespace }}
{{- end }}
spec:
endpoints:
- targetPort: http
{{- if .Values.prometheus.serviceMonitor.interval }}
interval: {{ .Values.prometheus.serviceMonitor.interval }}
{{- end }}
{{- if .Values.prometheus.serviceMonitor.timeout }}
scrapeTimeout: {{ .Values.prometheus.serviceMonitor.timeout }}
{{- end }}
jobLabel: {{ template "promitor-agent-resource-discovery.fullname" . }}
namespaceSelector:
matchNames:
- {{ .Release.Namespace }}
selector:
matchLabels:
{{- include "promitor-agent-resource-discovery.selectorLabels" . | nindent 6 }}
{{- end }}
11 changes: 11 additions & 0 deletions promitor-agent-resource-discovery/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,21 @@ azureAuthentication:
id: ""
key: ""
binding: ""

cache:
enabled: true
durationInMinutes: 5

prometheus:
enabled: true
enableServiceDiscovery: true
serviceMonitor:
enabled: false
namespace: ""
labels: {}
interval: 60s
timeout: 10s

telemetry:
defaultLogLevel: "Error"
applicationInsights:
Expand Down

0 comments on commit d0ab503

Please sign in to comment.