Skip to content

Commit f56350e

Browse files
authored
chore(metrics): add metric about opendal retries count (#16724)
* add OPENDAL_RETRIES_COUNT * fix clippy
1 parent c5c7fce commit f56350e

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/common/storage/src/operator.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,13 @@ use std::env;
1616
use std::io::Error;
1717
use std::io::ErrorKind;
1818
use std::io::Result;
19+
use std::sync::LazyLock;
1920
use std::time::Duration;
2021

2122
use anyhow::anyhow;
2223
use databend_common_base::base::GlobalInstance;
24+
use databend_common_base::runtime::metrics::register_counter_family;
25+
use databend_common_base::runtime::metrics::FamilyCounter;
2326
use databend_common_base::runtime::GlobalIORuntime;
2427
use databend_common_base::runtime::TrySpawn;
2528
use databend_common_exception::ErrorCode;
@@ -58,6 +61,9 @@ use crate::runtime_layer::RuntimeLayer;
5861
use crate::StorageConfig;
5962
use crate::StorageHttpClient;
6063

64+
static METRIC_OPENDAL_RETRIES_COUNT: LazyLock<FamilyCounter<Vec<(&'static str, String)>>> =
65+
LazyLock::new(|| register_counter_family("opendal_retries_count"));
66+
6167
/// init_operator will init an opendal operator based on storage config.
6268
pub fn init_operator(cfg: &StorageParams) -> Result<Operator> {
6369
let op = match &cfg {
@@ -397,6 +403,8 @@ pub struct DatabendRetryInterceptor;
397403

398404
impl RetryInterceptor for DatabendRetryInterceptor {
399405
fn intercept(&self, err: &opendal::Error, dur: Duration) {
406+
let labels = vec![("err", err.kind().to_string())];
407+
METRIC_OPENDAL_RETRIES_COUNT.get_or_create(&labels).inc();
400408
warn!(
401409
target: "opendal::layers::retry",
402410
"will retry after {:.2}s because: {:?}",

0 commit comments

Comments
 (0)