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
|
# frozen_string_literal: true
require 'rails/generators'
module Gitlab
module UsageMetricDefinition
class RedisHllGenerator < Rails::Generators::Base
desc 'Generates a metric definition .yml file with defaults for Redis HLL.'
argument :category, type: :string, desc: "Category name"
argument :events, type: :array, desc: "Unique event names", banner: 'event_one event_two event_three'
class_option :ee, type: :boolean, optional: true, default: false, desc: 'Indicates if metric is for ee'
def create_metrics
weekly_key_paths = key_paths.map { |key_path| "#{key_path}_weekly" }
weekly_params = [*weekly_key_paths, '--dir', '7d', '--class_name', 'RedisHLLMetric']
weekly_params << '--ee' if ee?
Gitlab::UsageMetricDefinitionGenerator.start(weekly_params)
monthly_key_paths = key_paths.map { |key_path| "#{key_path}_monthly" }
monthly_params = [*monthly_key_paths, '--dir', '28d', '--class_name', 'RedisHLLMetric']
monthly_params << '--ee' if ee?
Gitlab::UsageMetricDefinitionGenerator.start(monthly_params)
end
private
def ee?
options[:ee]
end
def key_paths
events.map { |event| "redis_hll_counters.#{category}.#{event}" }
end
end
end
end
|