Class Labels
java.lang.Object
io.prometheus.metrics.model.snapshots.Labels
- All Implemented Interfaces:
Comparable<Labels>,Iterable<Label>
Immutable set of name/value pairs, sorted by name.
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionCreate a new Labels instance containing the labels of this and the label passed as name and value.private voidappendEscapedLabelValue(StringBuilder b, String value) asList()static Labels.Builderbuilder()private intintbooleanTest if these labels contain a specific label name.booleanGet the label value for a given label name.getName(int i) getPrometheusName(int i) LikegetName(int), but dots are replaced with underscores.getValue(int i) inthashCode()booleanhasSameNames(Labels other) booleanhasSameValues(Labels other) booleanisEmpty()iterator()(package private) static String[]makePrometheusNames(String[] names) Create a new Labels instance containing the labels of this and the labels of other.Create a new Labels instance containing the labels of this and the labels passed as names and values.static LabelsCreate a new Labels instance.static LabelsCreate a new Labels instance.static LabelsCreate a new Labels instance.intsize()private static voidprivate static voidsortAndValidate(String[] names, String[] prometheusNames, String[] values) stream()private static voidtoString()This must not be used in Prometheus exposition formats because names may contain dots.private static voidvalidateNames(String[] names, String[] prometheusNames) Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
EMPTY
-
prometheusNames
-
names
-
values
-
-
Constructor Details
-
Labels
-
-
Method Details
-
isEmpty
public boolean isEmpty() -
of
Create a new Labels instance. You can either create Labels with one of the staticLabels.of(...)methods, or you can use thebuilder().- Parameters:
keyValuePairs- as in{name1, value1, name2, value2}. Length must be even.PrometheusNaming.isValidLabelName(String)must be true for each name. UsePrometheusNaming.sanitizeLabelName(String)to convert arbitrary strings to valid label names. Label names must be unique (no duplicate label names).
-
of
Create a new Labels instance. You can either create Labels with one of the staticLabels.of(...)methods, or you can use thebuilder().- Parameters:
names- label names.PrometheusNaming.isValidLabelName(String)must be true for each name. UsePrometheusNaming.sanitizeLabelName(String)to convert arbitrary strings to valid label names. Label names must be unique (no duplicate label names).values- label values.names.size()must be equal tovalues.size().
-
of
Create a new Labels instance. You can either create Labels with one of the staticLabels.of(...)methods, or you can use thebuilder().- Parameters:
names- label names.PrometheusNaming.isValidLabelName(String)must be true for each name. UsePrometheusNaming.sanitizeLabelName(String)to convert arbitrary strings to valid label names. Label names must be unique (no duplicate label names).values- label values.names.lengthmust be equal tovalues.length.
-
makePrometheusNames
-
contains
Test if these labels contain a specific label name.Dots are treated as underscores, so
contains("my.label")andcontains("my_label")are the same. -
get
Get the label value for a given label name.Returns
nullif thelabelNameis not found.Dots are treated as underscores, so
get("my.label")andget("my_label")are the same. -
sortAndValidate
-
validateNames
-
sort
-
swap
-
iterator
-
stream
-
size
public int size() -
getName
-
getPrometheusName
LikegetName(int), but dots are replaced with underscores.This is used by Prometheus exposition formats.
-
getValue
-
merge
Create a new Labels instance containing the labels of this and the labels of other. This and other must not contain the same label name. -
merge
Create a new Labels instance containing the labels of this and the labels passed as names and values. The new label names must not already be contained in this Labels instance. -
add
Create a new Labels instance containing the labels of this and the label passed as name and value. The label name must not already be contained in this Labels instance. -
hasSameNames
-
hasSameValues
-
compareTo
- Specified by:
compareToin interfaceComparable<Labels>
-
compare
-
asList
-
toString
This must not be used in Prometheus exposition formats because names may contain dots.However, for debugging it's better to show the original names rather than the Prometheus names.
-
appendEscapedLabelValue
-
equals
-
hashCode
public int hashCode() -
builder
-