Interface NBLabels

All Known Implementing Classes:
MapLabels

public interface NBLabels

The NBLabels type represents sets of identifying label names and values for any element in the NoSQLBench runtime which needs to be named. This allows for hierarchic naming for instances by including the naming elements of parents as owned objects are created.

The recommended way to use this type is to require a parent element in constructors, and to combine instance data at that time into a cached view. This means that further processing will be minimized, since these elements will be consulted frequently, such as when rendering metrics values.

  • Method Details

    • linearizeValues

      String linearizeValues(char delim, String... included)
      Create a string representation of the label data, including only the values. Each value is concatenated with the others using the delim character. If a specified label name is included in square brackets like , then it is considered optional, and will be skipped over gracefully if it is not present in the label set. Otherwise all names are considered required.
      Parameters:
      delim - A single character
      included - Which fields from the label set to include in the rendered string. If none are specified then all are included.
      Returns:
      A string representation of the labels
      Throws:
      RuntimeException - if a required label name is not present, or its value is null.
    • linearizeValues

      default String linearizeValues(String... included)
      This is equivalent to call ing linearizeValues(char, String...) with the '.' character.
      Parameters:
      included - Which fields from the label set to include in the rendered string. If none are specified, then all are included.
      Returns:
      A string representation of the labels
    • linearize_bare

      String linearize_bare(String... barewords)
    • linearize

      String linearize(String barename, String... included)
      Render a string representation of the label set according to the prometheus exposition naming format. This means that a label set which includes the JSON data:
      
       {
         "name": "fooname",
         "label1": "label1value"
       }
       
      would render to
      fooname{label1="label1value"}
      IF called as linearize("name").

      The included fields are added to the label set. If none are specified then all are included by default.

      Parameters:
      barename - The field from the label set to use as the nominal metric family name part.
      included - Fields to be used in rendered label set.
      Returns:
      A string representation of the labels that is parsable in the prometheus exposition format.
    • forMap

      static NBLabels forMap(Map<String,String> labels)
      Create an NBLabels instance from the given map.
      Parameters:
      labels - label data
      Returns:
      a new NBLabels instance
    • forKV

      static NBLabels forKV(Object... keysAndValues)
      Create an NBLabels instance from the given keys and values (even,odd,...)
      Parameters:
      keysAndValues - Keys and values such as "key1", "value1", "key2", "value2", ...
      Returns:
      a new NBLabels instance
    • modifyName

      NBLabels modifyName(String element, Function<String,String> transform)
      Return a new NBLabels value with the specified key transformed according to the provided Lambda. The associated value is not modified.
      Parameters:
      element - The key to modify
      transform - A Lambda which will modify the existing key name.
      Returns:
      A new NBLabels value, separate from the original
    • modifyValue

      NBLabels modifyValue(String labelName, Function<String,String> transform)
      Return a new NBLabels value with the specified value transformed according to the provided Lambda. The associated key name is not modified.
      Parameters:
      labelName - The named label to modify
      transform - A Lambda which will modify the existing value.
      Returns:
      A new NBLabels value, separate from the original
      Throws:
      RuntimeException - if either the key is not found or the values is null.
    • linearizeAsMetrics

      String linearizeAsMetrics()
    • linearizeAsKvString

      String linearizeAsKvString()
    • and

      NBLabels and(Object... typeLabelsAndValues)
      Create a new NBLabels value with the additional keys and values appended.
      Parameters:
      typeLabelsAndValues - Keys and values in "key1", "value1", "key2", "value2", ... form
      Returns:
      A new NBLabels instance
    • and

      NBLabels and(NBLabels labels)
    • and

      NBLabels and(Map<String,String> typeLabelsAndValues)
      Create a new NBLabels value with the additional keys and values appended.
      Parameters:
      typeLabelsAndValues - a map of keys and values
      Returns:
      A new NBLabels instance
    • valueOf

      String valueOf(String name)
      Return the value of the specified label key.
      Parameters:
      name - The label name
      Returns:
      The named label's value
      Throws:
      RuntimeException - if the specified label does not exist in the set, or the value is null.
    • valueOfOptional

      Optional<String> valueOfOptional(String name)
    • asMap

      Map<String,String> asMap()
      Return a map representation of the label set, regardless of the underlying form.
      Returns:
      a Map of keys and values, in deterministic order
    • intersection

      NBLabels intersection(NBLabels labelset)
      Return a String representation of the metric's labels as you would see it in an openmetrics filter, like
      {__name__="metric_family_name",k="20"}
      Returns:
      a String
    • difference

      NBLabels difference(NBLabels otherLabels)
    • isEmpty

      boolean isEmpty()
    • andDefault

      NBLabels andDefault(String name, String value)
    • andDefault

      NBLabels andDefault(NBLabels defaults)