@@ -132,15 +132,16 @@ mod tests {
132
132
use std:: time:: Duration ;
133
133
134
134
// Run all tests in this mod
135
- // cargo test metrics::tests --features=testing
135
+ // cargo test metrics::tests --features=testing,spec_unstable_metrics_views
136
136
// Note for all tests from this point onwards in this mod:
137
137
// "multi_thread" tokio flavor must be used else flush won't
138
138
// be able to make progress!
139
139
140
140
#[ tokio:: test( flavor = "multi_thread" , worker_threads = 1 ) ]
141
+ #[ cfg( not( feature = "experimental_metrics_disable_name_validation" ) ) ]
141
142
async fn invalid_instrument_config_noops ( ) {
142
143
// Run this test with stdout enabled to see output.
143
- // cargo test invalid_instrument_config_noops --features=testing -- --nocapture
144
+ // cargo test invalid_instrument_config_noops --features=testing,spec_unstable_metrics_views -- --nocapture
144
145
let invalid_instrument_names = vec ! [
145
146
"_startWithNoneAlphabet" ,
146
147
"utf8char锈" ,
@@ -215,6 +216,66 @@ mod tests {
215
216
}
216
217
}
217
218
219
+ #[ tokio:: test( flavor = "multi_thread" , worker_threads = 1 ) ]
220
+ #[ cfg( feature = "experimental_metrics_disable_name_validation" ) ]
221
+ async fn valid_instrument_config_noops_with_feature_experimental_metrics_disable_name_validation (
222
+ ) {
223
+ // Run this test with stdout enabled to see output.
224
+ // cargo test valid_instrument_config_noops_with_feature_experimental_metrics_disable_name_validation --features "testing,spec_unstable_metrics_views,experimental_metrics_disable_name_validation" -- --nocapture
225
+ let invalid_instrument_names = vec ! [
226
+ "_startWithNoneAlphabet" ,
227
+ "utf8char锈" ,
228
+ "\\ allow\\ slash /sec" ,
229
+ "\\ allow\\ $$slash /sec" ,
230
+ "Total $ Count" ,
231
+ "\\ test\\ UsagePercent(Total) > 80%" ,
232
+ "invalid name" ,
233
+ ] ;
234
+ for name in invalid_instrument_names {
235
+ let test_context = TestContext :: new ( Temporality :: Cumulative ) ;
236
+ let counter = test_context. meter ( ) . u64_counter ( name) . build ( ) ;
237
+ counter. add ( 1 , & [ ] ) ;
238
+
239
+ let up_down_counter = test_context. meter ( ) . i64_up_down_counter ( name) . build ( ) ;
240
+ up_down_counter. add ( 1 , & [ ] ) ;
241
+
242
+ let gauge = test_context. meter ( ) . f64_gauge ( name) . build ( ) ;
243
+ gauge. record ( 1.9 , & [ ] ) ;
244
+
245
+ let histogram = test_context. meter ( ) . f64_histogram ( name) . build ( ) ;
246
+ histogram. record ( 1.0 , & [ ] ) ;
247
+
248
+ let _observable_counter = test_context
249
+ . meter ( )
250
+ . u64_observable_counter ( name)
251
+ . with_callback ( move |observer| {
252
+ observer. observe ( 1 , & [ ] ) ;
253
+ } )
254
+ . build ( ) ;
255
+
256
+ let _observable_gauge = test_context
257
+ . meter ( )
258
+ . f64_observable_gauge ( name)
259
+ . with_callback ( move |observer| {
260
+ observer. observe ( 1.0 , & [ ] ) ;
261
+ } )
262
+ . build ( ) ;
263
+
264
+ let _observable_up_down_counter = test_context
265
+ . meter ( )
266
+ . i64_observable_up_down_counter ( name)
267
+ . with_callback ( move |observer| {
268
+ observer. observe ( 1 , & [ ] ) ;
269
+ } )
270
+ . build ( ) ;
271
+
272
+ test_context. flush_metrics ( ) ;
273
+
274
+ // As instrument name is invalid, no metrics should be exported
275
+ test_context. check_no_metrics ( ) ;
276
+ }
277
+ }
278
+
218
279
#[ tokio:: test( flavor = "multi_thread" , worker_threads = 1 ) ]
219
280
async fn counter_aggregation_delta ( ) {
220
281
// Run this test with stdout enabled to see output.
@@ -2495,6 +2556,10 @@ mod tests {
2495
2556
. get_finished_metrics ( )
2496
2557
. expect ( "metrics expected to be exported" ) ; // TODO: Need to fix InMemoryMetricExporter to return None.
2497
2558
2559
+ #[ cfg( feature = "experimental_metrics_disable_name_validation" ) ]
2560
+ assert ! ( !resource_metrics. is_empty( ) , "metrics should be exported" ) ; // TODO: Update this when enhanced feature flag is added.
2561
+
2562
+ #[ cfg( not( feature = "experimental_metrics_disable_name_validation" ) ) ]
2498
2563
assert ! ( resource_metrics. is_empty( ) , "no metrics should be exported" ) ;
2499
2564
}
2500
2565
0 commit comments