Skip to content

Commit cd0ec36

Browse files
committed
feature: Add routes for ancillary_files_restored, complete_restoration and partial_restoration
1 parent 90316d7 commit cd0ec36

8 files changed

+607
-79
lines changed

mithril-aggregator/src/http_server/routes/statistics_routes.rs

+362-62
Large diffs are not rendered by default.

mithril-aggregator/src/metrics/service.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,20 @@ build_metrics_service!(
1919
"Number of Cardano immutable files full restorations since startup on a Mithril aggregator node"
2020
),
2121
cardano_database_immutable_files_restored:MetricCounter(
22-
"mithril_aggregator_cardano_db_immutable_files_restored_since_startup",
23-
"Number of Cardano immutable files restored since startup on a Mithril aggregator node"
22+
"mithril_aggregator_cardano_db_immutable_files_restored",
23+
"Number of Cardano immutable files restored on a Mithril aggregator node"
2424
),
2525
cardano_database_ancillary_files_restored:MetricCounter(
26-
"mithril_aggregator_cardano_db_ancillary_files_restored_since_startup",
27-
"Number of Cardano ancillary files restored since startup on a Mithril aggregator node"
26+
"mithril_aggregator_cardano_db_ancillary_files_restored",
27+
"Number of Cardano ancillary files restored on a Mithril aggregator node"
2828
),
29-
cardano_database_full_restoration_since_startup:MetricCounter(
30-
"mithril_aggregator_cardano_db_full_restoration_since_startup",
31-
"Number of full Cardano database restoration since startup on a Mithril aggregator node"
29+
cardano_database_complete_restoration:MetricCounter(
30+
"mithril_aggregator_cardano_db_complete_restoration",
31+
"Number of complete Cardano database restoration on a Mithril aggregator node"
3232
),
33-
cardano_database_partial_restoration_since_startup:MetricCounter(
34-
"mithril_aggregator_cardano_db_partial_restoration_since_startup",
35-
"Number of partial Cardano database restoration since startup on a Mithril aggregator node"
33+
cardano_database_partial_restoration:MetricCounter(
34+
"mithril_aggregator_cardano_db_partial_restoration",
35+
"Number of partial Cardano database restoration on a Mithril aggregator node"
3636
),
3737
artifact_detail_cardano_database_total_served_since_startup:MetricCounter(
3838
"mithril_aggregator_artifact_detail_cardano_database_total_served_since_startup",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
use serde::{Deserialize, Serialize};
2+
3+
/// Message structure of an ancillary files restoration
4+
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
5+
pub struct CardanoDatabaseAncillaryFilesRestoredMessage {
6+
/// Number of ancillary files restored.
7+
pub nb_ancillary_files: u32,
8+
}
9+
10+
impl CardanoDatabaseAncillaryFilesRestoredMessage {
11+
/// Return a dummy test entity (test-only).
12+
pub fn dummy() -> Self {
13+
Self {
14+
nb_ancillary_files: 34,
15+
}
16+
}
17+
}
18+
19+
#[cfg(test)]
20+
mod tests {
21+
use super::*;
22+
23+
const CURRENT_JSON: &str = r#"{
24+
"nb_ancillary_files": 62
25+
}"#;
26+
27+
fn golden_message_current() -> CardanoDatabaseAncillaryFilesRestoredMessage {
28+
CardanoDatabaseAncillaryFilesRestoredMessage {
29+
nb_ancillary_files: 62,
30+
}
31+
}
32+
33+
#[test]
34+
fn test_current_json_deserialized_into_current_message() {
35+
let json = CURRENT_JSON;
36+
let message: CardanoDatabaseAncillaryFilesRestoredMessage =
37+
serde_json::from_str(json).unwrap();
38+
39+
assert_eq!(golden_message_current(), message);
40+
}
41+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
use serde::{Deserialize, Serialize};
2+
3+
/// Message structure of a complete Cardano database restoration
4+
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
5+
pub struct CardanoDatabaseCompleteRestorationMessage {
6+
/// Number of complete restoration.
7+
pub nb_complete_restoration: u32,
8+
}
9+
10+
impl CardanoDatabaseCompleteRestorationMessage {
11+
/// Return a dummy test entity (test-only).
12+
pub fn dummy() -> Self {
13+
Self {
14+
nb_complete_restoration: 34,
15+
}
16+
}
17+
}
18+
19+
#[cfg(test)]
20+
mod tests {
21+
use super::*;
22+
23+
const CURRENT_JSON: &str = r#"{
24+
"nb_complete_restoration": 62
25+
}"#;
26+
27+
fn golden_message_current() -> CardanoDatabaseCompleteRestorationMessage {
28+
CardanoDatabaseCompleteRestorationMessage {
29+
nb_complete_restoration: 62,
30+
}
31+
}
32+
33+
#[test]
34+
fn test_current_json_deserialized_into_current_message() {
35+
let json = CURRENT_JSON;
36+
let message: CardanoDatabaseCompleteRestorationMessage =
37+
serde_json::from_str(json).unwrap();
38+
39+
assert_eq!(golden_message_current(), message);
40+
}
41+
}

mithril-common/src/messages/cardano_database_immutable_files_restored.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize};
44
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
55
pub struct CardanoDatabaseImmutableFilesRestoredMessage {
66
/// Number of immutable files restored.
7-
pub nb_immutable_files: u64,
7+
pub nb_immutable_files: u32,
88
}
99

1010
impl CardanoDatabaseImmutableFilesRestoredMessage {
@@ -22,11 +22,10 @@ mod tests {
2222

2323
const CURRENT_JSON: &str = r#"{
2424
"nb_immutable_files": 62
25-
},
2625
}"#;
2726

28-
fn golden_message_current() -> SnapshotMessage {
29-
SnapshotMessage {
27+
fn golden_message_current() -> CardanoDatabaseImmutableFilesRestoredMessage {
28+
CardanoDatabaseImmutableFilesRestoredMessage {
3029
nb_immutable_files: 62,
3130
}
3231
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
use serde::{Deserialize, Serialize};
2+
3+
/// Message structure of a partial Cardano database restoration
4+
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
5+
pub struct CardanoDatabasePartialRestorationMessage {
6+
/// Number of partial restoration.
7+
pub nb_partial_restoration: u32,
8+
}
9+
10+
impl CardanoDatabasePartialRestorationMessage {
11+
/// Return a dummy test entity (test-only).
12+
pub fn dummy() -> Self {
13+
Self {
14+
nb_partial_restoration: 34,
15+
}
16+
}
17+
}
18+
19+
#[cfg(test)]
20+
mod tests {
21+
use super::*;
22+
23+
const CURRENT_JSON: &str = r#"{
24+
"nb_partial_restoration": 62
25+
}"#;
26+
27+
fn golden_message_current() -> CardanoDatabasePartialRestorationMessage {
28+
CardanoDatabasePartialRestorationMessage {
29+
nb_partial_restoration: 62,
30+
}
31+
}
32+
33+
#[test]
34+
fn test_current_json_deserialized_into_current_message() {
35+
let json = CURRENT_JSON;
36+
let message: CardanoDatabasePartialRestorationMessage = serde_json::from_str(json).unwrap();
37+
38+
assert_eq!(golden_message_current(), message);
39+
}
40+
}

mithril-common/src/messages/mod.rs

+6
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33
mod aggregator_features;
44
mod aggregator_status;
55
mod cardano_database;
6+
mod cardano_database_ancillary_files_restored;
7+
mod cardano_database_complete_restoration;
68
mod cardano_database_digest_list;
79
mod cardano_database_immutable_files_restored;
810
mod cardano_database_list;
11+
mod cardano_database_partial_restoration;
912
mod cardano_stake_distribution;
1013
mod cardano_stake_distribution_list;
1114
mod cardano_transaction_snapshot;
@@ -30,13 +33,16 @@ pub use aggregator_features::{
3033
};
3134
pub use aggregator_status::AggregatorStatusMessage;
3235
pub use cardano_database::{ArtifactsLocationsMessagePart, CardanoDatabaseSnapshotMessage};
36+
pub use cardano_database_ancillary_files_restored::CardanoDatabaseAncillaryFilesRestoredMessage;
37+
pub use cardano_database_complete_restoration::CardanoDatabaseCompleteRestorationMessage;
3338
pub use cardano_database_digest_list::{
3439
CardanoDatabaseDigestListItemMessage, CardanoDatabaseDigestListMessage,
3540
};
3641
pub use cardano_database_immutable_files_restored::CardanoDatabaseImmutableFilesRestoredMessage;
3742
pub use cardano_database_list::{
3843
CardanoDatabaseSnapshotListItemMessage, CardanoDatabaseSnapshotListMessage,
3944
};
45+
pub use cardano_database_partial_restoration::CardanoDatabasePartialRestorationMessage;
4046
pub use cardano_stake_distribution::CardanoStakeDistributionMessage;
4147
pub use cardano_stake_distribution_list::{
4248
CardanoStakeDistributionListItemMessage, CardanoStakeDistributionListMessage,

openapi.yaml

+104-3
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,70 @@ paths:
766766
application/json:
767767
schema:
768768
$ref: "#/components/schemas/Error"
769+
770+
/statistics/cardano-database/ancillary-files-restored:
771+
post:
772+
summary: Records ancillary files restored event
773+
description: Records ancillary files restored event
774+
requestBody:
775+
description: Ancillary files restored message
776+
required: true
777+
content:
778+
application/json:
779+
schema:
780+
$ref: "#/components/schemas/CardanoDatabaseAncillaryFilesRestoredMessage"
781+
responses:
782+
"201":
783+
description: Event successfully recorded
784+
default:
785+
description: Record event bad request
786+
content:
787+
application/json:
788+
schema:
789+
$ref: "#/components/schemas/Error"
790+
791+
/statistics/cardano-database/complete-restoration:
792+
post:
793+
summary: Records complete restoration event
794+
description: Records complete restoration event
795+
requestBody:
796+
description: Complete restoration message
797+
required: true
798+
content:
799+
application/json:
800+
schema:
801+
$ref: "#/components/schemas/CardanoDatabaseCompleteRestorationMessage"
802+
responses:
803+
"201":
804+
description: Event successfully recorded
805+
default:
806+
description: Record event bad request
807+
content:
808+
application/json:
809+
schema:
810+
$ref: "#/components/schemas/Error"
811+
812+
/statistics/cardano-database/partial-restoration:
813+
post:
814+
summary: Records partial restoration event
815+
description: Records partial restoration event
816+
requestBody:
817+
description: Partial restoration message
818+
required: true
819+
content:
820+
application/json:
821+
schema:
822+
$ref: "#/components/schemas/CardanoDatabasePartialRestorationMessage"
823+
responses:
824+
"201":
825+
description: Event successfully recorded
826+
default:
827+
description: Record event bad request
828+
content:
829+
application/json:
830+
schema:
831+
$ref: "#/components/schemas/Error"
832+
769833
components:
770834
schemas:
771835
AggregatorStatusMessage:
@@ -1911,9 +1975,46 @@ components:
19111975
description: Number of immutable files restored
19121976
type: integer
19131977
examples:
1914-
- {
1915-
"nb_immutable_files": 15
1916-
}
1978+
- { "nb_immutable_files": 15 }
1979+
1980+
CardanoDatabaseAncillaryFilesRestoredMessage:
1981+
description: CardanoDatabaseAncillaryFilesRestoredMessage represents a Cardano database Ancillary files restored event
1982+
type: object
1983+
additionalProperties: false
1984+
required:
1985+
- nb_ancillary_files
1986+
properties:
1987+
nb_ancillary_files:
1988+
description: Number of ancillary files restored
1989+
type: integer
1990+
examples:
1991+
- { "nb_ancillary_files": 15 }
1992+
1993+
CardanoDatabaseCompleteRestorationMessage:
1994+
description: CardanoDatabaseCompleteRestorationMessage represents a Cardano database complete restoration event
1995+
type: object
1996+
additionalProperties: false
1997+
required:
1998+
- nb_complete_restoration
1999+
properties:
2000+
nb_complete_restoration:
2001+
description: Number of complete restoration
2002+
type: integer
2003+
examples:
2004+
- { "nb_complete_restoration": 15 }
2005+
2006+
CardanoDatabasePartialRestorationMessage:
2007+
description: CardanoDatabasePartialRestorationMessage represents a Cardano database partial restoration event
2008+
type: object
2009+
additionalProperties: false
2010+
required:
2011+
- nb_partial_restoration
2012+
properties:
2013+
nb_partial_restoration:
2014+
description: Number of partial restoration
2015+
type: integer
2016+
examples:
2017+
- { "nb_partial_restoration": 15 }
19172018

19182019
CardanoDatabaseArtifactsLocationsMessagePart:
19192020
description: CardanoDatabaseArtifactsLocationsMessagePart represents the locations of the Cardano database artifacts

0 commit comments

Comments
 (0)