Add add operation
Add the add
operation to metrics instrumentation classes
The add operation is adding up an array of values
Current implementation
#lib/gitlab/utils/usage_data.rb
def add(*args)
return -1 if args.any?(&:negative?)
args.sum
rescue StandardError
FALLBACK
end
=> add(12, 2, 1)
=> 15
- This operation might not fit under the
DatabaseMetric
as it is not taking a relation as a parameter. - This could be a different type of instrumentation class that can handle an array of numbers on which we can have arithmetic operations.
- The same result could be achieved if we use individual GenericMetric instrumentation classes and we might not add a dedicated Metric instrumentation class.
Proposal for API for this metric and operation
BoardsCountMetric < NumbersMetric
operation :add
data { [1, 10] }
The same result could be achieved if we use individual generic metrics for the metric that use add operation.
BaseMetric
class includes the Gitlab::Utils::UsageData
and all the methods are available.
For example:
module Gitlab
module Usage
module Metrics
module Instrumentations
class CountProjectImports < GnericMetric
value do
project_imports = distinct_count(::Project.where(time_period).where.not(import_type: nil), :creator_id)
bulk_imports = distinct_count(::BulkImport.where(time_period), :user_id)
jira_issue_imports = distinct_count(::JiraImportState.where(time_period), :user_id)
csv_issue_imports = distinct_count(Issues::CsvImport.where(time_period), :user_id)
group_imports = distinct_count(::GroupImportState.where(time_period), :user_id)
add(project_imports, bulk_imports, jira_issue_imports, csv_issue_imports, group_imports)
end
Edited by Alina Mihaila