Class HighCardinalityTagsDetector

java.lang.Object
io.micrometer.core.instrument.HighCardinalityTagsDetector
All Implemented Interfaces:
AutoCloseable

public class HighCardinalityTagsDetector extends Object implements AutoCloseable
Tries to detect high cardinality tags by checking if the amount of Meters with the same name is above a threshold. This mechanism will not detect if you have other memory-usage-related issues, like appending random values to the name of the Meters, the only purpose of this class is detecting the potential presence of high cardinality tags. You can use this class in two ways:
  • Call findFirst and check if you get any results, if so you probably have high cardinality tags
  • Call start which will start a scheduled job that will do this check for you.
You can also utilize MeterFilter.maximumAllowableTags(String, String, int, MeterFilter) and MeterFilter.maximumAllowableMetrics(int) to set an upper bound on the number of tags/metrics.
Since:
1.10.0
  • Constructor Details

    • HighCardinalityTagsDetector

      public HighCardinalityTagsDetector(MeterRegistry registry)
      Parameters:
      registry - The registry to use to check the Meters in it
    • HighCardinalityTagsDetector

      public HighCardinalityTagsDetector(MeterRegistry registry, long threshold, Duration delay)
      Parameters:
      registry - The registry to use to check the Meters in it
      threshold - The threshold to use to detect high cardinality tags (if the number of Meters with the same name is higher than this value, that's a high cardinality tag)
      delay - The delay between the termination of one check and the commencement of the next
    • HighCardinalityTagsDetector

      public HighCardinalityTagsDetector(MeterRegistry registry, long threshold, Duration delay, @Nullable Consumer<String> meterNameConsumer)
      Parameters:
      registry - The registry to use to check the Meters in it
      threshold - The threshold to use to detect high cardinality tags (if the number of Meters with the same name is higher than this value, that's a high cardinality tag)
      delay - The delay between the termination of one check and the commencement of the next
      meterNameConsumer - The action to execute if the first high cardinality tag is found
  • Method Details

    • start

      public void start()
      Starts a scheduled job that checks if you have high cardinality tags.
    • shutdown

      public void shutdown()
      Shuts down the scheduled job that checks if you have high cardinality tags.
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
    • findFirst

      public Optional<String> findFirst()
      Finds the name of the first Meter that potentially has high cardinality tags.
      Returns:
      the name of the first Meter that potentially has high cardinality tags, an empty Optional if none found.