Class: Prometheus::Client::LabelSetValidator
- Inherits:
-
Object
- Object
- Prometheus::Client::LabelSetValidator
- Defined in:
- lib/prometheus/client/label_set_validator.rb
Overview
LabelSetValidator ensures that all used label sets comply with the Prometheus specification.
Defined Under Namespace
Classes: InvalidLabelError, InvalidLabelSetError, LabelSetError, ReservedLabelError
Constant Summary collapse
- RESERVED_LABELS =
TODO: we might allow setting :instance in the future
[:job, :instance]
Instance Method Summary collapse
-
#initialize ⇒ LabelSetValidator
constructor
A new instance of LabelSetValidator.
- #valid?(labels) ⇒ Boolean
- #validate(labels) ⇒ Object
Constructor Details
#initialize ⇒ LabelSetValidator
Returns a new instance of LabelSetValidator.
16 17 18 |
# File 'lib/prometheus/client/label_set_validator.rb', line 16 def initialize @validated = {} end |
Instance Method Details
#valid?(labels) ⇒ Boolean
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/prometheus/client/label_set_validator.rb', line 20 def valid?(labels) unless labels.respond_to?(:all?) fail InvalidLabelSetError, "#{labels} is not a valid label set" end labels.all? do |key, _| validate_symbol(key) validate_name(key) validate_reserved_key(key) end end |
#validate(labels) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/prometheus/client/label_set_validator.rb', line 32 def validate(labels) return labels if @validated.key?(labels.hash) valid?(labels) unless @validated.empty? || match?(labels, @validated.first.last) fail InvalidLabelSetError, 'labels must have the same signature' end @validated[labels.hash] = labels end |