Skip to content

Commit b13950b

Browse files
committed
Retry requests once if they fail.
1 parent b10dcf0 commit b13950b

File tree

4 files changed

+31
-15
lines changed

4 files changed

+31
-15
lines changed

chain-prometheus-exporter/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
## Unreleased changes
22

3+
## 1.1.2
4+
5+
- Retry requests to the node once.
6+
37
## 1.1.1
48

59
- Add keep-alive to node connection.

chain-prometheus-exporter/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

chain-prometheus-exporter/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "chain-prometheus-exporter"
3-
version = "1.1.1"
3+
version = "1.1.2"
44
edition = "2021"
55

66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

chain-prometheus-exporter/src/main.rs

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use axum::{
77
use clap::Parser;
88
use concordium_rust_sdk::{
99
endpoints::QueryError,
10-
smart_contracts::common::AccountAddress,
10+
smart_contracts::common::{AccountAddress, Amount},
1111
v2::{self, BlockIdentifier},
1212
};
1313
use futures::{stream::FuturesOrdered, TryStreamExt};
@@ -187,12 +187,12 @@ type ServiceState = (
187187
Arc<Vec<(AccountAddress, GenericGauge<AtomicU64>)>>,
188188
);
189189

190-
#[tracing::instrument(level = "debug", skip(client, registry))]
191-
async fn text_metrics(
192-
axum::extract::State((client, registry, gauges)): axum::extract::State<ServiceState>,
193-
) -> Result<String, axum::response::ErrorResponse> {
190+
async fn get_data(
191+
client: v2::Client,
192+
gauges: impl Iterator<Item = AccountAddress>,
193+
) -> Result<Vec<Amount>, QueryError> {
194194
let mut futures = FuturesOrdered::new();
195-
for acc in gauges.iter().map(|x| x.0) {
195+
for acc in gauges {
196196
let mut client = client.clone();
197197
futures.push_back(async move {
198198
let acc = client
@@ -202,15 +202,27 @@ async fn text_metrics(
202202
Ok::<_, QueryError>(acc.account_amount)
203203
})
204204
}
205-
match futures.try_collect::<Vec<_>>().await {
206-
Ok(balances) => {
207-
for (balance, gauge) in balances.into_iter().zip(gauges.iter()) {
208-
gauge.1.set(balance.micro_ccd())
209-
}
205+
futures.try_collect::<Vec<_>>().await
206+
}
207+
208+
#[tracing::instrument(level = "debug", skip(client, registry))]
209+
async fn text_metrics(
210+
axum::extract::State((client, registry, gauges)): axum::extract::State<ServiceState>,
211+
) -> Result<String, axum::response::ErrorResponse> {
212+
let result = get_data(client.clone(), gauges.iter().map(|x| x.0)).await;
213+
let balances = match result {
214+
Ok(balances) => balances,
215+
Err(e) => {
216+
tracing::warn!("Query failed (retrying): {e:#}");
217+
// Sometimes we get a GoAway from the node. We retry the request once.
218+
get_data(client.clone(), gauges.iter().map(|x| x.0))
219+
.await
220+
.map_err(Error::Query)?
210221
}
211-
Err(e) => return Err(Error::Query(e).into()),
222+
};
223+
for (balance, gauge) in balances.into_iter().zip(gauges.iter()) {
224+
gauge.1.set(balance.micro_ccd())
212225
}
213-
214226
let encoder = TextEncoder::new();
215227
let metric_families = registry.gather();
216228
Ok(encoder

0 commit comments

Comments
 (0)