groups:
- name: api-gateway
  rules:
  - alert: APIGatewayDown
    annotations:
      message: API Gateway available replicas are lower than 50% of desired replicas in namespace kong.
    expr: |
      sum(kube_deployment_spec_replicas{namespace="kong"}) > 0
      and
      sum(kube_deployment_status_replicas_available{namespace="kong"}) < (sum(kube_deployment_spec_replicas{namespace="kong"}) / 2)
    for: 3m
    labels:
      severity: critical
      response_class: page
      component: api-gateway
      oncall_team: global_control
  - alert: APIGatewayMetricsMissing
    annotations:
      message: API Gateway metrics kong_http_status has been missing for 2 minutes.
    expr: |
      absent_over_time(kong_http_status{}[2m])
    for: 0m
    labels:
      severity: major
      response_class: ticket
      component: api-gateway
      oncall_team: global_control
  - alert: APIGatewayTooManyErrors
    annotations:
      message: API Gateway has 502/503 greater than 0.2 qps for 2 minutes.
    expr: |
      sum(rate(kong_http_status{code=~"502|503"}[1m])) by (code) > 0.2
    for: 2m
    labels:
      severity: major
      response_class: ticket
      component: api-gateway
      oncall_team: global_control
  - alert: APIGatewayTooMany4xx
    annotations:
      message: API Gateway has 4xx greater than 1 QPS for 3 minutes.
    expr: |
      sum(rate(kong_http_status{code=~"4(.*)",code!="401"}[1m])) by (code) > 1
    for: 3m
    labels:
      severity: major
      response_class: ticket
      component: api-gateway
      oncall_team: global_control
  - alert: APIGatewayTooMany5xx
    annotations:
      message: API Gateway has 5xx greater than 2 QPS for 3 minutes.
    expr: |
      sum(rate(kong_http_status{code=~"5(.*)"}[1m])) by (code) > 2
    for: 3m
    labels:
      severity: major
      response_class: ticket
      component: api-gateway
      oncall_team: global_control
  - alert: APIGatewayQPSIncreased
    annotations:
      message: API Gateway QPS has been greater than 200 qps for 2 minutes.
    expr: |
      sum(rate(kong_http_status{}[1m])) > 200
    for: 2m
    labels:
      severity: major
      response_class: ticket
      component: api-gateway
      oncall_team: global_control
