dapr / docs

Dapr user documentation, used to build docs.dapr.io
https://docs.dapr.io
Creative Commons Attribution 4.0 International
987 stars 715 forks source link

Add Prometheus Service Discovery Example for Dapr Metrics #4234

Open maulindesai opened 1 week ago

maulindesai commented 1 week ago

What content needs to be created or modified?

I would like to suggest adding a sample code snippet or example for Prometheus service-discovery configuration for Dapr metrics to the documentation. This will be highly beneficial for new Dapr users, allowing them to efficiently set up Prometheus for multiple services without needing to manually add individual targets for each service in the configuration file.

Describe the solution you'd like here is the configuration we are currently using for our Kubernetes Prometheus stack:

prometheus:
  prometheusSpec:
    enableRemoteWriteReceiver: true
    enable-feature:
      - remote-write-receiver
      - otlp-write-receiver
    additionalScrapeConfigs:
      - job_name: 'dapr-sidecars'
        kubernetes_sd_configs:
          - role: pod
        relabel_configs:
          - source_labels: [ __meta_kubernetes_pod_annotation_dapr_io_enabled ]
            action: keep
            regex: "true"
          - source_labels: [ __meta_kubernetes_pod_annotation_dapr_io_enable_metrics ]
            action: keep
            regex: "true"
          - source_labels: [ __meta_kubernetes_namespace ]
            action: replace
            target_label: namespace
            replacement: ${1}
          - source_labels: [ __meta_kubernetes_pod_name ]
            action: replace
            target_label: pod
            replacement: ${1}
          - source_labels: [ __meta_kubernetes_pod_ip ]
            action: replace
            target_label: __address__
            replacement: ${1}:9090

      - job_name: 'dapr'
        kubernetes_sd_configs:
          - role: pod
        relabel_configs:
          - source_labels: [ __meta_kubernetes_pod_label_app_kubernetes_io_name ]
            action: keep
            regex: "dapr"
          - source_labels: [ __meta_kubernetes_pod_label_app_kubernetes_io_part_of ]
            action: keep
            regex: "dapr"
          - source_labels: [ __meta_kubernetes_namespace ]
            action: replace
            target_label: namespace
            replacement: ${1}
          - source_labels: [ __meta_kubernetes_pod_name ]
            action: replace
            target_label: pod
            replacement: ${1}
          - source_labels: [ __meta_kubernetes_pod_ip ]
            action: replace
            target_label: __address__
            replacement: ${1}:9090

Where should the new material be placed?

The associated pull request from dapr/dapr, dapr/components-contrib, or other Dapr code repos

Additional context