blob: 66be7a7b64e0473715fdb88b68593d9980dd769c (
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
61
62
|
# frozen_string_literal: true
module Gitlab
module Usage
module Metrics
module Instrumentations
# Usage example
#
# In metric YAML definition:
#
# instrumentation_class: AggregatedMetric
# data_source: redis_hll
# options:
# aggregate:
# operator: OR
# attribute: user_id
# events:
# - 'incident_management_alert_status_changed'
# - 'incident_management_alert_assigned'
# - 'incident_management_alert_todo'
# - 'incident_management_alert_create_incident'
class AggregatedMetric < BaseMetric
FALLBACK = -1
def initialize(metric_definition)
super
@source = metric_definition[:data_source]
@aggregate = options.fetch(:aggregate, {})
end
def value
alt_usage_data(fallback: FALLBACK) do
Aggregates::Aggregate
.new(Time.current)
.calculate_count_for_aggregation(
aggregation: aggregate_config,
time_frame: time_frame
)
end
end
def suggested_name
Gitlab::Usage::Metrics::NameSuggestion.for(:alt)
end
private
attr_accessor :source, :aggregate
def aggregate_config
{
source: source,
events: options[:events],
operator: aggregate[:operator]
}
end
end
end
end
end
end
|