|
16 | 16 | * |
17 | 17 | */ |
18 | 18 |
|
| 19 | +use crate::metrics::METRICS_NAMESPACE; |
19 | 20 | use actix_web_prometheus::PrometheusMetrics; |
| 21 | +use once_cell::sync::Lazy; |
| 22 | +use prometheus::{CounterVec, HistogramOpts, HistogramVec, Opts}; |
| 23 | + |
| 24 | +// Global storage metric used by all storage providers |
| 25 | +pub static STORAGE_REQUEST_RESPONSE_TIME: Lazy<HistogramVec> = Lazy::new(|| { |
| 26 | + HistogramVec::new( |
| 27 | + HistogramOpts::new("storage_request_response_time", "Storage Request Latency") |
| 28 | + .namespace(METRICS_NAMESPACE), |
| 29 | + &["provider", "method", "status"], |
| 30 | + ) |
| 31 | + .expect("metric can be created") |
| 32 | +}); |
| 33 | + |
| 34 | +// Global storage metric for tracking number of files scanned |
| 35 | +pub static STORAGE_FILES_SCANNED: Lazy<CounterVec> = Lazy::new(|| { |
| 36 | + CounterVec::new( |
| 37 | + Opts::new( |
| 38 | + "storage_files_scanned_total", |
| 39 | + "Total number of files scanned in storage operations", |
| 40 | + ) |
| 41 | + .namespace(METRICS_NAMESPACE), |
| 42 | + &["provider", "operation"], |
| 43 | + ) |
| 44 | + .expect("metric can be created") |
| 45 | +}); |
20 | 46 |
|
21 | 47 | pub trait StorageMetrics { |
22 | 48 | fn register_metrics(&self, handler: &PrometheusMetrics); |
23 | 49 | } |
24 | 50 |
|
25 | 51 | pub mod localfs { |
26 | | - use crate::{metrics::METRICS_NAMESPACE, storage::FSConfig}; |
27 | | - use once_cell::sync::Lazy; |
28 | | - use prometheus::{HistogramOpts, HistogramVec}; |
29 | | - |
30 | | - use super::StorageMetrics; |
| 52 | + use crate::storage::FSConfig; |
31 | 53 |
|
32 | | - pub static REQUEST_RESPONSE_TIME: Lazy<HistogramVec> = Lazy::new(|| { |
33 | | - HistogramVec::new( |
34 | | - HistogramOpts::new("local_fs_response_time", "FileSystem Request Latency") |
35 | | - .namespace(METRICS_NAMESPACE), |
36 | | - &["method", "status"], |
37 | | - ) |
38 | | - .expect("metric can be created") |
39 | | - }); |
| 54 | + use super::{STORAGE_FILES_SCANNED, STORAGE_REQUEST_RESPONSE_TIME, StorageMetrics}; |
40 | 55 |
|
41 | 56 | impl StorageMetrics for FSConfig { |
42 | 57 | fn register_metrics(&self, handler: &actix_web_prometheus::PrometheusMetrics) { |
43 | 58 | handler |
44 | 59 | .registry |
45 | | - .register(Box::new(REQUEST_RESPONSE_TIME.clone())) |
| 60 | + .register(Box::new(STORAGE_REQUEST_RESPONSE_TIME.clone())) |
| 61 | + .expect("metric can be registered"); |
| 62 | + handler |
| 63 | + .registry |
| 64 | + .register(Box::new(STORAGE_FILES_SCANNED.clone())) |
46 | 65 | .expect("metric can be registered"); |
47 | 66 | } |
48 | 67 | } |
49 | 68 | } |
50 | 69 |
|
51 | 70 | pub mod s3 { |
52 | | - use crate::{metrics::METRICS_NAMESPACE, storage::S3Config}; |
53 | | - use once_cell::sync::Lazy; |
54 | | - use prometheus::{HistogramOpts, HistogramVec}; |
| 71 | + use crate::storage::S3Config; |
55 | 72 |
|
56 | | - use super::StorageMetrics; |
57 | | - |
58 | | - pub static REQUEST_RESPONSE_TIME: Lazy<HistogramVec> = Lazy::new(|| { |
59 | | - HistogramVec::new( |
60 | | - HistogramOpts::new("s3_response_time", "S3 Request Latency") |
61 | | - .namespace(METRICS_NAMESPACE), |
62 | | - &["method", "status"], |
63 | | - ) |
64 | | - .expect("metric can be created") |
65 | | - }); |
66 | | - |
67 | | - pub static QUERY_LAYER_STORAGE_REQUEST_RESPONSE_TIME: Lazy<HistogramVec> = Lazy::new(|| { |
68 | | - HistogramVec::new( |
69 | | - HistogramOpts::new("query_s3_response_time", "S3 Request Latency") |
70 | | - .namespace(METRICS_NAMESPACE), |
71 | | - &["method", "status"], |
72 | | - ) |
73 | | - .expect("metric can be created") |
74 | | - }); |
| 73 | + use super::{STORAGE_FILES_SCANNED, STORAGE_REQUEST_RESPONSE_TIME, StorageMetrics}; |
75 | 74 |
|
76 | 75 | impl StorageMetrics for S3Config { |
77 | 76 | fn register_metrics(&self, handler: &actix_web_prometheus::PrometheusMetrics) { |
78 | 77 | handler |
79 | 78 | .registry |
80 | | - .register(Box::new(REQUEST_RESPONSE_TIME.clone())) |
| 79 | + .register(Box::new(STORAGE_REQUEST_RESPONSE_TIME.clone())) |
81 | 80 | .expect("metric can be registered"); |
82 | 81 | handler |
83 | 82 | .registry |
84 | | - .register(Box::new(QUERY_LAYER_STORAGE_REQUEST_RESPONSE_TIME.clone())) |
| 83 | + .register(Box::new(STORAGE_FILES_SCANNED.clone())) |
85 | 84 | .expect("metric can be registered"); |
86 | 85 | } |
87 | 86 | } |
88 | 87 | } |
89 | 88 |
|
90 | 89 | pub mod azureblob { |
91 | | - use crate::{metrics::METRICS_NAMESPACE, storage::AzureBlobConfig}; |
92 | | - use once_cell::sync::Lazy; |
93 | | - use prometheus::{HistogramOpts, HistogramVec}; |
94 | | - |
95 | | - use super::StorageMetrics; |
| 90 | + use crate::storage::AzureBlobConfig; |
96 | 91 |
|
97 | | - pub static REQUEST_RESPONSE_TIME: Lazy<HistogramVec> = Lazy::new(|| { |
98 | | - HistogramVec::new( |
99 | | - HistogramOpts::new("azr_blob_response_time", "AzureBlob Request Latency") |
100 | | - .namespace(METRICS_NAMESPACE), |
101 | | - &["method", "status"], |
102 | | - ) |
103 | | - .expect("metric can be created") |
104 | | - }); |
105 | | - |
106 | | - pub static QUERY_LAYER_STORAGE_REQUEST_RESPONSE_TIME: Lazy<HistogramVec> = Lazy::new(|| { |
107 | | - HistogramVec::new( |
108 | | - HistogramOpts::new("query_azr_blob_response_time", "AzureBlob Request Latency") |
109 | | - .namespace(METRICS_NAMESPACE), |
110 | | - &["method", "status"], |
111 | | - ) |
112 | | - .expect("metric can be created") |
113 | | - }); |
| 92 | + use super::{STORAGE_FILES_SCANNED, STORAGE_REQUEST_RESPONSE_TIME, StorageMetrics}; |
114 | 93 |
|
115 | 94 | impl StorageMetrics for AzureBlobConfig { |
116 | 95 | fn register_metrics(&self, handler: &actix_web_prometheus::PrometheusMetrics) { |
117 | 96 | handler |
118 | 97 | .registry |
119 | | - .register(Box::new(REQUEST_RESPONSE_TIME.clone())) |
| 98 | + .register(Box::new(STORAGE_REQUEST_RESPONSE_TIME.clone())) |
120 | 99 | .expect("metric can be registered"); |
121 | 100 | handler |
122 | 101 | .registry |
123 | | - .register(Box::new(QUERY_LAYER_STORAGE_REQUEST_RESPONSE_TIME.clone())) |
| 102 | + .register(Box::new(STORAGE_FILES_SCANNED.clone())) |
124 | 103 | .expect("metric can be registered"); |
125 | 104 | } |
126 | 105 | } |
127 | 106 | } |
128 | 107 |
|
129 | 108 | pub mod gcs { |
130 | | - use crate::{metrics::METRICS_NAMESPACE, storage::GcsConfig}; |
131 | | - use once_cell::sync::Lazy; |
132 | | - use prometheus::{HistogramOpts, HistogramVec}; |
| 109 | + use crate::storage::GcsConfig; |
133 | 110 |
|
134 | | - use super::StorageMetrics; |
135 | | - |
136 | | - pub static REQUEST_RESPONSE_TIME: Lazy<HistogramVec> = Lazy::new(|| { |
137 | | - HistogramVec::new( |
138 | | - HistogramOpts::new("gcs_response_time", "GCS Request Latency") |
139 | | - .namespace(METRICS_NAMESPACE), |
140 | | - &["method", "status"], |
141 | | - ) |
142 | | - .expect("metric can be created") |
143 | | - }); |
144 | | - |
145 | | - pub static QUERY_LAYER_STORAGE_REQUEST_RESPONSE_TIME: Lazy<HistogramVec> = Lazy::new(|| { |
146 | | - HistogramVec::new( |
147 | | - HistogramOpts::new("query_gcs_response_time", "GCS Request Latency") |
148 | | - .namespace(METRICS_NAMESPACE), |
149 | | - &["method", "status"], |
150 | | - ) |
151 | | - .expect("metric can be created") |
152 | | - }); |
| 111 | + use super::{STORAGE_FILES_SCANNED, STORAGE_REQUEST_RESPONSE_TIME, StorageMetrics}; |
153 | 112 |
|
154 | 113 | impl StorageMetrics for GcsConfig { |
155 | 114 | fn register_metrics(&self, handler: &actix_web_prometheus::PrometheusMetrics) { |
156 | 115 | handler |
157 | 116 | .registry |
158 | | - .register(Box::new(REQUEST_RESPONSE_TIME.clone())) |
| 117 | + .register(Box::new(STORAGE_REQUEST_RESPONSE_TIME.clone())) |
159 | 118 | .expect("metric can be registered"); |
160 | 119 | handler |
161 | 120 | .registry |
162 | | - .register(Box::new(QUERY_LAYER_STORAGE_REQUEST_RESPONSE_TIME.clone())) |
| 121 | + .register(Box::new(STORAGE_FILES_SCANNED.clone())) |
163 | 122 | .expect("metric can be registered"); |
164 | 123 | } |
165 | 124 | } |
|
0 commit comments