Skip to content

Commit

Permalink
added metrics and logger
Browse files Browse the repository at this point in the history
  • Loading branch information
Akshay S authored and Akshay S committed May 16, 2024
1 parent d0ee8c2 commit b895cca
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
1 change: 1 addition & 0 deletions crates/storage_impl/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ counter_metric!(KV_OPERATION_SUCCESSFUL, GLOBAL_METER);
counter_metric!(KV_OPERATION_FAILED, GLOBAL_METER);
counter_metric!(KV_PUSHED_TO_DRAINER, GLOBAL_METER);
counter_metric!(KV_FAILED_TO_PUSH_TO_DRAINER, GLOBAL_METER);
counter_metric!(KV_SOFT_KILL_ACTIVE_UPDATE, GLOBAL_METER);
32 changes: 23 additions & 9 deletions crates/storage_impl/src/redis/kv_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,16 @@ pub enum Op<'a> {
Find,
}

impl<'a> std::fmt::Display for Op<'a> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result{
match self{
Op::Insert => f.write_str("insert"),
Op::Find => f.write_str("find"),
Op::Update(p_key, _, _) => f.write_str(&format!("update_{}", p_key)),
}
}
}

pub async fn decide_storage_scheme<'a, T, D>(
store: &KVRouterStore<T>,
storage_scheme: MerchantStorageScheme,
Expand All @@ -259,29 +269,33 @@ where
T: crate::database::store::DatabaseStore,
{
if store.soft_kill_mode {
let ops = operation.to_string();
let updated_scheme = match operation {
Op::Insert => MerchantStorageScheme::PostgresOnly,
Op::Find => MerchantStorageScheme::RedisKv,
Op::Update(partition_key, field, Some("redis_kv")) => {
match kv_wrapper::<D, _, _>(store, KvOperation::<D>::HGet(field), partition_key)
.await
{
Ok(_) => MerchantStorageScheme::RedisKv,
Ok(_) => {
metrics::KV_SOFT_KILL_ACTIVE_UPDATE.add(&metrics::CONTEXT, 1, &[]);
MerchantStorageScheme::RedisKv
},
Err(_) => MerchantStorageScheme::PostgresOnly,
}
}

Op::Update(_, _, None) => MerchantStorageScheme::PostgresOnly,
Op::Update(_, _, Some("postgres_only")) => MerchantStorageScheme::PostgresOnly,
_ => storage_scheme,
_ => {
logger::debug!("soft_kill_mode - using default storage scheme");
storage_scheme
},
};
if updated_scheme != storage_scheme {
let type_name = std::any::type_name::<D>();
println!(
"[decide_storage_scheme] output: {} for entity {}",
updated_scheme, type_name
);
}

let type_name = std::any::type_name::<D>();
logger::info!(soft_kill_mode = "decide_storage_scheme", decided_scheme = %updated_scheme, configured_scheme = %storage_scheme,entity = %type_name, operation = %ops);

updated_scheme
} else {
storage_scheme
Expand Down

0 comments on commit b895cca

Please sign in to comment.