Skip to content
This repository has been archived by the owner on Jul 17, 2024. It is now read-only.

Commit

Permalink
Add missing log entry for AIC creation (#80)
Browse files Browse the repository at this point in the history
* Add missing log entry for AIC creation
* Lint fix

Co-authored-by: Sarah Bird <[email protected]>
  • Loading branch information
jswinarton and birdsarah authored Oct 31, 2022
1 parent 29bc600 commit bab4ae0
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 12 deletions.
36 changes: 30 additions & 6 deletions src/lib/controllers/aic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,21 @@ pub async fn create(
data: web::Json<AICRequest>,
pool: web::Data<PgPool>,
settings: web::Data<Settings>,
statsd: web::Data<StatsD>,
) -> HttpResponse {
let aic = AICModel {
db_pool: pool.as_ref(),
};
match aic.create(&data.cj_id, &data.flow_id, &settings).await {
Ok(created) => {
info_and_incr!(
statsd,
LogKey::AicRecordCreate,
aic_id = created.id.to_string().as_str(),
flow_id = created.flow_id.as_str(),
expired = created.expires.to_string().as_str(),
"AIC created."
);
let response = AICResponse {
aic_id: created.id,
expires: created.expires,
Expand Down Expand Up @@ -97,12 +106,27 @@ pub async fn update(

match updated {
Ok(updated) => {
info_and_incr!(
statsd,
LogKey::AicRecordUpdate,
aic_id = &aic_id.to_string().as_str(),
"AIC updated."
);
if updated.cj_event_value == data.cj_id || data.cj_id == empty_cj_id() {
info_and_incr!(
statsd,
LogKey::AicRecordUpdate,
aic_id = updated.id.to_string().as_str(),
flow_id = updated.flow_id.as_str(),
expires = updated.expires.to_string().as_str(),
"AIC updated."
);
} else {
info_and_incr!(
statsd,
LogKey::AicRecordUpdate,
aic_id = updated.id.to_string().as_str(),
flow_id = updated.flow_id.as_str(),
expires = updated.expires.to_string().as_str(),
cj_event_value = updated.cj_event_value.as_str(),
"AIC updated."
);
}

let response = AICResponse {
aic_id: updated.id,
expires: updated.expires,
Expand Down
4 changes: 2 additions & 2 deletions src/lib/telemetry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ macro_rules! error {
#[macro_export]
macro_rules! info_and_incr {
( $statsd_client:expr, $trace_type:expr, $($arg:tt)+ ) => {
crate::info!($trace_type.to_string().as_str(), $($arg)*);
$crate::info!($trace_type.to_string().as_str(), $($arg)*);
$statsd_client.incr(&$trace_type);
}
}
Expand Down Expand Up @@ -331,7 +331,7 @@ macro_rules! info_and_incr {
#[macro_export]
macro_rules! error_and_incr {
( $statsd_client:expr, $trace_type:expr, $($arg:tt)+ ) => {
crate::error!($trace_type.to_string().as_str(), $($arg)*);
$crate::error!($trace_type.to_string().as_str(), $($arg)*);
$statsd_client.incr(&$trace_type);
}
}
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/corrections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@ async fn test_corrections_by_day_auth() {

async fn get_authed_path(path: &str, password: &str) -> Response {
let client = reqwest::Client::new();
let r = client

client
.get(path)
.basic_auth("user", Some(password))
.send()
.await
.expect("Failed to GET");
r
.expect("Failed to GET")
}

#[tokio::test]
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl TestApp {
async fn create_test_database(database_url: &str) -> String {
let randomized_test_database_url = format!("{}_test_{}", database_url, Uuid::new_v4());
let url_parts: Vec<&str> = randomized_test_database_url.rsplit('/').collect();
let database_name = url_parts.get(0).unwrap().to_string();
let database_name = url_parts.first().unwrap().to_string();
let mut connection = PgConnection::connect(database_url)
.await
.expect("Failed to connect to postgres.");
Expand Down

0 comments on commit bab4ae0

Please sign in to comment.