Class: Sematext::Metrics::RawValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/sematext/metrics/validator.rb

Constant Summary collapse

MAX_STRING_LENGTH =
255
VALID_AGG_TYPES =
%w(sum avg min max)

Instance Method Summary collapse

Instance Method Details

#check_bounds(name, value) ⇒ Object



21
22
23
# File 'lib/sematext/metrics/validator.rb', line 21

def check_bounds name, value
  raise "'#{name}' value can't be longer than 255 characters" unless value.size <= 255
end

#check_obligatory(name, value) ⇒ Object



25
26
27
# File 'lib/sematext/metrics/validator.rb', line 25

def check_obligatory name, value
  raise "'#{name}' should be defined" unless value
end

#validate(datapoint) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/sematext/metrics/validator.rb', line 29

def validate datapoint
  [:name, :value, :agg_type].each do |field|
    check_obligatory field, datapoint[field]
  end
  raise "name can't be empty" if datapoint[:name].empty?
  raise "value should be a number" unless datapoint[:value].kind_of?(Numeric)
  [:name, :filter1, :filter2].each do |field|
    value = datapoint[field]
    check_bounds field, datapoint[field] if value
  end
  unless VALID_AGG_TYPES.include? datapoint[:agg_type].to_s
    raise "Invalid aggregation type, valid values are: #{VALID_AGG_TYPES.join(', ')}"
  end
end