apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
  name: custom-metrics-consumer
  namespace: default
  labels:
    application: custom-metrics-consumer
  annotations:
    # metric-config.<metricType>.<metricName>.<collectorType>/<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"
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: Pods
    pods:
      metric:
        name: queue-length
      target:
        averageValue: 1k
        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: app-queue-length
        selector:
          matchLabels:
            type: sqs-queue-length
            queue-name: foobar
            region: eu-central-1
      target:
        averageValue: "30"
        type: AverageValue
