blob: 3b20e6ad100c041ad02a963c9fd4fd8d13611252 (
plain)
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
60
|
# frozen_string_literal: true
module Gitlab
module Usage
module Metrics
module Instrumentations
class NumbersMetric < BaseMetric
# Usage Example
#
# class BoardsCountMetric < NumbersMetric
# operation :add
#
# data do |time_frame|
# [
# CountIssuesMetric.new(time_frame: time_frame).value,
# CountBoardsMetric.new(time_frame: time_frame).value,
# ]
# end
# end
UnimplementedOperationError = Class.new(StandardError) # rubocop:disable UsageData/InstrumentationSuperclass
class << self
IMPLEMENTED_OPERATIONS = %i(add).freeze
private_constant :IMPLEMENTED_OPERATIONS
def data(&block)
return @metric_data&.call unless block
@metric_data = block
end
def operation(symbol)
raise UnimplementedOperationError unless symbol.in?(IMPLEMENTED_OPERATIONS)
@metric_operation = symbol
end
attr_reader :metric_operation, :metric_data
end
def value
method(self.class.metric_operation).call(*data)
end
def suggested_name
Gitlab::Usage::Metrics::NameSuggestion.for(:alt)
end
private
def data
self.class.metric_data.call(time_frame)
end
end
end
end
end
end
|