Commit 00727526 authored by Adam Hegyi's avatar Adam Hegyi

Merge branch '335391-add-state-id-to-vsa-tables' into 'master'

Include state_id when gathering VSA data

See merge request gitlab-org/gitlab!72974
parents 621cb9c9 f576360f
......@@ -8,6 +8,9 @@ module Analytics
validates(*%i[stage_event_hash_id issue_id group_id project_id start_event_timestamp], presence: true)
alias_attribute :state, :state_id
enum state: Issue.available_states, _suffix: true
def self.issuable_id_column
:issue_id
end
......
......@@ -8,6 +8,9 @@ module Analytics
validates(*%i[stage_event_hash_id merge_request_id group_id project_id start_event_timestamp], presence: true)
alias_attribute :state, :state_id
enum state: MergeRequest.available_states, _suffix: true
def self.issuable_id_column
:merge_request_id
end
......
......@@ -15,6 +15,7 @@ module Analytics
:project_id,
:author_id,
:milestone_id,
:state_id,
:start_event_timestamp,
:end_event_timestamp
)
......@@ -31,6 +32,7 @@ module Analytics
project_id,
milestone_id,
author_id,
state_id,
start_event_timestamp,
end_event_timestamp
)
......@@ -39,10 +41,11 @@ module Analytics
DO UPDATE SET
group_id = excluded.group_id,
project_id = excluded.project_id,
start_event_timestamp = excluded.start_event_timestamp,
end_event_timestamp = excluded.end_event_timestamp,
milestone_id = excluded.milestone_id,
author_id = excluded.author_id
author_id = excluded.author_id,
state_id = excluded.state_id,
start_event_timestamp = excluded.start_event_timestamp,
end_event_timestamp = excluded.end_event_timestamp
SQL
result = connection.execute(query)
......
# frozen_string_literal: true
class AddStateIdToVsaIssueStageEvents < Gitlab::Database::Migration[1.0]
def change
add_column :analytics_cycle_analytics_issue_stage_events, :state_id, :smallint, default: 1, null: false
end
end
# frozen_string_literal: true
class AddStateIdToVsaMergeRequestStageEvents < Gitlab::Database::Migration[1.0]
def change
add_column :analytics_cycle_analytics_merge_request_stage_events, :state_id, :smallint, default: 1, null: false
end
end
56f86f2a20509f2052d0eab918a6d2bbb679d785cf5349916ba695aa92f0609f
\ No newline at end of file
1722382c5141157497f48b209c0fa60c5959fa16c53d09fb6e8e6b2cb6e6ab9b
\ No newline at end of file
This diff is collapsed.
......@@ -126,6 +126,7 @@ module Analytics
project_id: record['project_id'],
author_id: record['author_id'],
milestone_id: record['milestone_id'],
state_id: record['state_id'],
start_event_timestamp: record[event_column_name(stage.start_event)],
end_event_timestamp: record[event_column_name(stage.end_event)]
}
......@@ -146,6 +147,7 @@ module Analytics
model.arel_table[project_column].as('project_id'),
model.arel_table[:milestone_id],
model.arel_table[:author_id],
model.arel_table[:state_id],
Project.arel_table[:parent_id].as('group_id')
]
end
......
......@@ -103,7 +103,8 @@ RSpec.describe Analytics::CycleAnalytics::DataLoaderService do
mr.project.parent_id,
mr.project_id,
mr.created_at,
mr.metrics.merged_at
mr.metrics.merged_at,
mr.state_id
]
end
......@@ -116,7 +117,8 @@ RSpec.describe Analytics::CycleAnalytics::DataLoaderService do
event.group_id,
event.project_id,
event.start_event_timestamp,
event.end_event_timestamp
event.end_event_timestamp,
Analytics::CycleAnalytics::MergeRequestStageEvent.states[event.state_id]
]
end
......@@ -191,7 +193,8 @@ RSpec.describe Analytics::CycleAnalytics::DataLoaderService do
issue.project.parent_id,
issue.project_id,
issue.created_at,
issue.closed_at
issue.closed_at,
issue.state_id
]
end
......@@ -204,7 +207,8 @@ RSpec.describe Analytics::CycleAnalytics::DataLoaderService do
event.group_id,
event.project_id,
event.start_event_timestamp,
event.end_event_timestamp
event.end_event_timestamp,
Analytics::CycleAnalytics::IssueStageEvent.states[event.state_id]
]
end
......
......@@ -18,8 +18,8 @@ RSpec.describe 'Database schema' do
approvals: %w[user_id],
approver_groups: %w[target_id],
approvers: %w[target_id user_id],
analytics_cycle_analytics_merge_request_stage_events: %w[author_id group_id merge_request_id milestone_id project_id stage_event_hash_id],
analytics_cycle_analytics_issue_stage_events: %w[author_id group_id issue_id milestone_id project_id stage_event_hash_id],
analytics_cycle_analytics_merge_request_stage_events: %w[author_id group_id merge_request_id milestone_id project_id stage_event_hash_id state_id],
analytics_cycle_analytics_issue_stage_events: %w[author_id group_id issue_id milestone_id project_id stage_event_hash_id state_id],
audit_events: %w[author_id entity_id target_id],
award_emoji: %w[awardable_id user_id],
aws_roles: %w[role_external_id],
......
......@@ -9,5 +9,9 @@ RSpec.describe Analytics::CycleAnalytics::IssueStageEvent do
it { is_expected.to validate_presence_of(:project_id) }
it { is_expected.to validate_presence_of(:start_event_timestamp) }
it 'has state enum' do
expect(described_class.states).to eq(Issue.available_states)
end
it_behaves_like 'StageEventModel'
end
......@@ -9,5 +9,9 @@ RSpec.describe Analytics::CycleAnalytics::MergeRequestStageEvent do
it { is_expected.to validate_presence_of(:project_id) }
it { is_expected.to validate_presence_of(:start_event_timestamp) }
it 'has state enum' do
expect(described_class.states).to eq(MergeRequest.available_states)
end
it_behaves_like 'StageEventModel'
end
......@@ -12,6 +12,7 @@ RSpec.shared_examples 'StageEventModel' do
project_id: 4,
author_id: 5,
milestone_id: 6,
state_id: 1,
start_event_timestamp: time,
end_event_timestamp: time
},
......@@ -22,6 +23,7 @@ RSpec.shared_examples 'StageEventModel' do
project_id: 11,
author_id: 12,
milestone_id: 13,
state_id: 1,
start_event_timestamp: time,
end_event_timestamp: time
}
......@@ -36,6 +38,7 @@ RSpec.shared_examples 'StageEventModel' do
:project_id,
:milestone_id,
:author_id,
:state_id,
:start_event_timestamp,
:end_event_timestamp
]
......@@ -59,7 +62,13 @@ RSpec.shared_examples 'StageEventModel' do
upsert_data
output_data = described_class.all.map do |record|
column_order.map { |column| record[column] }
column_order.map do |column|
if column == :state_id
described_class.states[record[column]]
else
record[column]
end
end
end.sort
expect(input_data.map(&:values).sort).to eq(output_data)
......
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