Skip to content

Commit

Permalink
Merge pull request #565 from helium/jg/error-region-params-failure
Browse files Browse the repository at this point in the history
fail region params lookup on db error
  • Loading branch information
jeffgrunewald authored Jul 7, 2023
2 parents d0bdc67 + d93d2b6 commit e253815
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
13 changes: 11 additions & 2 deletions iot_config/src/gateway_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,14 +184,23 @@ impl iot_config::Gateway for GatewayService {
})?;

let (region, gain) = match self.resolve_gateway_info(address).await {
Err(_) => {
Err(status) if status.code() == tonic::Code::NotFound => {
tracing::debug!(
pubkey = %address,
%default_region,
"unable to retrieve gateway from chain"
);
(default_region, 0)
}
Err(status) => {
tracing::error!(
pubkey = %address,
%default_region,
"gateway lookup failed"
);
telemetry::count_region_lookup(default_region, None);
return Err(Status::internal(status.message().to_string()));
}
Ok(GatewayInfo { metadata, .. }) => match metadata {
None => {
tracing::debug!(
Expand All @@ -204,7 +213,7 @@ impl iot_config::Gateway for GatewayService {
Some(metadata) => (metadata.region, metadata.gain),
},
};
telemetry::count_region_lookup(default_region, region);
telemetry::count_region_lookup(default_region, Some(region));

let params = self.region_map.get_params(&region);

Expand Down
6 changes: 4 additions & 2 deletions iot_config/src/telemetry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@ pub fn gauge_hexes(cells: usize) {

pub fn count_region_lookup(
default_region: helium_proto::Region,
reported_region: helium_proto::Region,
reported_region: Option<helium_proto::Region>,
) {
let reported_region =
reported_region.map_or_else(|| "LOOKUP_FAILED".to_string(), |region| region.to_string());
metrics::increment_counter!(
REGION_LOOKUP_METRIC,
// per metrics docs, &str should be preferred for performance; should the regions be
// mapped through a match of region => &'static str of the name?
"default_region" => default_region.to_string(), "reported_region" => reported_region.to_string()
"default_region" => default_region.to_string(), "reported_region" => reported_region
);
}

Expand Down

0 comments on commit e253815

Please sign in to comment.