Sha256: 15984e67bf897fd1a06e41f50bbb934cbf36dc5f4039ad73c352fc1c1801fcb8

Contents?: true

Size: 1.29 KB

Versions: 10

Compression:

Stored size: 1.29 KB

Contents

# frozen_string_literal: true

module Aspecto
  # Aspecto OpenTelemetry Distro
  module OpenTelemetry
    # Sampling logic for aspecto otel distribution
    module Sampler
      # A single operator used to evaluate sampling rules
      class Operator
        def initialize(operator, expected)  # rubocop:disable Metrics/AbcSize
          @expected = expected&.downcase
          @expected = Regexp.new(@expected) if operator == "matches"

          operator_to_proc = {
            "eq" => proc { |actual| @expected == actual },
            "ne" => proc { |actual| @expected != actual },
            "starts_with" => proc { |actual| actual&.start_with?(expected) },
            "ends_with" => proc { |actual| actual&.end_with?(expected) },
            "contains" => proc { |actual| actual&.include?(expected) },
            "not_contains" => proc { |actual| !actual&.include?(expected) },
            "matches" => proc { |actual| @expected.match(actual) },
            "defined" => proc { |actual| !actual.nil? },
            "undefined" => proc { |actual| actual.nil? },
            "any" => proc { true }
          }

          @evaluate = operator_to_proc.fetch(operator, proc { false })
        end

        def satisfies?(actual)
          @evaluate.call actual&.downcase
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
aspecto-opentelemetry-0.1.10 lib/aspecto/opentelemetry/sampler/operator.rb
aspecto-opentelemetry-0.1.9 lib/aspecto/opentelemetry/sampler/operator.rb
aspecto-opentelemetry-0.1.8 lib/aspecto/opentelemetry/sampler/operator.rb
aspecto-opentelemetry-0.1.7 lib/aspecto/opentelemetry/sampler/operator.rb
aspecto-opentelemetry-0.1.7.rc0 lib/aspecto/opentelemetry/sampler/operator.rb
aspecto-opentelemetry-0.1.6 lib/aspecto/opentelemetry/sampler/operator.rb
aspecto-opentelemetry-0.1.5 lib/aspecto/opentelemetry/sampler/operator.rb
aspecto-opentelemetry-0.1.4 lib/aspecto/opentelemetry/sampler/operator.rb
aspecto-opentelemetry-0.1.3 lib/aspecto/opentelemetry/sampler/operator.rb
aspecto-opentelemetry-0.1.2 lib/aspecto/opentelemetry/sampler/operator.rb