Sha256: 62ee7a97435264aab52580815df85ab9254c735b133d697763ca9ef9962e4b35

Contents?: true

Size: 1.59 KB

Versions: 67

Compression:

Stored size: 1.59 KB

Contents

# encoding: utf-8
require "logstash/instrument/metric"

module LogStash module Instrument
  # This class is used in the context when we disable the metric collection
  # for specific plugin to replace the `NamespacedMetric` class with this one
  # which doesn't produce any metric to the collector.
  class NullMetric
    attr_reader :namespace_name, :collector

    def initialize(collector = nil)
      @collector = collector
    end

    def increment(namespace, key, value = 1)
      Metric.validate_key!(key)
    end

    def decrement(namespace, key, value = 1)
      Metric.validate_key!(key)
    end

    def gauge(namespace, key, value)
      Metric.validate_key!(key)
    end

    def report_time(namespace, key, duration)
      Metric.validate_key!(key)
    end

    # We have to manually redefine this method since it can return an
    # object this object also has to be implemented as a NullObject
    def time(namespace, key)
      Metric.validate_key!(key)
      if block_given?
        yield
      else
        NullTimedExecution
      end
    end

    def counter(_)
      NullGauge
    end

    def namespace(name)
      raise MetricNoNamespaceProvided if name.nil? || name.empty?
      NamespacedNullMetric.new(self, name)
    end

    def self.validate_key!(key)
      raise MetricNoKeyProvided if key.nil? || key.empty?
    end

    private

    class NullGauge
      def self.increment(_)
      end
    end

    # Null implementation of the internal timer class
    #
    # @see LogStash::Instrument::TimedExecution`
    class NullTimedExecution
      def self.stop
        0
      end
    end
  end
end; end

Version data entries

67 entries across 67 versions & 5 rubygems

Version Path
logstash-output-scalyr-0.2.1.beta vendor/bundle/jruby/2.5.0/gems/logstash-core-5.6.4-java/lib/logstash/instrument/null_metric.rb
logstash-output-scalyr-0.2.0 vendor/bundle/jruby/2.5.0/gems/logstash-core-5.6.4-java/lib/logstash/instrument/null_metric.rb
logstash-output-scalyr-0.2.0.beta vendor/bundle/jruby/2.5.0/gems/logstash-core-5.6.4-java/lib/logstash/instrument/null_metric.rb
logstash-output-scalyr-0.1.26.beta vendor/bundle/jruby/2.5.0/gems/logstash-core-5.6.4-java/lib/logstash/instrument/null_metric.rb
logstash-output-scalyr-0.1.25.beta vendor/bundle/jruby/2.5.0/gems/logstash-core-5.6.4-java/lib/logstash/instrument/null_metric.rb
logstash-output-scalyr-0.1.24.beta vendor/bundle/jruby/2.5.0/gems/logstash-core-5.6.4-java/lib/logstash/instrument/null_metric.rb
logstash-output-scalyr-0.1.23.beta vendor/bundle/jruby/2.5.0/gems/logstash-core-5.6.4-java/lib/logstash/instrument/null_metric.rb
logstash-output-scalyr-0.1.22.beta vendor/bundle/jruby/2.5.0/gems/logstash-core-5.6.4-java/lib/logstash/instrument/null_metric.rb
logstash-output-scalyr-0.1.21.beta vendor/bundle/jruby/2.5.0/gems/logstash-core-5.6.4-java/lib/logstash/instrument/null_metric.rb
logstash-output-scalyr-0.1.20.beta vendor/bundle/jruby/2.5.0/gems/logstash-core-5.6.4-java/lib/logstash/instrument/null_metric.rb
logstash-output-scalyr-0.1.19.beta vendor/bundle/jruby/2.5.0/gems/logstash-core-5.6.4-java/lib/logstash/instrument/null_metric.rb
logstash-output-scalyr-0.1.18.beta vendor/bundle/jruby/2.5.0/gems/logstash-core-5.6.4-java/lib/logstash/instrument/null_metric.rb
logstash-output-scalyr-0.1.17.beta vendor/bundle/jruby/2.5.0/gems/logstash-core-5.6.4-java/lib/logstash/instrument/null_metric.rb
logstash-output-scalyr-0.1.16.beta vendor/bundle/jruby/2.5.0/gems/logstash-core-5.6.4-java/lib/logstash/instrument/null_metric.rb
logstash-output-scalyr-0.1.15.beta vendor/bundle/jruby/2.5.0/gems/logstash-core-5.6.4-java/lib/logstash/instrument/null_metric.rb
logstash-output-scalyr-0.1.14.beta vendor/bundle/jruby/2.5.0/gems/logstash-core-5.6.4-java/lib/logstash/instrument/null_metric.rb
logstash-output-scalyr-0.1.13 vendor/bundle/jruby/2.5.0/gems/logstash-core-5.6.4-java/lib/logstash/instrument/null_metric.rb
logstash-output-scalyr-0.1.12 vendor/bundle/jruby/2.5.0/gems/logstash-core-5.6.4-java/lib/logstash/instrument/null_metric.rb
logstash-output-scalyr-0.1.11.beta vendor/bundle/jruby/2.5.0/gems/logstash-core-5.6.4-java/lib/logstash/instrument/null_metric.rb
logstash-output-scalyr-0.1.10.beta vendor/bundle/jruby/2.5.0/gems/logstash-core-5.6.4-java/lib/logstash/instrument/null_metric.rb