<commit_before>metrics {
  metric: "luci/envoy/cluster/membership"
  kind: GAUGE
  fields: "cluster"
  fields: "state"

  rules {
    pattern: "*.cluster.${cluster}.membership_healthy"
    fields {
      key: "cluster"
      value: "${cluster}"
    }
    fields {
      key: "state"
      value: "healthy"
    }
  }
  rules {
    pattern: "*.cluster.${cluster}.membership_degraded"
    fields {
      key: "cluster"
      value: "${cluster}"
    }
    fields {
      key: "state"
      value: "degraded"
    }
  }
}
<commit_msg>[envoy] Add metrics related to upstream clusters.<commit_after># Cluster stats.
# https://www.envoyproxy.io/docs/envoy/latest/configuration/upstream/cluster_manager/cluster_stats


metrics {
  metric: "luci/envoy/cluster/cx/active"
  kind: GAUGE
  desc: "Number of currently active upstream connections"

  fields: "cluster"

  rules {
    pattern: "*.cluster.${cluster}.upstream_cx_active"
    fields {
      key: "cluster"
      value: "${cluster}"
    }
  }
}


metrics {
  metric: "luci/envoy/cluster/cx/total"
  kind: COUNTER
  desc: "Total number of upstream connections made"

  fields: "cluster"
  fields: "protocol"

  rules {
    pattern: "*.cluster.${cluster}.upstream_cx_http1_total"
    fields {
      key: "cluster"
      value: "${cluster}"
    }
    fields {
      key: "protocol"
      value: "http1"
    }
  }
  rules {
    pattern: "*.cluster.${cluster}.upstream_cx_http2_total"
    fields {
      key: "cluster"
      value: "${cluster}"
    }
    fields {
      key: "protocol"
      value: "http2"
    }
  }
}


metrics {
  metric: "luci/envoy/cluster/cx/issues"
  kind: COUNTER
  desc: "Total number of upstream connection failures/timeouts/disconnects"

  fields: "cluster"
  fields: "kind"

  rules {
    pattern: "*.cluster.${cluster}.upstream_cx_connect_fail"
    fields {
      key: "cluster"
      value: "${cluster}"
    }
    fields {
      key: "kind"
      value: "connect_fail"
    }
  }
  rules {
    pattern: "*.cluster.${cluster}.upstream_cx_connect_timeout"
    fields {
      key: "cluster"
      value: "${cluster}"
    }
    fields {
      key: "kind"
      value: "connect_timeout"
    }
  }
  rules {
    pattern: "*.cluster.${cluster}.upstream_cx_idle_timeout"
    fields {
      key: "cluster"
      value: "${cluster}"
    }
    fields {
      key: "kind"
      value: "idle_timeout"
    }
  }
  rules {
    pattern: "*.cluster.${cluster}.upstream_cx_connect_attempts_exceeded"
    fields {
      key: "cluster"
      value: "${cluster}"
    }
    fields {
      key: "kind"
      value: "connect_attempts_exceeded"
    }
  }
  rules {
    pattern: "*.cluster.${cluster}.upstream_cx_overflow"
    fields {
      key: "cluster"
      value: "${cluster}"
    }
    fields {
      key: "kind"
      value: "overflow"
    }
  }
  rules {
    pattern: "*.cluster.${cluster}.upstream_cx_close_notify"
    fields {
      key: "cluster"
      value: "${cluster}"
    }
    fields {
      key: "kind"
      value: "close_notify"
    }
  }
  rules {
    pattern: "*.cluster.${cluster}.upstream_cx_pool_overflow"
    fields {
      key: "cluster"
      value: "${cluster}"
    }
    fields {
      key: "kind"
      value: "pool_overflow"
    }
  }
  rules {
    pattern: "*.cluster.${cluster}.upstream_cx_protocol_error"
    fields {
      key: "cluster"
      value: "${cluster}"
    }
    fields {
      key: "kind"
      value: "protocol_error"
    }
  }
  rules {
    pattern: "*.cluster.${cluster}.upstream_cx_max_requests"
    fields {
      key: "cluster"
      value: "${cluster}"
    }
    fields {
      key: "kind"
      value: "max_requests"
    }
  }
  rules {
    pattern: "*.cluster.${cluster}.upstream_cx_none_healthy"
    fields {
      key: "cluster"
      value: "${cluster}"
    }
    fields {
      key: "kind"
      value: "none_healthy"
    }
  }
}


