Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions stats/stats-proto/proto/stats.proto
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ message UpdateStatus {

message BatchUpdateChartsRequest {
repeated string chart_names = 1;
// Will ignore `chart_names` and update all charts
optional bool update_all = 4;
// Default is today
optional string from = 2;
optional bool update_later = 3;
Expand Down
3 changes: 3 additions & 0 deletions stats/stats-proto/swagger/stats.swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,9 @@ definitions:
type: array
items:
type: string
update_all:
type: boolean
title: Will ignore `chart_names` and update all charts
from:
type: string
title: Default is today
Expand Down
7 changes: 6 additions & 1 deletion stats/stats-server/src/read_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,12 @@ impl StatsService for ReadService {
let update_later = request.update_later.unwrap_or(false);
let result = self
.update_service
.handle_update_request(request.chart_names, from, update_later)
.handle_update_request(
request.chart_names,
request.update_all.unwrap_or(false),
from,
update_later,
)
.await
.map_err(|e| match e {
OnDemandReupdateError::AllChartsNotFound => Status::not_found(e.to_string()),
Expand Down
7 changes: 6 additions & 1 deletion stats/stats-server/src/update_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,12 +450,17 @@ impl UpdateService {
}
}

/// `update_all=true` will ignore `chart_names` and update all enabled charts
pub async fn handle_update_request(
self: &Arc<Self>,
chart_names: Vec<String>,
mut chart_names: Vec<String>,
update_all: bool,
from: Option<NaiveDate>,
update_later: bool,
) -> Result<OnDemandReupdateAccepted, OnDemandReupdateError> {
if update_all {
chart_names = self.charts.charts_info.keys().cloned().collect();
}
let (accepted_keys, accepted_names, rejections) =
self.split_update_request_input(chart_names);
if accepted_keys.is_empty() {
Expand Down
2 changes: 2 additions & 0 deletions stats/stats-server/tests/it/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ pub async fn request_reupdate_from(
key: &ApiKey,
from: &str,
charts: Vec<&str>,
update_all: bool,
) -> proto_v1::BatchUpdateChartsResult {
let chart_names = charts.into_iter().map(|s| s.to_string()).collect();
send_request_with_key(
Expand All @@ -146,6 +147,7 @@ pub async fn request_reupdate_from(
reqwest::Method::POST,
Some(&proto_v1::BatchUpdateChartsRequest {
chart_names,
update_all: Some(update_all),
from: Some(from.into()),
update_later: None,
}),
Expand Down
15 changes: 11 additions & 4 deletions stats/stats-server/tests/it/mock_blockscout_reindex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use blockscout_service_launcher::{
test_server::{init_server, send_get_request},
};
use chrono::{Days, NaiveDate, Utc};
use pretty_assertions::assert_eq;
use pretty_assertions::{assert_eq, assert_ne};
use stats::tests::{
init_db::init_db_all,
mock_blockscout::{default_mock_blockscout_api, fill_mock_blockscout_data, imitate_reindex},
Expand Down Expand Up @@ -71,7 +71,7 @@ async fn test_reupdate_works() {

// should reindex newTxns transitively
let reupdate_response =
request_reupdate_from(&base, &api_key, "2023-01-01", vec!["txnsGrowth"]).await;
request_reupdate_from(&base, &api_key, "2023-01-01", vec!["txnsGrowth"], false).await;
assert_eq!(
reupdate_response,
BatchUpdateChartsResult {
Expand Down Expand Up @@ -101,7 +101,7 @@ async fn test_reupdate_works() {
);

let reupdate_response =
request_reupdate_from(&base, &api_key, "2022-11-11", vec!["newTxns"]).await;
request_reupdate_from(&base, &api_key, "2022-11-11", vec!["newTxns"], false).await;
assert_eq!(
reupdate_response,
BatchUpdateChartsResult {
Expand Down Expand Up @@ -131,7 +131,7 @@ async fn test_reupdate_works() {
);

let reupdate_response =
request_reupdate_from(&base, &api_key, "2000-01-01", vec!["newTxns"]).await;
request_reupdate_from(&base, &api_key, "2000-01-01", vec!["newTxns"], false).await;
assert_eq!(
reupdate_response,
BatchUpdateChartsResult {
Expand All @@ -158,6 +158,11 @@ async fn test_reupdate_works() {
("2023-03-01", "2"),
])
);

let reupdate_response =
request_reupdate_from(&base, &api_key, "2022-11-11", vec![], true).await;
assert_eq!(reupdate_response.total_rejected, 0);
assert_ne!(reupdate_response.accepted.len(), 0);
blockscout_db.close_all_unwrap().await;
stats_db.close_all_unwrap().await;
shutdown.cancel_wait_timeout(None).await.unwrap();
Expand All @@ -170,6 +175,7 @@ pub async fn test_incorrect_reupdate_requests(base: &Url, key: ApiKey) {
);
request = request.json(&proto_v1::BatchUpdateChartsRequest {
chart_names: vec!["txnsGrowth".to_string()],
update_all: None,
from: Some("2023-01-01".to_string()),
update_later: None,
});
Expand Down Expand Up @@ -201,6 +207,7 @@ pub async fn test_incorrect_reupdate_requests(base: &Url, key: ApiKey) {
.unwrap()
.json(&proto_v1::BatchUpdateChartsRequest {
chart_names: vec!["txnsGrowth".to_string()],
update_all: None,
from: Some(tomorrow.format("%Y-%m-%d").to_string()),
update_later: None,
});
Expand Down