Skip to content

Commit

Permalink
XC-246: add RejectionCode to err_http_outcall
Browse files Browse the repository at this point in the history
  • Loading branch information
gregorydemay committed Nov 28, 2024
1 parent 809c3ff commit db42c7f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion candid/evm_rpc.did
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ type Metrics = record {
responses : vec record { record { text; text; text }; nat64 };
inconsistentResponses : vec record { record { text; text }; nat64 };
cyclesCharged : vec record { record { text; text }; nat };
errHttpOutcall : vec record { record { text; text }; nat64 };
errHttpOutcall : vec record { record { text; text; RejectionCode }; nat64 };
};
type MultiFeeHistoryResult = variant {
Consistent : FeeHistoryResult;
Expand Down
2 changes: 1 addition & 1 deletion src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ pub async fn http_request(
Ok(response)
}
Err((code, message)) => {
add_metric_entry!(err_http_outcall, (rpc_method, rpc_host), 1);
add_metric_entry!(err_http_outcall, (rpc_method, rpc_host, code), 1);
Err(HttpOutcallError::IcError { code, message }.into())
}
}
Expand Down
19 changes: 18 additions & 1 deletion src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::memory::get_api_key;
use crate::util::hostname_from_url;
use crate::validate::validate_api_key;
use candid::CandidType;
use ic_cdk::api::call::RejectionCode;
use ic_cdk::api::management_canister::http_request::HttpHeader;
use ic_stable_structures::storable::Bound;
use ic_stable_structures::Storable;
Expand Down Expand Up @@ -115,6 +116,22 @@ impl MetricLabels for MetricHttpStatusCode {
}
}

impl MetricLabels for RejectionCode {
fn metric_labels(&self) -> Vec<(&str, &str)> {
let code = match self {
RejectionCode::NoError => "NO_ERROR",
RejectionCode::SysFatal => "SYS_FATAL",
RejectionCode::SysTransient => "SYS_TRANSIENT",
RejectionCode::DestinationInvalid => "DESTINATION_INVALID",
RejectionCode::CanisterReject => "CANISTER_REJECT",
RejectionCode::CanisterError => "CANISTER_ERROR",
RejectionCode::Unknown => "UNKNOWN",
};

vec![("code", code)]
}
}

#[derive(Clone, Debug, Default, PartialEq, Eq, CandidType, Deserialize)]
pub struct Metrics {
pub requests: HashMap<(MetricRpcMethod, MetricRpcHost), u64>,
Expand All @@ -124,7 +141,7 @@ pub struct Metrics {
#[serde(rename = "cyclesCharged")]
pub cycles_charged: HashMap<(MetricRpcMethod, MetricRpcHost), u128>,
#[serde(rename = "errHttpOutcall")]
pub err_http_outcall: HashMap<(MetricRpcMethod, MetricRpcHost), u64>,
pub err_http_outcall: HashMap<(MetricRpcMethod, MetricRpcHost, RejectionCode), u64>,
}

#[derive(Clone, Copy, Debug, PartialEq, Eq)]
Expand Down

0 comments on commit db42c7f

Please sign in to comment.