Class: Librato::Rack::ValidatingQueue

Inherits:
Metrics::Queue
  • Object
show all
Defined in:
lib/librato/rack/validating_queue.rb

Overview

Queue with special upfront validating logic, this should probably be available in librato-metrics but spiking here to work out the kinks

Constant Summary collapse

DEFAULT_TAGS_LIMIT =
4
METRIC_NAME_REGEX =
/\A[-.:_\w]{1,255}\z/
TAGS_KEY_REGEX =
/\A[-.:_\w]{1,64}\z/
TAGS_VALUE_REGEX =
/\A[-.:_\w\s]{1,255}\z/

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#loggerObject

Returns the value of attribute logger.



13
14
15
# File 'lib/librato/rack/validating_queue.rb', line 13

def logger
  @logger
end

Instance Method Details

#submitObject



15
16
17
18
19
# File 'lib/librato/rack/validating_queue.rb', line 15

def submit
  validate_measurements

  super
end

#validate_measurementsObject

screen all measurements for validity before sending



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/librato/rack/validating_queue.rb', line 22

def validate_measurements
  @queued[:measurements].delete_if do |entry|
    name = entry[:name].to_s
    tags = entry[:tags]
    if name !~ METRIC_NAME_REGEX
      log :warn, "invalid metric name '#{name}', not sending."
      true # delete
    elsif tags && tags.any? { |k,v| k.to_s !~ TAGS_KEY_REGEX || v.to_s !~ TAGS_VALUE_REGEX }
      log :warn, "halting: '#{tags}' are invalid tags."
      true # delete
    else
      false # preserve
    end
  end
end