@@ -27,11 +27,111 @@ use crate::{
27
27
} ;
28
28
29
29
#[ cfg( with_metrics) ]
30
- /// The runtime of hash computation
31
- static KEY_VALUE_STORE_VIEW_HASH_RUNTIME : LazyLock < HistogramVec > = LazyLock :: new ( || {
30
+ /// The latency of hash computation
31
+ static KEY_VALUE_STORE_VIEW_HASH_LATENCY : LazyLock < HistogramVec > = LazyLock :: new ( || {
32
32
prometheus_util:: register_histogram_vec (
33
- "key_value_store_view_hash_runtime" ,
34
- "KeyValueStoreView hash runtime" ,
33
+ "key_value_store_view_hash_latency" ,
34
+ "KeyValueStoreView hash latency" ,
35
+ & [ ] ,
36
+ Some ( vec ! [
37
+ 0.001 , 0.003 , 0.01 , 0.03 , 0.1 , 0.2 , 0.3 , 0.4 , 0.5 , 0.75 , 1.0 , 2.0 , 5.0 ,
38
+ ] ) ,
39
+ )
40
+ . expect ( "Histogram can be created" )
41
+ } ) ;
42
+
43
+ #[ cfg( with_metrics) ]
44
+ /// The latency of get operation
45
+ static KEY_VALUE_STORE_VIEW_GET_LATENCY : LazyLock < HistogramVec > = LazyLock :: new ( || {
46
+ prometheus_util:: register_histogram_vec (
47
+ "key_value_store_view_get_latency" ,
48
+ "KeyValueStoreView get latency" ,
49
+ & [ ] ,
50
+ Some ( vec ! [
51
+ 0.001 , 0.003 , 0.01 , 0.03 , 0.1 , 0.2 , 0.3 , 0.4 , 0.5 , 0.75 , 1.0 , 2.0 , 5.0 ,
52
+ ] ) ,
53
+ )
54
+ . expect ( "Histogram can be created" )
55
+ } ) ;
56
+
57
+ #[ cfg( with_metrics) ]
58
+ /// The latency of multi get
59
+ static KEY_VALUE_STORE_VIEW_MULTI_GET_LATENCY : LazyLock < HistogramVec > = LazyLock :: new ( || {
60
+ prometheus_util:: register_histogram_vec (
61
+ "key_value_store_view_multi_get_latency" ,
62
+ "KeyValueStoreView multi get latency" ,
63
+ & [ ] ,
64
+ Some ( vec ! [
65
+ 0.001 , 0.003 , 0.01 , 0.03 , 0.1 , 0.2 , 0.3 , 0.4 , 0.5 , 0.75 , 1.0 , 2.0 , 5.0 ,
66
+ ] ) ,
67
+ )
68
+ . expect ( "Histogram can be created" )
69
+ } ) ;
70
+
71
+ #[ cfg( with_metrics) ]
72
+ /// The latency of contains key
73
+ static KEY_VALUE_STORE_VIEW_CONTAINS_KEY_LATENCY : LazyLock < HistogramVec > = LazyLock :: new ( || {
74
+ prometheus_util:: register_histogram_vec (
75
+ "key_value_store_view_contains_key_latency" ,
76
+ "KeyValueStoreView contains key latency" ,
77
+ & [ ] ,
78
+ Some ( vec ! [
79
+ 0.001 , 0.003 , 0.01 , 0.03 , 0.1 , 0.2 , 0.3 , 0.4 , 0.5 , 0.75 , 1.0 , 2.0 , 5.0 ,
80
+ ] ) ,
81
+ )
82
+ . expect ( "Histogram can be created" )
83
+ } ) ;
84
+
85
+ #[ cfg( with_metrics) ]
86
+ /// The latency of contains keys
87
+ static KEY_VALUE_STORE_VIEW_CONTAINS_KEYS_LATENCY : LazyLock < HistogramVec > = LazyLock :: new ( || {
88
+ prometheus_util:: register_histogram_vec (
89
+ "key_value_store_view_contains_keys_latency" ,
90
+ "KeyValueStoreView contains keys latency" ,
91
+ & [ ] ,
92
+ Some ( vec ! [
93
+ 0.001 , 0.003 , 0.01 , 0.03 , 0.1 , 0.2 , 0.3 , 0.4 , 0.5 , 0.75 , 1.0 , 2.0 , 5.0 ,
94
+ ] ) ,
95
+ )
96
+ . expect ( "Histogram can be created" )
97
+ } ) ;
98
+
99
+ #[ cfg( with_metrics) ]
100
+ /// The latency of find keys by prefix operation
101
+ static KEY_VALUE_STORE_VIEW_FIND_KEYS_BY_PREFIX_LATENCY : LazyLock < HistogramVec > =
102
+ LazyLock :: new ( || {
103
+ prometheus_util:: register_histogram_vec (
104
+ "key_value_store_view_find_keys_by_prefix_latency" ,
105
+ "KeyValueStoreView find keys by prefix latency" ,
106
+ & [ ] ,
107
+ Some ( vec ! [
108
+ 0.001 , 0.003 , 0.01 , 0.03 , 0.1 , 0.2 , 0.3 , 0.4 , 0.5 , 0.75 , 1.0 , 2.0 , 5.0 ,
109
+ ] ) ,
110
+ )
111
+ . expect ( "Histogram can be created" )
112
+ } ) ;
113
+
114
+ #[ cfg( with_metrics) ]
115
+ /// The latency of find key values by prefix operation
116
+ static KEY_VALUE_STORE_VIEW_FIND_KEY_VALUES_BY_PREFIX_LATENCY : LazyLock < HistogramVec > =
117
+ LazyLock :: new ( || {
118
+ prometheus_util:: register_histogram_vec (
119
+ "key_value_store_view_find_key_values_by_prefix_latency" ,
120
+ "KeyValueStoreView find key values by prefix latency" ,
121
+ & [ ] ,
122
+ Some ( vec ! [
123
+ 0.001 , 0.003 , 0.01 , 0.03 , 0.1 , 0.2 , 0.3 , 0.4 , 0.5 , 0.75 , 1.0 , 2.0 , 5.0 ,
124
+ ] ) ,
125
+ )
126
+ . expect ( "Histogram can be created" )
127
+ } ) ;
128
+
129
+ #[ cfg( with_metrics) ]
130
+ /// The latency of write batch operation
131
+ static KEY_VALUE_STORE_VIEW_WRITE_BATCH_LATENCY : LazyLock < HistogramVec > = LazyLock :: new ( || {
132
+ prometheus_util:: register_histogram_vec (
133
+ "key_value_store_view_write_batch_latency" ,
134
+ "KeyValueStoreView write batch latency" ,
35
135
& [ ] ,
36
136
Some ( vec ! [
37
137
0.001 , 0.003 , 0.01 , 0.03 , 0.1 , 0.2 , 0.3 , 0.4 , 0.5 , 0.75 , 1.0 , 2.0 , 5.0 ,
@@ -614,6 +714,8 @@ where
614
714
/// # })
615
715
/// ```
616
716
pub async fn get ( & self , index : & [ u8 ] ) -> Result < Option < Vec < u8 > > , ViewError > {
717
+ #[ cfg( with_metrics) ]
718
+ let _latency = KEY_VALUE_STORE_VIEW_GET_LATENCY . measure_latency ( ) ;
617
719
ensure ! ( index. len( ) <= self . max_key_size( ) , ViewError :: KeyTooLong ) ;
618
720
if let Some ( update) = self . updates . get ( index) {
619
721
let value = match update {
@@ -643,6 +745,8 @@ where
643
745
/// # })
644
746
/// ```
645
747
pub async fn contains_key ( & self , index : & [ u8 ] ) -> Result < bool , ViewError > {
748
+ #[ cfg( with_metrics) ]
749
+ let _latency = KEY_VALUE_STORE_VIEW_CONTAINS_KEY_LATENCY . measure_latency ( ) ;
646
750
ensure ! ( index. len( ) <= self . max_key_size( ) , ViewError :: KeyTooLong ) ;
647
751
if let Some ( update) = self . updates . get ( index) {
648
752
let test = match update {
@@ -673,6 +777,8 @@ where
673
777
/// # })
674
778
/// ```
675
779
pub async fn contains_keys ( & self , indices : Vec < Vec < u8 > > ) -> Result < Vec < bool > , ViewError > {
780
+ #[ cfg( with_metrics) ]
781
+ let _latency = KEY_VALUE_STORE_VIEW_CONTAINS_KEYS_LATENCY . measure_latency ( ) ;
676
782
let mut results = Vec :: with_capacity ( indices. len ( ) ) ;
677
783
let mut missed_indices = Vec :: new ( ) ;
678
784
let mut vector_query = Vec :: new ( ) ;
@@ -719,6 +825,8 @@ where
719
825
& self ,
720
826
indices : Vec < Vec < u8 > > ,
721
827
) -> Result < Vec < Option < Vec < u8 > > > , ViewError > {
828
+ #[ cfg( with_metrics) ]
829
+ let _latency = KEY_VALUE_STORE_VIEW_MULTI_GET_LATENCY . measure_latency ( ) ;
722
830
let mut result = Vec :: with_capacity ( indices. len ( ) ) ;
723
831
let mut missed_indices = Vec :: new ( ) ;
724
832
let mut vector_query = Vec :: new ( ) ;
@@ -765,6 +873,8 @@ where
765
873
/// # })
766
874
/// ```
767
875
pub async fn write_batch ( & mut self , batch : Batch ) -> Result < ( ) , ViewError > {
876
+ #[ cfg( with_metrics) ]
877
+ let _latency = KEY_VALUE_STORE_VIEW_WRITE_BATCH_LATENCY . measure_latency ( ) ;
768
878
* self . hash . get_mut ( ) . unwrap ( ) = None ;
769
879
let max_key_size = self . max_key_size ( ) ;
770
880
for operation in batch. operations {
@@ -901,6 +1011,8 @@ where
901
1011
/// # })
902
1012
/// ```
903
1013
pub async fn find_keys_by_prefix ( & self , key_prefix : & [ u8 ] ) -> Result < Vec < Vec < u8 > > , ViewError > {
1014
+ #[ cfg( with_metrics) ]
1015
+ let _latency = KEY_VALUE_STORE_VIEW_FIND_KEYS_BY_PREFIX_LATENCY . measure_latency ( ) ;
904
1016
ensure ! (
905
1017
key_prefix. len( ) <= self . max_key_size( ) ,
906
1018
ViewError :: KeyTooLong
@@ -975,6 +1087,8 @@ where
975
1087
& self ,
976
1088
key_prefix : & [ u8 ] ,
977
1089
) -> Result < Vec < ( Vec < u8 > , Vec < u8 > ) > , ViewError > {
1090
+ #[ cfg( with_metrics) ]
1091
+ let _latency = KEY_VALUE_STORE_VIEW_FIND_KEY_VALUES_BY_PREFIX_LATENCY . measure_latency ( ) ;
978
1092
ensure ! (
979
1093
key_prefix. len( ) <= self . max_key_size( ) ,
980
1094
ViewError :: KeyTooLong
@@ -1033,7 +1147,7 @@ where
1033
1147
1034
1148
async fn compute_hash ( & self ) -> Result < <sha3:: Sha3_256 as Hasher >:: Output , ViewError > {
1035
1149
#[ cfg( with_metrics) ]
1036
- let _hash_latency = KEY_VALUE_STORE_VIEW_HASH_RUNTIME . measure_latency ( ) ;
1150
+ let _hash_latency = KEY_VALUE_STORE_VIEW_HASH_LATENCY . measure_latency ( ) ;
1037
1151
let mut hasher = sha3:: Sha3_256 :: default ( ) ;
1038
1152
let mut count = 0 ;
1039
1153
self . for_each_index_value ( |index, value| -> Result < ( ) , ViewError > {
0 commit comments