Add feature to run adherence report scan on demand
Description
Add the ability at group level to run an adherence report scan manually. Check out the related frontend issue for designs.
Implementation Plan
- Create a GraphQL mutation to trigger the adherence checks for all the projects within that group.
runStandardsAdherenceChecks(input: {groupPath: "flightjs"}) {
errors,
adherenceChecksStatus{
startedAt: Types::TimeType,
adherenceChecksCompleted: GraphQL::Types::Int,
totalAdherenceChecks: GraphQL::Types::Int
}
}
- We need to show the progress of the running checks on the UI, we can rely on Redis for storing that information.
- Create a class similar to
InactiveProjectsDeletionWarningTracker
for tracking the status/progress of the running adherence checks in redis. - Create a new redis key named
group:{id}:progress_of_standards_adherence_checks
of hash type. This hash would contain the following information{started_at: <timestamp when the running of checks was started>, total_checks: <number of projects multiplied by number of checks>, checks_completed: <total checks completed>}
. This will be used for displaying the progress on frontend. - Create a new param
track_progress
for theGroupBaseWorker
class. Only when this param is passed to the worker, we track the status of checks in Redis. This logic can be hooked inside theComplianceManagement::Standards::Gitlab::BaseService
class and we increase the value ofchecks_completed
by 1 whenever a check is completed. We should do this by using the HINCRBY command to avoid any race conditions where two different workers try to increment this key.
- Create a class similar to
- If the GraphQL API is called again while the checks are being run, we can check if redis key
group:{id}:progress_of_standards_adherence_checks
exists and return the appropriate status. - Set the TTL of the above key to 24 hours, so that the users don't abuse the feature by running the scan for the group multiple times. This will prevent running the checks again within 24 hours even though if they are completed. (Need to confirm this from product).
Edited by Huzaifa Iftikhar