Skip to content

Create On-call schedules via GraphQL

Vitali Tatarintev requested to merge 262847-create-on-call-schedules into master

What does this MR do?

Contributes to #262847 (closed)

Feature flag roll-out issue #283914 (closed)

  • Creates an OncallSchedule model to persist Incident Management on-call schedules
  • Adds a GraphQL query to fetch on-call schedules
  • Adds a GraphQL mutation to create an on-call schedule
  • Permissions (for details: #262847 (comment 447339235))
    • Maintainers have manage permissions (read/create/modify/delete)
    • Developers and reporters have read permissions
  • Adds a changelog entry for new database table
  • Doesn't add a change entry for GraphQL endpoints because they are behind a feature flag

We ended up with a big MR because I was trying to follow a vertical slicing approach (described here gitlab-com/www-gitlab-com!58851 (merged)).

Enable feature flag on localhost

Feature.enable(:oncall_schedules_mvc, Project.find_by_full_path('<PROJECT-FULL-PATH>'))

GraphQL mutation example

Use http://127.0.0.1:3000/-/graphql-explorer to test

mutation($oncallScheduleCreateInput: OncallScheduleCreateInput!) {
  oncallScheduleCreate(input: $oncallScheduleCreateInput) {
    clientMutationId
    errors
    oncallSchedule {
      iid
      name
      description
      timezone
    }
  }
}

query variables

{
  "oncallScheduleCreateInput": {
    "projectPath": "<PROJECT-FULL-PATH>",
    "name": "New on-call schedule",
    "description": "on-call schedule description",
    "timezone": "Europe/Berlin"
  }
}

GraphQL query example

Use http://127.0.0.1:3000/-/graphql-explorer to test

query {
  project(fullPath: "<PROJECT-FULL-PATH>") {
    incidentManagementOncallSchedules {
      nodes {
        iid
        name
        description
        timezone
      }
    }
  }
}

rails db:migrate output

Click this to collapse/fold.

→ be rake db:migrate
== 20201111115414 CreateIncidentManagementOncallSchedules: migrating ==========
-- table_exists?(:incident_management_oncall_schedules)
   -> 0.0004s
-- create_table(:incident_management_oncall_schedules)
   -> 0.0198s
-- transaction_open?()
   -> 0.0000s
-- current_schema()
   -> 0.0002s
-- execute("ALTER TABLE incident_management_oncall_schedules\nADD CONSTRAINT check_e6ef43a664\nCHECK ( char_length(name) <= 200 )\nNOT VALID;\n")
   -> 0.0008s
-- current_schema()
   -> 0.0002s
-- execute("SET statement_timeout TO 0")
   -> 0.0002s
-- execute("ALTER TABLE incident_management_oncall_schedules VALIDATE CONSTRAINT check_e6ef43a664;")
   -> 0.0005s
-- execute("RESET ALL")
   -> 0.0002s
-- transaction_open?()
   -> 0.0000s
-- current_schema()
   -> 0.0002s
-- execute("ALTER TABLE incident_management_oncall_schedules\nADD CONSTRAINT check_7ed1fd5aa7\nCHECK ( char_length(description) <= 1000 )\nNOT VALID;\n")
   -> 0.0003s
-- current_schema()
   -> 0.0001s
-- execute("ALTER TABLE incident_management_oncall_schedules VALIDATE CONSTRAINT check_7ed1fd5aa7;")
   -> 0.0004s
-- transaction_open?()
   -> 0.0000s
-- current_schema()
   -> 0.0002s
-- execute("ALTER TABLE incident_management_oncall_schedules\nADD CONSTRAINT check_cc77cbb103\nCHECK ( char_length(timezone) <= 100 )\nNOT VALID;\n")
   -> 0.0003s
-- current_schema()
   -> 0.0001s
-- execute("ALTER TABLE incident_management_oncall_schedules VALIDATE CONSTRAINT check_cc77cbb103;")
   -> 0.0005s
== 20201111115414 CreateIncidentManagementOncallSchedules: migrated (0.0384s) =

rails db:rollback output

Click this to collapse/fold.

→ be rails db:rollback
== 20201111115414 CreateIncidentManagementOncallSchedules: reverting ==========
-- drop_table(:incident_management_oncall_schedules)
   -> 0.0049s
== 20201111115414 CreateIncidentManagementOncallSchedules: reverted (0.0208s) =

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • [-] 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
Edited by Peter Leitzen

Merge request reports