apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
  name: custom-metrics-consumer
  namespace: default
  labels:
    application: custom-metrics-consumer
  annotations:
    # metric-config.<metricType>.<metricName>.<collectorName>/<configKey>
    # metric-config.pods.queue-length.json-path/json-key: "$.queue.length"
    # metric-config.pods.queue-length.json-path/path: /metrics
    # metric-config.pods.queue-length.json-path/port: "9090"
    # metric-config.object.requests-per-second.prometheus/query: |
    #   scalar(sum(rate(skipper_serve_host_duration_seconds_count{host="custom-metrics_example_org"}[1m])))
    # metric-config.object.requests-per-second.prometheus/per-replica: "true"
    # metric-config.object.requests-per-second.skipper/interval: "1s"
    metric-config.external.prometheus-query.prometheus/prometheus-server: http://prometheus-operator-prometheus.monitoring.svc:9090
    metric-config.external.prometheus-query.prometheus/processed-events-per-second: |
      sum(rate(nginx_ingress_controller_nginx_process_connections_total{}[1m]))
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: custom-metrics-consumer
  minReplicas: 1
  maxReplicas: 10
  metrics:
  # - type: Resource
  #   resource:
  #     name: cpu
  #     current:
  #       averageUtilization: 50

  - type: External
    external:
      metric:
        name: prometheus-query
        selector:
          matchLabels:
            query-name: processed-events-per-second
      target:
        type: AverageValue
        averageValue: "1"

  # - type: Pods
  #   pods:
  #     metric:
  #       name: queue-length
  #     target:
  #       averageValue: 10k
  #       type: AverageValue

  # - type: Object
  #   object:
  #     describedObject:
  #       apiVersion: extensions/v1beta1
  #       kind: Ingress
  #       name: custom-metrics-consumer
  #     metric:
  #       name: requests-per-second
  #     target:
  #       averageValue: "10"
  #       type: AverageValue
  # - type: External
  #   external:
  #     metric:
  #       name: sqs-queue-length
  #       selector:
  #         matchLabels:
  #           queue-name: foobar
  #           region: eu-central-1
  #     target:
  #       averageValue: "30"
  #       type: AverageValue
