Skip to content

Commit

Permalink
Use recommended error message style
Browse files Browse the repository at this point in the history
  • Loading branch information
sd109 committed Dec 9, 2024
1 parent 2b478a7 commit a1e5167
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,34 @@ lazy_static! {
pub static ref INCOMING_REQUESTS: IntCounterVec = IntCounterVec::new(
Opts::new("incoming_requests", "The number of HTTP requests received"),
&["http_method", "path"]
).expect("Prometheus metric initialization failed");
).expect("Prometheus metric options should be valid");
// Request counter by status code
pub static ref RESPONSE_CODE_COLLECTOR: IntCounterVec = IntCounterVec::new(
Opts::new("outgoing_response", "The number of responses sent"),
&["status_code", "http_method", "path"]
).expect("Prometheus metric initialization failed");
).expect("Prometheus metric options should be valid");
// Response histogram by response time
pub static ref RESPONSE_TIME_COLLECTOR: HistogramVec = HistogramVec::new(
HistogramOpts{
common_opts: Opts::new("response_time", "The time taken to respond to each request"),
buckets: prometheus::DEFAULT_BUCKETS.to_vec(), // Change buckets here if desired
},
&["status_code", "http_method", "path"],
).expect("Prometheus metric initialization failed");
).expect("Prometheus metric options should be valid");
}

/// Registers various prometheus metrics with the global registry
pub fn register_metrics() {
let registry = prometheus::default_registry();
registry
.register(Box::new(INCOMING_REQUESTS.clone()))
.expect("registering prometheus metrics during initialization failed");
.expect("Prometheus metrics registration should not fail during initialization");
registry
.register(Box::new(RESPONSE_CODE_COLLECTOR.clone()))
.expect("registering prometheus metrics during initialization failed");
.expect("Prometheus metrics registration should not fail during initialization");
registry
.register(Box::new(RESPONSE_TIME_COLLECTOR.clone()))
.expect("registering prometheus metrics during initialization failed");
.expect("Prometheus metrics registration should not fail during initialization");
}

/// Returns currently gathered prometheus metrics
Expand Down

0 comments on commit a1e5167

Please sign in to comment.