-
Notifications
You must be signed in to change notification settings - Fork 296
/
metrics.rs
1060 lines (983 loc) · 41.7 KB
/
metrics.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
use ic_consensus_utils::{get_block_hash_string, pool_reader::PoolReader};
use ic_https_outcalls_consensus::payload_builder::CanisterHttpBatchStats;
use ic_ic00_types::EcdsaKeyId;
use ic_metrics::{
buckets::{decimal_buckets, decimal_buckets_with_zero, linear_buckets},
MetricsRegistry,
};
use ic_types::{
batch::BatchPayload,
consensus::{
ecdsa::{
CompletedReshareRequest, CompletedSignature, EcdsaPayload, HasEcdsaKeyId,
KeyTranscriptCreation,
},
Block, BlockProposal, ConsensusMessageHashable, HasHeight, HasRank,
},
CountBytes, Height,
};
use prometheus::{
GaugeVec, Histogram, HistogramVec, IntCounter, IntCounterVec, IntGauge, IntGaugeVec,
};
use std::{collections::BTreeMap, sync::RwLock};
// For certain metrics, we record metrics based on block's rank.
// Since we can only record limited number of them, the follow is
// the range of ranks that are permitted to show up in metrics.
const RANKS_TO_RECORD: [&str; 6] = ["0", "1", "2", "3", "4", "5"];
pub(crate) const CRITICAL_ERROR_PAYLOAD_TOO_LARGE: &str = "consensus_payload_too_large";
pub(crate) const CRITICAL_ERROR_VALIDATION_NOT_PASSED: &str = "consensus_validation_not_passed";
pub(crate) const CRITICAL_ERROR_SUBNET_RECORD_ISSUE: &str = "consensus_subnet_record_issue";
pub(crate) const CRITICAL_ERROR_ECDSA_KEY_TRANSCRIPT_MISSING: &str = "ecdsa_key_transcript_missing";
pub(crate) const CRITICAL_ERROR_ECDSA_RETAIN_ACTIVE_TRANSCRIPTS: &str =
"ecdsa_retain_active_transcripts_error";
pub struct BlockMakerMetrics {
pub get_payload_calls: IntCounterVec,
pub block_size_bytes_estimate: IntGaugeVec,
}
impl BlockMakerMetrics {
pub fn new(metrics_registry: MetricsRegistry) -> Self {
Self {
get_payload_calls: metrics_registry.int_counter_vec(
"consensus_get_payload_calls",
"The number of times of calling get_payload(), for success, pending or other status.",
&["status"],
),
block_size_bytes_estimate: metrics_registry.int_gauge_vec(
"consensus_block_size_bytes_estimate",
"An estimate about the block size produced by the block maker.",
&["payload_type"])
}
}
/// Reports byte estimate metrics.
pub fn report_byte_estimate_metrics(&self, xnet_bytes: usize, ingress_bytes: usize) {
let _ = self
.block_size_bytes_estimate
.get_metric_with_label_values(&["xnet"])
.map(|gauge| gauge.set(xnet_bytes as i64));
let _ = self
.block_size_bytes_estimate
.get_metric_with_label_values(&["ingress"])
.map(|gauge| gauge.set(ingress_bytes as i64));
}
}
pub struct ConsensusMetrics {
pub on_state_change_duration: HistogramVec,
pub on_state_change_invocations: IntCounterVec,
pub on_state_change_change_set_size: HistogramVec,
pub time_since_last_invoked: GaugeVec,
pub starvation_counter: IntCounterVec,
}
impl ConsensusMetrics {
pub fn new(metrics_registry: MetricsRegistry) -> Self {
Self {
on_state_change_duration: metrics_registry.histogram_vec(
"consensus_on_state_change_duration_seconds",
"The time it took to execute on_state_change(), in seconds",
// 0.1ms, 0.2ms, 0.5ms, 1ms, 2ms, 5ms, 10ms, 20ms, 50ms, 100ms, 200ms, 500ms,
// 1s, 2s, 5s, 10s, 20s, 50s, 100s, 200s, 500s
decimal_buckets(-4, 2),
&["sub_component"],
),
on_state_change_invocations: metrics_registry.int_counter_vec(
"consensus_on_state_change_invocations",
"The number of times the on_state_change() method has been called",
&["sub_component"],
),
on_state_change_change_set_size: metrics_registry.histogram_vec(
"consensus_on_state_change_change_set_size",
"The size of the ChangeSet returned by on_state_change()",
// 0, 1, 2, 5, 10, 20, 50, 100, 200, 500, 1000, 2000, 5000
decimal_buckets_with_zero(0, 3),
&["sub_component"],
),
time_since_last_invoked: metrics_registry.gauge_vec(
"consensus_time_since_last_invoked",
"The time between two invocations of the component",
&["sub_component"],
),
starvation_counter: metrics_registry.int_counter_vec(
"consensus_starvation_counter",
"Counts the number of starvations that happened.",
&["sub_component"],
),
}
}
}
pub struct ConsensusGossipMetrics {
pub get_priority_update_block_duration: HistogramVec,
}
impl ConsensusGossipMetrics {
pub fn new(metrics_registry: MetricsRegistry) -> Self {
Self {
get_priority_update_block_duration: metrics_registry.histogram_vec(
"consensus_get_priority_update_block_duration",
"The time it took to execute the update_block sections of get_priority",
// 0.1ms, 0.2ms, 0.5ms, 1ms, 2ms, 5ms, 10ms, 20ms, 50ms, 100ms, 200ms, 500ms,
// 1s, 2s, 5s, 10s, 20s, 50s, 100s, 200s, 500s
decimal_buckets(-4, 2),
&["block_type"],
),
}
}
}
// Block related stats
pub struct BlockStats {
pub block_hash: String,
pub block_height: u64,
pub block_context_certified_height: u64,
pub ecdsa_stats: Option<EcdsaStats>,
}
impl From<&Block> for BlockStats {
fn from(block: &Block) -> Self {
Self {
block_hash: get_block_hash_string(block),
block_height: block.height().get(),
block_context_certified_height: block.context.certified_height.get(),
ecdsa_stats: block.payload.as_ref().as_ecdsa().map(EcdsaStats::from),
}
}
}
// Batch payload stats
#[derive(Debug, Default)]
pub struct BatchStats {
pub batch_height: u64,
pub ingress_messages_delivered: usize,
pub ingress_message_bytes_delivered: usize,
pub xnet_bytes_delivered: usize,
pub ingress_ids: Vec<ic_types::artifact::IngressMessageId>,
pub canister_http: CanisterHttpBatchStats,
}
impl BatchStats {
pub(crate) fn new(batch_height: Height) -> Self {
Self {
batch_height: batch_height.get(),
..Self::default()
}
}
pub(crate) fn add_from_payload(&mut self, payload: &BatchPayload) {
self.ingress_messages_delivered += payload.ingress.message_count();
self.ingress_message_bytes_delivered += payload.ingress.count_bytes();
self.xnet_bytes_delivered += payload.xnet.size_bytes();
self.ingress_ids
.extend_from_slice(&payload.ingress.message_ids());
}
}
// TODO(kpop): remove this Option eventually
type CounterPerEcdsaKeyId = BTreeMap<Option<EcdsaKeyId>, usize>;
// Ecdsa payload stats
pub struct EcdsaStats {
pub signature_agreements: usize,
pub key_transcript_created: CounterPerEcdsaKeyId,
pub ongoing_signatures: CounterPerEcdsaKeyId,
pub available_quadruples: CounterPerEcdsaKeyId,
pub quadruples_in_creation: CounterPerEcdsaKeyId,
pub ongoing_xnet_reshares: CounterPerEcdsaKeyId,
pub xnet_reshare_agreements: CounterPerEcdsaKeyId,
pub available_quadruples_with_key_transcript: usize,
}
impl From<&EcdsaPayload> for EcdsaStats {
fn from(payload: &EcdsaPayload) -> Self {
let mut key_transcript_created = CounterPerEcdsaKeyId::new();
if let KeyTranscriptCreation::Created(transcript) = payload.key_transcript.next_in_creation
{
let transcript_id = &transcript.as_ref().transcript_id;
let current_transcript_id = payload
.key_transcript
.current
.as_ref()
.map(|transcript| &transcript.as_ref().transcript_id);
if Some(transcript_id) != current_transcript_id
&& payload.idkg_transcripts.get(transcript_id).is_some()
{
*key_transcript_created
.entry(Some(payload.key_transcript.key_id.clone()))
.or_default() += 1;
}
}
let keys = vec![None, Some(payload.key_transcript.key_id.clone())];
Self {
key_transcript_created,
signature_agreements: payload
.signature_agreements
.values()
.filter(|status| matches!(status, CompletedSignature::Unreported(_)))
.count(),
ongoing_signatures: count_by_ecdsa_key_id(payload.ongoing_signatures.keys(), &keys),
available_quadruples: count_by_ecdsa_key_id(payload.available_quadruples.keys(), &keys),
quadruples_in_creation: count_by_ecdsa_key_id(
payload.quadruples_in_creation.keys(),
&keys,
),
ongoing_xnet_reshares: count_by_ecdsa_key_id(
payload.ongoing_xnet_reshares.keys(),
&keys,
),
xnet_reshare_agreements: count_by_ecdsa_key_id(
payload
.xnet_reshare_agreements
.iter()
.filter(|(_, status)| matches!(status, CompletedReshareRequest::Unreported(_))),
&keys,
),
available_quadruples_with_key_transcript: payload
.available_quadruples
.values()
.filter(|quadruple| quadruple.key_unmasked_ref.is_some())
.count(),
}
}
}
fn count_by_ecdsa_key_id<T: HasEcdsaKeyId>(
collection: impl Iterator<Item = T>,
expected_keys: &Vec<Option<EcdsaKeyId>>,
) -> CounterPerEcdsaKeyId {
let mut counter_per_key_id = CounterPerEcdsaKeyId::new();
// To properly report `0` for ecdsa keys which do not appear in the `collection`, we insert the
// default values for all the ecdsa keys which we expect to see in the payload.
for key in expected_keys {
counter_per_key_id.insert(key.clone(), 0);
}
for item in collection {
*counter_per_key_id
.entry(item.key_id().cloned())
.or_default() += 1;
}
counter_per_key_id
}
pub struct FinalizerMetrics {
pub batches_delivered: IntCounterVec,
pub batch_height: IntGauge,
pub ingress_messages_delivered: Histogram,
pub ingress_message_bytes_delivered: Histogram,
pub xnet_bytes_delivered: Histogram,
pub finalization_certified_state_difference: IntGauge,
// ecdsa payload related metrics
pub ecdsa_key_transcript_created: IntCounterVec,
pub ecdsa_signature_agreements: IntCounter,
pub ecdsa_ongoing_signatures: IntGaugeVec,
pub ecdsa_available_quadruples: IntGaugeVec,
pub ecdsa_quadruples_in_creation: IntGaugeVec,
pub ecdsa_ongoing_xnet_reshares: IntGaugeVec,
pub ecdsa_xnet_reshare_agreements: IntCounterVec,
pub ecdsa_available_quadruples_with_key_transcript: IntGauge,
// canister http payload metrics
pub canister_http_success_delivered: IntCounter,
pub canister_http_timeouts_delivered: IntCounter,
pub canister_http_divergences_delivered: IntCounter,
}
const ECDSA_KEY_ID_LABEL: &str = "key_id";
impl FinalizerMetrics {
pub fn new(metrics_registry: MetricsRegistry) -> Self {
Self {
batches_delivered: metrics_registry.int_counter_vec(
"consensus_batches_delivered",
"The number of batches sent to Message Routing, by status",
&["status"],
),
batch_height: metrics_registry.int_gauge(
"consensus_batch_height",
"The height of batches sent to Message Routing",
),
finalization_certified_state_difference: metrics_registry.int_gauge(
"consensus_finalization_certified_state_difference",
"The height difference between the finalized tip and the referenced certified state",
),
ingress_messages_delivered: metrics_registry.histogram(
"consensus_ingress_messages_delivered",
"The number of the ingress messages delivered to Message Routing",
// 0, 1, 2, 5, 10, 20, 50, 100, 200, 500, 1000, 2000, 5000
decimal_buckets_with_zero(0, 3),
),
ingress_message_bytes_delivered: metrics_registry.histogram(
"consensus_ingress_message_bytes_delivered",
"The number of bytes in ingress messages delivered to Message Routing",
// 0, 1, 2, 5, 10, 20, 50, 100, ..., 10MB, 20MB, 50MB
decimal_buckets_with_zero(0, 7),
),
xnet_bytes_delivered: metrics_registry.histogram(
"consensus_xnet_bytes_delivered",
"The number of bytes in xnet messages delivered to Message Routing",
// 0, 1, 2, 5, 10, 20, 50, 100, ..., 10MB, 20MB, 50MB
decimal_buckets_with_zero(0, 7),
),
// ecdsa payload related metrics
ecdsa_key_transcript_created: metrics_registry.int_counter_vec(
"consensus_ecdsa_key_transcript_created",
"The number of times ECDSA key transcript is created",
&[ECDSA_KEY_ID_LABEL],
),
ecdsa_signature_agreements: metrics_registry.int_counter(
"consensus_ecdsa_signature_agreements",
"Total number of ECDSA signature agreements created",
),
ecdsa_ongoing_signatures: metrics_registry.int_gauge_vec(
"consensus_ecdsa_ongoing_signatures",
"The number of ongoing ECDSA signatures",
&[ECDSA_KEY_ID_LABEL],
),
ecdsa_available_quadruples: metrics_registry.int_gauge_vec(
"consensus_ecdsa_available_quadruples",
"The number of available ECDSA quadruples",
&[ECDSA_KEY_ID_LABEL],
),
ecdsa_available_quadruples_with_key_transcript: metrics_registry.int_gauge(
"consensus_ecdsa_available_quadruples_with_key_transcript",
"The number of available ECDSA quadruples with key transcript",
),
ecdsa_quadruples_in_creation: metrics_registry.int_gauge_vec(
"consensus_ecdsa_quadruples_in_creation",
"The number of ECDSA quadruples in creation",
&[ECDSA_KEY_ID_LABEL],
),
ecdsa_ongoing_xnet_reshares: metrics_registry.int_gauge_vec(
"consensus_ecdsa_ongoing_xnet_reshares",
"The number of ongoing ECDSA xnet reshares",
&[ECDSA_KEY_ID_LABEL],
),
ecdsa_xnet_reshare_agreements: metrics_registry.int_counter_vec(
"consensus_ecdsa_reshare_agreements",
"Total number of ECDSA reshare agreements created",
&[ECDSA_KEY_ID_LABEL],
),
// canister http payload metrics
canister_http_success_delivered: metrics_registry.int_counter(
"canister_http_success_delivered",
"Total number of canister http messages successfully delivered",
),
canister_http_timeouts_delivered: metrics_registry.int_counter(
"canister_http_timeouts_delivered",
"Total number of canister http messages delivered as timeouts",
),
canister_http_divergences_delivered: metrics_registry.int_counter(
"canister_http_divergences_delivered",
"Total number of canister http messages delivered as divergences",
),
}
}
pub fn process(&self, block_stats: &BlockStats, batch_stats: &BatchStats) {
self.batches_delivered.with_label_values(&["success"]).inc();
self.batch_height.set(batch_stats.batch_height as i64);
self.ingress_messages_delivered
.observe(batch_stats.ingress_messages_delivered as f64);
self.ingress_message_bytes_delivered
.observe(batch_stats.ingress_message_bytes_delivered as f64);
self.xnet_bytes_delivered
.observe(batch_stats.xnet_bytes_delivered as f64);
self.finalization_certified_state_difference.set(
block_stats.block_height as i64 - block_stats.block_context_certified_height as i64,
);
self.canister_http_success_delivered
.inc_by(batch_stats.canister_http.responses as u64);
self.canister_http_timeouts_delivered
.inc_by(batch_stats.canister_http.timeouts as u64);
self.canister_http_divergences_delivered
.inc_by(batch_stats.canister_http.divergence_responses as u64);
if let Some(ecdsa) = &block_stats.ecdsa_stats {
let key_id_label = |key_id: &Option<EcdsaKeyId>| {
key_id
.as_ref()
.map(|key_id| key_id.to_string())
.unwrap_or_default()
};
let set = |metric: &IntGaugeVec, counts: &CounterPerEcdsaKeyId| {
for (key_id, count) in counts.iter() {
metric
.with_label_values(&[&key_id_label(key_id)])
.set(*count as i64);
}
};
let inc_by = |metric: &IntCounterVec, counts: &CounterPerEcdsaKeyId| {
for (key_id, count) in counts.iter() {
metric
.with_label_values(&[&key_id_label(key_id)])
.inc_by(*count as u64);
}
};
inc_by(
&self.ecdsa_key_transcript_created,
&ecdsa.key_transcript_created,
);
set(&self.ecdsa_ongoing_signatures, &ecdsa.ongoing_signatures);
self.ecdsa_signature_agreements
.inc_by(ecdsa.signature_agreements as u64);
set(
&self.ecdsa_available_quadruples,
&ecdsa.available_quadruples,
);
set(
&self.ecdsa_quadruples_in_creation,
&ecdsa.quadruples_in_creation,
);
set(
&self.ecdsa_ongoing_xnet_reshares,
&ecdsa.ongoing_xnet_reshares,
);
inc_by(
&self.ecdsa_xnet_reshare_agreements,
&ecdsa.xnet_reshare_agreements,
);
self.ecdsa_available_quadruples_with_key_transcript
.set(ecdsa.available_quadruples_with_key_transcript as i64);
}
}
}
pub struct NotaryMetrics {
pub time_to_notary_sign: HistogramVec,
}
impl NotaryMetrics {
pub fn new(metrics_registry: MetricsRegistry) -> Self {
Self {
time_to_notary_sign: metrics_registry.histogram_vec(
"consensus_time_to_notary_sign",
"The duration since round start for replicas to notary-sign a block, labelled by ranks",
vec![0.0, 0.2, 0.4, 0.6, 0.8, 1.0, 1.2, 1.4, 1.6, 1.8, 2.0, 2.2, 2.4, 2.6, 2.8, 3.0, 3.5, 4.0, 4.5, 5.0, 6.0, 8.0, 10.0, 15.0, 20.0],
&["rank"],
),
}
}
/// Report metrics after notarizing `block`
pub fn report_notarization(&self, block: &Block, elapsed: std::time::Duration) {
let rank = block.rank().0 as usize;
if rank < RANKS_TO_RECORD.len() {
self.time_to_notary_sign
.with_label_values(&[RANKS_TO_RECORD[rank]])
.observe(elapsed.as_secs_f64())
}
}
}
pub struct PayloadBuilderMetrics {
pub get_payload_duration: Histogram,
pub validate_payload_duration: Histogram,
pub past_payloads_length: Histogram,
/// Critical error for payloads above the maximum supported size
pub critical_error_payload_too_large: IntCounter,
/// Critical error for newly created payloads that do not pass their own validation function
pub critical_error_validation_not_passed: IntCounter,
/// Critical error triggered if the subnet record contains entries that would not make sense to consensus
pub critical_error_subnet_record_data_issue: IntCounter,
}
impl PayloadBuilderMetrics {
pub fn new(metrics_registry: MetricsRegistry) -> Self {
Self {
get_payload_duration: metrics_registry.histogram(
"consensus_get_payload_duration_seconds",
"The time it took to execute get_payload(), in seconds",
// 0.1ms, 0.2ms, 0.5ms, 1ms, 2ms, 5ms, 10ms, 20ms, 50ms, 100ms, 200ms, 500ms,
// 1s, 2s, 5s
decimal_buckets(-4, 0),
),
validate_payload_duration: metrics_registry.histogram(
"consensus_validate_payload_duration_seconds",
"The time it took to execute validate_payload(), in seconds",
// 0.1ms, 0.2ms, 0.5ms, 1ms, 2ms, 5ms, 10ms, 20ms, 50ms, 100ms, 200ms, 500ms,
// 1s, 2s, 5s
decimal_buckets(-4, 0),
),
past_payloads_length: metrics_registry.histogram(
"consensus_past_payloads_length",
"The length of past_payloads in payload selection",
linear_buckets(0.0, 1.0, 6),
),
critical_error_payload_too_large: metrics_registry
.error_counter(CRITICAL_ERROR_PAYLOAD_TOO_LARGE),
critical_error_validation_not_passed: metrics_registry
.error_counter(CRITICAL_ERROR_VALIDATION_NOT_PASSED),
critical_error_subnet_record_data_issue: metrics_registry
.error_counter(CRITICAL_ERROR_SUBNET_RECORD_ISSUE),
}
}
}
/// Metrics for a consensus validator.
pub struct ValidatorMetrics {
pub(crate) time_to_receive_block: HistogramVec,
pub(crate) duplicate_artifact: IntCounterVec,
pub(crate) validation_duration: HistogramVec,
pub(crate) dkg_validator: IntCounterVec,
// Used to sum the values within a single validator run
dkg_time_per_validator_run: RwLock<f64>,
pub(crate) ecdsa_validation_duration: HistogramVec,
pub(crate) validation_random_tape_shares_count: IntGauge,
pub(crate) validation_random_beacon_shares_count: IntGauge,
pub(crate) validation_share_batch_size: HistogramVec,
}
impl ValidatorMetrics {
/// The constructor creates a [`ValidatorMetrics`] instance.
pub fn new(metrics_registry: MetricsRegistry) -> Self {
Self {
time_to_receive_block: metrics_registry.histogram_vec(
"consensus_time_to_receive_block",
"The duration to receive a block since round start, labelled by ranks, in seconds.",
vec![
0.0, 0.2, 0.4, 0.6, 0.8, 1.0, 1.2, 1.4, 1.6, 1.8, 2.0, 2.2, 2.4, 2.6, 2.8, 3.0,
3.5, 4.0, 4.5, 5.0, 6.0, 8.0, 10.0, 15.0, 20.0,
],
&["rank"],
),
duplicate_artifact: metrics_registry.int_counter_vec(
"consensus_duplicate_artifact",
"The number of duplicate notarizations and finalizations Consensus has received",
&["artifact"],
),
validation_duration: metrics_registry.histogram_vec(
"consensus_validation_duration_seconds",
"Time to validate by subcomponent, in seconds",
// 0.1ms, 0.2ms, 0.5ms, 1ms, 2ms, 5ms, 10ms, 20ms, 50ms, 100ms, 200ms, 500ms,
// 1s, 2s, 5s, 10s, 20s, 50s, 100s, 200s, 500s
decimal_buckets(-4, 2),
&["type"],
),
dkg_validator: metrics_registry.int_counter_vec(
"consensus_dkg_validator",
"DKG validator counter",
&["type"],
),
dkg_time_per_validator_run: RwLock::new(0.0),
ecdsa_validation_duration: metrics_registry.histogram_vec(
"consensus_ecdsa_validation_duration_seconds",
"Time to validate ECDSA component, in seconds",
// 0.1ms, 0.2ms, 0.5ms, 1ms, 2ms, 5ms, 10ms, 20ms, 50ms, 100ms, 200ms, 500ms,
// 1s, 2s, 5s, 10s, 20s, 50s, 100s, 200s, 500s
decimal_buckets(-4, 2),
&["type"],
),
validation_random_tape_shares_count: metrics_registry.int_gauge(
"consensus_validation_tape_shares",
"Number of random tape shares being validated every block",
),
validation_random_beacon_shares_count: metrics_registry.int_gauge(
"consensus_validation_beacon_shares",
"Number of random beacon shares being validated every block",
),
validation_share_batch_size: metrics_registry.histogram_vec(
"consensus_validation_share_batch_size",
"Number of validation shares per state change invocation, labels: [tape, beacon]",
linear_buckets(1.0, 1.0, 10),
&["type"],
),
}
}
pub(crate) fn observe_block(&self, pool_reader: &PoolReader, proposal: &BlockProposal) {
let rank = proposal.rank().0 as usize;
if rank < RANKS_TO_RECORD.len() {
if let Some(start_time) = pool_reader.get_round_start_time(proposal.height()) {
if let Some(timestamp) = pool_reader
.pool()
.unvalidated()
.get_timestamp(&proposal.get_id())
{
if timestamp >= start_time {
self.time_to_receive_block
.with_label_values(&[RANKS_TO_RECORD[rank]])
.observe((timestamp.saturating_sub(start_time)).as_secs_f64());
}
}
}
}
}
pub(crate) fn add_to_dkg_time_per_validator_run(&self, elapsed_time: f64) {
let mut dkg_time = self.dkg_time_per_validator_run.write().unwrap();
*dkg_time += elapsed_time;
}
pub(crate) fn observe_and_reset_dkg_time_per_validator_run(&self) {
let mut dkg_time = self.dkg_time_per_validator_run.write().unwrap();
self.validation_duration
.with_label_values(&["DkgPerRun"])
.observe(*dkg_time);
*dkg_time = 0.0;
}
}
pub struct PurgerMetrics {
pub unvalidated_pool_purge_height: IntGauge,
pub validated_pool_purge_height: IntGauge,
pub replicated_state_purge_height: IntGauge,
pub replicated_state_purge_height_disk: IntGauge,
}
impl PurgerMetrics {
pub fn new(metrics_registry: MetricsRegistry) -> Self {
Self {
unvalidated_pool_purge_height: metrics_registry.int_gauge(
"unvalidated_pool_purge_height",
"The height below which unvalidated artifacts are purged",
),
validated_pool_purge_height: metrics_registry.int_gauge(
"validated_pool_purge_height",
"The height below which unvalidated artifacts are purged",
),
replicated_state_purge_height: metrics_registry.int_gauge(
"replicated_state_purge_height",
"The height below which in-memory replicated states are purged",
),
replicated_state_purge_height_disk: metrics_registry.int_gauge(
"replicated_state_purge_height_disk",
"The height below which on-disk replicated states (checkpoints) are purged",
),
}
}
}
#[derive(Clone)]
pub struct EcdsaClientMetrics {
pub on_state_change_duration: HistogramVec,
pub client_metrics: IntCounterVec,
pub client_errors: IntCounterVec,
/// critical error when retain_active_transcripts fails
pub critical_error_ecdsa_retain_active_transcripts: IntCounter,
}
impl EcdsaClientMetrics {
pub fn new(metrics_registry: MetricsRegistry) -> Self {
Self {
on_state_change_duration: metrics_registry.histogram_vec(
"ecdsa_on_state_change_duration_seconds",
"The time it took to execute ECDSA on_state_change(), in seconds",
// 0.1ms, 0.2ms, 0.5ms, 1ms, 2ms, 5ms, 10ms, 20ms, 50ms, 100ms, 200ms, 500ms,
// 1s, 2s, 5s, 10s, 20s, 50s, 100s, 200s, 500s
decimal_buckets(-4, 2),
&["sub_component"],
),
client_metrics: metrics_registry.int_counter_vec(
"ecdsa_client_metrics",
"ECDSA client related metrics",
&["type"],
),
client_errors: metrics_registry.int_counter_vec(
"ecdsa_client_errors",
"ECDSA client related errors",
&["type"],
),
critical_error_ecdsa_retain_active_transcripts: metrics_registry
.error_counter(CRITICAL_ERROR_ECDSA_RETAIN_ACTIVE_TRANSCRIPTS),
}
}
}
#[derive(Clone)]
pub struct EcdsaGossipMetrics {
pub dropped_adverts: IntCounterVec,
}
impl EcdsaGossipMetrics {
pub fn new(metrics_registry: MetricsRegistry) -> Self {
Self {
dropped_adverts: metrics_registry.int_counter_vec(
"ecdsa_priority_fn_dropped_adverts",
"ECDSA adverts dropped by priority fn",
&["type"],
),
}
}
}
#[derive(Clone)]
pub struct EcdsaPreSignerMetrics {
pub on_state_change_duration: HistogramVec,
pub pre_sign_metrics: IntCounterVec,
pub pre_sign_errors: IntCounterVec,
}
impl EcdsaPreSignerMetrics {
pub fn new(metrics_registry: MetricsRegistry) -> Self {
Self {
on_state_change_duration: metrics_registry.histogram_vec(
"ecdsa_pre_signer_on_state_change_duration_seconds",
"The time it took to execute pre-signer on_state_change(), in seconds",
// 0.1ms, 0.2ms, 0.5ms, 1ms, 2ms, 5ms, 10ms, 20ms, 50ms, 100ms, 200ms, 500ms,
// 1s, 2s, 5s, 10s, 20s, 50s, 100s, 200s, 500s
decimal_buckets(-4, 2),
&["sub_component"],
),
pre_sign_metrics: metrics_registry.int_counter_vec(
"ecdsa_pre_signer_metrics",
"Pre-signing related metrics",
&["type"],
),
pre_sign_errors: metrics_registry.int_counter_vec(
"ecdsa_pre_signer_errors",
"Pre-signing related errors",
&["type"],
),
}
}
pub fn pre_sign_metrics_inc(&self, label: &str) {
self.pre_sign_metrics.with_label_values(&[label]).inc();
}
pub fn pre_sign_errors_inc(&self, label: &str) {
self.pre_sign_errors.with_label_values(&[label]).inc();
}
}
#[derive(Clone)]
pub struct EcdsaSignerMetrics {
pub on_state_change_duration: HistogramVec,
pub sign_metrics: IntCounterVec,
pub sign_errors: IntCounterVec,
}
impl EcdsaSignerMetrics {
pub fn new(metrics_registry: MetricsRegistry) -> Self {
Self {
on_state_change_duration: metrics_registry.histogram_vec(
"ecdsa_signer_on_state_change_duration_seconds",
"The time it took to execute signer on_state_change(), in seconds",
// 0.1ms, 0.2ms, 0.5ms, 1ms, 2ms, 5ms, 10ms, 20ms, 50ms, 100ms, 200ms, 500ms,
// 1s, 2s, 5s, 10s, 20s, 50s, 100s, 200s, 500s
decimal_buckets(-4, 2),
&["sub_component"],
),
sign_metrics: metrics_registry.int_counter_vec(
"ecdsa_signer_metrics",
"Signing related metrics",
&["type"],
),
sign_errors: metrics_registry.int_counter_vec(
"ecdsa_signer_errors",
"Signing related errors",
&["type"],
),
}
}
pub fn sign_metrics_inc(&self, label: &str) {
self.sign_metrics.with_label_values(&[label]).inc();
}
pub fn sign_errors_inc(&self, label: &str) {
self.sign_errors.with_label_values(&[label]).inc();
}
}
pub struct EcdsaPayloadMetrics {
pub payload_metrics: IntGaugeVec,
pub payload_errors: IntCounterVec,
pub transcript_builder_metrics: IntCounterVec,
pub transcript_builder_errors: IntCounterVec,
pub transcript_builder_duration: HistogramVec,
/// Critical error for failure to create/reshare key transcript
pub critical_error_ecdsa_key_transcript_missing: IntCounter,
}
impl EcdsaPayloadMetrics {
pub fn new(metrics_registry: MetricsRegistry) -> Self {
Self {
payload_metrics: metrics_registry.int_gauge_vec(
"ecdsa_payload_metrics",
"ECDSA payload related metrics",
&["type"],
),
payload_errors: metrics_registry.int_counter_vec(
"ecdsa_payload_errors",
"ECDSA payload related errors",
&["type"],
),
transcript_builder_metrics: metrics_registry.int_counter_vec(
"ecdsa_transcript_builder_metrics",
"ECDSA transcript builder metrics",
&["type"],
),
transcript_builder_errors: metrics_registry.int_counter_vec(
"ecdsa_transcript_builder_errors",
"ECDSA transcript builder related errors",
&["type"],
),
transcript_builder_duration: metrics_registry.histogram_vec(
"ecdsa_transcript_builder_duration_seconds",
"Time taken by transcript builder, in seconds",
// 0.1ms, 0.2ms, 0.5ms, 1ms, 2ms, 5ms, 10ms, 20ms, 50ms, 100ms, 200ms, 500ms,
// 1s, 2s, 5s, 10s, 20s, 50s, 100s, 200s, 500s
decimal_buckets(-4, 2),
&["sub_component"],
),
critical_error_ecdsa_key_transcript_missing: metrics_registry
.error_counter(CRITICAL_ERROR_ECDSA_KEY_TRANSCRIPT_MISSING),
}
}
pub fn report(&self, payload: &EcdsaPayload) {
self.payload_metrics_set("signature_agreements", payload.signature_agreements.len());
self.payload_metrics_set("ongoing_signatures", payload.ongoing_signatures.len());
self.payload_metrics_set("available_quadruples", payload.available_quadruples.len());
self.payload_metrics_set(
"quaruples_in_creation",
payload.quadruples_in_creation.len(),
);
self.payload_metrics_set("ongoing_xnet_reshares", payload.ongoing_xnet_reshares.len());
self.payload_metrics_set(
"xnet_reshare_agreements",
payload.xnet_reshare_agreements.len(),
);
}
fn payload_metrics_set(&self, label: &str, value: usize) {
self.payload_metrics
.with_label_values(&[label])
.set(value as i64);
}
pub fn payload_metrics_inc(&self, label: &str) {
self.payload_metrics.with_label_values(&[label]).inc();
}
pub fn payload_errors_inc(&self, label: &str) {
self.payload_errors.with_label_values(&[label]).inc();
}
pub fn transcript_builder_metrics_inc(&self, label: &str) {
self.transcript_builder_metrics
.with_label_values(&[label])
.inc();
}
pub fn transcript_builder_metrics_inc_by(&self, value: u64, label: &str) {
self.transcript_builder_metrics
.with_label_values(&[label])
.inc_by(value);
}
pub fn transcript_builder_errors_inc(&self, label: &str) {
self.transcript_builder_errors
.with_label_values(&[label])
.inc();
}
}
pub fn timed_call<F, R>(label: &str, call_fn: F, metric: &HistogramVec) -> R
where
F: FnOnce() -> R,
{
let _timer = metric.with_label_values(&[label]).start_timer();
(call_fn)()
}
#[derive(Clone)]
pub struct EcdsaComplaintMetrics {
pub on_state_change_duration: HistogramVec,
pub complaint_metrics: IntCounterVec,
pub complaint_errors: IntCounterVec,
}
impl EcdsaComplaintMetrics {
pub fn new(metrics_registry: MetricsRegistry) -> Self {
Self {
on_state_change_duration: metrics_registry.histogram_vec(
"ecdsa_complaint_on_state_change_duration_seconds",
"The time it took to execute complaint on_state_change(), in seconds",
// 0.1ms, 0.2ms, 0.5ms, 1ms, 2ms, 5ms, 10ms, 20ms, 50ms, 100ms, 200ms, 500ms,
// 1s, 2s, 5s, 10s, 20s, 50s, 100s, 200s, 500s
decimal_buckets(-4, 2),
&["sub_component"],
),
complaint_metrics: metrics_registry.int_counter_vec(
"ecdsa_complaint_metrics",
"Complaint related metrics",
&["type"],
),
complaint_errors: metrics_registry.int_counter_vec(
"ecdsa_complaint_errors",
"Complaint related errors",
&["type"],
),
}
}
pub fn complaint_metrics_inc(&self, label: &str) {
self.complaint_metrics.with_label_values(&[label]).inc();
}
pub fn complaint_errors_inc(&self, label: &str) {
self.complaint_errors.with_label_values(&[label]).inc();
}
}
#[derive(Clone)]
pub struct EcdsaTranscriptMetrics {
pub active_transcripts: IntGauge,
pub support_validation_duration: HistogramVec,
pub support_validation_total_duration: HistogramVec,
pub support_aggregation_duration: HistogramVec,
pub support_aggregation_total_duration: HistogramVec,
pub create_transcript_duration: HistogramVec,
pub create_transcript_total_duration: HistogramVec,
pub transcript_e2e_latency: HistogramVec,
}
impl EcdsaTranscriptMetrics {
pub fn new(metrics_registry: MetricsRegistry) -> Self {
Self {
active_transcripts: metrics_registry
.int_gauge("ecdsa_active_transcripts", "Currently active transcripts"),
support_validation_duration: metrics_registry.histogram_vec(
"ecdsa_support_validation_duration",
"Support validation duration, in msec",
decimal_buckets(0, 2),
&["type"],
),
support_validation_total_duration: metrics_registry.histogram_vec(
"ecdsa_support_validation_total_duration",
"Total support validation duration, in msec",
decimal_buckets(0, 4),
&["type"],
),
support_aggregation_duration: metrics_registry.histogram_vec(
"ecdsa_support_aggregation_duration",
"Support aggregation duration, in msec",
decimal_buckets(0, 2),
&["type"],
),
support_aggregation_total_duration: metrics_registry.histogram_vec(
"ecdsa_support_aggregation_total_duration",
"Total support aggregation duration, in msec",
decimal_buckets(0, 4),
&["type"],
),
create_transcript_duration: metrics_registry.histogram_vec(
"ecdsa_create_transcript_duration",
"Time to create transcript, in msec",
decimal_buckets(0, 5),
&["type"],
),
create_transcript_total_duration: metrics_registry.histogram_vec(
"ecdsa_create_transcript_total_duration",
"Total time to create transcript, in msec",
decimal_buckets(0, 5),
&["type"],
),
transcript_e2e_latency: metrics_registry.histogram_vec(
"ecdsa_transcript_e2e_latency",
"End to end latency to build the transcript, in sec",
linear_buckets(0.5, 0.5, 30),
&["type"],
),
}
}
}