Class MetricImpl<T>

java.lang.Object
org.apache.solr.cluster.placement.impl.MetricImpl<T>
All Implemented Interfaces:
Metric<T>
Direct Known Subclasses:
NodeMetricImpl, ReplicaMetricImpl

public abstract class MetricImpl<T> extends Object implements Metric<T>
Base class for Metric implementations.
  • Field Details

    • IDENTITY_CONVERTER

      public final Function<Object,T> IDENTITY_CONVERTER
      Identity converter. It returns the raw value unchanged IFF the value's type can be cast to the generic type of this attribute, otherwise it returns null.
    • MB_TO_GB_CONVERTER

      public static final Function<Object,Double> MB_TO_GB_CONVERTER
      Megabytes to gigabytes converter. Supports converting number or string representations of raw values expressed in megabytes.
    • name

      protected final String name
    • internalName

      protected final String internalName
    • converter

      protected final Function<Object,T> converter
    • labelKey

      protected final String labelKey
    • labelValue

      protected final String labelValue
  • Constructor Details

    • MetricImpl

      public MetricImpl(String name, String internalName)
      Create a metric attribute.
      Parameters:
      name - short-hand name that identifies this attribute.
      internalName - internal name of a Solr metric.
    • MetricImpl

      public MetricImpl(String name, String internalName, Function<Object,T> converter)
      Create a metric attribute.
      Parameters:
      name - short-hand name that identifies this attribute.
      internalName - internal name of a Solr metric.
      converter - optional raw value converter. If null then IDENTITY_CONVERTER will be used.
    • MetricImpl

      public MetricImpl(String name, String internalName, String labelKey, String labelValue, Function<Object,T> converter)
      Create a metric attribute with labels.
      Parameters:
      name - short-hand name that identifies this attribute.
      internalName - internal name of a Solr metric.
      labelKey - optional label key for Prometheus format labeled metrics.
      labelValue - optional label value for Prometheus format labeled metrics.
      converter - optional raw value converter. If null then IDENTITY_CONVERTER will be used.
  • Method Details

    • getName

      public String getName()
      Description copied from interface: Metric
      Return the short-hand name that identifies this attribute.
      Specified by:
      getName in interface Metric<T>
    • getInternalName

      public String getInternalName()
      Description copied from interface: Metric
      Return the internal name of a Solr metric associated with this attribute.
      Specified by:
      getInternalName in interface Metric<T>
    • getLabelKey

      public String getLabelKey()
      Description copied from interface: Metric
      Return the label key for Prometheus metrics filtering, if any.
      Specified by:
      getLabelKey in interface Metric<T>
      Returns:
      label key or null if no label filtering is needed
    • getLabelValue

      public String getLabelValue()
      Description copied from interface: Metric
      Return the label value for Prometheus metrics filtering, if any.
      Specified by:
      getLabelValue in interface Metric<T>
      Returns:
      label value or null if no label filtering is needed
    • hasLabels

      public boolean hasLabels()
      Description copied from interface: Metric
      Return true if this metric has label filtering.
      Specified by:
      hasLabels in interface Metric<T>
      Returns:
      true if both label key and value are non-null
    • convert

      public T convert(Object value)
      Description copied from interface: Metric
      Convert raw value. This may involve changing raw value type or units.
      Specified by:
      convert in interface Metric<T>
      Parameters:
      value - raw value
      Returns:
      converted value
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object