Skip to content

Draft: Use instrumented classes in Usage Ping [RUN ALL RSPEC] [RUN AS-IF-FOSS]

What does this MR do?

  • Add feature flag usage_ping_with_instrumentation_classes
  • Add Gitlab::Usage::UsageDataInstrumentation class where we merge hash generated with usage_data.rb with hash generated with instrumentation classes if feature enabled in SubmitUsagePingService
  • Use Gitlab::Usage::UsageDataInstrumentation in app/services/submit_usage_ping_service.rb
  • Use Gitlab::Usage::UsageDataInstrumentation in lib/tasks/gitlab/usage_data.rake rake taskthat generates usage ping payload
  • Use Gitlab::Usage::UsageDataInstrumentation in app/controllers/admin/application_settings_controller.rb this is in admin side where we can preview usage ping
  • Use Gitlab::Usage::UsageDataInstrumentation in app/controllers/admin/instance_review_controller.rb this is .../admin/instance_review
  • Use Gitlab::Usage::UsageDataInstrumentation in ee/spec/config/metrics/every_metric_definition_spec.rb

If feature usage_ping_with_instrumentation_classes is enabled then we merged data generated with instrumentation classes and we do not add the metrics instrumented in usage_data.rb

If the feature is disabled we compute all metrics in usage_data.rb including the ones that have instrumentation classes

Metrics that have instrumentation classes are:

Note:

This should be merged in %14.1

Screenshots (strongly suggested)

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

  • Test usage ping service in rails console with featured enabled and disabled we should get the same payload.
Feature.disable(:usage_data_instrumentation)
SubmitUsagePingService.new.execute
old = RawUsageData.last.payload
puts Gitlab::Json.pretty_generate(old)

Feature.enable(:usage_data_instrumentation)
SubmitUsagePingService.new.execute
new = RawUsageData.last.payload
puts Gitlab::Json.pretty_generate(new)

# Check the values for instrumented classes old should be equal with new
[18] pry(main)> old['counts']['issues']
=> 14
[19] pry(main)> old['counts']['boards']
=> 2
[20] pry(main)> old["usage_activity_by_stage_monthly"]["plan"]["issues"]
=> 1
[21] pry(main)> old["redis_hll_counters"]["quickactions"]["i_quickactions_approve_monthly"]
=> 0
[22] pry(main)> old["redis_hll_counters"]["quickactions"]["i_quickactions_approve_weekly"]
=> 0
[23] pry(main)> old["usage_activity_by_stage"]["plan"]["issues"]
=> 2
[24] pry(main)> old["instance_auto_devops_enabled"]
=> true
[25] pry(main)> new['counts']['issues']


[27] pry(main)> new['counts']['issues']
=> 14
[28] pry(main)> new['counts']['boards']
=> 2
[29] pry(main)> new["usage_activity_by_stage_monthly"]["plan"]["issues"]
=> 1
[32] pry(main)> new["redis_hll_counters"]["quickactions"]["i_quickactions_approve_monthly"]
=> 0
[33] pry(main)> new["redis_hll_counters"]["quickactions"]["i_quickactions_approve_weekly"]
=> 0
[34] pry(main)> new["usage_activity_by_stage"]["plan"]["issues"]
=> 2
[35] pry(main)> new["instance_auto_devops_enabled"]
=> true

Use diff

diff old.json new.json 
➜ diff new.json old.json 
567c567
<     "duration_s": 0.17775100003927946
---
>     "duration_s": 0.18792900000698864
570c570
<   "recorded_at": "2021-06-15T06:36:34.157Z",
---
>   "recorded_at": "2021-06-15T06:33:14.062Z",
1943,1944c1943,1944
<   "recording_ce_finished_at": "2021-06-15T06:36:47.544Z",
<   "recording_ee_finished_at": "2021-06-15T06:36:47.544Z",
---
>   "recording_ce_finished_at": "2021-06-15T06:33:28.977Z",
>   "recording_ee_finished_at": "2021-06-15T06:33:28.977Z",

This is ok to be different, as these are timestamps

Security

Does this MR contain changes to processing or storing of credentials or tokens, authorization and authentication methods or other items described in the security review guidelines? If not, then delete this Security section.

  • Label as security and @ mention @gitlab-com/gl-security/appsec
  • The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • Security reports checked/validated by a reviewer from the AppSec team

Related to #330842 (closed)

Edited by Alina Mihaila

Merge request reports