scrape_configs:
  - job_name: 'knative-controller'
    scrape_interval: 3s
    scrape_timeout: 3s
    kubernetes_sd_configs:
      - role: pod
        api_server: EKS_API_SERVER
        tls_config:
          insecure_skip_verify: true
        authorization:
          credentials_file: EKS_AUTH_TOKEN_FILE
    scheme: https
    tls_config:
      insecure_skip_verify: true
    authorization:
      credentials_file: EKS_AUTH_TOKEN_FILE
    relabel_configs:
      - source_labels: [__meta_kubernetes_namespace, __meta_kubernetes_pod_label_app, __meta_kubernetes_pod_container_port_name]
        action: keep
        regex: knative-serving;controller;metrics
      - target_label: __address__
        replacement: CLUSTER_ENDPOINT
      - source_labels: [__meta_kubernetes_namespace,__meta_kubernetes_pod_name, __meta_kubernetes_pod_container_port_number]
        regex: "(.*)+;(.*)+;(.*)"
        target_label: __metrics_path__
        replacement: /api/v1/namespaces/${1}/pods/${2}:${3}/proxy/metrics
      - source_labels: [__meta_kubernetes_namespace]
        target_label: namespace
      - source_labels: [__meta_kubernetes_pod_name]
        target_label: pod
      - source_labels: [__meta_kubernetes_service_name]
        target_label: service

  # Autoscaler endpoint
  - job_name: 'knative-autoscaler'
    scrape_interval: 3s
    scrape_timeout: 3s
    kubernetes_sd_configs:
      - role: pod
        api_server: EKS_API_SERVER
        tls_config:
          insecure_skip_verify: true
        authorization:
          credentials_file: EKS_AUTH_TOKEN_FILE
    scheme: https
    tls_config:
      insecure_skip_verify: true
    authorization:
      credentials_file: EKS_AUTH_TOKEN_FILE
    relabel_configs:
      - source_labels: [__meta_kubernetes_namespace, __meta_kubernetes_pod_label_app, __meta_kubernetes_pod_container_port_name]
        action: keep
        regex: knative-serving;autoscaler;metrics
      - target_label: __address__
        replacement: CLUSTER_ENDPOINT
      - source_labels: [__meta_kubernetes_namespace,__meta_kubernetes_pod_name, __meta_kubernetes_pod_container_port_number]
        regex: "(.*)+;(.*)+;(.*)"
        target_label: __metrics_path__
        replacement: /api/v1/namespaces/${1}/pods/${2}:${3}/proxy/metrics
      - source_labels: [__meta_kubernetes_namespace]
        target_label: namespace
      - source_labels: [__meta_kubernetes_pod_name]
        target_label: pod
      - source_labels: [__meta_kubernetes_service_name]
        target_label: service
  # Activator pods
  - job_name: 'knative-activator'
    scrape_interval: 3s
    scrape_timeout: 3s
    kubernetes_sd_configs:
      - role: pod
        api_server: EKS_API_SERVER
        tls_config:
          insecure_skip_verify: true
        authorization:
          credentials_file: EKS_AUTH_TOKEN_FILE
    scheme: https
    tls_config:
      insecure_skip_verify: true
    authorization:
      credentials_file: EKS_AUTH_TOKEN_FILE
    relabel_configs:
      - source_labels: [__meta_kubernetes_namespace, __meta_kubernetes_pod_label_app, __meta_kubernetes_pod_container_port_name]
        action: keep
        regex: knative-serving;activator;metrics
      - target_label: __address__
        replacement: CLUSTER_ENDPOINT
      - source_labels: [__meta_kubernetes_namespace, __meta_kubernetes_pod_name, __meta_kubernetes_pod_container_port_number]
        regex: "(.*)+;(.*)+;(.*)"
        target_label: __metrics_path__
        replacement: /api/v1/namespaces/${1}/pods/${2}:${3}/proxy/metrics
      - source_labels: [__meta_kubernetes_namespace]
        target_label: namespace
      - source_labels: [__meta_kubernetes_pod_name]
        target_label: pod
      - source_labels: [__meta_kubernetes_service_name]
        target_label: service
  # Webhook pods
  - job_name: 'knative-webhook'
    scrape_interval: 3s
    scrape_timeout: 3s
    kubernetes_sd_configs:
      - role: pod
        api_server: EKS_API_SERVER
        tls_config:
          insecure_skip_verify: true
        authorization:
          credentials_file: EKS_AUTH_TOKEN_FILE
    scheme: https
    tls_config:
      insecure_skip_verify: true
    authorization:
      credentials_file: EKS_AUTH_TOKEN_FILE
    relabel_configs:
      - source_labels: [__meta_kubernetes_namespace, __meta_kubernetes_pod_label_role, __meta_kubernetes_pod_container_port_name]
        action: keep
        regex: knative-serving;webhook;metrics
      - target_label: __address__
        replacement: CLUSTER_ENDPOINT
      - source_labels: [__meta_kubernetes_namespace, __meta_kubernetes_pod_name, __meta_kubernetes_pod_container_port_number]
        regex: "(.*)+;(.*)+;(.*)"
        target_label: __metrics_path__
        replacement: /api/v1/namespaces/${1}/pods/${2}:${3}/proxy/metrics
      - source_labels: [__meta_kubernetes_namespace]
        target_label: namespace
      - source_labels: [__meta_kubernetes_pod_name]
        target_label: pod
      - source_labels: [__meta_kubernetes_service_name]
        target_label: service

  - job_name: 'knative-queue-proxy'
    scrape_interval: 3s
    scrape_timeout: 3s
    kubernetes_sd_configs:
      - role: pod
        api_server: EKS_API_SERVER
        tls_config:
          insecure_skip_verify: true
        authorization:
          credentials_file: EKS_AUTH_TOKEN_FILE
    scheme: https
    tls_config:
      insecure_skip_verify: true
    authorization:
      credentials_file: EKS_AUTH_TOKEN_FILE
    relabel_configs:
      - source_labels: [__meta_kubernetes_pod_label_serving_knative_dev_revision, __meta_kubernetes_pod_container_port_name]
        action: keep
        regex: .+;http-usermetric
      - target_label: __address__
        replacement: CLUSTER_ENDPOINT
      - source_labels: [__meta_kubernetes_namespace, __meta_kubernetes_pod_name, __meta_kubernetes_pod_container_port_number]
        regex: "(.*)+;(.*)+;(.*)"
        target_label: __metrics_path__
        replacement: /api/v1/namespaces/${1}/pods/${2}:${3}/proxy/metrics
      - source_labels: [__meta_kubernetes_namespace]
        target_label: namespace
      - source_labels: [__meta_kubernetes_pod_name]
        target_label: pod
      - source_labels: [__meta_kubernetes_service_name]
        target_label: service

  - job_name: 'kubernetes-cadvisor'
    scrape_interval: 15s
    kubernetes_sd_configs:
      - role: endpoints
        api_server: EKS_API_SERVER
        tls_config:
          insecure_skip_verify: true
        authorization:
          credentials_file: EKS_AUTH_TOKEN_FILE
    scheme: https
    tls_config:
      insecure_skip_verify: true
    authorization:
      credentials_file: EKS_AUTH_TOKEN_FILE
    relabel_configs:
      - source_labels: [__meta_kubernetes_service_label_app]
        action: keep
        regex: cadvisor
      - target_label: __address__
        replacement: ${cluster_endpoint}
      - source_labels: [__meta_kubernetes_namespace, __meta_kubernetes_service_name, __meta_kubernetes_pod_container_port_number]
        regex: "(.*)+;(.*)+;(.*)"
        target_label: __metrics_path__
        replacement: /api/v1/namespaces/${1}/services/${2}:${3}/proxy/metrics
      - source_labels: [__meta_kubernetes_pod_node_name]
        target_label: node

  - job_name: 'istio-envoy'
    scrape_interval: 15s
    metrics_path: /stats/prometheus
    kubernetes_sd_configs:
      - role: endpoints
        api_server: EKS_API_SERVER
        tls_config:
          insecure_skip_verify: true
        authorization:
          credentials_file: EKS_AUTH_TOKEN_FILE
    scheme: https
    tls_config:
      insecure_skip_verify: true
    authorization:
      credentials_file: EKS_AUTH_TOKEN_FILE
    relabel_configs:
      - source_labels: [__meta_kubernetes_pod_container_port_name]
        action: keep
        regex: '.*-envoy-prom'
      - target_label: __address__
        replacement: CLUSTER_ENDPOINT
      - source_labels: [__meta_kubernetes_namespace, __meta_kubernetes_pod_name, __meta_kubernetes_pod_container_port_number]
        regex: "(.*)+;(.*)+;(.*)"
        target_label: __metrics_path__
        replacement: /api/v1/namespaces/${1}/pods/${2}:${3}/proxy/stats/prometheus
      - source_labels: [__meta_kubernetes_namespace]
        target_label: namespace
      - source_labels: [__meta_kubernetes_pod_name]
        target_label: pod
      - source_labels: [__meta_kubernetes_service_name]
        target_label: service

  - job_name: kube-state-metrics
    kubernetes_sd_configs:
      - role: endpoints
        api_server: EKS_API_SERVER
        tls_config:
          insecure_skip_verify: true
        authorization:
          credentials_file: EKS_AUTH_TOKEN_FILE
    scheme: https
    tls_config:
      insecure_skip_verify: true
    authorization:
      credentials_file: EKS_AUTH_TOKEN_FILE
    relabel_configs:
      - source_labels: [__meta_kubernetes_service_label_app_kubernetes_io_name]
        action: keep
        regex: kube-state-metrics
      - target_label: __address__
        replacement: CLUSTER_ENDPOINT
      - source_labels: [__meta_kubernetes_namespace, __meta_kubernetes_service_name, __meta_kubernetes_pod_container_port_number]
        regex: "(.*)+;(.*)+;(.*)"
        target_label: __metrics_path__
        replacement: /api/v1/namespaces/${1}/services/${2}:${3}/proxy/metrics
      - source_labels: [__meta_kubernetes_namespace]
        target_label: namespace
      - source_labels: [__meta_kubernetes_pod_name]
        target_label: pod
      - source_labels: [__meta_kubernetes_service_name]
        target_label: service
