Add new service to use instrumentation classes
Summary
Add new service to use instrumentation classes
Details
We add a new service to take care of generating the service ping payload. This is behind merge_service_ping_instrumented_metrics
feature flag.
The UsageData
class will not be used directly anymore.
UsageData
class will be used only in the new service
Proposed new service name: ServicePingReport
we can find a better name
-
Add the new service together with a test to check the integrity of the payload.
From @nicolasdular
We might want to have a "blackbox" test for the
ServicePingReport
class where we check ifServicePingMetrics.run
returns a given payload that is prepared as a fixture.
- The payload should stay the same when a metric gets removed from
usage_data.rb
and added as an Instrumentation class.- We can have multiple payload tests based on the data category in the future.
-
Use the new service to handle UsageDataNonSqlMetrics
,UsageDataQueries
. This can be done by having a parameter inrun(mode: 'values/queries/non_queries')
method in ServicePingMetrics -
Migrate first metric
Pseudo code of the new service class
class ServicePingReport
def for(output: 'all_metrics_values')
case mode
when :all_metrics_values
instrumentation_classes_values
when :metrics_queries
instrumentation_classes_queries
when :non_sql_metrics_values
instrumentation_classes_non_queries
end
end
private
def instrumentation_classes_values
# The metrics migrated will be removed from usage_data.rb and automatically computed here
# using the diff on keys present
# hash with values we migrate
# Build the old payload using usage_data.rb
old_payload = UsageData.uncached_data
# Get the metrics defintion
metrics_defintions_keys = Gitlab::Usage::MetricDefinition.with_instrumentation_class.map(:key_path)
# Do we have any missing values in old_payload?
missing_keys = metrics_defintions_keys - old_payload_keys(old_payload) # Build method to get the keys from the hash
if missing_keys.any?
old_payload.deep_merge(compute_missing_keys_using_instrumentation_classes)
end
old_payload
end
def instrumentation_classes_queries
UsageDataQueries.uncached_data.deep_merge(queries_hash)
end
def instrumentation_classes_non_queries
UsageData.uncached_data.deep_merge(non_queries_hash)
end
end
Related to #338029.