Line data Source code
1 : use metrics::core::Collector;
2 : use metrics::proto::MetricFamily;
3 : use metrics::{register_int_counter_vec, register_uint_gauge_vec, IntCounterVec, UIntGaugeVec};
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",
36 0 : &["rpc"]
37 0 : )
38 0 : .expect("failed to define a metric")
39 0 : });
40 :
41 0 : pub(crate) static CPLANE_REQUESTS_FAILED: Lazy<IntCounterVec> = Lazy::new(|| {
42 0 : register_int_counter_vec!(
43 0 : "compute_ctl_cplane_requests_failed_total",
44 0 : "Total number of failed control plane requests made by compute_ctl",
45 0 : &["rpc", "http_status"]
46 0 : )
47 0 : .expect("failed to define a metric")
48 0 : });
49 :
50 : /// Total number of failed database migrations. Per-compute, this is actually a boolean metric,
51 : /// either empty or with a single value (1, migration_id) because we stop at the first failure.
52 : /// Yet, the sum over the fleet will provide the total number of failures.
53 0 : pub(crate) static DB_MIGRATION_FAILED: Lazy<IntCounterVec> = Lazy::new(|| {
54 0 : register_int_counter_vec!(
55 0 : "compute_ctl_db_migration_failed_total",
56 0 : "Total number of failed database migrations",
57 0 : &["migration_id"]
58 0 : )
59 0 : .expect("failed to define a metric")
60 0 : });
61 :
62 0 : pub(crate) static REMOTE_EXT_REQUESTS_TOTAL: Lazy<IntCounterVec> = Lazy::new(|| {
63 0 : register_int_counter_vec!(
64 0 : "compute_ctl_remote_ext_requests_total",
65 0 : "Total number of requests made by compute_ctl to download extensions from S3 proxy",
66 0 : // Do not use any labels like extension name yet.
67 0 : // We can add them later if needed.
68 0 : &[]
69 0 : )
70 0 : .expect("failed to define a metric")
71 0 : });
72 :
73 0 : pub(crate) static REMOTE_EXT_REQUESTS_FAILED: Lazy<IntCounterVec> = Lazy::new(|| {
74 0 : register_int_counter_vec!(
75 0 : "compute_ctl_remote_ext_requests_failed_total",
76 0 : "Total number of failed requests to S3 proxy",
77 0 : &["http_status"]
78 0 : )
79 0 : .expect("failed to define a metric")
80 0 : });
81 :
82 0 : pub fn collect() -> Vec<MetricFamily> {
83 0 : let mut metrics = INSTALLED_EXTENSIONS.collect();
84 0 : metrics.extend(CPLANE_REQUESTS_TOTAL.collect());
85 0 : metrics.extend(CPLANE_REQUESTS_FAILED.collect());
86 0 : metrics.extend(DB_MIGRATION_FAILED.collect());
87 0 : metrics.extend(REMOTE_EXT_REQUESTS_TOTAL.collect());
88 0 : metrics.extend(REMOTE_EXT_REQUESTS_FAILED.collect());
89 0 : metrics
90 0 : }
|