Use DeploymentsFinder in VSA [RUN ALL RSPEC] [RUN AS-IF-FOSS]
What does this MR do?
Use finished_at (instead of created_at) for calculating deployment frequency in value stream analytics.
Additionally there is a refactor to merge DeploymenysFinder
and Analytics::DeploymentsFinder
to avoid duplicated functionality.
Value stream analytics is also available on the group level, so I added an option to query group level deployments.
The new deployment queries for VSA are behind a feature flag: query_deploymenys_via_finished_at_in_vsa
Queries
Project level:
SELECT COUNT(*) FROM "deployments" WHERE "deployments"."project_id" = 278964 AND "deployments"."status" = 2 AND (finished_at >= '2021-01-04 16:40:54.913319')
Plan: https://explain.depesz.com/s/gYpx
Group level:
SELECT count(*) FROM "deployments" WHERE "deployments"."project_id" IN (SELECT "projects"."id" FROM "projects" WHERE "projects"."namespace_id" IN (WITH RECURSIVE "base_and_descendants" AS ((SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = 9970)
UNION
(SELECT "namespaces".* FROM "namespaces", "base_and_descendants" WHERE "namespaces"."type" = 'Group' AND "namespaces"."parent_id" = "base_and_descendants"."id")) SELECT "namespaces"."id" FROM "base_and_descendants" AS "namespaces")) AND "deployments"."status" = 2 AND (deployments.finished_at > '2021-01-05 00:00:00') AND (deployments.finished_at < '2021-02-03 23:59:59.999999')
Plan: https://explain.depesz.com/s/Rhgm
Note: this query plan has cached timings. The execution time is around 1s which is similar to the old query (so the performance didn't get worse): https://explain.depesz.com/s/odnU
Old query:
SELECT COUNT(*) FROM "deployments" INNER JOIN "projects" ON "projects"."id" = "deployments"."project_id" INNER JOIN routes rs ON rs.source_id = projects.id AND rs.source_type = 'Project' WHERE (rs.path LIKE 'gitlab-org/%') AND (deployments.created_at > '2021-01-05 00:00:00') AND (deployments.created_at < '2021-02-03 23:59:59.999999') AND "deployments"."status" = 2
Screenshots (strongly suggested)
Does this MR meet the acceptance criteria?
Conformity
-
Changelog entry -
Documentation (if required) -
Code review guidelines -
Merge request performance guidelines -
Style guides -
Database guides -
Separation of EE specific content
Availability and Testing
-
Review and add/update tests for this feature/bug. Consider all test levels. See the Test Planning Process. -
Tested in all supported browsers -
Informed Infrastructure department of a default or new setting change, if applicable per definition of done
Security
If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:
-
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 #300193 (closed)