Commit bf44eb60 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch '221184-rolling-28-day-deployments-metrics' into 'master'

Rolling 28 day time period counter for deployments

See merge request gitlab-org/gitlab!35493
parents e880ed94 63c161ee
---
title: Rolling 28 day time period counter for deployments
merge_request: 35493
author:
type: added
......@@ -422,9 +422,12 @@ appear to be associated to any of the services running, since they all appear to
| `auto_devops_disabled` | `counts` | `configure` | | | Projects with Auto DevOps template disabled |
| `deploy_keys` | `counts` | | | | |
| `deployments` | `counts` | `release` | | | Total deployments |
| `deployments` | `counts_monthly` | `release` | | | Total deployments last 28 days |
| `dast_jobs` | `counts` | | | | |
| `successful_deployments` | `counts` | `release` | | | Total successful deployments |
| `successful_deployments` | `counts_monthly` | `release` | | | Total successful deployments last 28 days |
| `failed_deployments` | `counts` | `release` | | | Total failed deployments |
| `failed_deployments` | `counts_monthly` | `release` | | | Total failed deployments last 28 days |
| `environments` | `counts` | `release` | | | Total available and stopped environments |
| `clusters` | `counts` | `configure` | | | Total GitLab Managed clusters both enabled and disabled |
| `clusters_enabled` | `counts` | `configure` | | | Total GitLab Managed clusters currently enabled |
......
......@@ -170,6 +170,9 @@ module Gitlab
def system_usage_data_monthly
{
counts_monthly: {
deployments: count(Deployment.where(last_28_days_time_period)),
successful_deployments: count(Deployment.success.where(last_28_days_time_period)),
failed_deployments: count(Deployment.failed.where(last_28_days_time_period)),
personal_snippets: count(PersonalSnippet.where(last_28_days_time_period)),
project_snippets: count(ProjectSnippet.where(last_28_days_time_period))
}.tap do |data|
......
......@@ -7,7 +7,7 @@ FactoryBot.define do
tag { false }
user { nil }
project { nil }
deployable { association :ci_build, environment: environment.name, project: environment.project }
deployable { association :ci_build, environment: environment.name, pipeline: association(:ci_pipeline, project: environment.project) }
environment factory: :environment
after(:build) do |deployment, evaluator|
......
......@@ -5,7 +5,8 @@ FactoryBot.define do
skip_create # non-model factories (i.e. without #save)
initialize_with do
projects = create_list(:project, 4)
projects = create_list(:project, 3)
projects << create(:project, :repository)
create(:board, project: projects[0])
create(:jira_service, project: projects[0])
create(:jira_service, :without_properties_callback, project: projects[1])
......@@ -91,7 +92,11 @@ FactoryBot.define do
ProjectFeature.first.update_attribute('repository_access_level', 0)
# Create fresh & a month (28-days SMAU) old data
env = create(:environment, project: projects[3])
[2, 29].each do |n|
deployment_options = { created_at: n.days.ago, project: env.project, environment: env }
create(:deployment, :failed, deployment_options)
create(:deployment, :success, deployment_options)
create_list(:project_snippet, 2, project: projects[0], created_at: n.days.ago)
create(:personal_snippet, created_at: n.days.ago)
end
......
......@@ -130,7 +130,7 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
expect(subject[:counts_monthly]).to be_an(Hash)
end
it 'gathers projects data correctly' do
it 'gathers usage counts correctly' do
count_data = subject[:counts]
expect(count_data[:projects]).to eq(4)
......@@ -188,6 +188,9 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
expect(count_data[:clusters_applications_jupyter]).to eq(1)
expect(count_data[:clusters_management_project]).to eq(1)
expect(count_data[:deployments]).to eq(4)
expect(count_data[:successful_deployments]).to eq(2)
expect(count_data[:failed_deployments]).to eq(2)
expect(count_data[:snippets]).to eq(6)
expect(count_data[:personal_snippets]).to eq(2)
expect(count_data[:project_snippets]).to eq(4)
......@@ -274,9 +277,12 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
subject { described_class.system_usage_data_monthly }
it 'gathers projects data correctly' do
it 'gathers monthly usage counts correctly' do
counts_monthly = subject[:counts_monthly]
expect(counts_monthly[:deployments]).to eq(2)
expect(counts_monthly[:successful_deployments]).to eq(1)
expect(counts_monthly[:failed_deployments]).to eq(1)
expect(counts_monthly[:snippets]).to eq(3)
expect(counts_monthly[:personal_snippets]).to eq(1)
expect(counts_monthly[:project_snippets]).to eq(2)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment