Line data Source code
1 : use metrics::core::Collector;
2 : use metrics::proto::MetricFamily;
3 : use metrics::{IntCounterVec, UIntGaugeVec, register_int_counter_vec, register_uint_gauge_vec};
4 : use once_cell::sync::Lazy;
5 :
6 0 : pub(crate) static INSTALLED_EXTENSIONS: Lazy<UIntGaugeVec> = Lazy::new(|| {
7 0 : register_uint_gauge_vec!(
8 0 : "compute_installed_extensions",
9 0 : "Number of databases where the version of extension is installed",
10 0 : &["extension_name", "version", "owned_by_superuser"]
11 0 : )
12 0 : .expect("failed to define a metric")
13 0 : });
14 :
15 : // Normally, any HTTP API request is described by METHOD (e.g. GET, POST, etc.) + PATH,
16 : // but for all our APIs we defined a 'slug'/method/operationId in the OpenAPI spec.
17 : // And it's fair to call it a 'RPC' (Remote Procedure Call).
18 : pub enum CPlaneRequestRPC {
19 : GetSpec,
20 : }
21 :
22 : impl CPlaneRequestRPC {
23 0 : pub fn as_str(&self) -> &str {
24 0 : match self {
25 0 : CPlaneRequestRPC::GetSpec => "GetSpec",
26 0 : }
27 0 : }
28 : }
29 :
30 : pub const UNKNOWN_HTTP_STATUS: &str = "unknown";
31 :
32 0 : pub(crate) static CPLANE_REQUESTS_TOTAL: Lazy<IntCounterVec> = Lazy::new(|| {
33 0 : register_int_counter_vec!(
34 0 : "compute_ctl_cplane_requests_total",
35 0 : "Total number of control plane requests made by compute_ctl by status",
36 0 : &["rpc", "http_status"]
37 0 : )
38 0 : .expect("failed to define a metric")
39 0 : });
40 :
41 : /// Total number of failed database migrations. Per-compute, this is actually a boolean metric,
42 : /// either empty or with a single value (1, migration_id) because we stop at the first failure.
43 : /// Yet, the sum over the fleet will provide the total number of failures.
44 0 : pub(crate) static DB_MIGRATION_FAILED: Lazy<IntCounterVec> = Lazy::new(|| {
45 0 : register_int_counter_vec!(
46 0 : "compute_ctl_db_migration_failed_total",
47 0 : "Total number of failed database migrations",
48 0 : &["migration_id"]
49 0 : )
50 0 : .expect("failed to define a metric")
51 0 : });
52 :
53 0 : pub(crate) static REMOTE_EXT_REQUESTS_TOTAL: Lazy<IntCounterVec> = Lazy::new(|| {
54 0 : register_int_counter_vec!(
55 0 : "compute_ctl_remote_ext_requests_total",
56 0 : "Total number of requests made by compute_ctl to download extensions from S3 proxy by status",
57 0 : &["http_status", "filename"]
58 0 : )
59 0 : .expect("failed to define a metric")
60 0 : });
61 :
62 0 : pub fn collect() -> Vec<MetricFamily> {
63 0 : let mut metrics = INSTALLED_EXTENSIONS.collect();
64 0 : metrics.extend(CPLANE_REQUESTS_TOTAL.collect());
65 0 : metrics.extend(REMOTE_EXT_REQUESTS_TOTAL.collect());
66 0 : metrics.extend(DB_MIGRATION_FAILED.collect());
67 0 : metrics
68 0 : }
|