metrics {
  metric: "luci/envoy/cluster/cx/bytes/buffered"
  kind: GAUGE
  desc: "Currently buffered connection bytes (per direction)"
  units: BYTES

  fields: "cluster"
  fields: "direction"

  rules {
    pattern: "*.cluster.${cluster}.upstream_cx_rx_bytes_buffered"
    fields {
      key: "cluster"
      value: "${cluster}"
    }
    fields {
      key: "direction"
      value: "received"
    }
  }
  rules {
    pattern: "*.cluster.${cluster}.upstream_cx_tx_bytes_buffered"
    fields {
      key: "cluster"
      value: "${cluster}"
    }
    fields {
      key: "direction"
      value: "sent"
    }
  }
}


metrics {
  metric: "luci/envoy/cluster/cx/bytes/total"
  kind: COUNTER
  desc: "Total connection bytes (per direction)"
  units: BYTES

  fields: "cluster"
  fields: "direction"

  rules {
    pattern: "*.cluster.${cluster}.upstream_cx_rx_bytes_total"
    fields {
      key: "cluster"
      value: "${cluster}"
    }
    fields {
      key: "direction"
      value: "received"
    }
  }
  rules {
    pattern: "*.cluster.${cluster}.upstream_cx_tx_bytes_total"
    fields {
      key: "cluster"
      value: "${cluster}"
    }
    fields {
      key: "direction"
      value: "sent"
    }
  }
}


metrics {
  metric: "luci/envoy/cluster/cx/connect"
  kind: CUMULATIVE_DISTRIBUTION
  desc: "How long it takes to connect to an upstream"
  units: MILLISECONDS

  fields: "cluster"

  rules {
    pattern: "*.cluster.${cluster}.upstream_cx_connect_ms"
    fields {
      key: "cluster"
      value: "${cluster}"
    }
  }
}


metrics {
  metric: "luci/envoy/cluster/cx/length"
  kind: CUMULATIVE_DISTRIBUTION
  desc: "Total lifetime of a connection"
  units: MILLISECONDS

  fields: "cluster"

  rules {
    pattern: "*.cluster.${cluster}.upstream_cx_length_ms"
    fields {
      key: "cluster"
      value: "${cluster}"
    }
  }
}


metrics {
  metric: "luci/envoy/cluster/rq/active"
  kind: GAUGE
  desc: "Number of currently active upstream requests"

  fields: "cluster"

  rules {
    pattern: "*.cluster.${cluster}.upstream_rq_active"
    fields {
      key: "cluster"
      value: "${cluster}"
    }
  }
}


metrics {
  metric: "luci/envoy/cluster/rq/pending/active"
  kind: GAUGE
  desc: "Number of active requests pending a connection pool connection"

  fields: "cluster"

  rules {
    pattern: "*.cluster.${cluster}.upstream_rq_pending_active"
    fields {
      key: "cluster"
      value: "${cluster}"
    }
  }
}


metrics {
  metric: "luci/envoy/cluster/rq/pending/total"
  kind: COUNTER
  desc: "Total number of requests that were delayed waiting for a connection"

  fields: "cluster"

  rules {
    pattern: "*.cluster.${cluster}.upstream_rq_pending_total"
    fields {
      key: "cluster"
      value: "${cluster}"
    }
  }
}


