Skip to content

Commit

Permalink
Workflow Execution logidze (#890)
Browse files Browse the repository at this point in the history
* Added logidze log_data column for workflow executions

* Added tests and updated blacklisting of columns

* Updated counts for log size and version that was missed in previous commit which blacklisted attachments_updated_at column

* Fixed rubocop warnings

* Regenerated new trigger and migration to whitelist the columns required

* Updated to include deleted_at in whitelist and updated migration to create logidze snapshots for existing workflow executions

* Updated db schema

* Fixed rubocop warning

* Fixed sql.squish rubocop warning
  • Loading branch information
deepsidhu85 authored Jan 10, 2025
1 parent d11b67d commit 9c15cbf
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 1 deletion.
24 changes: 24 additions & 0 deletions db/migrate/20250109162252_add_logidze_to_workflow_executions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# frozen_string_literal: true

# Migration to add Logidze to WorkflowExecutions table
class AddLogidzeToWorkflowExecutions < ActiveRecord::Migration[7.2]
def change
add_column :workflow_executions, :log_data, :jsonb

reversible do |dir|
dir.up do
create_trigger :logidze_on_workflow_executions, on: :workflow_executions

execute <<-SQL.squish
UPDATE "workflow_executions" as t SET log_data = logidze_snapshot(to_jsonb(t), 'created_at', '{"run_id","name","state","deleted_at"}', true);
SQL
end

dir.down do
execute <<~SQL.squish
DROP TRIGGER IF EXISTS "logidze_on_workflow_executions" on "workflow_executions";
SQL
end
end
end
end
6 changes: 5 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions db/triggers/logidze_on_workflow_executions_v01.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
CREATE TRIGGER "logidze_on_workflow_executions"
BEFORE UPDATE OR INSERT ON "workflow_executions" FOR EACH ROW
WHEN (coalesce(current_setting('logidze.disabled', true), '') <> 'on')
-- Parameters: history_size_limit (integer), timestamp_column (text), filtered_columns (text[]),
-- include_columns (boolean), debounce_time_ms (integer)
EXECUTE PROCEDURE logidze_logger(null, 'updated_at', '{run_id,name,state,deleted_at}', true);
9 changes: 9 additions & 0 deletions test/services/workflow_executions/cancel_service_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,23 @@ def setup
test 'cancel initial workflow_execution' do
@workflow_execution = workflow_executions(:irida_next_example_new)

@workflow_execution.create_logidze_snapshot!

assert 'initial', @workflow_execution.state
assert_equal 1, @workflow_execution.log_data.version
assert_equal 1, @workflow_execution.log_data.size

assert WorkflowExecutions::CancelService.new(@workflow_execution, @user).execute

assert_no_enqueued_jobs(except: Turbo::Streams::BroadcastStreamJob)

assert_equal 'canceled', @workflow_execution.reload.state
assert @workflow_execution.cleaned?

@workflow_execution.create_logidze_snapshot!
assert 'canceled', @workflow_execution.state
assert_equal 2, @workflow_execution.log_data.version
assert_equal 2, @workflow_execution.log_data.size
end
end
end
10 changes: 10 additions & 0 deletions test/services/workflow_executions/completion_service_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,13 @@ def setup # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
test 'sample outputs on samples_workflow_executions' do
workflow_execution = @workflow_execution_with_samples

workflow_execution.create_logidze_snapshot!

assert 'completing', workflow_execution.state

assert_equal 1, workflow_execution.log_data.version
assert_equal 1, workflow_execution.log_data.size

assert WorkflowExecutions::CompletionService.new(workflow_execution, {}).execute

assert_equal 'my_run_id_c', workflow_execution.run_id
Expand Down Expand Up @@ -298,8 +303,13 @@ def setup # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
assert_equal @normal2_output_analysis3_file_blob.filename, output3.filename
assert_equal @normal2_output_analysis3_file_blob.checksum, output3.file.checksum

workflow_execution.create_logidze_snapshot!

assert_equal 'completed', workflow_execution.state

assert_equal 2, workflow_execution.log_data.version
assert_equal 2, workflow_execution.log_data.size

assert_no_enqueued_emails

assert_nil PublicActivity::Activity.find_by(
Expand Down
6 changes: 6 additions & 0 deletions test/services/workflow_executions/create_service_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,12 @@ def setup

@workflow_execution = WorkflowExecutions::CreateService.new(@user, workflow_params).execute

@workflow_execution.create_logidze_snapshot!

assert 'initial', @workflow_execution.state
assert_equal 1, @workflow_execution.log_data.version
assert_equal 1, @workflow_execution.log_data.size

assert_equal test_name, @workflow_execution.name
expected_tags = { 'createdBy' => @user.email }
assert_equal expected_tags, @workflow_execution.tags
Expand Down
8 changes: 8 additions & 0 deletions test/services/workflow_executions/preparation_service_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ def setup
test 'prepare workflow_execution with valid params' do
assert @workflow_execution.initial?

@workflow_execution.create_logidze_snapshot!
assert_equal 1, @workflow_execution.log_data.version
assert_equal 1, @workflow_execution.log_data.size

assert_difference -> { ActiveStorage::Attachment.count } => 2 do
WorkflowExecutions::PreparationService.new(@workflow_execution, @user, {}).execute
end
Expand Down Expand Up @@ -42,6 +46,10 @@ def setup
assert_equal sample1_row, samplesheet_csv[1]

assert_equal 'prepared', @workflow_execution.state

@workflow_execution.create_logidze_snapshot!
assert_equal 2, @workflow_execution.log_data.version
assert_equal 2, @workflow_execution.log_data.size
end

test 'should return false since chosen pipeline is not executable' do
Expand Down

0 comments on commit 9c15cbf

Please sign in to comment.