Commit a0b916b0 authored by Paul Asmuth's avatar Paul Asmuth
Browse files

implemented default_flush_interval

parent 9afd39ef
Loading
Loading
Loading
Loading
+1 −6
Original line number Diff line number Diff line
@@ -16,11 +16,6 @@ FnordMetric::ZERO_CONFIG_HANDLER = proc {
    next
  end

  unless data[:flush_interval]
    FnordMetric.error("missing key for zero config event: flush_interval")
    next
  end

  unless data[:value]
    FnordMetric.error("missing key for zero config event: value")
    next
@@ -30,7 +25,7 @@ FnordMetric::ZERO_CONFIG_HANDLER = proc {
    namespace.gauges[gauge_key]
  else
    namespace.opt_gauge(gauge_key,
      :tick => data[:flush_interval].to_i,
      :flush_interval => data[:flush_interval],
      :average => (type == :_avg),
      :zero_config => true)
  end
+2 −1
Original line number Diff line number Diff line
@@ -11,7 +11,8 @@ class FnordMetric::Gauge
  end

  def tick
    (@opts[:tick] || @opts[:resolution] || 3600).to_i
    (@opts[:tick] || @opts[:resolution] || @opts[:flush_interval] ||
      FnordMetric.options[:default_flush_interval]).to_i
  end

  def retention
+1 −1
Original line number Diff line number Diff line
@@ -3,7 +3,7 @@ class ZeroConfigGauge
  class EmtpyGauge

    def self.tick
      60
      FnordMetric.options[:default_flush_interval]
    end

    def self.retention
+18 −3
Original line number Diff line number Diff line
@@ -25,12 +25,12 @@ describe FnordMetric::GaugeModifiers do
        :_time => 1360584960,
        :value => 42,
        :gauge => "sales-per-second",
        :flush_interval => 10
        :flush_interval => 20
      )

      @namespace.gauges[:"sales-per-second"].should be_a(Gauge)

      gauge_key = "fnordmetric-myns_213-gauge-sales-per-second-10"
      gauge_key = "fnordmetric-myns_213-gauge-sales-per-second-20"
      @redis.hget(gauge_key, "1360584960").should == "42"

      @namespace.announce(
@@ -39,13 +39,28 @@ describe FnordMetric::GaugeModifiers do
        :_time => 1360584960,
        :value => 11,
        :gauge => "sales-per-second",
        :flush_interval => 10
        :flush_interval => 20
      )

      @redis.hget(gauge_key, "1360584960").should == "53"
      @namespace.gauges[:"sales-per-second"].value_at(1360584961).should == "53"
    end

    it "should create and increment zero-config gauges with the default flush interval" do
      @namespace.announce(
        :_type => "_incr",
        :_eid  => 1234,
        :_time => 1360584960,
        :value => 42,
        :gauge => "sales-per-second-default"
      )

      @namespace.gauges[:"sales-per-second-default"].should be_a(Gauge)

      gauge_key = "fnordmetric-myns_213-gauge-sales-per-second-default-10"
      @redis.hget(gauge_key, "1360584960").should == "42"
    end

    it "should create and set zero-config gauges" do
      @namespace.announce(
        :_type => "_set",
+7 −2
Original line number Diff line number Diff line
@@ -22,9 +22,14 @@ describe FnordMetric::Gauge do
      gauge.tick.should == 23
    end

    it "should return the correct tick if configured with flush_interval" do
      gauge = FnordMetric::Gauge.new({:flush_interval => 42, :key_prefix => "fnordmetrics-myns", :key => "mygauge"})
      gauge.tick.should == 42
    end

    it "should return the default tick if none configured" do
      gauge = FnordMetric::Gauge.new({:key_prefix => "fnordmetrics-myns", :key => "mygauge"})
      gauge.tick.should == 3600
      gauge.tick.should == FnordMetric.options[:default_flush_interval]
    end

    it "should return the correct tick_at" do
Loading