diff --git a/promitor-agent-resource-discovery/README.md b/promitor-agent-resource-discovery/README.md index cdb6a17..06dfc91 100644 --- a/promitor-agent-resource-discovery/README.md +++ b/promitor-agent-resource-discovery/README.md @@ -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` | diff --git a/promitor-agent-resource-discovery/templates/service.yaml b/promitor-agent-resource-discovery/templates/service.yaml index 5a074de..bf70975 100644 --- a/promitor-agent-resource-discovery/templates/service.yaml +++ b/promitor-agent-resource-discovery/templates/service.yaml @@ -5,9 +5,9 @@ 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 }} @@ -15,6 +15,11 @@ metadata: 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 }} diff --git a/promitor-agent-resource-discovery/templates/servicemonitor.yaml b/promitor-agent-resource-discovery/templates/servicemonitor.yaml new file mode 100644 index 0000000..c69cd4d --- /dev/null +++ b/promitor-agent-resource-discovery/templates/servicemonitor.yaml @@ -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 }} diff --git a/promitor-agent-resource-discovery/values.yaml b/promitor-agent-resource-discovery/values.yaml index c69edc2..6bfc005 100644 --- a/promitor-agent-resource-discovery/values.yaml +++ b/promitor-agent-resource-discovery/values.yaml @@ -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: