-
Notifications
You must be signed in to change notification settings - Fork 284
Expand file tree
/
Copy pathregistered_view.rb
More file actions
59 lines (47 loc) · 1.94 KB
/
Copy pathregistered_view.rb
File metadata and controls
59 lines (47 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# frozen_string_literal: true
# Copyright The OpenTelemetry Authors
#
# SPDX-License-Identifier: Apache-2.0
module OpenTelemetry
module SDK
module Metrics
module View
# RegisteredView is an internal class used to match Views with a given {MetricStream}
class RegisteredView
attr_reader :name, :aggregation, :attribute_keys, :regex, :aggregation_cardinality_limit
def initialize(name, **options)
@name = name
@options = options
@aggregation = options[:aggregation]
@attribute_keys = options[:attribute_keys] || {}
@aggregation_cardinality_limit = options[:aggregation_cardinality_limit]
generate_regex_pattern(name)
end
def match_instrument?(metric_stream)
return false if @name && !name_match(metric_stream.name)
return false if @options[:type] && @options[:type] != metric_stream.instrument_kind
return false if @options[:unit] && @options[:unit] != metric_stream.unit
return false if @options[:meter_name] && @options[:meter_name] != metric_stream.instrumentation_scope.name
return false if @options[:meter_version] && @options[:meter_version] != metric_stream.instrumentation_scope.version
true
end
def name_match(stream_name) # rubocop:disable Naming/PredicateMethod
!!@regex&.match(stream_name)
end
def valid_aggregation?
@aggregation.class.name.rpartition('::')[0] == 'OpenTelemetry::SDK::Metrics::Aggregation'
end
private
def generate_regex_pattern(view_name)
regex_pattern = Regexp.escape(view_name)
regex_pattern.gsub!('\*', '.*')
regex_pattern.gsub!('\?', '.')
@regex = Regexp.new("^#{regex_pattern}$")
rescue StandardError
@regex = nil
end
end
end
end
end
end