Skip to content

Commit

Permalink
Format server.rs and http_metrics.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
cybershang committed Sep 18, 2024
1 parent 8b0afd9 commit 0650b99
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
13 changes: 10 additions & 3 deletions src/cli/command/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ use std::{
sync::{Arc, RwLock},
};

use actix_web::{middleware::{self, from_fn}, web, App, HttpResponse, HttpServer};
use actix_web::{
middleware::{self, from_fn},
web, App, HttpResponse, HttpServer,
};
use anyhow::format_err;
use clap::ArgMatches;
use openssl::{
Expand All @@ -17,7 +20,12 @@ use openssl::{
use sysexits::ExitCode;

use crate::{
cli::config, core::Core, errors::RvError, http, metrics::{manager::MetricsManager, middleware::metrics_midleware}, storage, EXIT_CODE_INSUFFICIENT_PARAMS, EXIT_CODE_LOAD_CONFIG_FAILURE, EXIT_CODE_OK
cli::config,
core::Core,
errors::RvError,
http,
metrics::{manager::MetricsManager, middleware::metrics_midleware},
storage, EXIT_CODE_INSUFFICIENT_PARAMS, EXIT_CODE_LOAD_CONFIG_FAILURE, EXIT_CODE_OK,
};

pub const WORK_DIR_PATH_DEFAULT: &str = "/tmp/rusty_vault";
Expand Down Expand Up @@ -111,7 +119,6 @@ pub fn main(config_path: &str) -> Result<(), RvError> {
let metrics_manager = Arc::new(RwLock::new(MetricsManager::new()));
let system_metrics = Arc::clone(&metrics_manager.read().unwrap().system_metrics);


let core = Arc::new(RwLock::new(Core {
physical: backend,
barrier: Arc::new(barrier),
Expand Down
9 changes: 4 additions & 5 deletions src/metrics/http_metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,8 @@ pub struct HttpMetrics {
impl HttpMetrics {
pub fn new(registry: &mut Registry) -> Self {
let requests = Family::<HttpLabel, Counter>::default();
let histogram = Family::<HttpLabel, Histogram>::new_with_constructor(|| {
Histogram::new(linear_buckets(0.1, 0.1, 10))
});
let histogram =
Family::<HttpLabel, Histogram>::new_with_constructor(|| Histogram::new(linear_buckets(0.1, 0.1, 10)));

registry.register(
"http_request_count",
Expand All @@ -62,11 +61,11 @@ impl HttpMetrics {
Self { requests, histogram }
}

pub fn increment_request_count(&self, label:&HttpLabel) {
pub fn increment_request_count(&self, label: &HttpLabel) {
self.requests.get_or_create(label).inc();
}

pub fn observe_duration(&self, label:&HttpLabel, duration: f64,) {
pub fn observe_duration(&self, label: &HttpLabel, duration: f64) {
self.histogram.get_or_create(label).observe(duration);
}
}

0 comments on commit 0650b99

Please sign in to comment.