Sha256: 70f407ab494984098d45eb3a5b0c891aee0278e834253e483e6c563aa540b08a

Contents?: true

Size: 883 Bytes

Versions: 2

Compression:

Stored size: 883 Bytes

Contents

module Druid
  module Writer
    module Tranquilizer
      class Datapoint
        TIMESTAMP_LABEL = 'timestamp'.freeze

        attr_reader :dimensions, :timestamp, :metrics

        def initialize(datapoint)
          @timestamp = build_time(datapoint[:timestamp])
          @dimensions = parse_dimensions(datapoint[:dimensions])
          @metrics = parse_metrics(datapoint[:metrics])
        end

        private

        def build_time(time)
          time = Time.now.utc unless time
          Hash[TIMESTAMP_LABEL, time.iso8601]
        end

        def parse_dimensions(dimensions)
          dimensions.present? ? dimensions.with_indifferent_access : {}
        end

        def parse_metrics(metrics)
          raise ValidationError, 'Must specify at least one metric' unless metrics.present?
          metrics.with_indifferent_access
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
jruby-druid-1.0.0.pre.rc4 lib/druid/writer/tranquilizer/datapoint.rb
jruby-druid-1.0.0.pre.rc3 lib/druid/writer/tranquilizer/datapoint.rb