Skip to content

Commit

Permalink
chore: disable metrics (#280)
Browse files Browse the repository at this point in the history
  • Loading branch information
aleortega authored Oct 18, 2023
1 parent b81f7a1 commit e33aa4b
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 49 deletions.
8 changes: 4 additions & 4 deletions src/api/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ pub fn get_app_router(
App::new()
.app_data(data.clone())
.wrap(TracingLogger::default())
.wrap(initialize_metrics(data.config.env.clone()))
.wrap(CheckMetricsToken::new(
data.config.wkc_metrics_bearer_token.clone(),
))
// .wrap(initialize_metrics(data.config.env.clone()))
// .wrap(CheckMetricsToken::new(
// data.config.wkc_metrics_bearer_token.clone(),
// ))
.wrap(CheckAuthToken::new(protected_routes))
.wrap(middleware::NormalizePath::trim())
.service(live)
Expand Down
90 changes: 45 additions & 45 deletions tests/route_metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,70 +3,70 @@ pub use common::*;

use actix_web::test;

const METRICS_URI: &str = "/metrics";
// const METRICS_URI: &str = "/metrics";

#[actix_web::test]
async fn metrics_endpoint_should_work() {
let mut config = get_configuration().await;
config.wkc_metrics_bearer_token = String::from("TEST_TOKEN");
let token = config.wkc_metrics_bearer_token.clone();
// #[actix_web::test]
// async fn metrics_endpoint_should_work() {
// let mut config = get_configuration().await;
// config.wkc_metrics_bearer_token = String::from("TEST_TOKEN");
// let token = config.wkc_metrics_bearer_token.clone();

let app = test::init_service(get_app(config, None).await).await;
// let app = test::init_service(get_app(config, None).await).await;

let header = ("authorization", format!("Bearer {token}"));
// let header = ("authorization", format!("Bearer {token}"));

let req = test::TestRequest::get()
.uri(METRICS_URI)
.insert_header(header)
.to_request();
// let req = test::TestRequest::get()
// .uri(METRICS_URI)
// .insert_header(header)
// .to_request();

let response = test::call_service(&app, req).await;
// let response = test::call_service(&app, req).await;

assert!(response.status().is_success());
}
// assert!(response.status().is_success());
// }

#[actix_web::test]
async fn metrics_endpoint_should_fail_401_when_no_token() {
let mut config = get_configuration().await;
config.wkc_metrics_bearer_token = String::from("TEST_TOKEN");
// #[actix_web::test]
// async fn metrics_endpoint_should_fail_401_when_no_token() {
// let mut config = get_configuration().await;
// config.wkc_metrics_bearer_token = String::from("TEST_TOKEN");

let app = test::init_service(get_app(config, None).await).await;
// let app = test::init_service(get_app(config, None).await).await;

let header = ("authorization", format!("Bearer {}", ""));
// let header = ("authorization", format!("Bearer {}", ""));

let req = test::TestRequest::get()
.uri(METRICS_URI)
.insert_header(header)
.to_request();
// let req = test::TestRequest::get()
// .uri(METRICS_URI)
// .insert_header(header)
// .to_request();

let response = test::call_service(&app, req).await;
// let response = test::call_service(&app, req).await;

assert_eq!(response.status(), 401)
}
// assert_eq!(response.status(), 401)
// }

#[actix_web::test]
async fn metrics_endpoint_should_fail_401_when_no_header() {
let mut config = get_configuration().await;
config.wkc_metrics_bearer_token = String::from("TEST_TOKEN");
// #[actix_web::test]
// async fn metrics_endpoint_should_fail_401_when_no_header() {
// let mut config = get_configuration().await;
// config.wkc_metrics_bearer_token = String::from("TEST_TOKEN");

let app = test::init_service(get_app(config, None).await).await;
// let app = test::init_service(get_app(config, None).await).await;

let req = test::TestRequest::get().uri(METRICS_URI).to_request();
// let req = test::TestRequest::get().uri(METRICS_URI).to_request();

let response = test::call_service(&app, req).await;
// let response = test::call_service(&app, req).await;

assert_eq!(response.status(), 401)
}
// assert_eq!(response.status(), 401)
// }

#[actix_web::test]
async fn metrics_endpoint_should_fail_500() {
let config = get_configuration().await;
// #[actix_web::test]
// async fn metrics_endpoint_should_fail_500() {
// let config = get_configuration().await;

let app = test::init_service(get_app(config, None).await).await;
// let app = test::init_service(get_app(config, None).await).await;

let req = test::TestRequest::get().uri(METRICS_URI).to_request();
// let req = test::TestRequest::get().uri(METRICS_URI).to_request();

let response = test::call_service(&app, req).await;
// let response = test::call_service(&app, req).await;

assert_eq!(response.status(), 500)
}
// assert_eq!(response.status(), 500)
// }

0 comments on commit e33aa4b

Please sign in to comment.