subject: namespace:ns
revision: "2022"
rules:
- selector: # must be empty for preprocessing adapters
  aspects:
  - kind: quotas
    params:
      quotas:
      - descriptorName: RequestCount
        maxAmount: 5000
        expiration: 1s
  - kind: metrics
    adapter: prometheus
    params:
      metrics:
      - descriptor_name: request_count
        # we want to increment this counter by 1 for each unique (source, target, service, method, response_code) tuple
        value: "1"
        labels:
          source: source.labels["app"] | "unknown"
          target: destination.service | "unknown"
          service: destination.labels["app"] | "unknown"
          method: request.path | "unknown"
          version: destination.labels["version"] | "unknown"
          response_code: response.code | 200
      - descriptor_name:  request_duration
        value: response.duration | "0ms"
        labels:
          source: source.labels["app"] | "unknown"
          target: destination.service | "unknown"
          service: destination.labels["app"] | "unknown"
          method: request.path | "unknown"
          version: destination.labels["version"] | "unknown"
          response_code: response.code | 200
  - kind: access-logs
    params:
      logName: access_log
      log:
        descriptor_name: accesslog.common
        template_expressions:
           originIp: origin.ip
           sourceUser: origin.user
           timestamp: request.time
           method: request.method
           url: request.path
           protocol: request.scheme
           responseCode: response.code
           responseSize: response.size
        labels:
           originIp: origin.ip
           sourceUser: origin.user
           timestamp: request.time
           method: request.method
           url: request.path
           protocol: request.scheme
           responseCode: response.code
           responseSize: response.size
