1
1
use anyhow:: Context ;
2
2
use async_trait:: async_trait;
3
3
use semver:: Version ;
4
- use slog_scope :: { debug, warn} ;
4
+ use slog :: { debug, warn, Logger } ;
5
5
use std:: sync:: Arc ;
6
6
use thiserror:: Error ;
7
7
@@ -11,6 +11,7 @@ use crate::{
11
11
} ;
12
12
13
13
use super :: ArtifactBuilder ;
14
+ use mithril_common:: logging:: LoggerExtensions ;
14
15
use mithril_common:: {
15
16
entities:: {
16
17
CardanoDbBeacon , Certificate , CompressionAlgorithm , ProtocolMessagePartKey , Snapshot ,
@@ -33,6 +34,7 @@ pub struct CardanoImmutableFilesFullArtifactBuilder {
33
34
snapshotter : Arc < dyn Snapshotter > ,
34
35
snapshot_uploader : Arc < dyn SnapshotUploader > ,
35
36
compression_algorithm : CompressionAlgorithm ,
37
+ logger : Logger ,
36
38
}
37
39
38
40
impl CardanoImmutableFilesFullArtifactBuilder {
@@ -42,12 +44,14 @@ impl CardanoImmutableFilesFullArtifactBuilder {
42
44
snapshotter : Arc < dyn Snapshotter > ,
43
45
snapshot_uploader : Arc < dyn SnapshotUploader > ,
44
46
compression_algorithm : CompressionAlgorithm ,
47
+ logger : Logger ,
45
48
) -> Self {
46
49
Self {
47
50
cardano_node_version : cardano_node_version. clone ( ) ,
48
51
snapshotter,
49
52
snapshot_uploader,
50
53
compression_algorithm,
54
+ logger : logger. new_with_component_name :: < Self > ( ) ,
51
55
}
52
56
}
53
57
@@ -56,7 +60,10 @@ impl CardanoImmutableFilesFullArtifactBuilder {
56
60
beacon : & CardanoDbBeacon ,
57
61
snapshot_digest : & str ,
58
62
) -> StdResult < OngoingSnapshot > {
59
- debug ! ( "CardanoImmutableFilesFullArtifactBuilder: create snapshot archive" ) ;
63
+ debug ! (
64
+ self . logger,
65
+ "CardanoImmutableFilesFullArtifactBuilder: create snapshot archive"
66
+ ) ;
60
67
61
68
let snapshotter = self . snapshotter . clone ( ) ;
62
69
let snapshot_name = format ! (
@@ -74,7 +81,7 @@ impl CardanoImmutableFilesFullArtifactBuilder {
74
81
} )
75
82
. await ??;
76
83
77
- debug ! ( " > snapshot created: '{:?}'" , ongoing_snapshot ) ;
84
+ debug ! ( self . logger , " > snapshot created: '{ongoing_snapshot :?}'" ) ;
78
85
79
86
Ok ( ongoing_snapshot)
80
87
}
@@ -83,16 +90,19 @@ impl CardanoImmutableFilesFullArtifactBuilder {
83
90
& self ,
84
91
ongoing_snapshot : & OngoingSnapshot ,
85
92
) -> StdResult < Vec < SnapshotLocation > > {
86
- debug ! ( "CardanoImmutableFilesFullArtifactBuilder: upload snapshot archive" ) ;
93
+ debug ! (
94
+ self . logger,
95
+ "CardanoImmutableFilesFullArtifactBuilder: upload snapshot archive"
96
+ ) ;
87
97
let location = self
88
98
. snapshot_uploader
89
99
. upload_snapshot ( ongoing_snapshot. get_file_path ( ) )
90
100
. await ;
91
101
92
102
if let Err ( error) = tokio:: fs:: remove_file ( ongoing_snapshot. get_file_path ( ) ) . await {
93
103
warn ! (
94
- " > Post upload ongoing snapshot file removal failure: {}" ,
95
- error
104
+ self . logger ,
105
+ " > Post upload ongoing snapshot file removal failure: { error}"
96
106
) ;
97
107
}
98
108
@@ -106,7 +116,10 @@ impl CardanoImmutableFilesFullArtifactBuilder {
106
116
snapshot_digest : String ,
107
117
remote_locations : Vec < String > ,
108
118
) -> StdResult < Snapshot > {
109
- debug ! ( "CardanoImmutableFilesFullArtifactBuilder: create snapshot" ) ;
119
+ debug ! (
120
+ self . logger,
121
+ "CardanoImmutableFilesFullArtifactBuilder: create snapshot"
122
+ ) ;
110
123
111
124
let snapshot = Snapshot :: new (
112
125
snapshot_digest,
@@ -167,7 +180,10 @@ mod tests {
167
180
168
181
use super :: * ;
169
182
170
- use crate :: { snapshot_uploaders:: MockSnapshotUploader , DumbSnapshotUploader , DumbSnapshotter } ;
183
+ use crate :: {
184
+ snapshot_uploaders:: MockSnapshotUploader , test_tools:: TestLogger , DumbSnapshotUploader ,
185
+ DumbSnapshotter ,
186
+ } ;
171
187
172
188
#[ tokio:: test]
173
189
async fn should_compute_valid_artifact ( ) {
@@ -187,6 +203,7 @@ mod tests {
187
203
dumb_snapshotter. clone ( ) ,
188
204
dumb_snapshot_uploader. clone ( ) ,
189
205
CompressionAlgorithm :: Zstandard ,
206
+ TestLogger :: stdout ( ) ,
190
207
) ;
191
208
let artifact = cardano_immutable_files_full_artifact_builder
192
209
. compute_artifact ( beacon. clone ( ) , & certificate)
@@ -224,6 +241,7 @@ mod tests {
224
241
Arc :: new ( DumbSnapshotter :: new ( ) ) ,
225
242
Arc :: new ( DumbSnapshotUploader :: new ( ) ) ,
226
243
CompressionAlgorithm :: default ( ) ,
244
+ TestLogger :: stdout ( ) ,
227
245
) ;
228
246
229
247
cardano_immutable_files_full_artifact_builder
@@ -248,6 +266,7 @@ mod tests {
248
266
Arc :: new ( DumbSnapshotter :: new ( ) ) ,
249
267
Arc :: new ( DumbSnapshotUploader :: new ( ) ) ,
250
268
CompressionAlgorithm :: Gzip ,
269
+ TestLogger :: stdout ( ) ,
251
270
) ;
252
271
253
272
let ongoing_snapshot = cardano_immutable_files_full_artifact_builder
@@ -275,6 +294,7 @@ mod tests {
275
294
Arc :: new ( DumbSnapshotter :: new ( ) ) ,
276
295
Arc :: new ( DumbSnapshotUploader :: new ( ) ) ,
277
296
algorithm,
297
+ TestLogger :: stdout ( ) ,
278
298
) ;
279
299
280
300
let ongoing_snapshot = cardano_immutable_files_full_artifact_builder
@@ -316,6 +336,7 @@ mod tests {
316
336
Arc :: new ( DumbSnapshotter :: new ( ) ) ,
317
337
Arc :: new ( snapshot_uploader) ,
318
338
CompressionAlgorithm :: default ( ) ,
339
+ TestLogger :: stdout ( ) ,
319
340
) ;
320
341
321
342
cardano_immutable_files_full_artifact_builder
0 commit comments