metrics {
  metric: "luci/envoy/cluster/rq/completed"
  kind: COUNTER
  desc: "Total number of requests completed"

  fields: "cluster"
  fields: "codes"

  rules {
    pattern: "*.cluster.${cluster}.upstream_rq_1xx"
    fields {
      key: "cluster"
      value: "${cluster}"
    }
    fields {
      key: "codes"
      value: "1xx"
    }
  }
  rules {
    pattern: "*.cluster.${cluster}.upstream_rq_2xx"
    fields {
      key: "cluster"
      value: "${cluster}"
    }
    fields {
      key: "codes"
      value: "2xx"
    }
  }
  rules {
    pattern: "*.cluster.${cluster}.upstream_rq_3xx"
    fields {
      key: "cluster"
      value: "${cluster}"
    }
    fields {
      key: "codes"
      value: "3xx"
    }
  }
  rules {
    pattern: "*.cluster.${cluster}.upstream_rq_4xx"
    fields {
      key: "cluster"
      value: "${cluster}"
    }
    fields {
      key: "codes"
      value: "4xx"
    }
  }
  rules {
    pattern: "*.cluster.${cluster}.upstream_rq_5xx"
    fields {
      key: "cluster"
      value: "${cluster}"
    }
    fields {
      key: "codes"
      value: "5xx"
    }
  }
  rules {
    pattern: "*.cluster.${cluster}.upstream_rq_unknown"
    fields {
      key: "cluster"
      value: "${cluster}"
    }
    fields {
      key: "codes"
      value: "unknown"
    }
  }
}


metrics {
  metric: "luci/envoy/cluster/rx/duration"
  kind: CUMULATIVE_DISTRIBUTION
  desc: "Request time"
  units: MILLISECONDS

  fields: "cluster"

  rules {
    pattern: "*.cluster.${cluster}.upstream_rq_time"
    fields {
      key: "cluster"
      value: "${cluster}"
    }
  }
}


metrics {
  metric: "luci/envoy/cluster/rq/issues"
  kind: COUNTER
  desc: "Total number of requests failed due to cluster issues"

  fields: "cluster"
  fields: "kind"

  rules {
    pattern: "*.cluster.${cluster}.upstream_rq_pending_overflow"
    fields {
      key: "cluster"
      value: "${cluster}"
    }
    fields {
      key: "kind"
      value: "pending_overflow"
    }
  }
  rules {
    pattern: "*.cluster.${cluster}.upstream_rq_pending_failure_eject"
    fields {
      key: "cluster"
      value: "${cluster}"
    }
    fields {
      key: "kind"
      value: "pending_failure_eject"
    }
  }
  rules {
    pattern: "*.cluster.${cluster}.upstream_rq_cancelled"
    fields {
      key: "cluster"
      value: "${cluster}"
    }
    fields {
      key: "kind"
      value: "cancelled"
    }
  }
  rules {
    pattern: "*.cluster.${cluster}.upstream_rq_maintenance_mode"
    fields {
      key: "cluster"
      value: "${cluster}"
    }
    fields {
      key: "kind"
      value: "maintenance_mode"
    }
  }
  rules {
    pattern: "*.cluster.${cluster}.upstream_rq_timeout"
    fields {
      key: "cluster"
      value: "${cluster}"
    }
    fields {
      key: "kind"
      value: "timeout"
    }
  }
  rules {
    pattern: "*.cluster.${cluster}.upstream_rq_max_duration_reached"
    fields {
      key: "cluster"
      value: "${cluster}"
    }
    fields {
      key: "kind"
      value: "max_duration_reached"
    }
  }
  rules {
    pattern: "*.cluster.${cluster}.upstream_rq_per_try_timeout"
    fields {
      key: "cluster"
      value: "${cluster}"
    }
    fields {
      key: "kind"
      value: "per_try_timeout"
    }
  }
  rules {
    pattern: "*.cluster.${cluster}.upstream_rq_rx_reset"
    fields {
      key: "cluster"
      value: "${cluster}"
    }
    fields {
      key: "kind"
      value: "rx_reset"
    }
  }
  rules {
    pattern: "*.cluster.${cluster}.upstream_rq_tx_reset"
    fields {
      key: "cluster"
      value: "${cluster}"
    }
    fields {
      key: "kind"
      value: "tx_reset"
    }
  }
}


