Class Labels
Object
Labels
- All Implemented Interfaces:
Comparable<Labels>
,Iterable<Label>
Immutable set of name/value pairs, sorted by name.
-
Nested Class Summary
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionCreate a new Labels instance containing the labels of this and the label passed as name and value.static Labels.Builder
builder()
int
boolean
Test if these labels contain a specific label name.boolean
Get 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) int
hashCode()
boolean
hasSameNames
(Labels other) boolean
hasSameValues
(Labels other) boolean
isEmpty()
iterator()
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 Labels
Create a new Labels instance.static Labels
Create a new Labels instance.static Labels
Create a new Labels instance.int
size()
stream()
toString()
This must not be used in Prometheus exposition formats because names may contain dots.Methods inherited from interface Iterable
forEach, spliterator
-
Field Details
-
EMPTY
-
-
Method Details
-
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.length
must be equal tovalues.length
.
-
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
null
if thelabelName
is not found.Dots are treated as underscores, so
get("my.label")
andget("my_label")
are the same. -
iterator
-
stream
-
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:
compareTo
in interfaceComparable<Labels>
-
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.
-
equals
-
hashCode
-
builder
-