From 9c33449367f2cc7dffea5a07a937864880ec59cd Mon Sep 17 00:00:00 2001 From: Leonardo Rosa Date: Thu, 29 May 2025 11:45:19 -0300 Subject: [PATCH 1/7] Adds a warning when a migration is deleting data --- notifier/feedback.rb | 9 + notifier/migration.rb | 4 + notifier/query.rb | 5 + .../migration-testing/v4/expected-comment.txt | 124 +++++++++- .../v4/expected-migration-failure-notice.txt | 2 +- .../batch_1/batch-details.json | 10 + .../batch_1/migration-stats.json | 170 ++++++++++++++ .../batch_1/migration.log | 41 ++++ .../batch_1/query-details.json | 134 +++++++++++ .../batch_1/transaction-duration.json | 12 + .../DeleteUsersBatchedMigration/details.json | 5 + .../migration-stats.json | 220 ++++++++++++++++++ .../DeleteDataFromIssuesTable/migration.log | 44 ++++ .../query-details.json | 158 +++++++++++++ .../transaction-duration.json | 7 + .../migration-testing/v4/migrations.json | 14 ++ notifier/spec/migration_spec.rb | 15 +- notifier/templates/detail.erb | 3 + ...ersible_delete_from_statements_warning.erb | 9 + 19 files changed, 973 insertions(+), 13 deletions(-) create mode 100644 notifier/spec/fixtures/migration-testing/v4/main/background_migrations/DeleteUsersBatchedMigration/batch_1/batch-details.json create mode 100644 notifier/spec/fixtures/migration-testing/v4/main/background_migrations/DeleteUsersBatchedMigration/batch_1/migration-stats.json create mode 100644 notifier/spec/fixtures/migration-testing/v4/main/background_migrations/DeleteUsersBatchedMigration/batch_1/migration.log create mode 100644 notifier/spec/fixtures/migration-testing/v4/main/background_migrations/DeleteUsersBatchedMigration/batch_1/query-details.json create mode 100644 notifier/spec/fixtures/migration-testing/v4/main/background_migrations/DeleteUsersBatchedMigration/batch_1/transaction-duration.json create mode 100644 notifier/spec/fixtures/migration-testing/v4/main/background_migrations/DeleteUsersBatchedMigration/details.json create mode 100644 notifier/spec/fixtures/migration-testing/v4/main/up/DeleteDataFromIssuesTable/migration-stats.json create mode 100644 notifier/spec/fixtures/migration-testing/v4/main/up/DeleteDataFromIssuesTable/migration.log create mode 100644 notifier/spec/fixtures/migration-testing/v4/main/up/DeleteDataFromIssuesTable/query-details.json create mode 100644 notifier/spec/fixtures/migration-testing/v4/main/up/DeleteDataFromIssuesTable/transaction-duration.json create mode 100644 notifier/templates/irreversible_delete_from_statements_warning.erb diff --git a/notifier/feedback.rb b/notifier/feedback.rb index bec0629b..eb0daf39 100644 --- a/notifier/feedback.rb +++ b/notifier/feedback.rb @@ -31,6 +31,7 @@ class Feedback b = binding b.local_variable_set(:create_table_queries, migration.create_table_queries) b.local_variable_set(:create_index_queries, migration.create_index_queries) + b.local_variable_set(:delete_from_queries, migration.delete_from_queries) b.local_variable_set(:exceeds_time_guidance, migration.exceeds_time_guidance?) erb('detail').result(b) end @@ -90,6 +91,14 @@ class Feedback ) end + def render_deleted_from_warning(delete_from_queries) + erb('irreversible_delete_from_statements_warning').result_with_hash( + reference_url: "https://docs.gitlab.com/development/database_review/#preparation-when-adding-data-migrations", + queries: delete_from_queries, + plural: delete_from_queries.size > 1 + ) + end + def render_background_migration_batch_histogram(background_migration) Charts::ExecutionHistogram.for_background_migration_batches(background_migration).render end diff --git a/notifier/migration.rb b/notifier/migration.rb index b2c4ec82..7e6bb8d2 100644 --- a/notifier/migration.rb +++ b/notifier/migration.rb @@ -163,6 +163,10 @@ class Migration important_queries.select(&:create_index?) end + def delete_from_queries + important_queries.select(&:delete_from?) + end + def name_formatted "#{version} - #{name}" end diff --git a/notifier/query.rb b/notifier/query.rb index d83e194e..0cf57cf4 100644 --- a/notifier/query.rb +++ b/notifier/query.rb @@ -11,6 +11,7 @@ class Query TIMING_GUIDELINES = 'https://docs.gitlab.com/ee/development/database/query_performance.html#timing-guidelines-for-queries' CREATE_TABLE_STATMENT = 'create table' CREATE_INDEX_STATEMENT = 'create index' + DELETE_FROM_STATEMENT = 'delete from' COMMENT_TOKENS = [:C_COMMENT, :SQL_COMMENT].freeze attr_accessor :query, :calls, :total_time, :max_time, :mean_time, :rows, @@ -117,6 +118,10 @@ class Query query.downcase.include?(CREATE_INDEX_STATEMENT) end + def delete_from? + query.downcase.include?(DELETE_FROM_STATEMENT) + end + private def pg_statement diff --git a/notifier/spec/fixtures/migration-testing/v4/expected-comment.txt b/notifier/spec/fixtures/migration-testing/v4/expected-comment.txt index e1b770bf..19f19813 100644 --- a/notifier/spec/fixtures/migration-testing/v4/expected-comment.txt +++ b/notifier/spec/fixtures/migration-testing/v4/expected-comment.txt @@ -3,7 +3,7 @@ *Commit SHA:* 20c0da84ee54eee5ccfdd1720dbda853d1dfa8ba -| | 8 Warnings | +| | 9 Warnings | | --------- | -------------------- | | :warning: | 20210602144718 - CreateTestTable had a query that [exceeded timing guidelines](https://docs.gitlab.com/ee/development/database/query_performance.html#timing-guidelines-for-queries). Run time should not
exceed 100ms, but it was 192.8ms. Please consider possible options to improve the query performance.

CREATE TABLE "test_tables" ("id" bigserial primary key, "stars" bigint DEFAULT 0 NOT NULL,
"created_at" timestamp(6) NOT NULL, "updated_at" timestamp(6) NOT NULL, "title" text, "notes"
text)
| | :warning: | 20210603233011 - RegularMigrationWithFiveSecondQuery had a query that [exceeded timing guidelines](https://docs.gitlab.com/ee/development/database/query_performance.html#timing-guidelines-for-queries).
Run time should not exceed 100ms, but it was 5005.1ms. Please consider possible options to improve
the query performance.
SELECT pg_sleep($1)
| @@ -12,6 +12,7 @@ | :warning: | 20221012000001 - CreateLongRunningSyncIndex had a query that [exceeded timing guidelines](https://docs.gitlab.com/ee/development/database/query_performance.html#timing-guidelines-for-queries). Run time
should not exceed 300000ms, but it was 5377900.06ms. Please consider possible options to improve the
query performance.
CREATE INDEX CONCURRENTLY "tmp_index_for_null_member_namespace_id" ON
"members" ("member_namespace_id")
WHERE member_namespace_id IS NULL
| | :warning: | 20221012000001 - CreateLongRunningSyncIndex took 93.33min. Please add a comment that mentions
Release Managers (`@gitlab-org/release/managers`) so they are informed. | | :warning: | 20221012000001 - CreateLongRunningSyncIndex may need a [batched background migration](https://docs.gitlab.com/ee/development/database/batched_background_migrations.html) to comply with
[timing guidelines](https://docs.gitlab.com/ee/development/migration_style_guide.html#how-long-a-migration-should-take). It took 93.33min, but should not exceed 3.0min | +| :warning: | 20250521194808 - DeleteDataFromIssuesTable had a query that [exceeded timing guidelines](https://docs.gitlab.com/ee/development/database/query_performance.html#timing-guidelines-for-queries). Run time
should not exceed 100ms, but it was 1761.64ms. Please consider possible options to improve the query
performance.
DELETE
FROM "issues"WHERE "issues"."id" IN (
SELECT "issues"."id" FROM "issues" LIMIT $1
)
| | :warning: | 20990604233157 - MigrationThrowsException did not complete successfully, check the job log for
details | Migrations included in this change have been executed on gitlab.com data for testing purposes. For details, please see the [migration testing pipeline](https://gitlab.com/gitlab-org/database-team/gitlab-com-database-testing/-/pipelines/4711) (limited access). @@ -27,6 +28,7 @@ Migrations included in this change have been executed on gitlab.com data for tes | 20221012000001 - CreateLongRunningSyncIndex | Regular | 5600.3 s | :warning: | +32.00 KiB | | 20221130142531 - CreateEfficientlyOrderedColumnsTable | Regular | 1.2 s | :white_check_mark: | +32.00 KiB | | 20221130142617 - CreateInefficientlyOrderedColumnsTable | Regular | 1.2 s | :white_check_mark: | +40.00 KiB | +| 20250521194808 - DeleteDataFromIssuesTable | Regular | 5.6 s | :warning: | +0.00 B | | 20210604232017 - DropTestTable | Post deploy | 1.3 s | :white_check_mark: | -24.00 KiB | | 20990604233157 - MigrationThrowsException | Post deploy | 1.1 s | :boom: | +0.00 B | @@ -37,8 +39,8 @@ Migrations included in this change have been executed on gitlab.com data for tes |---------------|-------| |0 seconds - 0.01 seconds | 0 | |0.01 seconds - 0.1 seconds | 8 | -|0.1 seconds - 1 second | 1 | -|1 second - 5 seconds | 0 | +|0.1 seconds - 1 second | 4 | +|1 second - 5 seconds | 1 | |5 seconds - 15 seconds | 1 | |15 seconds - 5 minutes | 0 | |5 minutes + | 1 | @@ -269,6 +271,40 @@ Please examine the timing data on this query and consider if the [asynchronous i +
+ :warning:

Migration: 20250521194808 - DeleteDataFromIssuesTable

+* Type: Regular
+* Duration: 5.6 s
+* Database size change: +0.00 B + +| Calls | Total Time | Max Time | Mean Time | Rows | Query | +| ----- | ---------- | -------- | --------- | ---- | ----- | +| 1 | 1761.6 ms | 1761.6 ms | 1761.6 ms | 10 |
DELETE
FROM "issues"WHERE "issues"."id" IN (
SELECT "issues"."id" FROM "issues" LIMIT $1
)
| +| 1 | 0.1 ms | 0.1 ms | 0.1 ms | 1 |
SELECT "feature_gates"."key", "feature_gates"."value"  FROM "feature_gates"  WHERE "feature_gates"."feature_key" = $1
| +| 2 | 0.0 ms | 0.0 ms | 0.0 ms | 2 |
SELECT pg_backend_pid()
| + +#### :warning: Irreversible data changes statements (DELETE FROM) + +An irreversible statement was detected for this migration. + +Make sure you are following the [guidelines](https://docs.gitlab.com/development/database_review/#preparation-when-adding-data-migrations) for irreversible data operations. + +
+Histogram for DeleteDataFromIssuesTable + +| Query Runtime | Count | +|---------------|-------| +|0 seconds - 0.01 seconds | 0 | +|0.01 seconds - 0.1 seconds | 0 | +|0.1 seconds - 1 second | 3 | +|1 second - 5 seconds | 1 | +|5 seconds - 15 seconds | 0 | +|15 seconds - 5 minutes | 0 | +|5 minutes + | 0 | + +
+ +

Migration: 20210604232017 - DropTestTable

* Type: Post deploy
@@ -373,6 +409,71 @@ Please examine the timing data on this query and consider if the [asynchronous i
+ +
+ :boom:

Background Migration: DeleteUsersBatchedMigration

+ +
+Sampled 1 batches. Estimated Time to complete: 4 weeks, 11 hours, 21 minutes, and 11 seconds + + - Interval: 120s + - Max batch size: 0 + - Estimated seconds to complete: 2460071s + - Average batch time: 122.85s + - Batch size: 1000 + - N. of batches sampled: 1 + - N. of failed batches: 1 + - Failed batches: batch_1 + + Time estimation is conservative and based on sampling production data in a test environment. It represents the max time that migration could take. The actual time may differ from this estimation. +
+ +_Consider changing max_batch_size and interval if this estimate is unacceptable._ + + +| Calls | Total Time | Max Time | Mean Time | Rows | Query | +| ----- | ---------- | -------- | --------- | ---- | ----- | +| 1 | 1.0 ms | 1.0 ms | 1.0 ms | 1 |
INSERT INTO batched_background_migration_job_transition_logs (batched_background_migration_job_id, created_at, updated_at, previous_status, next_status) VALUES ($1, $2, $3, $4, $5) RETURNING id
| +| 1 | 0.9 ms | 0.9 ms | 0.9 ms | 1 |
UPDATE batched_background_migration_jobs
SET updated_at = $1, sub_batch_size = $2
WHERE batched_background_migration_jobs.id = $3
| +| 1 | 0.4 ms | 0.4 ms | 0.4 ms | 1 |
INSERT INTO batched_background_migration_job_transition_logs (batched_background_migration_job_id, created_at, updated_at, previous_status, next_status, exception_class, exception_message) VALUES ($1, $2, $3, $4, $5, $6, $7) RETURNING id
| +| 1 | 0.4 ms | 0.4 ms | 0.4 ms | 1 |
UPDATE batched_background_migration_jobs
SET updated_at = $1, finished_at = $2, status = $3
WHERE batched_background_migration_jobs.id = $4
| +| 1 | 0.2 ms | 0.2 ms | 0.2 ms | 1 |
UPDATE batched_background_migration_jobs
SET updated_at = $1, started_at = $2, status = $3, attempts = $4
WHERE batched_background_migration_jobs.id = $5
| +| 1 | 0.1 ms | 0.1 ms | 0.1 ms | 1 |
SELECT sum(batched_background_migration_jobs.batch_size)
FROM batched_background_migration_jobs
WHERE batched_background_migration_jobs.batched_background_migration_id = $1 AND batched_background_migration_jobs.status IN ($2)
| +| 1 | 0.0 ms | 0.0 ms | 0.0 ms | 1 |
SELECT batched_background_migration_jobs.*
FROM batched_background_migration_jobs
WHERE batched_background_migration_jobs.id = $1
LIMIT $2 FOR UPDATE
| +| 2 | 0.1 ms | 0.0 ms | 0.0 ms | 2 |
SELECT batched_background_migration_jobs.*
FROM batched_background_migration_jobs
WHERE batched_background_migration_jobs.id = $1
LIMIT $2
| +| 1 | 0.0 ms | 0.0 ms | 0.0 ms | 1 |
SELECT batched_background_migrations.*
FROM batched_background_migrations
WHERE batched_background_migrations.id = $1
LIMIT $2
| +| 1 | 0.0 ms | 0.0 ms | 0.0 ms | 1 |
SELECT users.id
FROM users
WHERE users.id = $1 AND users.id = $2
ORDER BY users.id ASC
LIMIT $3
| +| 1 | 0.0 ms | 0.0 ms | 0.0 ms | 0 |
SELECT users.id
FROM users
WHERE users.id = $1 AND users.id = $2 AND users.id >= $3
ORDER BY users.id ASC
LIMIT $4
OFFSET $5
| +| 1 | 0.0 ms | 0.0 ms | 0.0 ms | 0 |
SELECT feature_gates.key, feature_gates.value
FROM feature_gates
WHERE feature_gates.feature_key = $1
| + +
+Histogram of batch runtimes for DeleteUsersBatchedMigration + +| Batch Runtime | Count | +|---------------|-------| +|0 seconds - 10 seconds | 0 | +|10 seconds - 1 minute | 0 | +|1 minute - 2 minutes | 0 | +|2 minutes - 3 minutes | 1 | +|3 minutes - 5 minutes | 0 | +|5 minutes + | 0 | + +
+ +
+Histogram across all sampled batches of DeleteUsersBatchedMigration + +| Query Runtime | Count | +|---------------|-------| +|0 seconds - 0.1 seconds | 11 | +|0.1 seconds - 0.5 seconds | 2 | +|0.5 seconds - 1 second | 0 | +|1 second - 2 seconds | 0 | +|2 seconds - 5 seconds | 0 | +|5 seconds + | 1 | + +
+
#### Other information @@ -421,12 +522,17 @@ MjEwNzE3NTI5MDU4NDU2NCwidG90YWxfZGF0YWJhc2Vfc2l6ZV9jaGFuZ2Ui OjMyNzY4LCJzdWNjZXNzIjp0cnVlfSx7InZlcnNpb24iOnsidGltZXN0YW1w IjoyMDIyMTEzMDE0MjYxN30sIndhbGx0aW1lIjoxLjIxODAyMTgxMDA1NDc3 OSwidG90YWxfZGF0YWJhc2Vfc2l6ZV9jaGFuZ2UiOjQwOTYwLCJzdWNjZXNz -Ijp0cnVlfSx7InZlcnNpb24iOnsidGltZXN0YW1wIjoyMDIxMDYwNDIzMjAx -N30sIndhbGx0aW1lIjoxLjI5NDE0MzEyNTQxNDg0ODMsInRvdGFsX2RhdGFi -YXNlX3NpemVfY2hhbmdlIjotMjQ1NzYsInN1Y2Nlc3MiOnRydWV9LHsidmVy -c2lvbiI6eyJ0aW1lc3RhbXAiOjIwOTkwNjA0MjMzMTU3fSwid2FsbHRpbWUi -OjEuMDYwOTI0NTAwMjI2OTc0NSwidG90YWxfZGF0YWJhc2Vfc2l6ZV9jaGFu -Z2UiOjAsInN1Y2Nlc3MiOmZhbHNlfV19 +Ijp0cnVlfSx7InZlcnNpb24iOnsidGltZXN0YW1wIjoyMDI1MDUyMTE5NDgw +OCwibWlsZXN0b25lIjp7Im1ham9yIjoxOCwibWlub3IiOjEsInBhdGNoIjow +LCJzdWZmaXhfcyI6IiIsInN1ZmZpeCI6W119LCJ0eXBlX3ZhbHVlIjowfSwi +d2FsbHRpbWUiOjUuNTU4NzI1NjQwMTc3NzI3LCJ0b3RhbF9kYXRhYmFzZV9z +aXplX2NoYW5nZSI6MCwic3VjY2VzcyI6dHJ1ZX0seyJ2ZXJzaW9uIjp7InRp +bWVzdGFtcCI6MjAyMTA2MDQyMzIwMTd9LCJ3YWxsdGltZSI6MS4yOTQxNDMx +MjU0MTQ4NDgzLCJ0b3RhbF9kYXRhYmFzZV9zaXplX2NoYW5nZSI6LTI0NTc2 +LCJzdWNjZXNzIjp0cnVlfSx7InZlcnNpb24iOnsidGltZXN0YW1wIjoyMDk5 +MDYwNDIzMzE1N30sIndhbGx0aW1lIjoxLjA2MDkyNDUwMDIyNjk3NDUsInRv +dGFsX2RhdGFiYXNlX3NpemVfY2hhbmdlIjowLCJzdWNjZXNzIjpmYWxzZX1d +fQ== --> ### Database migrations (on the ci database) diff --git a/notifier/spec/fixtures/migration-testing/v4/expected-migration-failure-notice.txt b/notifier/spec/fixtures/migration-testing/v4/expected-migration-failure-notice.txt index a74c2233..b684c060 100644 --- a/notifier/spec/fixtures/migration-testing/v4/expected-migration-failure-notice.txt +++ b/notifier/spec/fixtures/migration-testing/v4/expected-migration-failure-notice.txt @@ -16,5 +16,5 @@ MR can be merged. | Database | Migration Name | |----------|----------------| -| main | TestBackgroundMigration | +| main | DeleteUsersBatchedMigration | | sec | TestBackgroundMigration | diff --git a/notifier/spec/fixtures/migration-testing/v4/main/background_migrations/DeleteUsersBatchedMigration/batch_1/batch-details.json b/notifier/spec/fixtures/migration-testing/v4/main/background_migrations/DeleteUsersBatchedMigration/batch_1/batch-details.json new file mode 100644 index 00000000..0b56227c --- /dev/null +++ b/notifier/spec/fixtures/migration-testing/v4/main/background_migrations/DeleteUsersBatchedMigration/batch_1/batch-details.json @@ -0,0 +1,10 @@ +{ + "time_spent": 122.85, + "min_value": 12972700, + "max_value": 12972700, + "batch_size": 1000, + "sub_batch_size": 100, + "pause_ms": 100, + "min_cursor": null, + "max_cursor": null +} diff --git a/notifier/spec/fixtures/migration-testing/v4/main/background_migrations/DeleteUsersBatchedMigration/batch_1/migration-stats.json b/notifier/spec/fixtures/migration-testing/v4/main/background_migrations/DeleteUsersBatchedMigration/batch_1/migration-stats.json new file mode 100644 index 00000000..46cac11a --- /dev/null +++ b/notifier/spec/fixtures/migration-testing/v4/main/background_migrations/DeleteUsersBatchedMigration/batch_1/migration-stats.json @@ -0,0 +1,170 @@ +{ + "version": null, + "name": "batch_1", + "walltime": 122.56930105388165, + "success": false, + "total_database_size_change": 81920, + "error_message": "PG::QueryCanceled: ERROR: canceling statement due to statement timeout\nCONTEXT: SQL statement \"UPDATE ONLY \"public\".\"merge_requests\" SET \"merge_user_id\" = NULL WHERE $1 OPERATOR(pg_catalog.=) \"merge_user_id\"\"\n", + "query_statistics": [ + { + "query": "select pg_database_size(current_database()) /*application:test,correlation_id:a1e2cc3c3c66b34934ab82ee9a40c9b7,db_config_database:gitlabhq_dblab,db_config_name:main,line:/lib/gitlab/database/migrations/observers/total_database_size_change.rb:25:in `get_total_database_size'*/", + "calls": 1, + "total_time": 180.23814199999998, + "max_time": 180.23814199999998, + "mean_time": 180.23814199999998, + "rows": 1 + }, + { + "query": "SELECT a.attname\n FROM (\n SELECT indrelid, indkey, generate_subscripts(indkey, $1) idx\n FROM pg_index\n WHERE indrelid = $2::regclass\n AND indisprimary\n ) i\n JOIN pg_attribute a\n ON a.attrelid = i.indrelid\n AND a.attnum = i.indkey[i.idx]\n ORDER BY i.idx", + "calls": 1, + "total_time": 1.614262, + "max_time": 1.614262, + "mean_time": 1.614262, + "rows": 1 + }, + { + "query": "INSERT INTO \"batched_background_migration_job_transition_logs\" (\"batched_background_migration_job_id\", \"created_at\", \"updated_at\", \"previous_status\", \"next_status\") VALUES ($1, $2, $3, $4, $5) RETURNING \"id\" /*application:test,db_config_database:gitlabhq_dblab,db_config_name:main,line:/lib/gitlab/database.rb:394:in `transaction'*/", + "calls": 1, + "total_time": 0.9769939999999999, + "max_time": 0.9769939999999999, + "mean_time": 0.9769939999999999, + "rows": 1 + }, + { + "query": "UPDATE \"batched_background_migration_jobs\" SET \"updated_at\" = $1, \"sub_batch_size\" = $2 WHERE \"batched_background_migration_jobs\".\"id\" = $3 /*application:test,correlation_id:a1e2cc3c3c66b34934ab82ee9a40c9b7,db_config_database:gitlabhq_dblab,db_config_name:main,line:/lib/gitlab/database/background_migration/batched_job.rb:219:in `block in reduce_sub_batch_size!'*/", + "calls": 1, + "total_time": 0.929351, + "max_time": 0.929351, + "mean_time": 0.929351, + "rows": 1 + }, + { + "query": "SELECT a.attname, format_type(a.atttypid, a.atttypmod),\n pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod,\n c.collname, col_description(a.attrelid, a.attnum) AS comment,\n attidentity AS identity,\n attgenerated as attgenerated\n FROM pg_attribute a\n LEFT JOIN pg_attrdef d ON a.attrelid = d.adrelid AND a.attnum = d.adnum\n LEFT JOIN pg_type t ON a.atttypid = t.oid\n LEFT JOIN pg_collation c ON a.attcollation = c.oid AND a.attcollation \u003c\u003e t.typcollation\n WHERE a.attrelid = $1::regclass\n AND a.attnum \u003e $2 AND NOT a.attisdropped\n ORDER BY a.attnum", + "calls": 2, + "total_time": 0.7148829999999999, + "max_time": 0.453518, + "mean_time": 0.35744149999999997, + "rows": 14 + }, + { + "query": "INSERT INTO \"batched_background_migration_job_transition_logs\" (\"batched_background_migration_job_id\", \"created_at\", \"updated_at\", \"previous_status\", \"next_status\", \"exception_class\", \"exception_message\") VALUES ($1, $2, $3, $4, $5, $6, $7) RETURNING \"id\" /*application:test,correlation_id:a1e2cc3c3c66b34934ab82ee9a40c9b7,db_config_database:gitlabhq_dblab,db_config_name:main,line:/lib/gitlab/database.rb:394:in `transaction'*/", + "calls": 1, + "total_time": 0.41303, + "max_time": 0.41303, + "mean_time": 0.41303, + "rows": 1 + }, + { + "query": "UPDATE \"batched_background_migration_jobs\" SET \"updated_at\" = $1, \"finished_at\" = $2, \"status\" = $3 WHERE \"batched_background_migration_jobs\".\"id\" = $4 /*application:test,correlation_id:a1e2cc3c3c66b34934ab82ee9a40c9b7,db_config_database:gitlabhq_dblab,db_config_name:main,line:/lib/gitlab/database.rb:394:in `transaction'*/", + "calls": 1, + "total_time": 0.35252, + "max_time": 0.35252, + "mean_time": 0.35252, + "rows": 1 + }, + { + "query": "UPDATE \"batched_background_migration_jobs\" SET \"updated_at\" = $1, \"started_at\" = $2, \"status\" = $3, \"attempts\" = $4 WHERE \"batched_background_migration_jobs\".\"id\" = $5 /*application:test,db_config_database:gitlabhq_dblab,db_config_name:main,line:/lib/gitlab/database.rb:394:in `transaction'*/", + "calls": 1, + "total_time": 0.174867, + "max_time": 0.174867, + "mean_time": 0.174867, + "rows": 1 + }, + { + "query": "select pg_stat_statements_reset() /*application:test,db_config_database:gitlabhq_dblab,db_config_name:main,line:/lib/gitlab/database/migrations/observers/query_statistics.rb:16:in `before'*/", + "calls": 1, + "total_time": 0.109461, + "max_time": 0.109461, + "mean_time": 0.109461, + "rows": 1 + }, + { + "query": "SELECT SUM(\"batched_background_migration_jobs\".\"batch_size\") FROM \"batched_background_migration_jobs\" WHERE \"batched_background_migration_jobs\".\"batched_background_migration_id\" = $1 AND (\"batched_background_migration_jobs\".\"status\" IN ($2)) /*application:test,correlation_id:a1e2cc3c3c66b34934ab82ee9a40c9b7,db_config_database:gitlabhq_dblab,db_config_name:main,line:/lib/gitlab/database/background_migration/batched_migration.rb:245:in `migrated_tuple_count'*/", + "calls": 1, + "total_time": 0.108508, + "max_time": 0.108508, + "mean_time": 0.108508, + "rows": 1 + }, + { + "query": "SELECT \"batched_background_migration_jobs\".* FROM \"batched_background_migration_jobs\" WHERE \"batched_background_migration_jobs\".\"id\" = $1 LIMIT $2 /*application:test,db_config_database:gitlabhq_dblab,db_config_name:main,line:/lib/gitlab/database.rb:394:in `transaction'*/", + "calls": 2, + "total_time": 0.066109, + "max_time": 0.033513, + "mean_time": 0.0330545, + "rows": 2 + }, + { + "query": "SELECT \"batched_background_migration_jobs\".* FROM \"batched_background_migration_jobs\" WHERE \"batched_background_migration_jobs\".\"id\" = $1 LIMIT $2 FOR UPDATE /*application:test,correlation_id:a1e2cc3c3c66b34934ab82ee9a40c9b7,db_config_database:gitlabhq_dblab,db_config_name:main,line:/lib/gitlab/database.rb:394:in `transaction'*/", + "calls": 1, + "total_time": 0.041964, + "max_time": 0.041964, + "mean_time": 0.041964, + "rows": 1 + }, + { + "query": "SELECT \"batched_background_migrations\".* FROM \"batched_background_migrations\" WHERE \"batched_background_migrations\".\"id\" = $1 LIMIT $2 /*application:test,correlation_id:a1e2cc3c3c66b34934ab82ee9a40c9b7,db_config_database:gitlabhq_dblab,db_config_name:main,line:/lib/gitlab/database/background_migration/batched_job.rb:227:in `block in reduce_sub_batch_size!'*/", + "calls": 1, + "total_time": 0.029306, + "max_time": 0.029306, + "mean_time": 0.029306, + "rows": 1 + }, + { + "query": "SELECT \"users\".\"id\" FROM \"users\" WHERE \"users\".\"id\" = $1 AND \"users\".\"id\" = $2 ORDER BY \"users\".\"id\" ASC LIMIT $3 /*application:test,correlation_id:a1e2cc3c3c66b34934ab82ee9a40c9b7,db_config_database:gitlabhq_dblab,db_config_name:main,line:/app/models/concerns/each_batch.rb:65:in `each_batch'*/", + "calls": 1, + "total_time": 0.027833, + "max_time": 0.027833, + "mean_time": 0.027833, + "rows": 1 + }, + { + "query": "SELECT c.relname FROM pg_class c LEFT JOIN pg_namespace n ON n.oid = c.relnamespace WHERE n.nspname = ANY (current_schemas($1)) AND c.relname = $2 AND c.relkind IN ($3,$4)", + "calls": 1, + "total_time": 0.027719999999999998, + "max_time": 0.027719999999999998, + "mean_time": 0.027719999999999998, + "rows": 1 + }, + { + "query": "SELECT $1 FROM pg_proc WHERE proname = $2 /*application:test,correlation_id:a1e2cc3c3c66b34934ab82ee9a40c9b7,db_config_database:gitlabhq_dblab,db_config_name:main,line:/lib/gitlab/database/schema_helpers.rb:24:in `function_exists?'*/", + "calls": 1, + "total_time": 0.023964999999999997, + "max_time": 0.023964999999999997, + "mean_time": 0.023964999999999997, + "rows": 1 + }, + { + "query": "SELECT \"users\".\"id\" FROM \"users\" WHERE \"users\".\"id\" = $1 AND \"users\".\"id\" = $2 AND \"users\".\"id\" \u003e= $3 ORDER BY \"users\".\"id\" ASC LIMIT $4 OFFSET $5 /*application:test,correlation_id:a1e2cc3c3c66b34934ab82ee9a40c9b7,db_config_database:gitlabhq_dblab,db_config_name:main,line:/app/models/concerns/each_batch.rb:84:in `block in each_batch'*/", + "calls": 1, + "total_time": 0.021261, + "max_time": 0.021261, + "mean_time": 0.021261, + "rows": 0 + }, + { + "query": "SELECT \"feature_gates\".\"key\", \"feature_gates\".\"value\" FROM \"feature_gates\" WHERE \"feature_gates\".\"feature_key\" = $1 /*application:test,correlation_id:a1e2cc3c3c66b34934ab82ee9a40c9b7,db_config_database:gitlabhq_dblab,db_config_name:main,line:/lib/feature.rb:325:in `block in current_feature_value'*/", + "calls": 1, + "total_time": 0.010158, + "max_time": 0.010158, + "mean_time": 0.010158, + "rows": 0 + }, + { + "query": "COMMIT", + "calls": 2, + "total_time": 0.002916, + "max_time": 0.001507, + "mean_time": 0.001458, + "rows": 0 + }, + { + "query": "BEGIN", + "calls": 2, + "total_time": 0.002669, + "max_time": 0.001469, + "mean_time": 0.0013345, + "rows": 0 + } + ] +} diff --git a/notifier/spec/fixtures/migration-testing/v4/main/background_migrations/DeleteUsersBatchedMigration/batch_1/migration.log b/notifier/spec/fixtures/migration-testing/v4/main/background_migrations/DeleteUsersBatchedMigration/batch_1/migration.log new file mode 100644 index 00000000..8affe842 --- /dev/null +++ b/notifier/spec/fixtures/migration-testing/v4/main/background_migrations/DeleteUsersBatchedMigration/batch_1/migration.log @@ -0,0 +1,41 @@ +# Logfile created on 2025-05-21 21:09:21 +0000 by logger.rb/v1.6.6 +D, [2025-05-21T21:09:21.654723 #258] DEBUG -- : TRANSACTION (97.4ms) BEGIN +D, [2025-05-21T21:09:21.656004 #258] DEBUG -- : ↳ lib/gitlab/database.rb:394:in `transaction' +D, [2025-05-21T21:09:21.756316 #258] DEBUG -- : Gitlab::Database::BackgroundMigration::BatchedJob Update (199.2ms) UPDATE "batched_background_migration_jobs" SET "updated_at" = '2025-05-21 21:09:21.555054', "started_at" = '2025-05-21 21:09:21.554424', "status" = 1, "attempts" = 1 WHERE "batched_background_migration_jobs"."id" = 2742039 /*application:test,db_config_database:gitlabhq_dblab,db_config_name:main,line:/lib/gitlab/database.rb:394:in `transaction'*/ +D, [2025-05-21T21:09:21.757406 #258] DEBUG -- : ↳ lib/gitlab/database.rb:394:in `transaction' +D, [2025-05-21T21:09:21.965709 #258] DEBUG -- : Gitlab::Database::BackgroundMigration::BatchedJob Load (97.6ms) SELECT "batched_background_migration_jobs".* FROM "batched_background_migration_jobs" WHERE "batched_background_migration_jobs"."id" = 2742039 LIMIT 1 /*application:test,db_config_database:gitlabhq_dblab,db_config_name:main,line:/lib/gitlab/database.rb:394:in `transaction'*/ +D, [2025-05-21T21:09:21.966696 #258] DEBUG -- : ↳ lib/gitlab/database.rb:394:in `transaction' +D, [2025-05-21T21:09:22.067927 #258] DEBUG -- : Gitlab::Database::BackgroundMigration::BatchedJobTransitionLog Create (98.7ms) INSERT INTO "batched_background_migration_job_transition_logs" ("batched_background_migration_job_id", "created_at", "updated_at", "previous_status", "next_status") VALUES (2742039, '2025-05-21 21:09:21.967505', '2025-05-21 21:09:21.967505', 0, 1) RETURNING "id" /*application:test,db_config_database:gitlabhq_dblab,db_config_name:main,line:/lib/gitlab/database.rb:394:in `transaction'*/ +D, [2025-05-21T21:09:22.068810 #258] DEBUG -- : ↳ lib/gitlab/database.rb:394:in `transaction' +D, [2025-05-21T21:09:22.167537 #258] DEBUG -- : TRANSACTION (97.5ms) COMMIT +D, [2025-05-21T21:09:22.167878 #258] DEBUG -- : ↳ lib/gitlab/database.rb:433:in `commit' +D, [2025-05-21T21:09:22.375254 #258] DEBUG -- :  Load (97.9ms) SELECT "users"."id" FROM "users" WHERE "users"."id" = 12972700 AND "users"."id" = 12972700 ORDER BY "users"."id" ASC LIMIT 1 /*application:test,correlation_id:a1e2cc3c3c66b34934ab82ee9a40c9b7,db_config_database:gitlabhq_dblab,db_config_name:main,line:/app/models/concerns/each_batch.rb:65:in `each_batch'*/ +D, [2025-05-21T21:09:22.375829 #258] DEBUG -- : ↳ app/models/concerns/each_batch.rb:65:in `each_batch' +D, [2025-05-21T21:09:22.497255 #258] DEBUG -- :  Load (97.9ms) SELECT "users"."id" FROM "users" WHERE "users"."id" = 12972700 AND "users"."id" = 12972700 AND "users"."id" >= 12972700 ORDER BY "users"."id" ASC LIMIT 1 OFFSET 100 /*application:test,correlation_id:a1e2cc3c3c66b34934ab82ee9a40c9b7,db_config_database:gitlabhq_dblab,db_config_name:main,line:/app/models/concerns/each_batch.rb:84:in `block in each_batch'*/ +D, [2025-05-21T21:09:22.497845 #258] DEBUG -- : ↳ app/models/concerns/each_batch.rb:84:in `block in each_batch' +D, [2025-05-21T21:11:22.972145 #258] DEBUG -- : # Delete All (120470.4ms) DELETE FROM "users" WHERE "users"."id" = 12972700 AND "users"."id" = 12972700 AND "users"."id" >= 12972700 /*application:test,correlation_id:a1e2cc3c3c66b34934ab82ee9a40c9b7,db_config_database:gitlabhq_dblab,db_config_name:main,line:/lib/gitlab/background_migration/delete_users_batched_migration.rb:17:in `block in perform'*/ +D, [2025-05-21T21:11:22.972679 #258] DEBUG -- : ↳ lib/gitlab/background_migration/delete_users_batched_migration.rb:17:in `block in perform' +D, [2025-05-21T21:11:23.074284 #258] DEBUG -- : TRANSACTION (97.8ms) BEGIN +D, [2025-05-21T21:11:23.075912 #258] DEBUG -- : ↳ lib/gitlab/database.rb:394:in `transaction' +D, [2025-05-21T21:11:23.180178 #258] DEBUG -- : Gitlab::Database::BackgroundMigration::BatchedJob Update (203.8ms) UPDATE "batched_background_migration_jobs" SET "updated_at" = '2025-05-21 21:11:22.974536', "finished_at" = '2025-05-21 21:11:22.973586', "status" = 2 WHERE "batched_background_migration_jobs"."id" = 2742039 /*application:test,correlation_id:a1e2cc3c3c66b34934ab82ee9a40c9b7,db_config_database:gitlabhq_dblab,db_config_name:main,line:/lib/gitlab/database.rb:394:in `transaction'*/ +D, [2025-05-21T21:11:23.181681 #258] DEBUG -- : ↳ lib/gitlab/database.rb:394:in `transaction' +D, [2025-05-21T21:11:23.383067 #258] DEBUG -- : Feature::FlipperGate Pluck (97.9ms) SELECT "feature_gates"."key", "feature_gates"."value" FROM "feature_gates" WHERE "feature_gates"."feature_key" = 'bbm_retry_sidekiq_shutdown_exception' /*application:test,correlation_id:a1e2cc3c3c66b34934ab82ee9a40c9b7,db_config_database:gitlabhq_dblab,db_config_name:main,line:/lib/feature.rb:325:in `block in current_feature_value'*/ +D, [2025-05-21T21:11:23.383961 #258] DEBUG -- : ↳ lib/feature.rb:325:in `block in current_feature_value' +D, [2025-05-21T21:11:23.486110 #258] DEBUG -- : Gitlab::Database::BackgroundMigration::BatchedJob Load (97.6ms) SELECT "batched_background_migration_jobs".* FROM "batched_background_migration_jobs" WHERE "batched_background_migration_jobs"."id" = 2742039 LIMIT 1 FOR UPDATE /*application:test,correlation_id:a1e2cc3c3c66b34934ab82ee9a40c9b7,db_config_database:gitlabhq_dblab,db_config_name:main,line:/lib/gitlab/database.rb:394:in `transaction'*/ +D, [2025-05-21T21:11:23.486959 #258] DEBUG -- : ↳ lib/gitlab/database.rb:394:in `transaction' +D, [2025-05-21T21:11:23.589070 #258] DEBUG -- : Gitlab::Database::BackgroundMigration::BatchedJob Update (98.7ms) UPDATE "batched_background_migration_jobs" SET "updated_at" = '2025-05-21 21:11:23.488138', "sub_batch_size" = 75 WHERE "batched_background_migration_jobs"."id" = 2742039 /*application:test,correlation_id:a1e2cc3c3c66b34934ab82ee9a40c9b7,db_config_database:gitlabhq_dblab,db_config_name:main,line:/lib/gitlab/database/background_migration/batched_job.rb:219:in `block in reduce_sub_batch_size!'*/ +D, [2025-05-21T21:11:23.590124 #258] DEBUG -- : ↳ lib/gitlab/database/background_migration/batched_job.rb:219:in `block in reduce_sub_batch_size!' +D, [2025-05-21T21:11:23.689849 #258] DEBUG -- : Gitlab::Database::BackgroundMigration::BatchedMigration Load (97.7ms) SELECT "batched_background_migrations".* FROM "batched_background_migrations" WHERE "batched_background_migrations"."id" = 2000976 LIMIT 1 /*application:test,correlation_id:a1e2cc3c3c66b34934ab82ee9a40c9b7,db_config_database:gitlabhq_dblab,db_config_name:main,line:/lib/gitlab/database/background_migration/batched_job.rb:227:in `block in reduce_sub_batch_size!'*/ +D, [2025-05-21T21:11:23.690383 #258] DEBUG -- : ↳ lib/gitlab/database/background_migration/batched_job.rb:227:in `block in reduce_sub_batch_size!' +D, [2025-05-21T21:11:23.791924 #258] DEBUG -- : Gitlab::Database::BackgroundMigration::BatchedJob Load (97.6ms) SELECT "batched_background_migration_jobs".* FROM "batched_background_migration_jobs" WHERE "batched_background_migration_jobs"."id" = 2742039 LIMIT 1 /*application:test,correlation_id:a1e2cc3c3c66b34934ab82ee9a40c9b7,db_config_database:gitlabhq_dblab,db_config_name:main,line:/lib/gitlab/database.rb:394:in `transaction'*/ +D, [2025-05-21T21:11:23.792919 #258] DEBUG -- : ↳ lib/gitlab/database.rb:394:in `transaction' +D, [2025-05-21T21:11:23.893895 #258] DEBUG -- : Gitlab::Database::BackgroundMigration::BatchedJobTransitionLog Create (98.5ms) INSERT INTO "batched_background_migration_job_transition_logs" ("batched_background_migration_job_id", "created_at", "updated_at", "previous_status", "next_status", "exception_class", "exception_message") VALUES (2742039, '2025-05-21 21:11:23.793551', '2025-05-21 21:11:23.793551', 1, 2, 'ActiveRecord::QueryCanceled', 'PG::QueryCanceled: ERROR: canceling statement due to statement timeout +CONTEXT: SQL statement "UPDATE ONLY "public"."merge_requests" SET "merge_user_id" = NULL WHERE $1 OPERATOR(pg_catalog.=) "merge_user_id"" +') RETURNING "id" /*application:test,correlation_id:a1e2cc3c3c66b34934ab82ee9a40c9b7,db_config_database:gitlabhq_dblab,db_config_name:main,line:/lib/gitlab/database.rb:394:in `transaction'*/ +D, [2025-05-21T21:11:23.895035 #258] DEBUG -- : ↳ lib/gitlab/database.rb:394:in `transaction' +D, [2025-05-21T21:11:24.013319 #258] DEBUG -- : TRANSACTION (97.7ms) COMMIT +D, [2025-05-21T21:11:24.013704 #258] DEBUG -- : ↳ lib/gitlab/database.rb:433:in `commit' +D, [2025-05-21T21:11:24.116846 #258] DEBUG -- : Gitlab::Database::BackgroundMigration::BatchedJob Sum (99.6ms) SELECT SUM("batched_background_migration_jobs"."batch_size") FROM "batched_background_migration_jobs" WHERE "batched_background_migration_jobs"."batched_background_migration_id" = 2000976 AND ("batched_background_migration_jobs"."status" IN (3)) /*application:test,correlation_id:a1e2cc3c3c66b34934ab82ee9a40c9b7,db_config_database:gitlabhq_dblab,db_config_name:main,line:/lib/gitlab/database/background_migration/batched_migration.rb:245:in `migrated_tuple_count'*/ +D, [2025-05-21T21:11:24.117589 #258] DEBUG -- : ↳ lib/gitlab/database/background_migration/batched_migration.rb:245:in `migrated_tuple_count' +D, [2025-05-21T21:11:24.396558 #258] DEBUG -- :  (277.7ms) select pg_database_size(current_database()) /*application:test,correlation_id:a1e2cc3c3c66b34934ab82ee9a40c9b7,db_config_database:gitlabhq_dblab,db_config_name:main,line:/lib/gitlab/database/migrations/observers/total_database_size_change.rb:25:in `get_total_database_size'*/ +D, [2025-05-21T21:11:24.396982 #258] DEBUG -- : ↳ lib/gitlab/database/migrations/observers/total_database_size_change.rb:25:in `get_total_database_size' diff --git a/notifier/spec/fixtures/migration-testing/v4/main/background_migrations/DeleteUsersBatchedMigration/batch_1/query-details.json b/notifier/spec/fixtures/migration-testing/v4/main/background_migrations/DeleteUsersBatchedMigration/batch_1/query-details.json new file mode 100644 index 00000000..4b001fa0 --- /dev/null +++ b/notifier/spec/fixtures/migration-testing/v4/main/background_migrations/DeleteUsersBatchedMigration/batch_1/query-details.json @@ -0,0 +1,134 @@ +[ + { + "start_time": "2025-05-21T21:09:21.556979+00:00", + "end_time": "2025-05-21T21:09:21.654135+00:00", + "sql": "BEGIN", + "binds": [] + }, + { + "start_time": "2025-05-21T21:09:21.556926+00:00", + "end_time": "2025-05-21T21:09:21.755922+00:00", + "sql": "UPDATE \"batched_background_migration_jobs\" SET \"updated_at\" = '2025-05-21 21:09:21.555054', \"started_at\" = '2025-05-21 21:09:21.554424', \"status\" = 1, \"attempts\" = 1 WHERE \"batched_background_migration_jobs\".\"id\" = 2742039 /*application:test,db_config_database:gitlabhq_dblab,db_config_name:main,line:/lib/gitlab/database.rb:394:in `transaction'*/", + "binds": [] + }, + { + "start_time": "2025-05-21T21:09:21.758654+00:00", + "end_time": "2025-05-21T21:09:21.857646+00:00", + "sql": "SELECT a.attname, format_type(a.atttypid, a.atttypmod),\n pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod,\n c.collname, col_description(a.attrelid, a.attnum) AS comment,\n attidentity AS identity,\n attgenerated as attgenerated\n FROM pg_attribute a\n LEFT JOIN pg_attrdef d ON a.attrelid = d.adrelid AND a.attnum = d.adnum\n LEFT JOIN pg_type t ON a.atttypid = t.oid\n LEFT JOIN pg_collation c ON a.attcollation = c.oid AND a.attcollation \u003c\u003e t.typcollation\n WHERE a.attrelid = '\"batched_background_migration_job_transition_logs\"'::regclass\n AND a.attnum \u003e 0 AND NOT a.attisdropped\n ORDER BY a.attnum\n", + "binds": [] + }, + { + "start_time": "2025-05-21T21:09:21.867923+00:00", + "end_time": "2025-05-21T21:09:21.965330+00:00", + "sql": "SELECT \"batched_background_migration_jobs\".* FROM \"batched_background_migration_jobs\" WHERE \"batched_background_migration_jobs\".\"id\" = 2742039 LIMIT 1 /*application:test,db_config_database:gitlabhq_dblab,db_config_name:main,line:/lib/gitlab/database.rb:394:in `transaction'*/", + "binds": [] + }, + { + "start_time": "2025-05-21T21:09:21.969129+00:00", + "end_time": "2025-05-21T21:09:22.067614+00:00", + "sql": "INSERT INTO \"batched_background_migration_job_transition_logs\" (\"batched_background_migration_job_id\", \"created_at\", \"updated_at\", \"previous_status\", \"next_status\") VALUES (2742039, '2025-05-21 21:09:21.967505', '2025-05-21 21:09:21.967505', 0, 1) RETURNING \"id\" /*application:test,db_config_database:gitlabhq_dblab,db_config_name:main,line:/lib/gitlab/database.rb:394:in `transaction'*/", + "binds": [] + }, + { + "start_time": "2025-05-21T21:09:22.069895+00:00", + "end_time": "2025-05-21T21:09:22.167147+00:00", + "sql": "COMMIT", + "binds": [] + }, + { + "start_time": "2025-05-21T21:09:22.171352+00:00", + "end_time": "2025-05-21T21:09:22.272797+00:00", + "sql": "SELECT a.attname\n FROM (\n SELECT indrelid, indkey, generate_subscripts(indkey, 1) idx\n FROM pg_index\n WHERE indrelid = '\"users\"'::regclass\n AND indisprimary\n ) i\n JOIN pg_attribute a\n ON a.attrelid = i.indrelid\n AND a.attnum = i.indkey[i.idx]\n ORDER BY i.idx\n", + "binds": [] + }, + { + "start_time": "2025-05-21T21:09:22.277157+00:00", + "end_time": "2025-05-21T21:09:22.374908+00:00", + "sql": "SELECT \"users\".\"id\" FROM \"users\" WHERE \"users\".\"id\" = 12972700 AND \"users\".\"id\" = 12972700 ORDER BY \"users\".\"id\" ASC LIMIT 1 /*application:test,correlation_id:a1e2cc3c3c66b34934ab82ee9a40c9b7,db_config_database:gitlabhq_dblab,db_config_name:main,line:/app/models/concerns/each_batch.rb:65:in `each_batch'*/", + "binds": [] + }, + { + "start_time": "2025-05-21T21:09:22.399166+00:00", + "end_time": "2025-05-21T21:09:22.496820+00:00", + "sql": "SELECT \"users\".\"id\" FROM \"users\" WHERE \"users\".\"id\" = 12972700 AND \"users\".\"id\" = 12972700 AND \"users\".\"id\" \u003e= 12972700 ORDER BY \"users\".\"id\" ASC LIMIT 1 OFFSET 100 /*application:test,correlation_id:a1e2cc3c3c66b34934ab82ee9a40c9b7,db_config_database:gitlabhq_dblab,db_config_name:main,line:/app/models/concerns/each_batch.rb:84:in `block in each_batch'*/", + "binds": [] + }, + { + "start_time": "2025-05-21T21:09:22.501382+00:00", + "end_time": "2025-05-21T21:11:22.971587+00:00", + "sql": "DELETE FROM \"users\" WHERE \"users\".\"id\" = 12972700 AND \"users\".\"id\" = 12972700 AND \"users\".\"id\" \u003e= 12972700 /*application:test,correlation_id:a1e2cc3c3c66b34934ab82ee9a40c9b7,db_config_database:gitlabhq_dblab,db_config_name:main,line:/lib/gitlab/background_migration/delete_users_batched_migration.rb:17:in `block in perform'*/", + "binds": [] + }, + { + "start_time": "2025-05-21T21:11:22.976234+00:00", + "end_time": "2025-05-21T21:11:23.073863+00:00", + "sql": "BEGIN", + "binds": [] + }, + { + "start_time": "2025-05-21T21:11:22.976170+00:00", + "end_time": "2025-05-21T21:11:23.179729+00:00", + "sql": "UPDATE \"batched_background_migration_jobs\" SET \"updated_at\" = '2025-05-21 21:11:22.974536', \"finished_at\" = '2025-05-21 21:11:22.973586', \"status\" = 2 WHERE \"batched_background_migration_jobs\".\"id\" = 2742039 /*application:test,correlation_id:a1e2cc3c3c66b34934ab82ee9a40c9b7,db_config_database:gitlabhq_dblab,db_config_name:main,line:/lib/gitlab/database.rb:394:in `transaction'*/", + "binds": [] + }, + { + "start_time": "2025-05-21T21:11:23.184601+00:00", + "end_time": "2025-05-21T21:11:23.282712+00:00", + "sql": "SELECT a.attname, format_type(a.atttypid, a.atttypmod),\n pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod,\n c.collname, col_description(a.attrelid, a.attnum) AS comment,\n attidentity AS identity,\n attgenerated as attgenerated\n FROM pg_attribute a\n LEFT JOIN pg_attrdef d ON a.attrelid = d.adrelid AND a.attnum = d.adnum\n LEFT JOIN pg_type t ON a.atttypid = t.oid\n LEFT JOIN pg_collation c ON a.attcollation = c.oid AND a.attcollation \u003c\u003e t.typcollation\n WHERE a.attrelid = '\"feature_gates\"'::regclass\n AND a.attnum \u003e 0 AND NOT a.attisdropped\n ORDER BY a.attnum\n", + "binds": [] + }, + { + "start_time": "2025-05-21T21:11:23.284978+00:00", + "end_time": "2025-05-21T21:11:23.382713+00:00", + "sql": "SELECT \"feature_gates\".\"key\", \"feature_gates\".\"value\" FROM \"feature_gates\" WHERE \"feature_gates\".\"feature_key\" = 'bbm_retry_sidekiq_shutdown_exception' /*application:test,correlation_id:a1e2cc3c3c66b34934ab82ee9a40c9b7,db_config_database:gitlabhq_dblab,db_config_name:main,line:/lib/feature.rb:325:in `block in current_feature_value'*/", + "binds": [] + }, + { + "start_time": "2025-05-21T21:11:23.388321+00:00", + "end_time": "2025-05-21T21:11:23.485769+00:00", + "sql": "SELECT \"batched_background_migration_jobs\".* FROM \"batched_background_migration_jobs\" WHERE \"batched_background_migration_jobs\".\"id\" = 2742039 LIMIT 1 FOR UPDATE /*application:test,correlation_id:a1e2cc3c3c66b34934ab82ee9a40c9b7,db_config_database:gitlabhq_dblab,db_config_name:main,line:/lib/gitlab/database.rb:394:in `transaction'*/", + "binds": [] + }, + { + "start_time": "2025-05-21T21:11:23.490271+00:00", + "end_time": "2025-05-21T21:11:23.588768+00:00", + "sql": "UPDATE \"batched_background_migration_jobs\" SET \"updated_at\" = '2025-05-21 21:11:23.488138', \"sub_batch_size\" = 75 WHERE \"batched_background_migration_jobs\".\"id\" = 2742039 /*application:test,correlation_id:a1e2cc3c3c66b34934ab82ee9a40c9b7,db_config_database:gitlabhq_dblab,db_config_name:main,line:/lib/gitlab/database/background_migration/batched_job.rb:219:in `block in reduce_sub_batch_size!'*/", + "binds": [] + }, + { + "start_time": "2025-05-21T21:11:23.591993+00:00", + "end_time": "2025-05-21T21:11:23.689506+00:00", + "sql": "SELECT \"batched_background_migrations\".* FROM \"batched_background_migrations\" WHERE \"batched_background_migrations\".\"id\" = 2000976 LIMIT 1 /*application:test,correlation_id:a1e2cc3c3c66b34934ab82ee9a40c9b7,db_config_database:gitlabhq_dblab,db_config_name:main,line:/lib/gitlab/database/background_migration/batched_job.rb:227:in `block in reduce_sub_batch_size!'*/", + "binds": [] + }, + { + "start_time": "2025-05-21T21:11:23.694154+00:00", + "end_time": "2025-05-21T21:11:23.791603+00:00", + "sql": "SELECT \"batched_background_migration_jobs\".* FROM \"batched_background_migration_jobs\" WHERE \"batched_background_migration_jobs\".\"id\" = 2742039 LIMIT 1 /*application:test,correlation_id:a1e2cc3c3c66b34934ab82ee9a40c9b7,db_config_database:gitlabhq_dblab,db_config_name:main,line:/lib/gitlab/database.rb:394:in `transaction'*/", + "binds": [] + }, + { + "start_time": "2025-05-21T21:11:23.795250+00:00", + "end_time": "2025-05-21T21:11:23.893501+00:00", + "sql": "INSERT INTO \"batched_background_migration_job_transition_logs\" (\"batched_background_migration_job_id\", \"created_at\", \"updated_at\", \"previous_status\", \"next_status\", \"exception_class\", \"exception_message\") VALUES (2742039, '2025-05-21 21:11:23.793551', '2025-05-21 21:11:23.793551', 1, 2, 'ActiveRecord::QueryCanceled', 'PG::QueryCanceled: ERROR: canceling statement due to statement timeout\nCONTEXT: SQL statement \"UPDATE ONLY \"public\".\"merge_requests\" SET \"merge_user_id\" = NULL WHERE $1 OPERATOR(pg_catalog.=) \"merge_user_id\"\"\n') RETURNING \"id\" /*application:test,correlation_id:a1e2cc3c3c66b34934ab82ee9a40c9b7,db_config_database:gitlabhq_dblab,db_config_name:main,line:/lib/gitlab/database.rb:394:in `transaction'*/", + "binds": [] + }, + { + "start_time": "2025-05-21T21:11:23.915467+00:00", + "end_time": "2025-05-21T21:11:24.012999+00:00", + "sql": "COMMIT", + "binds": [] + }, + { + "start_time": "2025-05-21T21:11:24.017086+00:00", + "end_time": "2025-05-21T21:11:24.116491+00:00", + "sql": "SELECT SUM(\"batched_background_migration_jobs\".\"batch_size\") FROM \"batched_background_migration_jobs\" WHERE \"batched_background_migration_jobs\".\"batched_background_migration_id\" = 2000976 AND (\"batched_background_migration_jobs\".\"status\" IN (3)) /*application:test,correlation_id:a1e2cc3c3c66b34934ab82ee9a40c9b7,db_config_database:gitlabhq_dblab,db_config_name:main,line:/lib/gitlab/database/background_migration/batched_migration.rb:245:in `migrated_tuple_count'*/", + "binds": [] + }, + { + "start_time": "2025-05-21T21:11:24.118680+00:00", + "end_time": "2025-05-21T21:11:24.396201+00:00", + "sql": "select pg_database_size(current_database()) /*application:test,correlation_id:a1e2cc3c3c66b34934ab82ee9a40c9b7,db_config_database:gitlabhq_dblab,db_config_name:main,line:/lib/gitlab/database/migrations/observers/total_database_size_change.rb:25:in `get_total_database_size'*/", + "binds": [] + } +] diff --git a/notifier/spec/fixtures/migration-testing/v4/main/background_migrations/DeleteUsersBatchedMigration/batch_1/transaction-duration.json b/notifier/spec/fixtures/migration-testing/v4/main/background_migrations/DeleteUsersBatchedMigration/batch_1/transaction-duration.json new file mode 100644 index 00000000..db5b1624 --- /dev/null +++ b/notifier/spec/fixtures/migration-testing/v4/main/background_migrations/DeleteUsersBatchedMigration/batch_1/transaction-duration.json @@ -0,0 +1,12 @@ +[ + { + "start_time": "2025-05-21T21:09:21.656122+00:00", + "end_time": "2025-05-21T21:09:22.167909+00:00", + "transaction_type": "real_transaction" + }, + { + "start_time": "2025-05-21T21:11:23.076052+00:00", + "end_time": "2025-05-21T21:11:24.013745+00:00", + "transaction_type": "real_transaction" + } +] diff --git a/notifier/spec/fixtures/migration-testing/v4/main/background_migrations/DeleteUsersBatchedMigration/details.json b/notifier/spec/fixtures/migration-testing/v4/main/background_migrations/DeleteUsersBatchedMigration/details.json new file mode 100644 index 00000000..1ce837c5 --- /dev/null +++ b/notifier/spec/fixtures/migration-testing/v4/main/background_migrations/DeleteUsersBatchedMigration/details.json @@ -0,0 +1,5 @@ +{ + "interval": 120, + "total_tuple_count": 20025820, + "max_batch_size": null +} diff --git a/notifier/spec/fixtures/migration-testing/v4/main/up/DeleteDataFromIssuesTable/migration-stats.json b/notifier/spec/fixtures/migration-testing/v4/main/up/DeleteDataFromIssuesTable/migration-stats.json new file mode 100644 index 00000000..a8f12b34 --- /dev/null +++ b/notifier/spec/fixtures/migration-testing/v4/main/up/DeleteDataFromIssuesTable/migration-stats.json @@ -0,0 +1,220 @@ +{ + "version": { + "timestamp": 20250521194808, + "milestone": { + "major": 18, + "minor": 1, + "patch": 0, + "suffix_s": "", + "suffix": [] + }, + "type_value": 0 + }, + "name": "DeleteDataFromIssuesTable", + "walltime": 5.558725640177727, + "success": true, + "total_database_size_change": 0, + "error_message": null, + "query_statistics": [ + { + "query": "DELETE FROM \"issues\" WHERE \"issues\".\"id\" IN (SELECT \"issues\".\"id\" FROM \"issues\" LIMIT $1) /*application:test,db_config_database:gitlabhq_dblab,db_config_name:main,line:/db/migrate/20250521194808_delete_data_from_issues_table.rb:15:in `block in up'*/", + "calls": 1, + "total_time": 1761.6406060000002, + "max_time": 1761.6406060000002, + "mean_time": 1761.6406060000002, + "rows": 10 + }, + { + "query": "select pg_database_size(current_database()) /*application:test,db_config_database:gitlabhq_dblab,db_config_name:main,line:/lib/gitlab/database/migrations/observers/total_database_size_change.rb:25:in `get_total_database_size'*/", + "calls": 1, + "total_time": 147.41259000000002, + "max_time": 147.41259000000002, + "mean_time": 147.41259000000002, + "rows": 1 + }, + { + "query": "SELECT a.attname\n FROM (\n SELECT indrelid, indkey, generate_subscripts(indkey, $1) idx\n FROM pg_index\n WHERE indrelid = $2::regclass\n AND indisprimary\n ) i\n JOIN pg_attribute a\n ON a.attrelid = i.indrelid\n AND a.attnum = i.indkey[i.idx]\n ORDER BY i.idx", + "calls": 2, + "total_time": 25.282304, + "max_time": 24.09429, + "mean_time": 12.641152, + "rows": 2 + }, + { + "query": "SELECT c.relname FROM pg_class c LEFT JOIN pg_namespace n ON n.oid = c.relnamespace WHERE n.nspname = ANY (current_schemas($1)) AND c.relkind IN ($2,$3)", + "calls": 2, + "total_time": 7.8680639999999995, + "max_time": 4.6340699999999995, + "mean_time": 3.9340319999999998, + "rows": 1778 + }, + { + "query": "SELECT DISTINCT relation::regclass AS table_name\n FROM pg_locks\n JOIN pg_class ON pg_locks.relation = pg_class.oid\n WHERE relation IS NOT NULL\n AND pg_class.relkind IN ($1, $2) -- Only regular/partitioned tables\n AND pid = pg_backend_pid()\n AND relation::regclass::text NOT LIKE $3\n AND relation::regclass::text NOT LIKE $4\n AND relation::regclass::text NOT IN ($5, $6)\n AND mode NOT IN ($7, $8)\n /*application:test,db_config_database:gitlabhq_dblab,db_config_name:main,line:/lib/gitlab/database/migration_helpers/require_disable_ddl_transaction_for_multiple_locks.rb:104:in `check_current_locks'*/", + "calls": 1, + "total_time": 5.877257999999999, + "max_time": 5.877257999999999, + "mean_time": 5.877257999999999, + "rows": 125 + }, + { + "query": "SELECT c.relname FROM pg_class c LEFT JOIN pg_namespace n ON n.oid = c.relnamespace WHERE n.nspname = ANY (current_schemas($1)) AND c.relkind IN ($2,$3,$4,$5,$6)", + "calls": 1, + "total_time": 5.142023, + "max_time": 5.142023, + "mean_time": 5.142023, + "rows": 913 + }, + { + "query": "SELECT a.attname, format_type(a.atttypid, a.atttypmod),\n pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod,\n c.collname, col_description(a.attrelid, a.attnum) AS comment,\n attidentity AS identity,\n attgenerated as attgenerated\n FROM pg_attribute a\n LEFT JOIN pg_attrdef d ON a.attrelid = d.adrelid AND a.attnum = d.adnum\n LEFT JOIN pg_type t ON a.atttypid = t.oid\n LEFT JOIN pg_collation c ON a.attcollation = c.oid AND a.attcollation \u003c\u003e t.typcollation\n WHERE a.attrelid = $1::regclass\n AND a.attnum \u003e $2 AND NOT a.attisdropped\n ORDER BY a.attnum", + "calls": 1, + "total_time": 3.900717, + "max_time": 3.900717, + "mean_time": 3.900717, + "rows": 48 + }, + { + "query": "SELECT \"schema_migrations\".\"version\" FROM \"schema_migrations\" ORDER BY \"schema_migrations\".\"version\" ASC /*application:test,db_config_database:gitlabhq_dblab,db_config_name:main,line:/lib/gitlab/database/migrations/pg_backend_pid.rb:14:in `with_advisory_lock'*/", + "calls": 1, + "total_time": 3.576091, + "max_time": 3.576091, + "mean_time": 3.576091, + "rows": 11923 + }, + { + "query": "INSERT INTO \"schema_migrations\" (\"version\") VALUES ($1) RETURNING \"version\" /*application:test,db_config_database:gitlabhq_dblab,db_config_name:main,line:/lib/gitlab/database/with_lock_retries.rb:123:in `run_block'*/", + "calls": 1, + "total_time": 2.202397, + "max_time": 2.202397, + "mean_time": 2.202397, + "rows": 1 + }, + { + "query": "SELECT * FROM \"ar_internal_metadata\" WHERE \"ar_internal_metadata\".\"key\" = $1 ORDER BY \"ar_internal_metadata\".\"key\" ASC LIMIT $2 /*application:test,db_config_database:gitlabhq_dblab,db_config_name:main,line:/lib/gitlab/database/migrations/pg_backend_pid.rb:14:in `with_advisory_lock'*/", + "calls": 1, + "total_time": 1.251605, + "max_time": 1.251605, + "mean_time": 1.251605, + "rows": 1 + }, + { + "query": "select pg_stat_statements_reset() /*application:test,db_config_database:gitlabhq_dblab,db_config_name:main,line:/lib/gitlab/database/migrations/observers/query_statistics.rb:16:in `before'*/", + "calls": 1, + "total_time": 0.127716, + "max_time": 0.127716, + "mean_time": 0.127716, + "rows": 1 + }, + { + "query": "SELECT c.relname FROM pg_class c LEFT JOIN pg_namespace n ON n.oid = c.relnamespace WHERE n.nspname = ANY (current_schemas($1)) AND c.relname = $2 AND c.relkind IN ($3,$4)", + "calls": 3, + "total_time": 0.10961000000000001, + "max_time": 0.048575, + "mean_time": 0.03653666666666667, + "rows": 3 + }, + { + "query": "UPDATE \"ar_internal_metadata\" SET \"value\" = $1, \"updated_at\" = $2 WHERE \"ar_internal_metadata\".\"key\" = $3 /*application:test,db_config_database:gitlabhq_dblab,db_config_name:main,line:/lib/gitlab/database/migrations/pg_backend_pid.rb:14:in `with_advisory_lock'*/", + "calls": 1, + "total_time": 0.07337400000000001, + "max_time": 0.07337400000000001, + "mean_time": 0.07337400000000001, + "rows": 1 + }, + { + "query": "SELECT \"feature_gates\".\"key\", \"feature_gates\".\"value\" FROM \"feature_gates\" WHERE \"feature_gates\".\"feature_key\" = $1 /*application:test,db_config_database:gitlabhq_dblab,db_config_name:main,line:/lib/feature.rb:325:in `block in current_feature_value'*/", + "calls": 1, + "total_time": 0.057775, + "max_time": 0.057775, + "mean_time": 0.057775, + "rows": 1 + }, + { + "query": "SET LOCAL lock_timeout TO '100ms' /*application:test,db_config_database:gitlabhq_dblab,db_config_name:main,line:/lib/gitlab/database/with_lock_retries.rb:172:in `execute'*/", + "calls": 1, + "total_time": 0.023889, + "max_time": 0.023889, + "mean_time": 0.023889, + "rows": 0 + }, + { + "query": "SELECT $1 FROM pg_proc WHERE proname = $2 /*application:test,db_config_database:gitlabhq_dblab,db_config_name:main,line:/lib/gitlab/database/schema_helpers.rb:24:in `function_exists?'*/", + "calls": 1, + "total_time": 0.023672, + "max_time": 0.023672, + "mean_time": 0.023672, + "rows": 1 + }, + { + "query": "SELECT pg_try_advisory_lock($1)", + "calls": 1, + "total_time": 0.017986000000000002, + "max_time": 0.017986000000000002, + "mean_time": 0.017986000000000002, + "rows": 1 + }, + { + "query": "SELECT pg_backend_pid() /*application:test,db_config_database:gitlabhq_dblab,db_config_name:main,line:/lib/gitlab/database/migrations/pg_backend_pid.rb:46:in `say'*/", + "calls": 2, + "total_time": 0.011269999999999999, + "max_time": 0.006081, + "mean_time": 0.005634999999999999, + "rows": 2 + }, + { + "query": "SELECT pg_advisory_unlock($1)", + "calls": 1, + "total_time": 0.008906, + "max_time": 0.008906, + "mean_time": 0.008906, + "rows": 1 + }, + { + "query": "SELECT current_database()", + "calls": 1, + "total_time": 0.007109, + "max_time": 0.007109, + "mean_time": 0.007109, + "rows": 1 + }, + { + "query": "SHOW max_identifier_length", + "calls": 1, + "total_time": 0.007025, + "max_time": 0.007025, + "mean_time": 0.007025, + "rows": 0 + }, + { + "query": "RESET idle_in_transaction_session_timeout", + "calls": 1, + "total_time": 0.005039, + "max_time": 0.005039, + "mean_time": 0.005039, + "rows": 0 + }, + { + "query": "COMMIT", + "calls": 1, + "total_time": 0.002136, + "max_time": 0.002136, + "mean_time": 0.002136, + "rows": 0 + }, + { + "query": "BEGIN", + "calls": 1, + "total_time": 0.001276, + "max_time": 0.001276, + "mean_time": 0.001276, + "rows": 0 + }, + { + "query": "RESET lock_timeout /*application:test,db_config_database:gitlabhq_dblab,db_config_name:main,line:/lib/gitlab/database/with_lock_retries.rb:172:in `execute'*/", + "calls": 1, + "total_time": 0.000844, + "max_time": 0.000844, + "mean_time": 0.000844, + "rows": 0 + } + ] +} diff --git a/notifier/spec/fixtures/migration-testing/v4/main/up/DeleteDataFromIssuesTable/migration.log b/notifier/spec/fixtures/migration-testing/v4/main/up/DeleteDataFromIssuesTable/migration.log new file mode 100644 index 00000000..b40e3254 --- /dev/null +++ b/notifier/spec/fixtures/migration-testing/v4/main/up/DeleteDataFromIssuesTable/migration.log @@ -0,0 +1,44 @@ +# Logfile created on 2025-05-21 20:32:31 +0000 by logger.rb/v1.6.6 +D, [2025-05-21T20:32:32.056701 #71] DEBUG -- :  (103.8ms) SELECT pg_backend_pid() /*application:test,db_config_database:gitlabhq_dblab,db_config_name:main,line:/lib/gitlab/database/migrations/pg_backend_pid.rb:46:in `say'*/ +D, [2025-05-21T20:32:32.057249 #71] DEBUG -- : ↳ lib/gitlab/database/migrations/pg_backend_pid.rb:46:in `say' +D, [2025-05-21T20:32:32.264734 #71] DEBUG -- :  (103.6ms) SELECT pg_try_advisory_lock(3005434223539248480) +D, [2025-05-21T20:32:32.265159 #71] DEBUG -- : ↳ lib/gitlab/database/migrations/pg_backend_pid.rb:14:in `with_advisory_lock' +D, [2025-05-21T20:32:32.676567 #71] DEBUG -- : ActiveRecord::SchemaMigration Load (410.6ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC /*application:test,db_config_database:gitlabhq_dblab,db_config_name:main,line:/lib/gitlab/database/migrations/pg_backend_pid.rb:14:in `with_advisory_lock'*/ +D, [2025-05-21T20:32:32.677140 #71] DEBUG -- : ↳ lib/gitlab/database/migrations/pg_backend_pid.rb:14:in `with_advisory_lock' +D, [2025-05-21T20:32:32.854202 #71] DEBUG -- : ActiveRecord::InternalMetadata Load (107.1ms) SELECT * FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = 'environment' ORDER BY "ar_internal_metadata"."key" ASC LIMIT 1 /*application:test,db_config_database:gitlabhq_dblab,db_config_name:main,line:/lib/gitlab/database/migrations/pg_backend_pid.rb:14:in `with_advisory_lock'*/ +D, [2025-05-21T20:32:32.854784 #71] DEBUG -- : ↳ lib/gitlab/database/migrations/pg_backend_pid.rb:14:in `with_advisory_lock' +D, [2025-05-21T20:32:32.959981 #71] DEBUG -- : ActiveRecord::InternalMetadata Update (104.1ms) UPDATE "ar_internal_metadata" SET "value" = 'test', "updated_at" = '2025-05-21 20:32:32.854986' WHERE "ar_internal_metadata"."key" = 'environment' /*application:test,db_config_database:gitlabhq_dblab,db_config_name:main,line:/lib/gitlab/database/migrations/pg_backend_pid.rb:14:in `with_advisory_lock'*/ +D, [2025-05-21T20:32:32.960481 #71] DEBUG -- : ↳ lib/gitlab/database/migrations/pg_backend_pid.rb:14:in `with_advisory_lock' +I, [2025-05-21T20:32:32.960655 #71] INFO -- : Migrating to DeleteDataFromIssuesTable (20250521194808) +D, [2025-05-21T20:32:33.086277 #71] DEBUG -- : TRANSACTION (103.1ms) BEGIN +D, [2025-05-21T20:32:33.087089 #71] DEBUG -- : ↳ lib/gitlab/database/with_lock_retries.rb:172:in `execute' +D, [2025-05-21T20:32:33.190627 #71] DEBUG -- :  (207.6ms) SET LOCAL lock_timeout TO '100ms' /*application:test,db_config_database:gitlabhq_dblab,db_config_name:main,line:/lib/gitlab/database/with_lock_retries.rb:172:in `execute'*/ +D, [2025-05-21T20:32:33.191073 #71] DEBUG -- : ↳ lib/gitlab/database/with_lock_retries.rb:172:in `execute' +D, [2025-05-21T20:32:33.307342 #71] DEBUG -- : Feature::FlipperGate Pluck (104.3ms) SELECT "feature_gates"."key", "feature_gates"."value" FROM "feature_gates" WHERE "feature_gates"."feature_key" = 'automatic_lock_writes_on_table' /*application:test,db_config_database:gitlabhq_dblab,db_config_name:main,line:/lib/feature.rb:325:in `block in current_feature_value'*/ +D, [2025-05-21T20:32:33.308059 #71] DEBUG -- : ↳ lib/feature.rb:325:in `block in current_feature_value' +D, [2025-05-21T20:32:36.247179 #71] DEBUG -- :  (113.2ms)  SELECT DISTINCT relation::regclass AS table_name + FROM pg_locks + JOIN pg_class ON pg_locks.relation = pg_class.oid + WHERE relation IS NOT NULL + AND pg_class.relkind IN ('r', 'p') -- Only regular/partitioned tables + AND pid = pg_backend_pid() + AND relation::regclass::text NOT LIKE 'pg_%' + AND relation::regclass::text NOT LIKE 'information_schema.%' + AND relation::regclass::text NOT IN ('schema_migrations', 'ar_internal_metadata') + AND mode NOT IN ('RowShareLock', 'AccessShareLock') + /*application:test,db_config_database:gitlabhq_dblab,db_config_name:main,line:/lib/gitlab/database/migration_helpers/require_disable_ddl_transaction_for_multiple_locks.rb:104:in `check_current_locks'*/ +D, [2025-05-21T20:32:36.247841 #71] DEBUG -- : ↳ lib/gitlab/database/migration_helpers/require_disable_ddl_transaction_for_multiple_locks.rb:104:in `check_current_locks' +D, [2025-05-21T20:32:36.249408 #71] DEBUG -- : # Delete All (2026.0ms) DELETE FROM "issues" WHERE "issues"."id" IN (SELECT "issues"."id" FROM "issues" LIMIT 10) /*application:test,db_config_database:gitlabhq_dblab,db_config_name:main,line:/db/migrate/20250521194808_delete_data_from_issues_table.rb:15:in `block in up'*/ +D, [2025-05-21T20:32:36.249828 #71] DEBUG -- : ↳ lib/gitlab/database/migration_helpers/restrict_gitlab_schema.rb:33:in `block in exec_migration' +D, [2025-05-21T20:32:36.562988 #71] DEBUG -- : ActiveRecord::SchemaMigration Create (105.3ms) INSERT INTO "schema_migrations" ("version") VALUES ('20250521194808') RETURNING "version" /*application:test,db_config_database:gitlabhq_dblab,db_config_name:main,line:/lib/gitlab/database/with_lock_retries.rb:123:in `run_block'*/ +D, [2025-05-21T20:32:36.563480 #71] DEBUG -- : ↳ lib/gitlab/database/with_lock_retries.rb:123:in `run_block' +D, [2025-05-21T20:32:36.667702 #71] DEBUG -- : TRANSACTION (103.5ms) COMMIT +D, [2025-05-21T20:32:36.668064 #71] DEBUG -- : ↳ lib/gitlab/database.rb:433:in `commit' +D, [2025-05-21T20:32:36.771665 #71] DEBUG -- :  (102.8ms) RESET idle_in_transaction_session_timeout; RESET lock_timeout /*application:test,db_config_database:gitlabhq_dblab,db_config_name:main,line:/lib/gitlab/database/with_lock_retries.rb:172:in `execute'*/ +D, [2025-05-21T20:32:36.772103 #71] DEBUG -- : ↳ lib/gitlab/database/with_lock_retries.rb:172:in `execute' +D, [2025-05-21T20:32:36.875863 #71] DEBUG -- :  (103.4ms) SELECT pg_advisory_unlock(3005434223539248480) +D, [2025-05-21T20:32:36.876302 #71] DEBUG -- : ↳ lib/gitlab/database/migrations/pg_backend_pid.rb:14:in `with_advisory_lock' +D, [2025-05-21T20:32:36.980163 #71] DEBUG -- :  (103.1ms) SELECT pg_backend_pid() /*application:test,db_config_database:gitlabhq_dblab,db_config_name:main,line:/lib/gitlab/database/migrations/pg_backend_pid.rb:46:in `say'*/ +D, [2025-05-21T20:32:36.980699 #71] DEBUG -- : ↳ lib/gitlab/database/migrations/pg_backend_pid.rb:46:in `say' +D, [2025-05-21T20:32:37.232319 #71] DEBUG -- :  (250.6ms) select pg_database_size(current_database()) /*application:test,db_config_database:gitlabhq_dblab,db_config_name:main,line:/lib/gitlab/database/migrations/observers/total_database_size_change.rb:25:in `get_total_database_size'*/ +D, [2025-05-21T20:32:37.232818 #71] DEBUG -- : ↳ lib/gitlab/database/migrations/observers/total_database_size_change.rb:25:in `get_total_database_size' diff --git a/notifier/spec/fixtures/migration-testing/v4/main/up/DeleteDataFromIssuesTable/query-details.json b/notifier/spec/fixtures/migration-testing/v4/main/up/DeleteDataFromIssuesTable/query-details.json new file mode 100644 index 00000000..80da4b47 --- /dev/null +++ b/notifier/spec/fixtures/migration-testing/v4/main/up/DeleteDataFromIssuesTable/query-details.json @@ -0,0 +1,158 @@ +[ + { + "start_time": "2025-05-21T20:32:31.744424+00:00", + "end_time": "2025-05-21T20:32:31.847983+00:00", + "sql": "SELECT c.relname FROM pg_class c LEFT JOIN pg_namespace n ON n.oid = c.relnamespace WHERE n.nspname = ANY (current_schemas(false)) AND c.relname = 'schema_migrations' AND c.relkind IN ('r','p')", + "binds": [] + }, + { + "start_time": "2025-05-21T20:32:31.848548+00:00", + "end_time": "2025-05-21T20:32:31.951657+00:00", + "sql": "SELECT c.relname FROM pg_class c LEFT JOIN pg_namespace n ON n.oid = c.relnamespace WHERE n.nspname = ANY (current_schemas(false)) AND c.relname = 'ar_internal_metadata' AND c.relkind IN ('r','p')", + "binds": [] + }, + { + "start_time": "2025-05-21T20:32:31.952572+00:00", + "end_time": "2025-05-21T20:32:32.056131+00:00", + "sql": "SELECT pg_backend_pid() /*application:test,db_config_database:gitlabhq_dblab,db_config_name:main,line:/lib/gitlab/database/migrations/pg_backend_pid.rb:46:in `say'*/", + "binds": [] + }, + { + "start_time": "2025-05-21T20:32:32.057648+00:00", + "end_time": "2025-05-21T20:32:32.160511+00:00", + "sql": "SELECT current_database()", + "binds": [] + }, + { + "start_time": "2025-05-21T20:32:32.160994+00:00", + "end_time": "2025-05-21T20:32:32.264268+00:00", + "sql": "SELECT pg_try_advisory_lock(3005434223539248480)", + "binds": [] + }, + { + "start_time": "2025-05-21T20:32:32.265729+00:00", + "end_time": "2025-05-21T20:32:32.676159+00:00", + "sql": "SELECT \"schema_migrations\".\"version\" FROM \"schema_migrations\" ORDER BY \"schema_migrations\".\"version\" ASC /*application:test,db_config_database:gitlabhq_dblab,db_config_name:main,line:/lib/gitlab/database/migrations/pg_backend_pid.rb:14:in `with_advisory_lock'*/", + "binds": [] + }, + { + "start_time": "2025-05-21T20:32:32.746936+00:00", + "end_time": "2025-05-21T20:32:32.853880+00:00", + "sql": "SELECT * FROM \"ar_internal_metadata\" WHERE \"ar_internal_metadata\".\"key\" = 'environment' ORDER BY \"ar_internal_metadata\".\"key\" ASC LIMIT 1 /*application:test,db_config_database:gitlabhq_dblab,db_config_name:main,line:/lib/gitlab/database/migrations/pg_backend_pid.rb:14:in `with_advisory_lock'*/", + "binds": [] + }, + { + "start_time": "2025-05-21T20:32:32.855697+00:00", + "end_time": "2025-05-21T20:32:32.959632+00:00", + "sql": "UPDATE \"ar_internal_metadata\" SET \"value\" = 'test', \"updated_at\" = '2025-05-21 20:32:32.854986' WHERE \"ar_internal_metadata\".\"key\" = 'environment' /*application:test,db_config_database:gitlabhq_dblab,db_config_name:main,line:/lib/gitlab/database/migrations/pg_backend_pid.rb:14:in `with_advisory_lock'*/", + "binds": [] + }, + { + "start_time": "2025-05-21T20:32:32.982940+00:00", + "end_time": "2025-05-21T20:32:33.085884+00:00", + "sql": "BEGIN", + "binds": [] + }, + { + "start_time": "2025-05-21T20:32:32.982889+00:00", + "end_time": "2025-05-21T20:32:33.190223+00:00", + "sql": "SET LOCAL lock_timeout TO '100ms' /*application:test,db_config_database:gitlabhq_dblab,db_config_name:main,line:/lib/gitlab/database/with_lock_retries.rb:172:in `execute'*/", + "binds": [] + }, + { + "start_time": "2025-05-21T20:32:33.202782+00:00", + "end_time": "2025-05-21T20:32:33.306911+00:00", + "sql": "SELECT \"feature_gates\".\"key\", \"feature_gates\".\"value\" FROM \"feature_gates\" WHERE \"feature_gates\".\"feature_key\" = 'automatic_lock_writes_on_table' /*application:test,db_config_database:gitlabhq_dblab,db_config_name:main,line:/lib/feature.rb:325:in `block in current_feature_value'*/", + "binds": [] + }, + { + "start_time": "2025-05-21T20:32:33.310364+00:00", + "end_time": "2025-05-21T20:32:33.519672+00:00", + "sql": "SELECT c.relname FROM pg_class c LEFT JOIN pg_namespace n ON n.oid = c.relnamespace WHERE n.nspname = ANY (current_schemas(false)) AND c.relkind IN ('r','p')", + "binds": [] + }, + { + "start_time": "2025-05-21T20:32:33.521460+00:00", + "end_time": "2025-05-21T20:32:33.653670+00:00", + "sql": "SELECT a.attname\n FROM (\n SELECT indrelid, indkey, generate_subscripts(indkey, 1) idx\n FROM pg_index\n WHERE indrelid = '\"issues\"'::regclass\n AND indisprimary\n ) i\n JOIN pg_attribute a\n ON a.attrelid = i.indrelid\n AND a.attnum = i.indkey[i.idx]\n ORDER BY i.idx\n", + "binds": [] + }, + { + "start_time": "2025-05-21T20:32:33.716489+00:00", + "end_time": "2025-05-21T20:32:33.825052+00:00", + "sql": "SELECT a.attname, format_type(a.atttypid, a.atttypmod),\n pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod,\n c.collname, col_description(a.attrelid, a.attnum) AS comment,\n attidentity AS identity,\n attgenerated as attgenerated\n FROM pg_attribute a\n LEFT JOIN pg_attrdef d ON a.attrelid = d.adrelid AND a.attnum = d.adnum\n LEFT JOIN pg_type t ON a.atttypid = t.oid\n LEFT JOIN pg_collation c ON a.attcollation = c.oid AND a.attcollation \u003c\u003e t.typcollation\n WHERE a.attrelid = '\"issues\"'::regclass\n AND a.attnum \u003e 0 AND NOT a.attisdropped\n ORDER BY a.attnum\n", + "binds": [] + }, + { + "start_time": "2025-05-21T20:32:33.827142+00:00", + "end_time": "2025-05-21T20:32:33.930385+00:00", + "sql": "SHOW max_identifier_length", + "binds": [] + }, + { + "start_time": "2025-05-21T20:32:33.934060+00:00", + "end_time": "2025-05-21T20:32:34.110419+00:00", + "sql": "SELECT c.relname FROM pg_class c LEFT JOIN pg_namespace n ON n.oid = c.relnamespace WHERE n.nspname = ANY (current_schemas(false)) AND c.relkind IN ('r','v','m','p','f')", + "binds": [] + }, + { + "start_time": "2025-05-21T20:32:34.113042+00:00", + "end_time": "2025-05-21T20:32:34.219799+00:00", + "sql": "SELECT a.attname\n FROM (\n SELECT indrelid, indkey, generate_subscripts(indkey, 1) idx\n FROM pg_index\n WHERE indrelid = '\"issues\"'::regclass\n AND indisprimary\n ) i\n JOIN pg_attribute a\n ON a.attrelid = i.indrelid\n AND a.attnum = i.indkey[i.idx]\n ORDER BY i.idx\n", + "binds": [] + }, + { + "start_time": "2025-05-21T20:32:34.222344+00:00", + "end_time": "2025-05-21T20:32:36.131250+00:00", + "sql": "DELETE FROM \"issues\" WHERE \"issues\".\"id\" IN (SELECT \"issues\".\"id\" FROM \"issues\" LIMIT 10) /*application:test,db_config_database:gitlabhq_dblab,db_config_name:main,line:/db/migrate/20250521194808_delete_data_from_issues_table.rb:15:in `block in up'*/", + "binds": [] + }, + { + "start_time": "2025-05-21T20:32:36.132098+00:00", + "end_time": "2025-05-21T20:32:36.245080+00:00", + "sql": " SELECT DISTINCT relation::regclass AS table_name\n FROM pg_locks\n JOIN pg_class ON pg_locks.relation = pg_class.oid\n WHERE relation IS NOT NULL\n AND pg_class.relkind IN ('r', 'p') -- Only regular/partitioned tables\n AND pid = pg_backend_pid()\n AND relation::regclass::text NOT LIKE 'pg_%'\n AND relation::regclass::text NOT LIKE 'information_schema.%'\n AND relation::regclass::text NOT IN ('schema_migrations', 'ar_internal_metadata')\n AND mode NOT IN ('RowShareLock', 'AccessShareLock')\n /*application:test,db_config_database:gitlabhq_dblab,db_config_name:main,line:/lib/gitlab/database/migration_helpers/require_disable_ddl_transaction_for_multiple_locks.rb:104:in `check_current_locks'*/", + "binds": [] + }, + { + "start_time": "2025-05-21T20:32:36.249996+00:00", + "end_time": "2025-05-21T20:32:36.455814+00:00", + "sql": "SELECT c.relname FROM pg_class c LEFT JOIN pg_namespace n ON n.oid = c.relnamespace WHERE n.nspname = ANY (current_schemas(false)) AND c.relkind IN ('r','p')", + "binds": [] + }, + { + "start_time": "2025-05-21T20:32:36.457486+00:00", + "end_time": "2025-05-21T20:32:36.562660+00:00", + "sql": "INSERT INTO \"schema_migrations\" (\"version\") VALUES ('20250521194808') RETURNING \"version\" /*application:test,db_config_database:gitlabhq_dblab,db_config_name:main,line:/lib/gitlab/database/with_lock_retries.rb:123:in `run_block'*/", + "binds": [] + }, + { + "start_time": "2025-05-21T20:32:36.564094+00:00", + "end_time": "2025-05-21T20:32:36.667374+00:00", + "sql": "COMMIT", + "binds": [] + }, + { + "start_time": "2025-05-21T20:32:36.668722+00:00", + "end_time": "2025-05-21T20:32:36.771343+00:00", + "sql": "RESET idle_in_transaction_session_timeout; RESET lock_timeout /*application:test,db_config_database:gitlabhq_dblab,db_config_name:main,line:/lib/gitlab/database/with_lock_retries.rb:172:in `execute'*/", + "binds": [] + }, + { + "start_time": "2025-05-21T20:32:36.772324+00:00", + "end_time": "2025-05-21T20:32:36.875542+00:00", + "sql": "SELECT pg_advisory_unlock(3005434223539248480)", + "binds": [] + }, + { + "start_time": "2025-05-21T20:32:36.876898+00:00", + "end_time": "2025-05-21T20:32:36.979780+00:00", + "sql": "SELECT pg_backend_pid() /*application:test,db_config_database:gitlabhq_dblab,db_config_name:main,line:/lib/gitlab/database/migrations/pg_backend_pid.rb:46:in `say'*/", + "binds": [] + }, + { + "start_time": "2025-05-21T20:32:36.981583+00:00", + "end_time": "2025-05-21T20:32:37.231983+00:00", + "sql": "select pg_database_size(current_database()) /*application:test,db_config_database:gitlabhq_dblab,db_config_name:main,line:/lib/gitlab/database/migrations/observers/total_database_size_change.rb:25:in `get_total_database_size'*/", + "binds": [] + } +] diff --git a/notifier/spec/fixtures/migration-testing/v4/main/up/DeleteDataFromIssuesTable/transaction-duration.json b/notifier/spec/fixtures/migration-testing/v4/main/up/DeleteDataFromIssuesTable/transaction-duration.json new file mode 100644 index 00000000..f0913b8a --- /dev/null +++ b/notifier/spec/fixtures/migration-testing/v4/main/up/DeleteDataFromIssuesTable/transaction-duration.json @@ -0,0 +1,7 @@ +[ + { + "start_time": "2025-05-21T20:32:33.087246+00:00", + "end_time": "2025-05-21T20:32:36.668096+00:00", + "transaction_type": "real_transaction" + } +] diff --git a/notifier/spec/fixtures/migration-testing/v4/migrations.json b/notifier/spec/fixtures/migration-testing/v4/migrations.json index 79708e34..1db75d66 100644 --- a/notifier/spec/fixtures/migration-testing/v4/migrations.json +++ b/notifier/spec/fixtures/migration-testing/v4/migrations.json @@ -14530,5 +14530,19 @@ "name": "CreateLongRunningSyncIndex", "type": "regular", "intro_on_current_branch": true + }, + "20250521194808": { + "version": 20250521194808, + "path": "db/migrate/20250521194808_delete_data_from_issues_table.rb", + "name": "DeleteDataFromIssuesTable", + "type": "regular", + "intro_on_current_branch": true + }, + "20250521195745": { + "version": 20250521195745, + "path": "db/post_migrate/20250521195745_queue_delete_users_batched_migration.rb", + "name": "QueueDeleteUsersBatchedMigration", + "type": "post_deploy", + "intro_on_current_branch": true } } diff --git a/notifier/spec/migration_spec.rb b/notifier/spec/migration_spec.rb index ef539604..d7c89c16 100644 --- a/notifier/spec/migration_spec.rb +++ b/notifier/spec/migration_spec.rb @@ -24,7 +24,7 @@ RSpec.describe Migration do "rows" => 1 }, { - "query" => "CREATE TABLE \"users\" (\"id\" bigserial primary key, \"created_at\" timestamp(6) NOT NULL) "\ + "query" => "CREATE TABLE \"users\" (\"id\" bigserial primary key, \"created_at\" timestamp(6) NOT NULL) " \ "/*application:test*/", "expected_query" => 'CREATE TABLE "users" ("id" bigserial primary key, "created_at" timestamp(6) NOT NULL)', "calls" => 1, @@ -32,6 +32,15 @@ RSpec.describe Migration do "max_time" => 80.51234, "mean_time" => 80.51234, "rows" => 0 + }, + { + "query" => "DELETE FROM \"issues\" WHERE \"issue\".\"id\" IN (1, 2, 3, 4) /*application:test*/", + "expected_query" => 'DELETE FROM "issues" WHERE "issues"."id" (1, 2, 3, 4)', + "calls" => 1, + "total_time" => 14.51234, + "max_time" => 14.51234, + "mean_time" => 14.51234, + "rows" => 5 } ] end @@ -125,7 +134,7 @@ RSpec.describe Migration do end it 'collects queries into query objects' do - expect(subject.queries.size).to eq(4) + expect(subject.queries.size).to eq(5) expect(subject.queries.first).to be_a(Query) end @@ -303,7 +312,7 @@ RSpec.describe Migration do describe '#important_queries' do it 'returns only unexcluded queries' do - expect(subject.important_queries.size).to eq(3) + expect(subject.important_queries.size).to eq(4) end end diff --git a/notifier/templates/detail.erb b/notifier/templates/detail.erb index 1580a838..aabaf17e 100644 --- a/notifier/templates/detail.erb +++ b/notifier/templates/detail.erb @@ -13,6 +13,9 @@ % if create_index_queries.present? && exceeds_time_guidance <%= render_index_creation_timing_exceeded_warning(create_index_queries) %> % end +% if delete_from_queries.present? +<%= render_deleted_from_warning(delete_from_queries) %> +% end % end <%= render_migration_histogram(migration) %> diff --git a/notifier/templates/irreversible_delete_from_statements_warning.erb b/notifier/templates/irreversible_delete_from_statements_warning.erb new file mode 100644 index 00000000..460cf2fd --- /dev/null +++ b/notifier/templates/irreversible_delete_from_statements_warning.erb @@ -0,0 +1,9 @@ +#### :warning: Irreversible data changes statements (DELETE FROM) + +<% if plural %> +Irreversible statements were detected for this migration. +<% else %> +An irreversible statement was detected for this migration. +<% end %> + +Make sure you are following the [guidelines](https://docs.gitlab.com/development/database_review/#preparation-when-adding-data-migrations) for irreversible data operations. -- GitLab From 0537226f7d23438c50d6cc619137c71fef1ea5ec Mon Sep 17 00:00:00 2001 From: Leonardo Rosa Date: Thu, 29 May 2025 13:18:47 -0300 Subject: [PATCH 2/7] Includes the DELETE warning in the general warnings header --- notifier/migration.rb | 9 ++++- .../migration-testing/v4/expected-comment.txt | 3 +- notifier/spec/migration_spec.rb | 38 +++++++++++-------- 3 files changed, 33 insertions(+), 17 deletions(-) diff --git a/notifier/migration.rb b/notifier/migration.rb index 7e6bb8d2..186e5729 100644 --- a/notifier/migration.rb +++ b/notifier/migration.rb @@ -190,6 +190,7 @@ class Migration end warnings << time_remedy if exceeds_time_guidance? + warnings << data_deletion_warning if delete_from_queries.any? if bbm_failed_finalze? warnings << "#{name_formatted} attempted to finalize a batched background migration that is still running." @@ -211,7 +212,7 @@ class Migration end def warning? - !success? || exceeds_time_guidance? || has_queries_with_warnings? + !success? || exceeds_time_guidance? || has_queries_with_warnings? || delete_from_queries.any? end def bbm_failed_finalze? @@ -245,4 +246,10 @@ class Migration def sort_key [regular? ? 0 : 1, version] end + + def data_deletion_warning + url = "https://docs.gitlab.com/development/database_review/#preparation-when-adding-data-migrations" + "#{name_formatted} performs irreversible data changes (DELETE). Make sure the [guidelines](#{url}) for " \ + "irreversible data operations were followed." + end end diff --git a/notifier/spec/fixtures/migration-testing/v4/expected-comment.txt b/notifier/spec/fixtures/migration-testing/v4/expected-comment.txt index 19f19813..39eb5d2e 100644 --- a/notifier/spec/fixtures/migration-testing/v4/expected-comment.txt +++ b/notifier/spec/fixtures/migration-testing/v4/expected-comment.txt @@ -3,7 +3,7 @@ *Commit SHA:* 20c0da84ee54eee5ccfdd1720dbda853d1dfa8ba -| | 9 Warnings | +| | 10 Warnings | | --------- | -------------------- | | :warning: | 20210602144718 - CreateTestTable had a query that [exceeded timing guidelines](https://docs.gitlab.com/ee/development/database/query_performance.html#timing-guidelines-for-queries). Run time should not
exceed 100ms, but it was 192.8ms. Please consider possible options to improve the query performance.

CREATE TABLE "test_tables" ("id" bigserial primary key, "stars" bigint DEFAULT 0 NOT NULL,
"created_at" timestamp(6) NOT NULL, "updated_at" timestamp(6) NOT NULL, "title" text, "notes"
text)
| | :warning: | 20210603233011 - RegularMigrationWithFiveSecondQuery had a query that [exceeded timing guidelines](https://docs.gitlab.com/ee/development/database/query_performance.html#timing-guidelines-for-queries).
Run time should not exceed 100ms, but it was 5005.1ms. Please consider possible options to improve
the query performance.
SELECT pg_sleep($1)
| @@ -13,6 +13,7 @@ | :warning: | 20221012000001 - CreateLongRunningSyncIndex took 93.33min. Please add a comment that mentions
Release Managers (`@gitlab-org/release/managers`) so they are informed. | | :warning: | 20221012000001 - CreateLongRunningSyncIndex may need a [batched background migration](https://docs.gitlab.com/ee/development/database/batched_background_migrations.html) to comply with
[timing guidelines](https://docs.gitlab.com/ee/development/migration_style_guide.html#how-long-a-migration-should-take). It took 93.33min, but should not exceed 3.0min | | :warning: | 20250521194808 - DeleteDataFromIssuesTable had a query that [exceeded timing guidelines](https://docs.gitlab.com/ee/development/database/query_performance.html#timing-guidelines-for-queries). Run time
should not exceed 100ms, but it was 1761.64ms. Please consider possible options to improve the query
performance.
DELETE
FROM "issues"WHERE "issues"."id" IN (
SELECT "issues"."id" FROM "issues" LIMIT $1
)
| +| :warning: | 20250521194808 - DeleteDataFromIssuesTable perform irreversible data changes (DELETE). Make sure the
[guidelines](https://docs.gitlab.com/development/database_review/#preparation-when-adding-data-migrations) for irreversible data operations were followed. | | :warning: | 20990604233157 - MigrationThrowsException did not complete successfully, check the job log for
details | Migrations included in this change have been executed on gitlab.com data for testing purposes. For details, please see the [migration testing pipeline](https://gitlab.com/gitlab-org/database-team/gitlab-com-database-testing/-/pipelines/4711) (limited access). diff --git a/notifier/spec/migration_spec.rb b/notifier/spec/migration_spec.rb index d7c89c16..2cef839b 100644 --- a/notifier/spec/migration_spec.rb +++ b/notifier/spec/migration_spec.rb @@ -32,6 +32,20 @@ RSpec.describe Migration do "max_time" => 80.51234, "mean_time" => 80.51234, "rows" => 0 + } + ] + end + + let(:bad_queries) do + [ + { + "query" => "select * from users limit 1000 /*application:test*/", + "expected_query" => "select * from users limit 1000", + "calls" => 1, + "total_time" => 222.49203, + "max_time" => Query::QUERY_GUIDANCE_MILLISECONDS * 2, + "mean_time" => 222.49203, + "rows" => 1 }, { "query" => "DELETE FROM \"issues\" WHERE \"issue\".\"id\" IN (1, 2, 3, 4) /*application:test*/", @@ -45,18 +59,6 @@ RSpec.describe Migration do ] end - let(:bad_query) do - { - "query" => "select * from users limit 1000 /*application:test*/", - "expected_query" => "select * from users limit 1000", - "calls" => 1, - "total_time" => 222.49203, - "max_time" => Query::QUERY_GUIDANCE_MILLISECONDS * 2, - "mean_time" => 222.49203, - "rows" => 1 - } - end - let(:concurrent_query) do { "query" => "create index concurrently tmp_index ON tmp_table (id)", @@ -69,7 +71,7 @@ RSpec.describe Migration do } end - let(:queries) { good_queries + [bad_query] } + let(:queries) { good_queries + bad_queries } let(:stats) do { @@ -194,7 +196,7 @@ RSpec.describe Migration do end context 'when at least one important commands is not concurrent' do - let(:queries) { [concurrent_query, bad_query] } + let(:queries) { [concurrent_query] + bad_queries } it { is_expected.not_to be_concurrent_only } end @@ -286,7 +288,13 @@ RSpec.describe Migration do end it 'is true if a query took too long' do - queries << bad_query + queries << bad_queries.first + + expect(subject.warning?).to be true + end + + it 'is true if a query has a delete statement' do + queries << bad_queries.last expect(subject.warning?).to be true end -- GitLab From 8403ce57b1c88ceee5f4a1f660acba32f96e97ec Mon Sep 17 00:00:00 2001 From: Leonardo Rosa Date: Thu, 29 May 2025 13:21:10 -0300 Subject: [PATCH 3/7] Update expected comment --- .../spec/fixtures/migration-testing/v4/expected-comment.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/notifier/spec/fixtures/migration-testing/v4/expected-comment.txt b/notifier/spec/fixtures/migration-testing/v4/expected-comment.txt index 39eb5d2e..f3b022d5 100644 --- a/notifier/spec/fixtures/migration-testing/v4/expected-comment.txt +++ b/notifier/spec/fixtures/migration-testing/v4/expected-comment.txt @@ -13,7 +13,7 @@ | :warning: | 20221012000001 - CreateLongRunningSyncIndex took 93.33min. Please add a comment that mentions
Release Managers (`@gitlab-org/release/managers`) so they are informed. | | :warning: | 20221012000001 - CreateLongRunningSyncIndex may need a [batched background migration](https://docs.gitlab.com/ee/development/database/batched_background_migrations.html) to comply with
[timing guidelines](https://docs.gitlab.com/ee/development/migration_style_guide.html#how-long-a-migration-should-take). It took 93.33min, but should not exceed 3.0min | | :warning: | 20250521194808 - DeleteDataFromIssuesTable had a query that [exceeded timing guidelines](https://docs.gitlab.com/ee/development/database/query_performance.html#timing-guidelines-for-queries). Run time
should not exceed 100ms, but it was 1761.64ms. Please consider possible options to improve the query
performance.
DELETE
FROM "issues"WHERE "issues"."id" IN (
SELECT "issues"."id" FROM "issues" LIMIT $1
)
| -| :warning: | 20250521194808 - DeleteDataFromIssuesTable perform irreversible data changes (DELETE). Make sure the
[guidelines](https://docs.gitlab.com/development/database_review/#preparation-when-adding-data-migrations) for irreversible data operations were followed. | +| :warning: | 20250521194808 - DeleteDataFromIssuesTable performs irreversible data changes (DELETE). Make sure
the [guidelines](https://docs.gitlab.com/development/database_review/#preparation-when-adding-data-migrations) for irreversible data operations were followed. | | :warning: | 20990604233157 - MigrationThrowsException did not complete successfully, check the job log for
details | Migrations included in this change have been executed on gitlab.com data for testing purposes. For details, please see the [migration testing pipeline](https://gitlab.com/gitlab-org/database-team/gitlab-com-database-testing/-/pipelines/4711) (limited access). -- GitLab From ee5d015cca353979c547fa2a83aa9c0ee6c47751 Mon Sep 17 00:00:00 2001 From: Leonardo Rosa Date: Thu, 29 May 2025 14:26:18 -0300 Subject: [PATCH 4/7] Update BBM comment --- .../migration-testing/v4/expected-comment.txt | 6 +++--- .../v4/expected-migration-failure-notice.txt | 2 +- .../batch_1/migration-stats.json | 12 ++++++++++-- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/notifier/spec/fixtures/migration-testing/v4/expected-comment.txt b/notifier/spec/fixtures/migration-testing/v4/expected-comment.txt index f3b022d5..c9bee9bc 100644 --- a/notifier/spec/fixtures/migration-testing/v4/expected-comment.txt +++ b/notifier/spec/fixtures/migration-testing/v4/expected-comment.txt @@ -412,7 +412,7 @@ Make sure you are following the [guidelines](https://docs.gitlab.com/development
- :boom:

Background Migration: DeleteUsersBatchedMigration

+

Background Migration: DeleteUsersBatchedMigration

Sampled 1 batches. Estimated Time to complete: 4 weeks, 11 hours, 21 minutes, and 11 seconds @@ -423,8 +423,7 @@ Make sure you are following the [guidelines](https://docs.gitlab.com/development - Average batch time: 122.85s - Batch size: 1000 - N. of batches sampled: 1 - - N. of failed batches: 1 - - Failed batches: batch_1 + - N. of failed batches: 0 Time estimation is conservative and based on sampling production data in a test environment. It represents the max time that migration could take. The actual time may differ from this estimation.
@@ -434,6 +433,7 @@ Make sure you are following the [guidelines](https://docs.gitlab.com/development | Calls | Total Time | Max Time | Mean Time | Rows | Query | | ----- | ---------- | -------- | --------- | ---- | ----- | +| 1 | 180.6 ms | 180.6 ms | 180.6 ms | 1 |
DELETE
FROM users
WHERE $1::users.id
| | 1 | 1.0 ms | 1.0 ms | 1.0 ms | 1 |
INSERT INTO batched_background_migration_job_transition_logs (batched_background_migration_job_id, created_at, updated_at, previous_status, next_status) VALUES ($1, $2, $3, $4, $5) RETURNING id
| | 1 | 0.9 ms | 0.9 ms | 0.9 ms | 1 |
UPDATE batched_background_migration_jobs
SET updated_at = $1, sub_batch_size = $2
WHERE batched_background_migration_jobs.id = $3
| | 1 | 0.4 ms | 0.4 ms | 0.4 ms | 1 |
INSERT INTO batched_background_migration_job_transition_logs (batched_background_migration_job_id, created_at, updated_at, previous_status, next_status, exception_class, exception_message) VALUES ($1, $2, $3, $4, $5, $6, $7) RETURNING id
| diff --git a/notifier/spec/fixtures/migration-testing/v4/expected-migration-failure-notice.txt b/notifier/spec/fixtures/migration-testing/v4/expected-migration-failure-notice.txt index b684c060..a74c2233 100644 --- a/notifier/spec/fixtures/migration-testing/v4/expected-migration-failure-notice.txt +++ b/notifier/spec/fixtures/migration-testing/v4/expected-migration-failure-notice.txt @@ -16,5 +16,5 @@ MR can be merged. | Database | Migration Name | |----------|----------------| -| main | DeleteUsersBatchedMigration | +| main | TestBackgroundMigration | | sec | TestBackgroundMigration | diff --git a/notifier/spec/fixtures/migration-testing/v4/main/background_migrations/DeleteUsersBatchedMigration/batch_1/migration-stats.json b/notifier/spec/fixtures/migration-testing/v4/main/background_migrations/DeleteUsersBatchedMigration/batch_1/migration-stats.json index 46cac11a..dadc7bcd 100644 --- a/notifier/spec/fixtures/migration-testing/v4/main/background_migrations/DeleteUsersBatchedMigration/batch_1/migration-stats.json +++ b/notifier/spec/fixtures/migration-testing/v4/main/background_migrations/DeleteUsersBatchedMigration/batch_1/migration-stats.json @@ -2,10 +2,18 @@ "version": null, "name": "batch_1", "walltime": 122.56930105388165, - "success": false, + "success": true, "total_database_size_change": 81920, - "error_message": "PG::QueryCanceled: ERROR: canceling statement due to statement timeout\nCONTEXT: SQL statement \"UPDATE ONLY \"public\".\"merge_requests\" SET \"merge_user_id\" = NULL WHERE $1 OPERATOR(pg_catalog.=) \"merge_user_id\"\"\n", + "error_message": null, "query_statistics": [ + { + "query": "DELETE FROM \"users\" WHERE \"users\".\"id\" $1 /*application:test,correlation_id:a1e2cc3c3c66b34934ab82ee9a40c9b7,db_config_database:gitlabhq_dblab,db_config_name:main,line:/app/models/concerns/each_batch.rb:65:in `each_batch'*/", + "calls": 1, + "total_time": 180.6406060000002, + "max_time": 180.6406060000002, + "mean_time": 180.6406060000002, + "rows": 1 + }, { "query": "select pg_database_size(current_database()) /*application:test,correlation_id:a1e2cc3c3c66b34934ab82ee9a40c9b7,db_config_database:gitlabhq_dblab,db_config_name:main,line:/lib/gitlab/database/migrations/observers/total_database_size_change.rb:25:in `get_total_database_size'*/", "calls": 1, -- GitLab From 0b71fe704bdf00af1ef472ec36e06e3e8fe78ece Mon Sep 17 00:00:00 2001 From: Leonardo Rosa Date: Thu, 29 May 2025 15:38:30 -0300 Subject: [PATCH 5/7] Extends warning to BBMs --- notifier/background_migration.rb | 16 ++ notifier/feedback.rb | 5 +- .../migration-testing/v4/expected-comment.txt | 248 ++++++++++++++---- .../templates/background_migration_detail.erb | 8 +- notifier/templates/detail.erb | 16 +- ...ersible_delete_from_statements_warning.erb | 2 +- 6 files changed, 240 insertions(+), 55 deletions(-) diff --git a/notifier/background_migration.rb b/notifier/background_migration.rb index be9174e5..6e73b468 100644 --- a/notifier/background_migration.rb +++ b/notifier/background_migration.rb @@ -87,6 +87,22 @@ class BackgroundMigration batches.present? && batches.all?(&:success?) end + def warnings? + delete_from_queries.any? + end + + def header_icon + return ':boom:' unless success? + + return ':warning:' if warnings? + + nil + end + + def delete_from_queries + batches.select { |batch| batch.delete_from_queries.any? } + end + private def collapse_in_statements(st) diff --git a/notifier/feedback.rb b/notifier/feedback.rb index eb0daf39..c94113e0 100644 --- a/notifier/feedback.rb +++ b/notifier/feedback.rb @@ -37,7 +37,9 @@ class Feedback end def render_background_migration_detail(background_migration) - erb('background_migration_detail').result(binding) + b = binding + b.local_variable_set(:delete_from_queries, background_migration.delete_from_queries) + erb('background_migration_detail').result(b) end def render_clone_details(clone_details) @@ -94,7 +96,6 @@ class Feedback def render_deleted_from_warning(delete_from_queries) erb('irreversible_delete_from_statements_warning').result_with_hash( reference_url: "https://docs.gitlab.com/development/database_review/#preparation-when-adding-data-migrations", - queries: delete_from_queries, plural: delete_from_queries.size > 1 ) end diff --git a/notifier/spec/fixtures/migration-testing/v4/expected-comment.txt b/notifier/spec/fixtures/migration-testing/v4/expected-comment.txt index c9bee9bc..b4b840d3 100644 --- a/notifier/spec/fixtures/migration-testing/v4/expected-comment.txt +++ b/notifier/spec/fixtures/migration-testing/v4/expected-comment.txt @@ -55,13 +55,16 @@ Migrations included in this change have been executed on gitlab.com data for tes * Duration: 2.2 s
* Database size change: +24.00 KiB + + | Calls | Total Time | Max Time | Mean Time | Rows | Query | | ----- | ---------- | -------- | --------- | ---- | ----- | | 1 | 192.8 ms | 192.8 ms | 192.8 ms | 0 |
CREATE TABLE "test_tables" ("id" bigserial primary key, "stars" bigint DEFAULT 0 NOT NULL, "created_at" timestamp(6) NOT NULL, "updated_at" timestamp(6) NOT NULL, "title" text, "notes" text)
| | 1 | 6.6 ms | 6.6 ms | 6.6 ms | 0 |
ALTER TABLE "test_tables" ADD CONSTRAINT "check_0770ba173a" CHECK (char_length("title") <= 128), ADD CONSTRAINT "check_9cfc473dbc" CHECK (char_length("notes") <= 1024)
| | 1 | 0.0 ms | 0.0 ms | 0.0 ms | 1 |
SELECT $1::regtype::oid
| - + +
Histogram for CreateTestTable @@ -79,17 +82,22 @@ Migrations included in this change have been executed on gitlab.com data for tes
-
+
+
:warning:

Migration: 20210603233011 - RegularMigrationWithFiveSecondQuery

* Type: Regular
* Duration: 6.5 s
* Database size change: +0.00 B + + | Calls | Total Time | Max Time | Mean Time | Rows | Query | | ----- | ---------- | -------- | --------- | ---- | ----- | | 1 | 5005.1 ms | 5005.1 ms | 5005.1 ms | 1 |
SELECT pg_sleep($1)
| + +
Histogram for RegularMigrationWithFiveSecondQuery @@ -106,7 +114,8 @@ Migrations included in this change have been executed on gitlab.com data for tes
-
+
+

Migration: 20210915152743 - MigrationInheritsGitlabDatabaseMigration

* Type: Regular
* Duration: 1.2 s
@@ -114,10 +123,15 @@ Migrations included in this change have been executed on gitlab.com data for tes + + + + No histogram available for visualization -
+
+

Migration: 20220223163519 - EnsureGitlabComInMigrations

* Type: Regular
* Duration: 1.2 s
@@ -125,10 +139,15 @@ Migrations included in this change have been executed on gitlab.com data for tes + + + + No histogram available for visualization -
+
+

Migration: 20220318174439 - QueueTestBackgroundMigration

* Type: Regular
* Duration: 1.8 s
@@ -136,21 +155,30 @@ Migrations included in this change have been executed on gitlab.com data for tes + + + + No histogram available for visualization -
+
+
:boom:

Migration: 20221012000000 - FinalizeTestBatchedBackgroundMigrationMain

* Type: Regular
* Duration: 1.4 s
* Database size change: +0.00 B + + | Calls | Total Time | Max Time | Mean Time | Rows | Query | | ----- | ---------- | -------- | --------- | ---- | ----- | | 1 | 0.1 ms | 0.1 ms | 0.1 ms | 1 |
SELECT "batched_background_migrations".*
FROM "batched_background_migrations" WHERE "batched_background_migrations"."job_class_name" = $1 AND "batched_background_migrations"."table_name" = $2 AND "batched_background_migrations"."column_name" = $3 AND (job_arguments = $4) AND "batched_background_migrations"."gitlab_schema" = $5
ORDER BY "batched_background_migrations"."id" ASC
LIMIT $6
| | 2 | 0.0 ms | 0.0 ms | 0.0 ms | 2 |
SELECT pg_backend_pid()
| + +
Histogram for FinalizeTestBatchedBackgroundMigrationMain @@ -167,17 +195,21 @@ Migrations included in this change have been executed on gitlab.com data for tes
-
+
+
:warning:

Migration: 20221012000001 - CreateLongRunningSyncIndex

* Type: Regular
* Duration: 5600.3 s
* Database size change: +32.00 KiB + + | Calls | Total Time | Max Time | Mean Time | Rows | Query | | ----- | ---------- | -------- | --------- | ---- | ----- | | 1 | 5377900.1 ms | 5377900.1 ms | 5377900.1 ms | 0 |
CREATE INDEX CONCURRENTLY "tmp_index_for_null_member_namespace_id" ON "members" ("member_namespace_id")
WHERE member_namespace_id IS NULL
| - #### :warning: Index creation timing exceeded + +#### :warning: Index creation timing exceeded This index creation query might have caused your migration to exceed timing guidelines. Please examine the timing data on this query and consider if the [asynchronous index creation](https://docs.gitlab.com/ee/development/database/adding_database_indexes.html#create-indexes-asynchronously) process is appropriate. @@ -199,17 +231,21 @@ Please examine the timing data on this query and consider if the [asynchronous i
-
+
+

Migration: 20221130142531 - CreateEfficientlyOrderedColumnsTable

* Type: Regular
* Duration: 1.2 s
* Database size change: +32.00 KiB + + | Calls | Total Time | Max Time | Mean Time | Rows | Query | | ----- | ---------- | -------- | --------- | ---- | ----- | | 1 | 9.4 ms | 9.4 ms | 9.4 ms | 0 |
CREATE TABLE "efficiently_ordered_columns_tables" ("line_attr" line, "circle_attr" circle, "uuid_attr" uuid, "point_attr" point, "id" bigserial primary key, "bigserial_attr" bigserial, "bigint_attr" bigint, "float_attr" float, "time_attr" time, "timestamp_attr" timestamp, "date_attr" date, "integer_attr" integer, "oid_attr" oid, "smallint_attr" smallint, "boolean_attr" boolean, "inet_attr" inet, "jsonb_attr" jsonb, "text_attr" text)
| - + +
Histogram for CreateEfficientlyOrderedColumnsTable @@ -227,17 +263,20 @@ Please examine the timing data on this query and consider if the [asynchronous i
-
+
+

Migration: 20221130142617 - CreateInefficientlyOrderedColumnsTable

* Type: Regular
* Duration: 1.2 s
* Database size change: +40.00 KiB + + | Calls | Total Time | Max Time | Mean Time | Rows | Query | | ----- | ---------- | -------- | --------- | ---- | ----- | | 1 | 5.7 ms | 5.7 ms | 5.7 ms | 0 |
CREATE TABLE "inefficiently_ordered_columns_tables" ("id" bigserial primary key, "text_attr" text, "boolean_attr" boolean, "smallint_attr" smallint, "integer_attr" integer, "point_attr" point, "circle_attr" circle, "line_attr" line)
| - :warning: Column ordering suggestions + :warning: Column ordering suggestions Ordering columns efficiently (as in below tables) will help us save more space, further details can be found here. @@ -256,6 +295,7 @@ Please examine the timing data on this query and consider if the [asynchronous i | text_attr | text | +
Histogram for CreateInefficientlyOrderedColumnsTable @@ -272,23 +312,28 @@ Please examine the timing data on this query and consider if the [asynchronous i
-
+
+
:warning:

Migration: 20250521194808 - DeleteDataFromIssuesTable

* Type: Regular
* Duration: 5.6 s
* Database size change: +0.00 B + +##### :warning: Irreversible data changes statements (DELETE FROM) + +An irreversible statement was detected for this migration. + +Make sure you are following the [guidelines](https://docs.gitlab.com/development/database_review/#preparation-when-adding-data-migrations) for irreversible data operations. + | Calls | Total Time | Max Time | Mean Time | Rows | Query | | ----- | ---------- | -------- | --------- | ---- | ----- | | 1 | 1761.6 ms | 1761.6 ms | 1761.6 ms | 10 |
DELETE
FROM "issues"WHERE "issues"."id" IN (
SELECT "issues"."id" FROM "issues" LIMIT $1
)
| | 1 | 0.1 ms | 0.1 ms | 0.1 ms | 1 |
SELECT "feature_gates"."key", "feature_gates"."value"  FROM "feature_gates"  WHERE "feature_gates"."feature_key" = $1
| | 2 | 0.0 ms | 0.0 ms | 0.0 ms | 2 |
SELECT pg_backend_pid()
| -#### :warning: Irreversible data changes statements (DELETE FROM) -An irreversible statement was detected for this migration. -Make sure you are following the [guidelines](https://docs.gitlab.com/development/database_review/#preparation-when-adding-data-migrations) for irreversible data operations.
Histogram for DeleteDataFromIssuesTable @@ -306,17 +351,22 @@ Make sure you are following the [guidelines](https://docs.gitlab.com/development
-
+
+

Migration: 20210604232017 - DropTestTable

* Type: Post deploy
* Duration: 1.3 s
* Database size change: -24.00 KiB + + | Calls | Total Time | Max Time | Mean Time | Rows | Query | | ----- | ---------- | -------- | --------- | ---- | ----- | | 1 | 2.6 ms | 2.6 ms | 2.6 ms | 0 |
DROP TABLE "test_tables"
| + +
Histogram for DropTestTable @@ -333,7 +383,8 @@ Make sure you are following the [guidelines](https://docs.gitlab.com/development
-
+
+
:boom:

Migration: 20990604233157 - MigrationThrowsException

* Type: Post deploy
* Duration: 1.1 s
@@ -341,14 +392,20 @@ Make sure you are following the [guidelines](https://docs.gitlab.com/development + + + + No histogram available for visualization
+
:boom:

Background Migration: TestBackgroundMigration

+
Sampled 6 batches. Estimated Time to complete: 1 hour and 36 minutes @@ -411,8 +468,15 @@ Make sure you are following the [guidelines](https://docs.gitlab.com/development
+
-

Background Migration: DeleteUsersBatchedMigration

+ :warning:

Background Migration: DeleteUsersBatchedMigration

+ +##### :warning: Irreversible data changes statements (DELETE FROM) + +An irreversible statement was detected for this migration. + +Make sure you are following the [guidelines](https://docs.gitlab.com/development/database_review/#preparation-when-adding-data-migrations) for irreversible data operations.
Sampled 1 batches. Estimated Time to complete: 4 weeks, 11 hours, 21 minutes, and 11 seconds @@ -476,6 +540,7 @@ Make sure you are following the [guidelines](https://docs.gitlab.com/development
+ #### Other information
@@ -582,13 +647,16 @@ Migrations included in this change have been executed on gitlab.com data for tes * Duration: 1.9 s
* Database size change: +24.00 KiB + + | Calls | Total Time | Max Time | Mean Time | Rows | Query | | ----- | ---------- | -------- | --------- | ---- | ----- | | 1 | 122.9 ms | 122.9 ms | 122.9 ms | 0 |
CREATE TABLE "test_tables" ("id" bigserial primary key, "stars" bigint DEFAULT 0 NOT NULL, "created_at" timestamp(6) NOT NULL, "updated_at" timestamp(6) NOT NULL, "title" text, "notes" text)
| | 1 | 8.3 ms | 8.3 ms | 8.3 ms | 0 |
ALTER TABLE "test_tables" ADD CONSTRAINT "check_0770ba173a" CHECK (char_length("title") <= 128), ADD CONSTRAINT "check_9cfc473dbc" CHECK (char_length("notes") <= 1024)
| | 1 | 0.0 ms | 0.0 ms | 0.0 ms | 1 |
SELECT $1::regtype::oid
| - + +
Histogram for CreateTestTable @@ -606,17 +674,22 @@ Migrations included in this change have been executed on gitlab.com data for tes
-
+
+
:warning:

Migration: 20210603233011 - RegularMigrationWithFiveSecondQuery

* Type: Regular
* Duration: 6.2 s
* Database size change: +0.00 B + + | Calls | Total Time | Max Time | Mean Time | Rows | Query | | ----- | ---------- | -------- | --------- | ---- | ----- | | 1 | 5005.1 ms | 5005.1 ms | 5005.1 ms | 1 |
SELECT pg_sleep($1)
| + +
Histogram for RegularMigrationWithFiveSecondQuery @@ -633,7 +706,8 @@ Migrations included in this change have been executed on gitlab.com data for tes
-
+
+

Migration: 20210915152743 - MigrationInheritsGitlabDatabaseMigration

* Type: Regular
* Duration: 1.2 s
@@ -641,10 +715,15 @@ Migrations included in this change have been executed on gitlab.com data for tes + + + + No histogram available for visualization -
+
+

Migration: 20220223163519 - EnsureGitlabComInMigrations

* Type: Regular
* Duration: 1.2 s
@@ -652,10 +731,15 @@ Migrations included in this change have been executed on gitlab.com data for tes + + + + No histogram available for visualization -
+
+

Migration: 20220318174439 - QueueTestBackgroundMigration

* Type: Regular
* Duration: 1.7 s
@@ -663,20 +747,28 @@ Migrations included in this change have been executed on gitlab.com data for tes + + + + No histogram available for visualization -
+
+

Migration: 20221130142531 - CreateEfficientlyOrderedColumnsTable

* Type: Regular
* Duration: 1.2 s
* Database size change: +40.00 KiB + + | Calls | Total Time | Max Time | Mean Time | Rows | Query | | ----- | ---------- | -------- | --------- | ---- | ----- | | 1 | 12.0 ms | 12.0 ms | 12.0 ms | 0 |
CREATE TABLE "efficiently_ordered_columns_tables" ("line_attr" line, "circle_attr" circle, "uuid_attr" uuid, "point_attr" point, "id" bigserial primary key, "bigserial_attr" bigserial, "bigint_attr" bigint, "float_attr" float, "time_attr" time, "timestamp_attr" timestamp, "date_attr" date, "integer_attr" integer, "oid_attr" oid, "smallint_attr" smallint, "boolean_attr" boolean, "inet_attr" inet, "jsonb_attr" jsonb, "text_attr" text)
| - + +
Histogram for CreateEfficientlyOrderedColumnsTable @@ -694,17 +786,20 @@ Migrations included in this change have been executed on gitlab.com data for tes
-
+
+

Migration: 20221130142617 - CreateInefficientlyOrderedColumnsTable

* Type: Regular
* Duration: 1.2 s
* Database size change: +48.00 KiB + + | Calls | Total Time | Max Time | Mean Time | Rows | Query | | ----- | ---------- | -------- | --------- | ---- | ----- | | 1 | 19.2 ms | 19.2 ms | 19.2 ms | 0 |
CREATE TABLE "inefficiently_ordered_columns_tables" ("id" bigserial primary key, "text_attr" text, "boolean_attr" boolean, "smallint_attr" smallint, "integer_attr" integer, "point_attr" point, "circle_attr" circle, "line_attr" line)
| - :warning: Column ordering suggestions + :warning: Column ordering suggestions Ordering columns efficiently (as in below tables) will help us save more space, further details can be found here. @@ -723,6 +818,7 @@ Migrations included in this change have been executed on gitlab.com data for tes | text_attr | text | +
Histogram for CreateInefficientlyOrderedColumnsTable @@ -739,17 +835,22 @@ Migrations included in this change have been executed on gitlab.com data for tes
-
+
+

Migration: 20210604232017 - DropTestTable

* Type: Post deploy
* Duration: 1.4 s
* Database size change: -24.00 KiB + + | Calls | Total Time | Max Time | Mean Time | Rows | Query | | ----- | ---------- | -------- | --------- | ---- | ----- | | 1 | 6.8 ms | 6.8 ms | 6.8 ms | 0 |
DROP TABLE "test_tables"
| + +
Histogram for DropTestTable @@ -766,7 +867,8 @@ Migrations included in this change have been executed on gitlab.com data for tes
-
+
+
:boom:

Migration: 20990604233157 - MigrationThrowsException

* Type: Post deploy
* Duration: 1.1 s
@@ -774,11 +876,16 @@ Migrations included in this change have been executed on gitlab.com data for tes + + + + No histogram available for visualization
+ #### Other information
@@ -882,13 +989,16 @@ Migrations included in this change have been executed on gitlab.com data for tes * Duration: 2.2 s
* Database size change: +24.00 KiB + + | Calls | Total Time | Max Time | Mean Time | Rows | Query | | ----- | ---------- | -------- | --------- | ---- | ----- | | 1 | 192.8 ms | 192.8 ms | 192.8 ms | 0 |
CREATE TABLE "test_tables" ("id" bigserial primary key, "stars" bigint DEFAULT 0 NOT NULL, "created_at" timestamp(6) NOT NULL, "updated_at" timestamp(6) NOT NULL, "title" text, "notes" text)
| | 1 | 6.6 ms | 6.6 ms | 6.6 ms | 0 |
ALTER TABLE "test_tables" ADD CONSTRAINT "check_0770ba173a" CHECK (char_length("title") <= 128), ADD CONSTRAINT "check_9cfc473dbc" CHECK (char_length("notes") <= 1024)
| | 1 | 0.0 ms | 0.0 ms | 0.0 ms | 1 |
SELECT $1::regtype::oid
| - + +
Histogram for CreateTestTable @@ -906,17 +1016,22 @@ Migrations included in this change have been executed on gitlab.com data for tes
-
+
+
:warning:

Migration: 20210603233011 - RegularMigrationWithFiveSecondQuery

* Type: Regular
* Duration: 6.5 s
* Database size change: +0.00 B + + | Calls | Total Time | Max Time | Mean Time | Rows | Query | | ----- | ---------- | -------- | --------- | ---- | ----- | | 1 | 5005.1 ms | 5005.1 ms | 5005.1 ms | 1 |
SELECT pg_sleep($1)
| + +
Histogram for RegularMigrationWithFiveSecondQuery @@ -933,7 +1048,8 @@ Migrations included in this change have been executed on gitlab.com data for tes
-
+
+

Migration: 20210915152743 - MigrationInheritsGitlabDatabaseMigration

* Type: Regular
* Duration: 1.2 s
@@ -941,10 +1057,15 @@ Migrations included in this change have been executed on gitlab.com data for tes + + + + No histogram available for visualization -
+
+

Migration: 20220223163519 - EnsureGitlabComInMigrations

* Type: Regular
* Duration: 1.2 s
@@ -952,10 +1073,15 @@ Migrations included in this change have been executed on gitlab.com data for tes + + + + No histogram available for visualization -
+
+

Migration: 20220318174439 - QueueTestBackgroundMigration

* Type: Regular
* Duration: 1.8 s
@@ -963,21 +1089,30 @@ Migrations included in this change have been executed on gitlab.com data for tes + + + + No histogram available for visualization -
+
+
:boom:

Migration: 20221012000000 - FinalizeTestBatchedBackgroundMigrationMain

* Type: Regular
* Duration: 1.4 s
* Database size change: +0.00 B + + | Calls | Total Time | Max Time | Mean Time | Rows | Query | | ----- | ---------- | -------- | --------- | ---- | ----- | | 1 | 0.1 ms | 0.1 ms | 0.1 ms | 1 |
SELECT "batched_background_migrations".*
FROM "batched_background_migrations" WHERE "batched_background_migrations"."job_class_name" = $1 AND "batched_background_migrations"."table_name" = $2 AND "batched_background_migrations"."column_name" = $3 AND (job_arguments = $4) AND "batched_background_migrations"."gitlab_schema" = $5
ORDER BY "batched_background_migrations"."id" ASC
LIMIT $6
| | 2 | 0.0 ms | 0.0 ms | 0.0 ms | 2 |
SELECT pg_backend_pid()
| + +
Histogram for FinalizeTestBatchedBackgroundMigrationMain @@ -994,17 +1129,21 @@ Migrations included in this change have been executed on gitlab.com data for tes
-
+
+
:warning:

Migration: 20221012000001 - CreateLongRunningSyncIndex

* Type: Regular
* Duration: 5600.3 s
* Database size change: +32.00 KiB + + | Calls | Total Time | Max Time | Mean Time | Rows | Query | | ----- | ---------- | -------- | --------- | ---- | ----- | | 1 | 5377900.1 ms | 5377900.1 ms | 5377900.1 ms | 0 |
CREATE INDEX CONCURRENTLY "tmp_index_for_null_member_namespace_id" ON "members" ("member_namespace_id")
WHERE member_namespace_id IS NULL
| - #### :warning: Index creation timing exceeded + +#### :warning: Index creation timing exceeded This index creation query might have caused your migration to exceed timing guidelines. Please examine the timing data on this query and consider if the [asynchronous index creation](https://docs.gitlab.com/ee/development/database/adding_database_indexes.html#create-indexes-asynchronously) process is appropriate. @@ -1026,17 +1165,21 @@ Please examine the timing data on this query and consider if the [asynchronous i
-
+
+

Migration: 20221130142531 - CreateEfficientlyOrderedColumnsTable

* Type: Regular
* Duration: 1.2 s
* Database size change: +32.00 KiB + + | Calls | Total Time | Max Time | Mean Time | Rows | Query | | ----- | ---------- | -------- | --------- | ---- | ----- | | 1 | 9.4 ms | 9.4 ms | 9.4 ms | 0 |
CREATE TABLE "efficiently_ordered_columns_tables" ("line_attr" line, "circle_attr" circle, "uuid_attr" uuid, "point_attr" point, "id" bigserial primary key, "bigserial_attr" bigserial, "bigint_attr" bigint, "float_attr" float, "time_attr" time, "timestamp_attr" timestamp, "date_attr" date, "integer_attr" integer, "oid_attr" oid, "smallint_attr" smallint, "boolean_attr" boolean, "inet_attr" inet, "jsonb_attr" jsonb, "text_attr" text)
| - + +
Histogram for CreateEfficientlyOrderedColumnsTable @@ -1054,17 +1197,20 @@ Please examine the timing data on this query and consider if the [asynchronous i
-
+
+

Migration: 20221130142617 - CreateInefficientlyOrderedColumnsTable

* Type: Regular
* Duration: 1.2 s
* Database size change: +40.00 KiB + + | Calls | Total Time | Max Time | Mean Time | Rows | Query | | ----- | ---------- | -------- | --------- | ---- | ----- | | 1 | 5.7 ms | 5.7 ms | 5.7 ms | 0 |
CREATE TABLE "inefficiently_ordered_columns_tables" ("id" bigserial primary key, "text_attr" text, "boolean_attr" boolean, "smallint_attr" smallint, "integer_attr" integer, "point_attr" point, "circle_attr" circle, "line_attr" line)
| - :warning: Column ordering suggestions + :warning: Column ordering suggestions Ordering columns efficiently (as in below tables) will help us save more space, further details can be found here. @@ -1083,6 +1229,7 @@ Please examine the timing data on this query and consider if the [asynchronous i | text_attr | text | +
Histogram for CreateInefficientlyOrderedColumnsTable @@ -1099,17 +1246,22 @@ Please examine the timing data on this query and consider if the [asynchronous i
-
+
+

Migration: 20210604232017 - DropTestTable

* Type: Post deploy
* Duration: 1.3 s
* Database size change: -24.00 KiB + + | Calls | Total Time | Max Time | Mean Time | Rows | Query | | ----- | ---------- | -------- | --------- | ---- | ----- | | 1 | 2.6 ms | 2.6 ms | 2.6 ms | 0 |
DROP TABLE "test_tables"
| + +
Histogram for DropTestTable @@ -1126,7 +1278,8 @@ Please examine the timing data on this query and consider if the [asynchronous i
-
+
+
:boom:

Migration: 20990604233157 - MigrationThrowsException

* Type: Post deploy
* Duration: 1.1 s
@@ -1134,14 +1287,20 @@ Please examine the timing data on this query and consider if the [asynchronous i + + + + No histogram available for visualization
+
:boom:

Background Migration: TestBackgroundMigration

+
Sampled 6 batches. Estimated Time to complete: 1 hour and 36 minutes @@ -1204,6 +1363,7 @@ Please examine the timing data on this query and consider if the [asynchronous i
+ #### Other information
diff --git a/notifier/templates/background_migration_detail.erb b/notifier/templates/background_migration_detail.erb index a07230f1..15842ca9 100644 --- a/notifier/templates/background_migration_detail.erb +++ b/notifier/templates/background_migration_detail.erb @@ -1,6 +1,10 @@
- <%= ':boom: ' unless background_migration.success? %>

Background Migration: <%= background_migration.name %>

+ <%= background_migration.header_icon %>

Background Migration: <%= background_migration.name %>

+ +% if delete_from_queries.any? +<%= render_deleted_from_warning(delete_from_queries) %> +% end % if background_migration.execution_details.present?
@@ -25,4 +29,4 @@ Sampled <%= background_migration.batches.count %> batches. <%= render_background_migration_batch_histogram(background_migration) %> <%= render_background_migration_query_histogram(background_migration) %> -
\ No newline at end of file +
diff --git a/notifier/templates/detail.erb b/notifier/templates/detail.erb index aabaf17e..026fa9b9 100644 --- a/notifier/templates/detail.erb +++ b/notifier/templates/detail.erb @@ -5,19 +5,23 @@ * Database size change: <%= total_size_change(migration) %><%= conditional_size_change_note(migration) %> % if migration.queries.any? + +% if delete_from_queries.any? +<%= render_deleted_from_warning(delete_from_queries) %> +% end + <%= render_pgss_table(migration.queries) %> % if create_table_queries.present? - <%= render_migration_column_ordering_suggestion(create_table_queries) %> +<%= render_migration_column_ordering_suggestion(create_table_queries) %> % end + % if create_index_queries.present? && exceeds_time_guidance - <%= render_index_creation_timing_exceeded_warning(create_index_queries) %> -% end -% if delete_from_queries.present? -<%= render_deleted_from_warning(delete_from_queries) %> +<%= render_index_creation_timing_exceeded_warning(create_index_queries) %> % end + % end <%= render_migration_histogram(migration) %> -
\ No newline at end of file + diff --git a/notifier/templates/irreversible_delete_from_statements_warning.erb b/notifier/templates/irreversible_delete_from_statements_warning.erb index 460cf2fd..1394e71a 100644 --- a/notifier/templates/irreversible_delete_from_statements_warning.erb +++ b/notifier/templates/irreversible_delete_from_statements_warning.erb @@ -1,4 +1,4 @@ -#### :warning: Irreversible data changes statements (DELETE FROM) +##### :warning: Irreversible data changes statements (DELETE FROM) <% if plural %> Irreversible statements were detected for this migration. -- GitLab From e534bc18a6e0043d113368724d7deebcdc0f025b Mon Sep 17 00:00:00 2001 From: Leonardo Rosa Date: Thu, 29 May 2025 16:25:43 -0300 Subject: [PATCH 6/7] Fix BBM ordering failures --- notifier/result.rb | 3 +- .../migration-testing/v4/expected-comment.txt | 134 +++++++++--------- 2 files changed, 69 insertions(+), 68 deletions(-) diff --git a/notifier/result.rb b/notifier/result.rb index f48ad497..035caee5 100644 --- a/notifier/result.rb +++ b/notifier/result.rb @@ -18,6 +18,7 @@ class Result background_migrations = Pathname(background_migrations_path) .children.select(&:directory?) .map { |d| BackgroundMigration.from_directory(d) } + .sort_by(&:name) # Migrations with statistics have been executed in this run, others not # Limit to executed migrations @@ -27,7 +28,7 @@ class Result database = metadata(database_testing_path)['database'] || 'main' - Result.new(migrations, background_migrations, clone_details, database) + Result.new(migrations.sort.to_h, background_migrations, clone_details, database) end attr_reader :migrations, :background_migrations, :clone_details, :database diff --git a/notifier/spec/fixtures/migration-testing/v4/expected-comment.txt b/notifier/spec/fixtures/migration-testing/v4/expected-comment.txt index b4b840d3..a7c0c58d 100644 --- a/notifier/spec/fixtures/migration-testing/v4/expected-comment.txt +++ b/notifier/spec/fixtures/migration-testing/v4/expected-comment.txt @@ -402,73 +402,6 @@ Make sure you are following the [guidelines](https://docs.gitlab.com/development -
- :boom:

Background Migration: TestBackgroundMigration

- - -
-Sampled 6 batches. Estimated Time to complete: 1 hour and 36 minutes - - - Interval: 120s - - Max batch size: 750 - - Estimated seconds to complete: 5760s - - Average batch time: 1.08s - - Batch size: 150 - - N. of batches sampled: 6 - - N. of failed batches: 1 - - Failed batches: batch_5 - - Time estimation is conservative and based on sampling production data in a test environment. It represents the max time that migration could take. The actual time may differ from this estimation. -
- -_Consider changing max_batch_size and interval if this estimate is unacceptable._ - - -| Calls | Total Time | Max Time | Mean Time | Rows | Collapsed |Query | -| ----- | ---------- | -------- | --------- | ---- | --------- |----- | -| 5 | 15012.1 ms | 5004.0 ms | 3002.4 ms | 5 | No |
SELECT pg_sleep($1)
| -| 5 | 901.4 ms | 616.5 ms | 180.3 ms | 72 | Yes |
UPDATE sent_notifications
SET recipient_id = $1
WHERE sent_notifications.id IN ($2)
| -| 2 | 34.4 ms | 34.1 ms | 17.2 ms | 2 | No |
INSERT INTO batched_background_migration_job_transition_logs (batched_background_migration_job_id, created_at, updated_at, previous_status, next_status) VALUES ($1, $2, $3, $4, $5) RETURNING id
| -| 1 | 6.9 ms | 6.9 ms | 6.9 ms | 1 | No |
UPDATE batched_background_migration_jobs
SET updated_at = $1, finished_at = $2, status = $3, metrics = $4
WHERE batched_background_migration_jobs.id = $5
| -| 4 | 7.5 ms | 5.0 ms | 1.9 ms | 80 | No |
SELECT sent_notifications.*
FROM sent_notifications
WHERE sent_notifications.id BETWEEN $1 AND $2 AND sent_notifications.id >= $3 AND sent_notifications.id < $4
| -| 1 | 3.9 ms | 3.9 ms | 3.9 ms | 1 | No |
UPDATE batched_background_migration_jobs
SET updated_at = $1, started_at = $2, status = $3, attempts = $4
WHERE batched_background_migration_jobs.id = $5
| -| 5 | 0.2 ms | 0.1 ms | 0.0 ms | 4 | No |
SELECT sent_notifications.id
FROM sent_notifications
WHERE sent_notifications.id BETWEEN $1 AND $2 AND sent_notifications.id >= $3
ORDER BY sent_notifications.id ASC
LIMIT $4
OFFSET $5
| -| 2 | 0.1 ms | 0.1 ms | 0.1 ms | 2 | No |
SELECT batched_background_migration_jobs.*
FROM batched_background_migration_jobs
WHERE batched_background_migration_jobs.id = $1
LIMIT $2
| -| 1 | 0.1 ms | 0.1 ms | 0.1 ms | 1 | No |
SELECT sum(batched_background_migration_jobs.batch_size)
FROM batched_background_migration_jobs
WHERE batched_background_migration_jobs.batched_background_migration_id = $1 AND batched_background_migration_jobs.status IN ($2)
| -| 1 | 0.0 ms | 0.0 ms | 0.0 ms | 1 | No |
SELECT batched_background_migrations.*
FROM batched_background_migrations
WHERE batched_background_migrations.id = $1
LIMIT $2
| -| 1 | 0.0 ms | 0.0 ms | 0.0 ms | 20 | No |
SELECT sent_notifications.*
FROM sent_notifications
WHERE sent_notifications.id BETWEEN $1 AND $2 AND sent_notifications.id >= $3
| -| 1 | 0.0 ms | 0.0 ms | 0.0 ms | 1 | No |
SELECT sent_notifications.id
FROM sent_notifications
WHERE sent_notifications.id BETWEEN $1 AND $2
ORDER BY sent_notifications.id ASC
LIMIT $3
| - -
-Histogram of batch runtimes for TestBackgroundMigration - -| Batch Runtime | Count | -|---------------|-------| -|0 seconds - 10 seconds | 6 | -|10 seconds - 1 minute | 0 | -|1 minute - 2 minutes | 0 | -|2 minutes - 3 minutes | 0 | -|3 minutes - 5 minutes | 0 | -|5 minutes + | 0 | - -
- -
-Histogram across all sampled batches of TestBackgroundMigration - -| Query Runtime | Count | -|---------------|-------| -|0 seconds - 0.1 seconds | 22 | -|0.1 seconds - 0.5 seconds | 1 | -|0.5 seconds - 1 second | 1 | -|1 second - 2 seconds | 1 | -|2 seconds - 5 seconds | 3 | -|5 seconds + | 1 | - -
- -
-
:warning:

Background Migration: DeleteUsersBatchedMigration

@@ -541,6 +474,73 @@ Make sure you are following the [guidelines](https://docs.gitlab.com/development
+
+ :boom:

Background Migration: TestBackgroundMigration

+ + +
+Sampled 6 batches. Estimated Time to complete: 1 hour and 36 minutes + + - Interval: 120s + - Max batch size: 750 + - Estimated seconds to complete: 5760s + - Average batch time: 1.08s + - Batch size: 150 + - N. of batches sampled: 6 + - N. of failed batches: 1 + - Failed batches: batch_5 + + Time estimation is conservative and based on sampling production data in a test environment. It represents the max time that migration could take. The actual time may differ from this estimation. +
+ +_Consider changing max_batch_size and interval if this estimate is unacceptable._ + + +| Calls | Total Time | Max Time | Mean Time | Rows | Collapsed |Query | +| ----- | ---------- | -------- | --------- | ---- | --------- |----- | +| 5 | 15012.1 ms | 5004.0 ms | 3002.4 ms | 5 | No |
SELECT pg_sleep($1)
| +| 5 | 901.4 ms | 616.5 ms | 180.3 ms | 72 | Yes |
UPDATE sent_notifications
SET recipient_id = $1
WHERE sent_notifications.id IN ($2)
| +| 2 | 34.4 ms | 34.1 ms | 17.2 ms | 2 | No |
INSERT INTO batched_background_migration_job_transition_logs (batched_background_migration_job_id, created_at, updated_at, previous_status, next_status) VALUES ($1, $2, $3, $4, $5) RETURNING id
| +| 1 | 6.9 ms | 6.9 ms | 6.9 ms | 1 | No |
UPDATE batched_background_migration_jobs
SET updated_at = $1, finished_at = $2, status = $3, metrics = $4
WHERE batched_background_migration_jobs.id = $5
| +| 4 | 7.5 ms | 5.0 ms | 1.9 ms | 80 | No |
SELECT sent_notifications.*
FROM sent_notifications
WHERE sent_notifications.id BETWEEN $1 AND $2 AND sent_notifications.id >= $3 AND sent_notifications.id < $4
| +| 1 | 3.9 ms | 3.9 ms | 3.9 ms | 1 | No |
UPDATE batched_background_migration_jobs
SET updated_at = $1, started_at = $2, status = $3, attempts = $4
WHERE batched_background_migration_jobs.id = $5
| +| 5 | 0.2 ms | 0.1 ms | 0.0 ms | 4 | No |
SELECT sent_notifications.id
FROM sent_notifications
WHERE sent_notifications.id BETWEEN $1 AND $2 AND sent_notifications.id >= $3
ORDER BY sent_notifications.id ASC
LIMIT $4
OFFSET $5
| +| 2 | 0.1 ms | 0.1 ms | 0.1 ms | 2 | No |
SELECT batched_background_migration_jobs.*
FROM batched_background_migration_jobs
WHERE batched_background_migration_jobs.id = $1
LIMIT $2
| +| 1 | 0.1 ms | 0.1 ms | 0.1 ms | 1 | No |
SELECT sum(batched_background_migration_jobs.batch_size)
FROM batched_background_migration_jobs
WHERE batched_background_migration_jobs.batched_background_migration_id = $1 AND batched_background_migration_jobs.status IN ($2)
| +| 1 | 0.0 ms | 0.0 ms | 0.0 ms | 1 | No |
SELECT batched_background_migrations.*
FROM batched_background_migrations
WHERE batched_background_migrations.id = $1
LIMIT $2
| +| 1 | 0.0 ms | 0.0 ms | 0.0 ms | 20 | No |
SELECT sent_notifications.*
FROM sent_notifications
WHERE sent_notifications.id BETWEEN $1 AND $2 AND sent_notifications.id >= $3
| +| 1 | 0.0 ms | 0.0 ms | 0.0 ms | 1 | No |
SELECT sent_notifications.id
FROM sent_notifications
WHERE sent_notifications.id BETWEEN $1 AND $2
ORDER BY sent_notifications.id ASC
LIMIT $3
| + +
+Histogram of batch runtimes for TestBackgroundMigration + +| Batch Runtime | Count | +|---------------|-------| +|0 seconds - 10 seconds | 6 | +|10 seconds - 1 minute | 0 | +|1 minute - 2 minutes | 0 | +|2 minutes - 3 minutes | 0 | +|3 minutes - 5 minutes | 0 | +|5 minutes + | 0 | + +
+ +
+Histogram across all sampled batches of TestBackgroundMigration + +| Query Runtime | Count | +|---------------|-------| +|0 seconds - 0.1 seconds | 22 | +|0.1 seconds - 0.5 seconds | 1 | +|0.5 seconds - 1 second | 1 | +|1 second - 2 seconds | 1 | +|2 seconds - 5 seconds | 3 | +|5 seconds + | 1 | + +
+ +
+ #### Other information
-- GitLab From 5c4bf1997370f6764df8b1c2767af0f30cdb1e2a Mon Sep 17 00:00:00 2001 From: Leonardo Rosa Date: Thu, 29 May 2025 16:43:22 -0300 Subject: [PATCH 7/7] Remove extra spaces --- .../migration-testing/v4/expected-comment.txt | 128 ------------------ notifier/templates/detail.erb | 4 - 2 files changed, 132 deletions(-) diff --git a/notifier/spec/fixtures/migration-testing/v4/expected-comment.txt b/notifier/spec/fixtures/migration-testing/v4/expected-comment.txt index a7c0c58d..46fd8c09 100644 --- a/notifier/spec/fixtures/migration-testing/v4/expected-comment.txt +++ b/notifier/spec/fixtures/migration-testing/v4/expected-comment.txt @@ -55,8 +55,6 @@ Migrations included in this change have been executed on gitlab.com data for tes * Duration: 2.2 s
* Database size change: +24.00 KiB - - | Calls | Total Time | Max Time | Mean Time | Rows | Query | | ----- | ---------- | -------- | --------- | ---- | ----- | | 1 | 192.8 ms | 192.8 ms | 192.8 ms | 0 |
CREATE TABLE "test_tables" ("id" bigserial primary key, "stars" bigint DEFAULT 0 NOT NULL, "created_at" timestamp(6) NOT NULL, "updated_at" timestamp(6) NOT NULL, "title" text, "notes" text)
| @@ -64,8 +62,6 @@ Migrations included in this change have been executed on gitlab.com data for tes | 1 | 0.0 ms | 0.0 ms | 0.0 ms | 1 |
SELECT $1::regtype::oid
| - -
Histogram for CreateTestTable @@ -89,15 +85,11 @@ Migrations included in this change have been executed on gitlab.com data for tes * Duration: 6.5 s
* Database size change: +0.00 B - - | Calls | Total Time | Max Time | Mean Time | Rows | Query | | ----- | ---------- | -------- | --------- | ---- | ----- | | 1 | 5005.1 ms | 5005.1 ms | 5005.1 ms | 1 |
SELECT pg_sleep($1)
| - -
Histogram for RegularMigrationWithFiveSecondQuery @@ -123,10 +115,6 @@ Migrations included in this change have been executed on gitlab.com data for tes - - - - No histogram available for visualization @@ -139,10 +127,6 @@ Migrations included in this change have been executed on gitlab.com data for tes - - - - No histogram available for visualization @@ -155,10 +139,6 @@ Migrations included in this change have been executed on gitlab.com data for tes - - - - No histogram available for visualization @@ -169,16 +149,12 @@ Migrations included in this change have been executed on gitlab.com data for tes * Duration: 1.4 s
* Database size change: +0.00 B - - | Calls | Total Time | Max Time | Mean Time | Rows | Query | | ----- | ---------- | -------- | --------- | ---- | ----- | | 1 | 0.1 ms | 0.1 ms | 0.1 ms | 1 |
SELECT "batched_background_migrations".*
FROM "batched_background_migrations" WHERE "batched_background_migrations"."job_class_name" = $1 AND "batched_background_migrations"."table_name" = $2 AND "batched_background_migrations"."column_name" = $3 AND (job_arguments = $4) AND "batched_background_migrations"."gitlab_schema" = $5
ORDER BY "batched_background_migrations"."id" ASC
LIMIT $6
| | 2 | 0.0 ms | 0.0 ms | 0.0 ms | 2 |
SELECT pg_backend_pid()
| - -
Histogram for FinalizeTestBatchedBackgroundMigrationMain @@ -202,19 +178,15 @@ Migrations included in this change have been executed on gitlab.com data for tes * Duration: 5600.3 s
* Database size change: +32.00 KiB - - | Calls | Total Time | Max Time | Mean Time | Rows | Query | | ----- | ---------- | -------- | --------- | ---- | ----- | | 1 | 5377900.1 ms | 5377900.1 ms | 5377900.1 ms | 0 |
CREATE INDEX CONCURRENTLY "tmp_index_for_null_member_namespace_id" ON "members" ("member_namespace_id")
WHERE member_namespace_id IS NULL
| - #### :warning: Index creation timing exceeded This index creation query might have caused your migration to exceed timing guidelines. Please examine the timing data on this query and consider if the [asynchronous index creation](https://docs.gitlab.com/ee/development/database/adding_database_indexes.html#create-indexes-asynchronously) process is appropriate. -
Histogram for CreateLongRunningSyncIndex @@ -238,15 +210,11 @@ Please examine the timing data on this query and consider if the [asynchronous i * Duration: 1.2 s
* Database size change: +32.00 KiB - - | Calls | Total Time | Max Time | Mean Time | Rows | Query | | ----- | ---------- | -------- | --------- | ---- | ----- | | 1 | 9.4 ms | 9.4 ms | 9.4 ms | 0 |
CREATE TABLE "efficiently_ordered_columns_tables" ("line_attr" line, "circle_attr" circle, "uuid_attr" uuid, "point_attr" point, "id" bigserial primary key, "bigserial_attr" bigserial, "bigint_attr" bigint, "float_attr" float, "time_attr" time, "timestamp_attr" timestamp, "date_attr" date, "integer_attr" integer, "oid_attr" oid, "smallint_attr" smallint, "boolean_attr" boolean, "inet_attr" inet, "jsonb_attr" jsonb, "text_attr" text)
| - -
Histogram for CreateEfficientlyOrderedColumnsTable @@ -270,8 +238,6 @@ Please examine the timing data on this query and consider if the [asynchronous i * Duration: 1.2 s
* Database size change: +40.00 KiB - - | Calls | Total Time | Max Time | Mean Time | Rows | Query | | ----- | ---------- | -------- | --------- | ---- | ----- | | 1 | 5.7 ms | 5.7 ms | 5.7 ms | 0 |
CREATE TABLE "inefficiently_ordered_columns_tables" ("id" bigserial primary key, "text_attr" text, "boolean_attr" boolean, "smallint_attr" smallint, "integer_attr" integer, "point_attr" point, "circle_attr" circle, "line_attr" line)
| @@ -294,8 +260,6 @@ Please examine the timing data on this query and consider if the [asynchronous i | boolean_attr | bool | | text_attr | text | - -
Histogram for CreateInefficientlyOrderedColumnsTable @@ -319,13 +283,11 @@ Please examine the timing data on this query and consider if the [asynchronous i * Duration: 5.6 s
* Database size change: +0.00 B - ##### :warning: Irreversible data changes statements (DELETE FROM) An irreversible statement was detected for this migration. Make sure you are following the [guidelines](https://docs.gitlab.com/development/database_review/#preparation-when-adding-data-migrations) for irreversible data operations. - | Calls | Total Time | Max Time | Mean Time | Rows | Query | | ----- | ---------- | -------- | --------- | ---- | ----- | | 1 | 1761.6 ms | 1761.6 ms | 1761.6 ms | 10 |
DELETE
FROM "issues"WHERE "issues"."id" IN (
SELECT "issues"."id" FROM "issues" LIMIT $1
)
| @@ -333,8 +295,6 @@ Make sure you are following the [guidelines](https://docs.gitlab.com/development | 2 | 0.0 ms | 0.0 ms | 0.0 ms | 2 |
SELECT pg_backend_pid()
| - -
Histogram for DeleteDataFromIssuesTable @@ -358,15 +318,11 @@ Make sure you are following the [guidelines](https://docs.gitlab.com/development * Duration: 1.3 s
* Database size change: -24.00 KiB - - | Calls | Total Time | Max Time | Mean Time | Rows | Query | | ----- | ---------- | -------- | --------- | ---- | ----- | | 1 | 2.6 ms | 2.6 ms | 2.6 ms | 0 |
DROP TABLE "test_tables"
| - -
Histogram for DropTestTable @@ -392,10 +348,6 @@ Make sure you are following the [guidelines](https://docs.gitlab.com/development - - - - No histogram available for visualization @@ -647,8 +599,6 @@ Migrations included in this change have been executed on gitlab.com data for tes * Duration: 1.9 s
* Database size change: +24.00 KiB - - | Calls | Total Time | Max Time | Mean Time | Rows | Query | | ----- | ---------- | -------- | --------- | ---- | ----- | | 1 | 122.9 ms | 122.9 ms | 122.9 ms | 0 |
CREATE TABLE "test_tables" ("id" bigserial primary key, "stars" bigint DEFAULT 0 NOT NULL, "created_at" timestamp(6) NOT NULL, "updated_at" timestamp(6) NOT NULL, "title" text, "notes" text)
| @@ -656,8 +606,6 @@ Migrations included in this change have been executed on gitlab.com data for tes | 1 | 0.0 ms | 0.0 ms | 0.0 ms | 1 |
SELECT $1::regtype::oid
| - -
Histogram for CreateTestTable @@ -681,15 +629,11 @@ Migrations included in this change have been executed on gitlab.com data for tes * Duration: 6.2 s
* Database size change: +0.00 B - - | Calls | Total Time | Max Time | Mean Time | Rows | Query | | ----- | ---------- | -------- | --------- | ---- | ----- | | 1 | 5005.1 ms | 5005.1 ms | 5005.1 ms | 1 |
SELECT pg_sleep($1)
| - -
Histogram for RegularMigrationWithFiveSecondQuery @@ -715,10 +659,6 @@ Migrations included in this change have been executed on gitlab.com data for tes - - - - No histogram available for visualization @@ -731,10 +671,6 @@ Migrations included in this change have been executed on gitlab.com data for tes - - - - No histogram available for visualization @@ -747,10 +683,6 @@ Migrations included in this change have been executed on gitlab.com data for tes - - - - No histogram available for visualization @@ -761,15 +693,11 @@ Migrations included in this change have been executed on gitlab.com data for tes * Duration: 1.2 s
* Database size change: +40.00 KiB - - | Calls | Total Time | Max Time | Mean Time | Rows | Query | | ----- | ---------- | -------- | --------- | ---- | ----- | | 1 | 12.0 ms | 12.0 ms | 12.0 ms | 0 |
CREATE TABLE "efficiently_ordered_columns_tables" ("line_attr" line, "circle_attr" circle, "uuid_attr" uuid, "point_attr" point, "id" bigserial primary key, "bigserial_attr" bigserial, "bigint_attr" bigint, "float_attr" float, "time_attr" time, "timestamp_attr" timestamp, "date_attr" date, "integer_attr" integer, "oid_attr" oid, "smallint_attr" smallint, "boolean_attr" boolean, "inet_attr" inet, "jsonb_attr" jsonb, "text_attr" text)
| - -
Histogram for CreateEfficientlyOrderedColumnsTable @@ -793,8 +721,6 @@ Migrations included in this change have been executed on gitlab.com data for tes * Duration: 1.2 s
* Database size change: +48.00 KiB - - | Calls | Total Time | Max Time | Mean Time | Rows | Query | | ----- | ---------- | -------- | --------- | ---- | ----- | | 1 | 19.2 ms | 19.2 ms | 19.2 ms | 0 |
CREATE TABLE "inefficiently_ordered_columns_tables" ("id" bigserial primary key, "text_attr" text, "boolean_attr" boolean, "smallint_attr" smallint, "integer_attr" integer, "point_attr" point, "circle_attr" circle, "line_attr" line)
| @@ -817,8 +743,6 @@ Migrations included in this change have been executed on gitlab.com data for tes | boolean_attr | bool | | text_attr | text | - -
Histogram for CreateInefficientlyOrderedColumnsTable @@ -842,15 +766,11 @@ Migrations included in this change have been executed on gitlab.com data for tes * Duration: 1.4 s
* Database size change: -24.00 KiB - - | Calls | Total Time | Max Time | Mean Time | Rows | Query | | ----- | ---------- | -------- | --------- | ---- | ----- | | 1 | 6.8 ms | 6.8 ms | 6.8 ms | 0 |
DROP TABLE "test_tables"
| - -
Histogram for DropTestTable @@ -876,10 +796,6 @@ Migrations included in this change have been executed on gitlab.com data for tes - - - - No histogram available for visualization @@ -989,8 +905,6 @@ Migrations included in this change have been executed on gitlab.com data for tes * Duration: 2.2 s
* Database size change: +24.00 KiB - - | Calls | Total Time | Max Time | Mean Time | Rows | Query | | ----- | ---------- | -------- | --------- | ---- | ----- | | 1 | 192.8 ms | 192.8 ms | 192.8 ms | 0 |
CREATE TABLE "test_tables" ("id" bigserial primary key, "stars" bigint DEFAULT 0 NOT NULL, "created_at" timestamp(6) NOT NULL, "updated_at" timestamp(6) NOT NULL, "title" text, "notes" text)
| @@ -998,8 +912,6 @@ Migrations included in this change have been executed on gitlab.com data for tes | 1 | 0.0 ms | 0.0 ms | 0.0 ms | 1 |
SELECT $1::regtype::oid
| - -
Histogram for CreateTestTable @@ -1023,15 +935,11 @@ Migrations included in this change have been executed on gitlab.com data for tes * Duration: 6.5 s
* Database size change: +0.00 B - - | Calls | Total Time | Max Time | Mean Time | Rows | Query | | ----- | ---------- | -------- | --------- | ---- | ----- | | 1 | 5005.1 ms | 5005.1 ms | 5005.1 ms | 1 |
SELECT pg_sleep($1)
| - -
Histogram for RegularMigrationWithFiveSecondQuery @@ -1057,10 +965,6 @@ Migrations included in this change have been executed on gitlab.com data for tes - - - - No histogram available for visualization @@ -1073,10 +977,6 @@ Migrations included in this change have been executed on gitlab.com data for tes - - - - No histogram available for visualization @@ -1089,10 +989,6 @@ Migrations included in this change have been executed on gitlab.com data for tes - - - - No histogram available for visualization @@ -1103,16 +999,12 @@ Migrations included in this change have been executed on gitlab.com data for tes * Duration: 1.4 s
* Database size change: +0.00 B - - | Calls | Total Time | Max Time | Mean Time | Rows | Query | | ----- | ---------- | -------- | --------- | ---- | ----- | | 1 | 0.1 ms | 0.1 ms | 0.1 ms | 1 |
SELECT "batched_background_migrations".*
FROM "batched_background_migrations" WHERE "batched_background_migrations"."job_class_name" = $1 AND "batched_background_migrations"."table_name" = $2 AND "batched_background_migrations"."column_name" = $3 AND (job_arguments = $4) AND "batched_background_migrations"."gitlab_schema" = $5
ORDER BY "batched_background_migrations"."id" ASC
LIMIT $6
| | 2 | 0.0 ms | 0.0 ms | 0.0 ms | 2 |
SELECT pg_backend_pid()
| - -
Histogram for FinalizeTestBatchedBackgroundMigrationMain @@ -1136,19 +1028,15 @@ Migrations included in this change have been executed on gitlab.com data for tes * Duration: 5600.3 s
* Database size change: +32.00 KiB - - | Calls | Total Time | Max Time | Mean Time | Rows | Query | | ----- | ---------- | -------- | --------- | ---- | ----- | | 1 | 5377900.1 ms | 5377900.1 ms | 5377900.1 ms | 0 |
CREATE INDEX CONCURRENTLY "tmp_index_for_null_member_namespace_id" ON "members" ("member_namespace_id")
WHERE member_namespace_id IS NULL
| - #### :warning: Index creation timing exceeded This index creation query might have caused your migration to exceed timing guidelines. Please examine the timing data on this query and consider if the [asynchronous index creation](https://docs.gitlab.com/ee/development/database/adding_database_indexes.html#create-indexes-asynchronously) process is appropriate. -
Histogram for CreateLongRunningSyncIndex @@ -1172,15 +1060,11 @@ Please examine the timing data on this query and consider if the [asynchronous i * Duration: 1.2 s
* Database size change: +32.00 KiB - - | Calls | Total Time | Max Time | Mean Time | Rows | Query | | ----- | ---------- | -------- | --------- | ---- | ----- | | 1 | 9.4 ms | 9.4 ms | 9.4 ms | 0 |
CREATE TABLE "efficiently_ordered_columns_tables" ("line_attr" line, "circle_attr" circle, "uuid_attr" uuid, "point_attr" point, "id" bigserial primary key, "bigserial_attr" bigserial, "bigint_attr" bigint, "float_attr" float, "time_attr" time, "timestamp_attr" timestamp, "date_attr" date, "integer_attr" integer, "oid_attr" oid, "smallint_attr" smallint, "boolean_attr" boolean, "inet_attr" inet, "jsonb_attr" jsonb, "text_attr" text)
| - -
Histogram for CreateEfficientlyOrderedColumnsTable @@ -1204,8 +1088,6 @@ Please examine the timing data on this query and consider if the [asynchronous i * Duration: 1.2 s
* Database size change: +40.00 KiB - - | Calls | Total Time | Max Time | Mean Time | Rows | Query | | ----- | ---------- | -------- | --------- | ---- | ----- | | 1 | 5.7 ms | 5.7 ms | 5.7 ms | 0 |
CREATE TABLE "inefficiently_ordered_columns_tables" ("id" bigserial primary key, "text_attr" text, "boolean_attr" boolean, "smallint_attr" smallint, "integer_attr" integer, "point_attr" point, "circle_attr" circle, "line_attr" line)
| @@ -1228,8 +1110,6 @@ Please examine the timing data on this query and consider if the [asynchronous i | boolean_attr | bool | | text_attr | text | - -
Histogram for CreateInefficientlyOrderedColumnsTable @@ -1253,15 +1133,11 @@ Please examine the timing data on this query and consider if the [asynchronous i * Duration: 1.3 s
* Database size change: -24.00 KiB - - | Calls | Total Time | Max Time | Mean Time | Rows | Query | | ----- | ---------- | -------- | --------- | ---- | ----- | | 1 | 2.6 ms | 2.6 ms | 2.6 ms | 0 |
DROP TABLE "test_tables"
| - -
Histogram for DropTestTable @@ -1287,10 +1163,6 @@ Please examine the timing data on this query and consider if the [asynchronous i - - - - No histogram available for visualization diff --git a/notifier/templates/detail.erb b/notifier/templates/detail.erb index 026fa9b9..27f9270a 100644 --- a/notifier/templates/detail.erb +++ b/notifier/templates/detail.erb @@ -5,21 +5,17 @@ * Database size change: <%= total_size_change(migration) %><%= conditional_size_change_note(migration) %> % if migration.queries.any? - % if delete_from_queries.any? <%= render_deleted_from_warning(delete_from_queries) %> % end - <%= render_pgss_table(migration.queries) %> % if create_table_queries.present? <%= render_migration_column_ordering_suggestion(create_table_queries) %> % end - % if create_index_queries.present? && exceeds_time_guidance <%= render_index_creation_timing_exceeded_warning(create_index_queries) %> % end - % end <%= render_migration_histogram(migration) %> -- GitLab