Sha256: 022a0e73989bfaab35b378a0a029ccb2de2a76d026af9bcaaefe814f2b92827c

Contents?: true

Size: 1.48 KB

Versions: 17

Compression:

Stored size: 1.48 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 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
    # 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

17 entries across 17 versions & 3 rubygems

Version Path
logstash-core-5.5.3-java lib/logstash/instrument/null_metric.rb
logstash-core-5.5.2-java lib/logstash/instrument/null_metric.rb
logstash-core-6.0.0.beta1-java lib/logstash/instrument/null_metric.rb
logstash-core-5.5.1-java lib/logstash/instrument/null_metric.rb
logstash-filter-cache-redis-0.3.1 vendor/bundle/jruby/1.9/gems/logstash-core-5.5.1.snapshot1-java/lib/logstash/instrument/null_metric.rb
logstash-filter-cache-redis-0.3.0 vendor/bundle/jruby/1.9/gems/logstash-core-5.5.1.snapshot1-java/lib/logstash/instrument/null_metric.rb
logstash-core-5.5.1.snapshot1-java lib/logstash/instrument/null_metric.rb
logstash-filter-cache-redis-0.2.0 vendor/bundle/jruby/1.9/gems/logstash-core-5.5.0-java/lib/logstash/instrument/null_metric.rb
logstash-filter-cache-redis-0.1.0 vendor/bundle/jruby/1.9/gems/logstash-core-5.4.0-java/lib/logstash/instrument/null_metric.rb
logstash-core-5.5.0-java lib/logstash/instrument/null_metric.rb
logstash-core-5.4.3-java lib/logstash/instrument/null_metric.rb
logstash-core-5.4.2-java lib/logstash/instrument/null_metric.rb
logstash-core-6.0.0.alpha2-java lib/logstash/instrument/null_metric.rb
logstash-core-5.4.1-java lib/logstash/instrument/null_metric.rb
logstash-filter-htmlentities-0.1.0 vendor/bundle/jruby/1.9/gems/logstash-core-5.4.0-java/lib/logstash/instrument/null_metric.rb
logstash-core-6.0.0.alpha1-java lib/logstash/instrument/null_metric.rb
logstash-core-5.4.0-java lib/logstash/instrument/null_metric.rb