File tree 3 files changed +17
-9
lines changed
3 files changed +17
-9
lines changed Original file line number Diff line number Diff line change 5
5
- Fix SimpleSpanProcessor to be consistent with log counterpart. Also removed
6
6
dependency on crossbeam-channel.
7
7
[ 1612] ( https://github.com/open-telemetry/opentelemetry-rust/pull/1612/files )
8
+ - [ #1422 ] ( https://github.com/open-telemetry/opentelemetry-rust/pull/1422 )
9
+ Fix metrics aggregation bug when using Views to drop attributes.
8
10
9
11
## v0.22.1
10
12
Original file line number Diff line number Diff line change @@ -138,16 +138,20 @@ impl From<&Resource> for AttributeSet {
138
138
}
139
139
}
140
140
141
+ fn calculate_hash ( values : & [ HashKeyValue ] ) -> u64 {
142
+ let mut hasher = DefaultHasher :: new ( ) ;
143
+ values. iter ( ) . fold ( & mut hasher, |mut hasher, item| {
144
+ item. hash ( & mut hasher) ;
145
+ hasher
146
+ } ) ;
147
+ hasher. finish ( )
148
+ }
149
+
141
150
impl AttributeSet {
142
151
fn new ( mut values : Vec < HashKeyValue > ) -> Self {
143
152
values. sort_unstable ( ) ;
144
- let mut hasher = DefaultHasher :: new ( ) ;
145
- values. iter ( ) . fold ( & mut hasher, |mut hasher, item| {
146
- item. hash ( & mut hasher) ;
147
- hasher
148
- } ) ;
149
-
150
- AttributeSet ( values, hasher. finish ( ) )
153
+ let hash = calculate_hash ( & values) ;
154
+ AttributeSet ( values, hash)
151
155
}
152
156
153
157
/// Returns the number of elements in the set.
@@ -165,7 +169,10 @@ impl AttributeSet {
165
169
where
166
170
F : Fn ( & KeyValue ) -> bool ,
167
171
{
168
- self . 0 . retain ( |kv| f ( & kv. 0 ) )
172
+ self . 0 . retain ( |kv| f ( & kv. 0 ) ) ;
173
+
174
+ // Recalculate the hash as elements are changed.
175
+ self . 1 = calculate_hash ( & self . 0 ) ;
169
176
}
170
177
171
178
/// Iterate over key value pairs in the set
Original file line number Diff line number Diff line change @@ -532,7 +532,6 @@ mod tests {
532
532
// "multi_thread" tokio flavor must be used else flush won't
533
533
// be able to make progress!
534
534
#[ tokio:: test( flavor = "multi_thread" , worker_threads = 1 ) ]
535
- #[ ignore = "Spatial aggregation is not yet implemented." ]
536
535
async fn spatial_aggregation_when_view_drops_attributes_counter ( ) {
537
536
// cargo test spatial_aggregation_when_view_drops_attributes_counter --features=metrics,testing
538
537
You can’t perform that action at this time.
0 commit comments