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