2022-04-04 11:22:00 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module Usage
|
|
|
|
class ServicePingReport
|
2022-07-16 23:28:13 +05:30
|
|
|
CACHE_KEY = 'usage_data'
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
class << self
|
|
|
|
def for(output:, cached: false)
|
|
|
|
case output.to_sym
|
|
|
|
when :all_metrics_values
|
2022-05-07 20:08:51 +05:30
|
|
|
with_instrumentation_classes(all_metrics_values(cached), :with_value)
|
2022-04-04 11:22:00 +05:30
|
|
|
when :metrics_queries
|
2022-05-07 20:08:51 +05:30
|
|
|
with_instrumentation_classes(metrics_queries, :with_instrumentation)
|
2022-04-04 11:22:00 +05:30
|
|
|
when :non_sql_metrics_values
|
2022-05-07 20:08:51 +05:30
|
|
|
with_instrumentation_classes(non_sql_metrics_values, :with_instrumentation)
|
2022-04-04 11:22:00 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2022-05-07 20:08:51 +05:30
|
|
|
def with_instrumentation_classes(old_payload, output_method)
|
2022-06-21 17:19:12 +05:30
|
|
|
instrumented_metrics_key_paths = Gitlab::Usage::ServicePing::PayloadKeysProcessor.new(old_payload).missing_instrumented_metrics_key_paths
|
2022-05-07 20:08:51 +05:30
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
instrumented_payload = Gitlab::Usage::ServicePing::InstrumentedPayload.new(instrumented_metrics_key_paths, output_method).build
|
2022-05-07 20:08:51 +05:30
|
|
|
|
2022-07-16 23:28:13 +05:30
|
|
|
old_payload.with_indifferent_access.deep_merge(instrumented_payload)
|
2022-05-07 20:08:51 +05:30
|
|
|
end
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
def all_metrics_values(cached)
|
2022-07-16 23:28:13 +05:30
|
|
|
Rails.cache.fetch(CACHE_KEY, force: !cached, expires_in: 2.weeks) do
|
2022-04-04 11:22:00 +05:30
|
|
|
Gitlab::UsageData.data
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def metrics_queries
|
|
|
|
Gitlab::UsageDataQueries.data
|
|
|
|
end
|
|
|
|
|
|
|
|
def non_sql_metrics_values
|
|
|
|
Gitlab::UsageDataNonSqlMetrics.data
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|