@@ -355,39 +355,40 @@ impl GenerateConfig for Config {
355355#[ derive( Debug , Snafu ) ]
356356pub enum BuildError {
357357 #[ snafu( display(
358- "cache_size_per_key set on per-tag entry `{tag_key}` but the inherited mode is \
359- `exact `, where it has no effect. Remove the field or switch to `probabilistic` mode."
358+ "cache_size_per_key set on per-tag entry `{tag_key}` but the inherited mode is not \
359+ `probabilistic `, where it has no effect. Remove the field or switch to `probabilistic` mode."
360360 ) ) ]
361- CacheSizeInExactMode { tag_key : String } ,
361+ CacheSizeRequiresProbabilistic { tag_key : String } ,
362362}
363363
364364impl Config {
365365 fn validate ( & self ) -> crate :: Result < ( ) > {
366- // Global per_tag_limits: validate against the global mode.
367- if self . global . mode == Mode :: Exact {
366+ // Global per_tag_limits: cache_size_per_key only applies in probabilistic mode.
367+ if ! matches ! ( self . global. mode, Mode :: Probabilistic ( _ ) ) {
368368 for ( tag_key, tag_cfg) in & self . per_tag_limits {
369369 if let PerTagMode :: LimitOverride {
370370 cache_size_per_key : Some ( _) ,
371371 ..
372372 } = tag_cfg. mode
373373 {
374- return Err ( Box :: new ( BuildError :: CacheSizeInExactMode {
374+ return Err ( Box :: new ( BuildError :: CacheSizeRequiresProbabilistic {
375375 tag_key : tag_key. clone ( ) ,
376376 } ) ) ;
377377 }
378378 }
379379 }
380380
381- // Per-metric per_tag_limits: validate against each per-metric mode.
381+ // Per-metric per_tag_limits: cache_size_per_key only applies when the per-metric
382+ // mode is probabilistic (not exact, and not excluded).
382383 for per_metric in self . per_metric_limits . values ( ) {
383- if per_metric. config . mode == OverrideMode :: Exact {
384+ if ! matches ! ( per_metric. config. mode, OverrideMode :: Probabilistic ( _ ) ) {
384385 for ( tag_key, tag_cfg) in & per_metric. per_tag_limits {
385386 if let PerTagMode :: LimitOverride {
386387 cache_size_per_key : Some ( _) ,
387388 ..
388389 } = tag_cfg. mode
389390 {
390- return Err ( Box :: new ( BuildError :: CacheSizeInExactMode {
391+ return Err ( Box :: new ( BuildError :: CacheSizeRequiresProbabilistic {
391392 tag_key : tag_key. clone ( ) ,
392393 } ) ) ;
393394 }
0 commit comments