Package codes.grow.packages.loki
Class Labels
java.lang.Object
codes.grow.packages.loki.Labels
Label helpers: validation, normalization and Prometheus label-set rendering.
Loki label names follow the Prometheus rules ([a-zA-Z_][a-zA-Z0-9_]*); names starting
with __ are reserved.
-
Field Summary
FieldsModifier and TypeFieldDescriptionKeys the cardinality guard lets become index labels by default (coordinator decision 3). -
Method Summary
Modifier and TypeMethodDescriptionstatic StringattrToString(Object value) Renders an attribute value as a structured metadata string: strings as is, numbers and booleans as their text, lists and maps as JSON.static StringformatLabelSet(Map<String, String> labels) Renders labels in Prometheus label-set syntax with sorted names and Go-quoted values:{a="b", c="d"}(the form protobuf push andlistStreams()use).static booleanisValidLabelName(String name) Returns whethernamematches[a-zA-Z_][a-zA-Z0-9_]*and does not start with__.static StringnormalizeLabelName(String key) Normalizes an attribute key the way Loki does for OTLP attributes: every character outside[a-zA-Z0-9_]becomes_(service.name→service_name) and a leading digit gets a_prefix.static voidvalidateLabel(String name, String value) Checks one index label: valid, non-reserved name and a non-empty value.static voidvalidateLabelName(String name) Checks a label name.
-
Field Details
-
DEFAULT_ALLOWED_LABELS
Keys the cardinality guard lets become index labels by default (coordinator decision 3). Every other attribute or resource key goes to structured metadata.
-
-
Method Details
-
isValidLabelName
Returns whethernamematches[a-zA-Z_][a-zA-Z0-9_]*and does not start with__.- Parameters:
name- label name- Returns:
- true when Loki accepts it as an index label name
-
validateLabel
Checks one index label: valid, non-reserved name and a non-empty value.- Parameters:
name- label namevalue- label value- Throws:
ValidationException- when the label is invalid
-
validateLabelName
Checks a label name.- Parameters:
name- label name- Throws:
ValidationException- unless the name is valid and not reserved
-
normalizeLabelName
Normalizes an attribute key the way Loki does for OTLP attributes: every character outside[a-zA-Z0-9_]becomes_(service.name→service_name) and a leading digit gets a_prefix. An empty key stays empty.- Parameters:
key- attribute key- Returns:
- the label / structured metadata name
-
formatLabelSet
Renders labels in Prometheus label-set syntax with sorted names and Go-quoted values:{a="b", c="d"}(the form protobuf push andlistStreams()use).- Parameters:
labels- labels- Returns:
- the label-set string
-
attrToString
Renders an attribute value as a structured metadata string: strings as is, numbers and booleans as their text, lists and maps as JSON.- Parameters:
value- attribute value- Returns:
- the string form (
""for null)
-