Implements Scheduling logic for on demand DAST
What does this MR do?
Issue link: #330308 (closed) Child MR: !68046 (merged)
- Add columns
timezone, cadence and starts_at
todast_profile_schedules
table. - Currently the
Dast Profile Schedule
feature is behind the feature flag, sodast_profile_schedule
table should be empty. - These columns will be used for storing user-provided data.
- Add logic to set next_run of DAST on-demand schedule.
Notes
The sequence of Merge, we will start from merging top MR to the master:
- !68031 (merged) -> Scheduling logic and DB changes
- !68046 (merged) -> dastProfileCreate mutation
- !68050 (merged) -> dastProfile fetch Query
- !66445 (merged) -> dastProfileUpdate mutation
Database changes
Migration
migrate
─>$ rails db:migrate
== 20210807101446 AddCadenceToDastProfileSchedules: migrating =================
-- add_column(:dast_profile_schedules, :cadence, :jsonb, {:null=>false, :default=>{}})
-> 0.0049s
== 20210807101446 AddCadenceToDastProfileSchedules: migrated (0.0050s) ========
== 20210807101621 AddTimezoneToDastProfileSchedules: migrating ================
-- execute("DELETE FROM dast_profile_schedules")
-> 0.0019s
-- column_exists?(:dast_profile_schedules, :timezone)
-> 0.0042s
-- add_column(:dast_profile_schedules, :timezone, :text, {:null=>false})
-> 0.0015s
-- transaction_open?()
-> 0.0000s
-- current_schema()
-> 0.0002s
-- execute("ALTER TABLE dast_profile_schedules\nADD CONSTRAINT check_be4d1c3af1\nCHECK ( char_length(timezone) <= 255 )\nNOT VALID;\n")
-> 0.0015s
-- current_schema()
-> 0.0002s
-- execute("SET statement_timeout TO 0")
-> 0.0006s
-- execute("ALTER TABLE dast_profile_schedules VALIDATE CONSTRAINT check_be4d1c3af1;")
-> 0.0011s
-- execute("RESET statement_timeout")
-> 0.0006s
== 20210807101621 AddTimezoneToDastProfileSchedules: migrated (0.0270s) =======
== 20210807102004 AddStartsAtToDastProfileSchedules: migrating ================
-- add_column(:dast_profile_schedules, :starts_at, :datetime_with_timezone, {:null=>false, :default=>#<Proc:0x00007f8ace609a68 /Users/aditya-work/Desktop/Work/gitlab-development-kit/gitlab/db/migrate/20210807102004_add_starts_at_to_dast_profile_schedules.rb:5 (lambda)>})
-> 0.0021s
== 20210807102004 AddStartsAtToDastProfileSchedules: migrated (0.0022s) =======
== 20210816095826 AddUniqueIndexOnDastProfileToDastProfileSchedules: migrating
-- execute("DELETE FROM dast_profile_schedules")
-> 0.0020s
-- indexes(:dast_profile_schedules)
-> 0.0033s
-- remove_index(:dast_profile_schedules, :dast_profile_id, {:name=>"index_dast_profile_schedules_on_dast_profile_id"})
-> 0.0026s
-- indexes(:dast_profile_schedules)
-> 0.0015s
-- current_schema()
-> 0.0001s
-- add_index(:dast_profile_schedules, :dast_profile_id, {:unique=>true, :name=>"index_dast_profile_schedules_on_dast_profile_id"})
-> 0.0019s
== 20210816095826 AddUniqueIndexOnDastProfileToDastProfileSchedules: migrated (0.0137s)
== 20210818061156 RemoveProjectProfileCompoundIndexFromDastProfileSchedules: migrating
-- execute("DELETE FROM dast_profile_schedules")
-> 0.0017s
-- indexes(:dast_profile_schedules)
-> 0.0018s
-- remove_index(:dast_profile_schedules, [:project_id, :dast_profile_id], {:name=>"index_dast_profile_schedules_on_project_id_and_dast_profile_id"})
-> 0.0025s
== 20210818061156 RemoveProjectProfileCompoundIndexFromDastProfileSchedules: migrated (0.0061s)
== 20210818115613 AddIndexProjectIdOnDastProfileSchedule: migrating ===========
-- add_index(:dast_profile_schedules, :project_id)
-> 0.0027s
== 20210818115613 AddIndexProjectIdOnDastProfileSchedule: migrated (0.0027s) ==
Rollback
rails db:migrate:down VERSION=20210807101446 && rails db:migrate:down VERSION=20210807101621 && rails db:migrate:down VERSION=20210807102004 && rails db:migrate:down VERSION=20210816095826 && rails db:migrate:down VERSION=20210818061156 && rails db:migrate:down VERSION=20210818115613
== 20210807101446 AddCadenceToDastProfileSchedules: reverting =================
-- remove_column(:dast_profile_schedules, :cadence, :jsonb, {:null=>false, :default=>{}})
-> 0.0026s
== 20210807101446 AddCadenceToDastProfileSchedules: reverted (0.0051s) ========
== 20210807101621 AddTimezoneToDastProfileSchedules: reverting ================
-- column_exists?(:dast_profile_schedules, :timezone)
-> 0.0016s
-- remove_column(:dast_profile_schedules, :timezone)
-> 0.0017s
== 20210807101621 AddTimezoneToDastProfileSchedules: reverted (0.0034s) =======
== 20210807102004 AddStartsAtToDastProfileSchedules: reverting ================
-- remove_column(:dast_profile_schedules, :starts_at, :datetime_with_timezone, {:null=>false, :default=>#<Proc:0x00007fb74cca15b0 /Users/aditya-work/Desktop/Work/gitlab-development-kit/gitlab/db/migrate/20210807102004_add_starts_at_to_dast_profile_schedules.rb:5 (lambda)>})
-> 0.0024s
== 20210807102004 AddStartsAtToDastProfileSchedules: reverted (0.0040s) =======
== 20210816095826 AddUniqueIndexOnDastProfileToDastProfileSchedules: reverting
-- execute("DELETE FROM dast_profile_schedules")
-> 0.0043s
-- indexes(:dast_profile_schedules)
-> 0.0028s
-- remove_index(:dast_profile_schedules, :dast_profile_id, {:name=>"index_dast_profile_schedules_on_dast_profile_id"})
-> 0.0028s
-- indexes(:dast_profile_schedules)
-> 0.0015s
-- current_schema()
-> 0.0001s
-- add_index(:dast_profile_schedules, :dast_profile_id)
-> 0.0030s
== 20210816095826 AddUniqueIndexOnDastProfileToDastProfileSchedules: reverted (0.0169s)
== 20210818061156 RemoveProjectProfileCompoundIndexFromDastProfileSchedules: reverting
-- execute("DELETE FROM dast_profile_schedules")
-> 0.0027s
-- indexes(:dast_profile_schedules)
-> 0.0032s
-- current_schema()
-> 0.0001s
-- add_index(:dast_profile_schedules, [:project_id, :dast_profile_id], {:unique=>true, :name=>"index_dast_profile_schedules_on_project_id_and_dast_profile_id"})
-> 0.0023s
== 20210818061156 RemoveProjectProfileCompoundIndexFromDastProfileSchedules: reverted (0.0105s)
== 20210818115613 AddIndexProjectIdOnDastProfileSchedule: reverting ===========
-- remove_index(:dast_profile_schedules, :project_id)
-> 0.0056s
== 20210818115613 AddIndexProjectIdOnDastProfileSchedule: reverted (0.0072s) ==
Insert transaction:
Dast::ProfileSchedule.create!(user_id: user.id, cron: "0 0 8 */3 *", next_run_at: Time.zone.now-1.minutes, dast_profile_id: profile.id, project_id: project.id, timezone: "UTC", starts_at: Time.now)
TRANSACTION (0.2ms) BEGIN /*application:console,line:(pry):20:in `__pry__'*/
Dast::Profile Load (0.3ms) SELECT "dast_profiles".* FROM "dast_profiles" WHERE "dast_profiles"."id" = 11 LIMIT 1 /*application:console,line:(pry):20:in `__pry__'*/
Dast::ProfileSchedule Create (0.8ms) INSERT INTO "dast_profile_schedules" ("project_id", "dast_profile_id", "user_id", "next_run_at", "created_at", "updated_at", "cron", "timezone", "starts_at") VALUES (23, 11, 1, '2021-10-08 00:07:00', '2021-08-07 10:46:30.339507', '2021-08-07 10:46:30.339507', '0 0 8 */3 *', 'UTC', '2021-08-07 10:46:30.329507') RETURNING "id" /*application:console,line:(pry):20:in `__pry__'*/
TRANSACTION (0.8ms) COMMIT /*application:console,line:(pry):20:in `__pry__'*/
Query
Currently, there are no queries based on the introduced fields.
Screenshots or Screencasts (strongly suggested)
How to setup and validate locally (strongly suggested)
Does this MR meet the acceptance criteria?
Conformity
-
I have included changelog trailers, or none are needed. (Does this MR need a changelog?) -
I have added/updated documentation, or it's not needed. (Is documentation required?) -
I have properly separated EE content from FOSS, or this MR is FOSS only. (Where should EE code go?) -
I have added information for database reviewers in the MR description, or it's not needed. (Does this MR have database related changes?) -
I have self-reviewed this MR per code review guidelines. -
This MR does not harm performance, or I have asked a reviewer to help assess the performance impact. (Merge request performance guidelines) -
I have followed the style guides. -
This change is backwards compatible across updates, or this does not apply.
Availability and Testing
-
I have added/updated tests following the Testing Guide, or it's not needed. (Consider all test levels. See the Test Planning Process.) -
I have tested this MR in all supported browsers, or it's not needed. -
I have informed the Infrastructure department of a default or new setting change per definition of done, or it's not needed.
Security
Does this MR contain changes to processing or storing of credentials or tokens, authorization and authentication methods or other items described in the security review guidelines? If not, then delete this Security section.
-
Label as security and @ mention @gitlab-com/gl-security/appsec
-
The MR includes necessary changes to maintain consistency between UI, API, email, or other methods -
Security reports checked/validated by a reviewer from the AppSec team
Related to #330308 (closed)
Edited by Aditya Tiwari