Class MicrometerUtils

java.lang.Object
de.oktoflow.platform.support.metrics.micrometer.MicrometerUtils

public class MicrometerUtils extends Object
Translation utilities, intentionally public.
Author:
Holger Eichelberger, SSE
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static interface 
    Abstract meter creator to translate among implementation and abstraction.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static io.micrometer.core.instrument.config.MeterFilter[]
    append(io.micrometer.core.instrument.config.MeterFilter[] base, io.micrometer.core.instrument.config.MeterFilter... addition)
    Appends addition to base.
    static void
    apply(io.micrometer.core.instrument.MeterRegistry registry, io.micrometer.core.instrument.config.MeterFilter... filters)
    Applies the given list of meter filters.
    static de.iip_ecosphere.platform.support.metrics.Meter
    createMeter(de.iip_ecosphere.platform.support.metrics.Meter meter, MicrometerUtils.MeterCreator creator)
    Creates a meter via an unknown implementation function.
    static io.micrometer.core.instrument.config.MeterFilter
    filterValue(de.iip_ecosphere.platform.support.metrics.MeterFilter filter)
    Translates an abstracted filter into a micrometer filter.
    static io.micrometer.core.instrument.config.MeterFilter[]
    filterValue(de.iip_ecosphere.platform.support.metrics.MeterFilter... filter)
    Translates abstracted filters into micrometer filters.
    static io.micrometer.core.instrument.Meter.Id
    idValue(de.iip_ecosphere.platform.support.metrics.Meter.Id id)
    Translates an abstracted id into a micrometer id.
    static boolean
    include(io.micrometer.core.instrument.Meter.Id id, io.micrometer.core.instrument.config.MeterFilter... filters)
    Returns whether a meter id shall be included into a result set.
    static boolean
    include(String id, io.micrometer.core.instrument.config.MeterFilter... filters)
    Returns whether a meter id shall be included into a result set.
    static de.iip_ecosphere.platform.support.metrics.MeterFilter
    mmFilterValue(io.micrometer.core.instrument.config.MeterFilter filter)
    Translates an abstracted filter into a micrometer filter.
    static de.iip_ecosphere.platform.support.metrics.MeterFilter[]
    mmFilterValue(io.micrometer.core.instrument.config.MeterFilter... filter)
    Translates micrometer filters into abstracted filters.
    static de.iip_ecosphere.platform.support.metrics.Statistic
    mmStatisticValue(io.micrometer.core.instrument.Statistic value)
    Turns a String into a Meter.Type using Statistic.UNKNOWN as default.
    static io.micrometer.core.instrument.Meter.Type
    mmTypeValue(de.iip_ecosphere.platform.support.metrics.Meter.Type value)
    Turns a String into a Meter.Type using Meter.Type.OTHER as default.
    static Iterable<de.iip_ecosphere.platform.support.metrics.Measurement>
    mmWrapMeasurementIterable(Iterable<io.micrometer.core.instrument.Measurement> iter)
    Maps an abstracted iterable of measurements to a micrometer iterable of measurements.
    static Iterable<de.iip_ecosphere.platform.support.metrics.Tag>
    mmWrapTagIterable(Iterable<io.micrometer.core.instrument.Tag> iter)
    Maps an abstracted iterable of tags to a micrometer iterable of tags.
    static io.micrometer.core.instrument.Statistic
    statisticValue(de.iip_ecosphere.platform.support.metrics.Statistic statistic)
    Turns a String into a Meter.Type using Statistic.UNKNOWN as default.
    static io.micrometer.core.instrument.Tag
    tagValue(de.iip_ecosphere.platform.support.metrics.Tag tag)
    Translates an abstracted id into a micrometer tag.
    static de.iip_ecosphere.platform.support.metrics.Meter.Type
    typeValue(io.micrometer.core.instrument.Meter.Type value)
    Turns a String into a Meter.Type using Meter.Type.OTHER as default.
    static <T extends Enum<T>>
    T
    value(Class<T> cls, Enum<?> value, T dflt)
    Turns an emum value into an enum value considering dflt.
    static <T extends Enum<T>>
    T
    value(Class<T> cls, String value, T dflt)
    Turns a string into an enum value considering dflt.
    static <TS, TT> Iterable<TT>
    wrapIterable(Iterable<TS> iter, Function<TS,TT> func)
    Wraps an iterable.
    static <TS, TT> Iterator<TT>
    wrapIterator(Iterator<TS> iter, Function<TS,TT> func)
    Wraps an iterator.
    static Iterable<io.micrometer.core.instrument.Measurement>
    wrapMeasurementIterable(Iterable<de.iip_ecosphere.platform.support.metrics.Measurement> iter)
    Maps an micrometer iterable of measurements to an abstracted iterable of measurements.
    static Iterable<io.micrometer.core.instrument.Tag>
    wrapTagIterable(Iterable<de.iip_ecosphere.platform.support.metrics.Tag> iter)
    Maps an abstracted iterable of tags to a micrometer iterable of tags.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • MicrometerUtils

      public MicrometerUtils()
  • Method Details

    • value

      public static <T extends Enum<T>> T value(Class<T> cls, Enum<?> value, T dflt)
      Turns an emum value into an enum value considering dflt.
      Type Parameters:
      T - the enum type
      Parameters:
      cls - the enum class
      value - the value (may be null)
      dflt - the default value if value cannot be converted/found
      Returns:
      the value
    • value

      public static <T extends Enum<T>> T value(Class<T> cls, String value, T dflt)
      Turns a string into an enum value considering dflt.
      Type Parameters:
      T - the enum type
      Parameters:
      cls - the enum class
      value - the value as string (may be null)
      dflt - the default value if value cannot be converted/found
      Returns:
      the value
    • idValue

      public static io.micrometer.core.instrument.Meter.Id idValue(de.iip_ecosphere.platform.support.metrics.Meter.Id id)
      Translates an abstracted id into a micrometer id.
      Parameters:
      id - the abstracted id
      Returns:
      the micrometer id, null of not translatable
    • tagValue

      public static io.micrometer.core.instrument.Tag tagValue(de.iip_ecosphere.platform.support.metrics.Tag tag)
      Translates an abstracted id into a micrometer tag.
      Parameters:
      tag - the abstracted tag
      Returns:
      the micrometer tag, null of not translatable
    • filterValue

      public static io.micrometer.core.instrument.config.MeterFilter filterValue(de.iip_ecosphere.platform.support.metrics.MeterFilter filter)
      Translates an abstracted filter into a micrometer filter.
      Parameters:
      filter - the abstracted filter
      Returns:
      the micrometer filter, null of not translatable
    • mmFilterValue

      public static de.iip_ecosphere.platform.support.metrics.MeterFilter mmFilterValue(io.micrometer.core.instrument.config.MeterFilter filter)
      Translates an abstracted filter into a micrometer filter.
      Parameters:
      filter - the abstracted filter
      Returns:
      the micrometer filter, null of not translatable
    • filterValue

      public static io.micrometer.core.instrument.config.MeterFilter[] filterValue(de.iip_ecosphere.platform.support.metrics.MeterFilter... filter)
      Translates abstracted filters into micrometer filters.
      Parameters:
      filter - the abstracted filters
      Returns:
      the micrometer filters, null of not translatable
    • mmFilterValue

      public static de.iip_ecosphere.platform.support.metrics.MeterFilter[] mmFilterValue(io.micrometer.core.instrument.config.MeterFilter... filter)
      Translates micrometer filters into abstracted filters.
      Parameters:
      filter - the micrometer filters
      Returns:
      the abstracted filters, null of not translatable
    • typeValue

      public static de.iip_ecosphere.platform.support.metrics.Meter.Type typeValue(io.micrometer.core.instrument.Meter.Type value)
      Turns a String into a Meter.Type using Meter.Type.OTHER as default.
      Parameters:
      value - the value
      Returns:
      the corresponding type or Meter.Type.OTHER
    • mmTypeValue

      public static io.micrometer.core.instrument.Meter.Type mmTypeValue(de.iip_ecosphere.platform.support.metrics.Meter.Type value)
      Turns a String into a Meter.Type using Meter.Type.OTHER as default.
      Parameters:
      value - the value
      Returns:
      the corresponding type or Meter.Type.OTHER
    • mmStatisticValue

      public static de.iip_ecosphere.platform.support.metrics.Statistic mmStatisticValue(io.micrometer.core.instrument.Statistic value)
      Turns a String into a Meter.Type using Statistic.UNKNOWN as default.
      Parameters:
      value - the value
      Returns:
      the corresponding type or Statistic.UNKNOWN
    • statisticValue

      public static io.micrometer.core.instrument.Statistic statisticValue(de.iip_ecosphere.platform.support.metrics.Statistic statistic)
      Turns a String into a Meter.Type using Statistic.UNKNOWN as default.
      Parameters:
      statistic - the value
      Returns:
      the corresponding type or Statistic.UNKNOWN
    • wrapIterable

      public static <TS, TT> Iterable<TT> wrapIterable(Iterable<TS> iter, Function<TS,TT> func)
      Wraps an iterable.
      Type Parameters:
      TS - the source type
      TT - the target type
      Parameters:
      iter - the source iterable
      func - the translation function
      Returns:
      the target iterable
    • wrapIterator

      public static <TS, TT> Iterator<TT> wrapIterator(Iterator<TS> iter, Function<TS,TT> func)
      Wraps an iterator.
      Type Parameters:
      TS - the source type
      TT - the target type
      Parameters:
      iter - the source iterator
      func - the translation function
      Returns:
      the target iterator
    • mmWrapMeasurementIterable

      public static Iterable<de.iip_ecosphere.platform.support.metrics.Measurement> mmWrapMeasurementIterable(Iterable<io.micrometer.core.instrument.Measurement> iter)
      Maps an abstracted iterable of measurements to a micrometer iterable of measurements.
      Parameters:
      iter - the abstracted iterable
      Returns:
      the micrometer iterable
    • wrapTagIterable

      public static Iterable<io.micrometer.core.instrument.Tag> wrapTagIterable(Iterable<de.iip_ecosphere.platform.support.metrics.Tag> iter)
      Maps an abstracted iterable of tags to a micrometer iterable of tags.
      Parameters:
      iter - the abstracted iterable
      Returns:
      the micrometer iterable
    • mmWrapTagIterable

      public static Iterable<de.iip_ecosphere.platform.support.metrics.Tag> mmWrapTagIterable(Iterable<io.micrometer.core.instrument.Tag> iter)
      Maps an abstracted iterable of tags to a micrometer iterable of tags.
      Parameters:
      iter - the abstracted iterable
      Returns:
      the micrometer iterable
    • wrapMeasurementIterable

      public static Iterable<io.micrometer.core.instrument.Measurement> wrapMeasurementIterable(Iterable<de.iip_ecosphere.platform.support.metrics.Measurement> iter)
      Maps an micrometer iterable of measurements to an abstracted iterable of measurements.
      Parameters:
      iter - the micrometer iterable
      Returns:
      the abstracted iterable
    • createMeter

      public static de.iip_ecosphere.platform.support.metrics.Meter createMeter(de.iip_ecosphere.platform.support.metrics.Meter meter, MicrometerUtils.MeterCreator creator)
      Creates a meter via an unknown implementation function.
      Parameters:
      meter - the meter
      creator - the creator function
      Returns:
      the created wrapped meter
    • append

      public static io.micrometer.core.instrument.config.MeterFilter[] append(io.micrometer.core.instrument.config.MeterFilter[] base, io.micrometer.core.instrument.config.MeterFilter... addition)
      Appends addition to base.
      Parameters:
      base - the base filters
      addition - the addition filters
      Returns:
      the combined filter array
    • apply

      public static void apply(io.micrometer.core.instrument.MeterRegistry registry, io.micrometer.core.instrument.config.MeterFilter... filters)
      Applies the given list of meter filters.
      Parameters:
      registry - the registry to apply the filters to
      filters - the filters to apply
    • include

      public static boolean include(io.micrometer.core.instrument.Meter.Id id, io.micrometer.core.instrument.config.MeterFilter... filters)
      Returns whether a meter id shall be included into a result set.
      Parameters:
      id - the meter id
      filters - the filters to be applied. The first matching filter returning MeterFilter.MeterFilterReply.DENY will remove a metric from the result list, an MeterFilter.MeterFilterReply.NEUTRAL will keep it as long as there is no MeterFilter.MeterFilterReply.DENY filter until the end of the filter list and MeterFilter.MeterFilterReply.ACCEPT will immediately accept the actual meter.
      Returns:
      true for apply, false else
    • include

      public static boolean include(String id, io.micrometer.core.instrument.config.MeterFilter... filters)
      Returns whether a meter id shall be included into a result set.
      Parameters:
      id - the meter id
      filters - the filters to be applied. The first matching filter returning MeterFilter.MeterFilterReply.DENY will remove a metric from the result list, an MeterFilter.MeterFilterReply.NEUTRAL will keep it as long as there is no MeterFilter.MeterFilterReply.DENY filter until the end of the filter list and MeterFilter.MeterFilterReply.ACCEPT will immediately accept the actual meter.
      Returns:
      true for apply, false else