Fix every metric definition test
Background
There is every metric definition spec that checks if every metric present in ServicePing payload has corresponding metrics definition. Recently there were issue https://gitlab.com/gitlab-data/product-analytics/-/issues/289#note_845118169, when metric was missing a definition but test did not catch this problem
Goal
Improve every metric definition spec to catch such cases during test phase
Implementation
- Use
BuildPayloadService
instead ofServicePingReport
because payload fromServicePingReport
is later filtered byBuildPayloadService
before being reported - Add new test assuring that there are no unused instrumentation classes, some half baked implementation might look like
context 'every instrumentation class is used' do
def assert_on_metric_classes(parent_namespace)
parent_namespace.constants.each do |const_name|
constant = Gitlab::Usage::Metrics::Instrumentations.const_get(const_name)
if constant.is_a? Class
metric_class_instance = instance_double(constant)
expect(constant).to receive(:new).at_least(:once).and_return(metric_class_instance)
expect(metric_class_instance).to receive(:value).at_least(:once).and_return(123)
elsif constant.is_a? Module
assert_on_metric_classes(constant)
end
end
end
it '' do
assert_on_metric_classes(Gitlab::Usage::Metrics::Instrumentations)
usage_ping
end
end