class Sematext::Metrics::RawValidator

Constants

MAX_STRING_LENGTH
VALID_AGG_TYPES

Public Instance Methods

check_bounds(name, value) click to toggle source
# 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) click to toggle source
# File lib/sematext/metrics/validator.rb, line 25
def check_obligatory name, value
  raise "'#{name}' should be defined" unless value
end
validate(datapoint) click to toggle source
# 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