metrics {
  metric: "luci/envoy/cluster/rq/retries"
  kind: COUNTER
  desc: "Total number request retries per outcome"

  fields: "cluster"
  fields: "outcome"

  rules {
    pattern: "*.cluster.${cluster}.upstream_rq_retry_success"
    fields {
      key: "cluster"
      value: "${cluster}"
    }
    fields {
      key: "outcome"
      value: "success"
    }
  }
  rules {
    pattern: "*.cluster.${cluster}.upstream_rq_retry_overflow"
    fields {
      key: "cluster"
      value: "${cluster}"
    }
    fields {
      key: "outcome"
      value: "overflow"
    }
  }
  rules {
    pattern: "*.cluster.${cluster}.upstream_rq_retry_limit_exceeded"
    fields {
      key: "cluster"
      value: "${cluster}"
    }
    fields {
      key: "outcome"
      value: "limit_exceeded"
    }
  }
}


metrics {
  metric: "luci/envoy/cluster/circuit_breakers/open"
  kind: GAUGE
  desc: "Whether the circuit breaker is closed (0) or open (1)"

  fields: "cluster"
  fields: "priority"
  fields: "name"

  rules {
    pattern: "*.cluster.${cluster}.circuit_breakers.${priority}.cx_open"
    fields {
      key: "cluster"
      value: "${cluster}"
    }
    fields {
      key: "priority"
      value: "${priority}"
    }
    fields {
      key: "name"
      value: "cx"
    }
  }
  rules {
    pattern: "*.cluster.${cluster}.circuit_breakers.${priority}.cx_pool_open"
    fields {
      key: "cluster"
      value: "${cluster}"
    }
    fields {
      key: "priority"
      value: "${priority}"
    }
    fields {
      key: "name"
      value: "cx_pool"
    }
  }
  rules {
    pattern: "*.cluster.${cluster}.circuit_breakers.${priority}.rq_pending_open"
    fields {
      key: "cluster"
      value: "${cluster}"
    }
    fields {
      key: "priority"
      value: "${priority}"
    }
    fields {
      key: "name"
      value: "rq_pending"
    }
  }
  rules {
    pattern: "*.cluster.${cluster}.circuit_breakers.${priority}.rq_open"
    fields {
      key: "cluster"
      value: "${cluster}"
    }
    fields {
      key: "priority"
      value: "${priority}"
    }
    fields {
      key: "name"
      value: "rq"
    }
  }
  rules {
    pattern: "*.cluster.${cluster}.circuit_breakers.${priority}.rq_retry_open"
    fields {
      key: "cluster"
      value: "${cluster}"
    }
    fields {
      key: "priority"
      value: "${priority}"
    }
    fields {
      key: "name"
      value: "rq_retry"
    }
  }
}


metrics {
  metric: "luci/envoy/cluster/membership"
  kind: GAUGE
  desc: "Number of cluster upstream endpoints per their health status"

  fields: "cluster"
  fields: "state"

  rules {
    pattern: "*.cluster.${cluster}.membership_healthy"
    fields {
      key: "cluster"
      value: "${cluster}"
    }
    fields {
      key: "state"
      value: "healthy"
    }
  }
  rules {
    pattern: "*.cluster.${cluster}.membership_degraded"
    fields {
      key: "cluster"
      value: "${cluster}"
    }
    fields {
      key: "state"
      value: "degraded"
    }
  }
}

{'fraction_non_alphanumeric': 0.14479945615227735, 'fraction_numerical': 0.0012085504947503588, 'mean_word_length': 2.2332112332112333, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '529694', 'n_tokens_mistral': 4638, 'n_tokens_neox': 4551, 'n_words': 927}