@@ -244,6 +244,122 @@ async fn flatten_summary() {
244244 . await ;
245245}
246246
247+ #[ tokio:: test]
248+ async fn change_mtype_counter_to_gauge ( ) {
249+ let mut helper = Helper :: new (
250+ r#"
251+ .mtype = "gauge"
252+ "# ,
253+ ) ;
254+
255+ helper
256+ . expect_send_and_receive (
257+ make_abs_counter ( "foo" , & [ ( "tag" , "value" ) ] , 0 , 1.0 ) ,
258+ vec ! [ make_gauge( "foo" , & [ ( "tag" , "value" ) ] , 0 , 1.0 ) ] ,
259+ )
260+ . await ;
261+ }
262+
263+ #[ tokio:: test]
264+ async fn change_mtype_gauge_to_delta_gauge ( ) {
265+ let mut helper = Helper :: new (
266+ r#"
267+ .mtype = "delta_gauge"
268+ "# ,
269+ ) ;
270+
271+ helper
272+ . expect_send_and_receive (
273+ make_gauge ( "foo" , & [ ( "tag" , "value" ) ] , 0 , 1.0 ) ,
274+ vec ! [ make_metric_ex(
275+ "foo" ,
276+ & [ ( "tag" , "value" ) ] ,
277+ 0 ,
278+ Some ( MetricType :: DeltaGauge ) ,
279+ None ,
280+ MetricValue :: Simple ( 1.0 ) ,
281+ MetricSource :: PromRemoteWrite ,
282+ DownstreamId :: LocalOrigin ,
283+ None ,
284+ ) ] ,
285+ )
286+ . await ;
287+ }
288+
289+ #[ tokio:: test]
290+ async fn reject_histogram_mtype_change ( ) {
291+ let helper = Helper :: new (
292+ r#"
293+ .mtype = "counter"
294+ "# ,
295+ ) ;
296+
297+ helper
298+ . processor
299+ . clone ( )
300+ . recv_samples ( vec ! [ make_metric_ex(
301+ "foo" ,
302+ & [ ] ,
303+ 0 ,
304+ Some ( MetricType :: Histogram ) ,
305+ None ,
306+ MetricValue :: Histogram ( HistogramData {
307+ buckets: vec![ HistogramBucket {
308+ le: 3.0 ,
309+ count: 1.0 ,
310+ } ] ,
311+ sample_count: 1.0 ,
312+ sample_sum: 2.0 ,
313+ } ) ,
314+ MetricSource :: PromRemoteWrite ,
315+ DownstreamId :: LocalOrigin ,
316+ None ,
317+ ) ] )
318+ . await ;
319+
320+ helper
321+ . helper
322+ . stats_helper
323+ . assert_counter_eq ( 1 , "processor:drop_error" , & labels ! { } ) ;
324+ }
325+
326+ #[ tokio:: test]
327+ async fn reject_summary_mtype_change ( ) {
328+ let helper = Helper :: new (
329+ r#"
330+ .mtype = "counter"
331+ "# ,
332+ ) ;
333+
334+ helper
335+ . processor
336+ . clone ( )
337+ . recv_samples ( vec ! [ make_metric_ex(
338+ "foo" ,
339+ & [ ] ,
340+ 0 ,
341+ Some ( MetricType :: Summary ) ,
342+ None ,
343+ MetricValue :: Summary ( SummaryData {
344+ quantiles: vec![ SummaryBucket {
345+ quantile: 3.0 ,
346+ value: 1.0 ,
347+ } ] ,
348+ sample_count: 1.0 ,
349+ sample_sum: 2.0 ,
350+ } ) ,
351+ MetricSource :: PromRemoteWrite ,
352+ DownstreamId :: LocalOrigin ,
353+ None ,
354+ ) ] )
355+ . await ;
356+
357+ helper
358+ . helper
359+ . stats_helper
360+ . assert_counter_eq ( 1 , "processor:drop_error" , & labels ! { } ) ;
361+ }
362+
247363#[ tokio:: test]
248364async fn modify_all_tags ( ) {
249365 let mut helper = Helper :: new (
@@ -768,6 +884,19 @@ fn editable_parsed_metric() {
768884 assert_matches ! ( metric. cached_metric( ) , CachedMetric :: NotInitialized ) ;
769885 }
770886
887+ {
888+ let mut metric = make_abs_counter ( "prod:some_service:test:name" , & [ ] , 0 , 1.0 ) ;
889+ metric. initialize_cache ( & metric_cache) ;
890+ let mut editable_metric = EditableParsedMetric :: new ( & mut metric) ;
891+ editable_metric. change_mtype ( b"gauge" ) . unwrap ( ) ;
892+ drop ( editable_metric) ;
893+ assert_eq ! (
894+ metric,
895+ make_gauge( "prod:some_service:test:name" , & [ ] , 0 , 1.0 )
896+ ) ;
897+ assert_matches ! ( metric. cached_metric( ) , CachedMetric :: NotInitialized ) ;
898+ }
899+
771900 {
772901 let mut metric = make_abs_counter (
773902 "prod:some_service:test:name" ,
0 commit comments