Skip to content

GitLab Next

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
GitLab GitLab
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 38,038
    • Issues 38,038
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 1,346
    • Merge requests 1,346
  • Requirements
    • Requirements
    • List
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Operations
    • Operations
    • Metrics
    • Incidents
    • Environments
  • Packages & Registries
    • Packages & Registries
    • Container Registry
  • Analytics
    • Analytics
    • CI/CD
    • Code Review
    • Insights
    • Issue
    • Repository
    • Value Stream
  • Snippets
    • Snippets
  • Members
    • Members
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • GitLab.org
  • GitLabGitLab
  • Merge requests
  • !25998

Merged
Created Feb 26, 2020 by Sean McGivern@smcgivernMaintainer3 of 3 tasks completed3/3 tasks

API endpoint to remove jobs from Sidekiq based on metadata

  • Overview 47
  • Commits 1
  • Pipelines 8
  • Changes 15

What does this MR do?

This API endpoint uses job metadata to remove jobs from a queue. It can only be used by admins, and deletes as many jobs as it can in 30 seconds. If it exceeds 30 seconds, it returns a flag indicating that the user should try again to finish processing the queue.

(Because of the way Sidekiq queues work, it can't resume where it left off, so you just have to start from scratch each time.)

To test this manually, I created a group with a bunch of users, turned off Sidekiq, then created three projects: two as root, and one as another user.

Sidekiq::Queue.new('authorized_projects').to_enum.map { |j| j['meta.user'] }
#=> ["olivia.towne", "olivia.towne", "olivia.towne", "olivia.towne", "olivia.towne", "olivia.towne", "olivia.towne", "root", "root", "root", "root", "root", "root", "root", "root", "root", "root", "root", "root", "root", "root"]

I then hit the API endpoint to delete root's jobs:

$ curl --request DELETE --header "Private-Token: $GITLAB_API_TOKEN_LOCAL" http://localhost:3000/api/v4/admin/sidekiq/queues/authorized_projects?user=root
{"completed":true,"deleted_jobs":14,"queue_size":7}

And I can see the relevant jobs are gone:

Sidekiq::Queue.new('authorized_projects').to_enum.map { |j| j['meta.user'] }
# => ["olivia.towne", "olivia.towne", "olivia.towne", "olivia.towne", "olivia.towne", "olivia.towne", "olivia.towne"]

I also tested this in the GraphQL explorer with:

mutation($input:AdminSidekiqQueuesDeleteJobsInput!) {
  adminSidekiqQueuesDeleteJobs(input: $input) {
    result {
      completed
      deletedJobs
      queueSize
    }
    errors
  }
}

And variables:

{
  "input":{
    "queueName": "authorized_projects",
    "user": "olivia.towne"
  }
}

With the result:

{
  "data": {
    "adminSidekiqQueuesDeleteJobs": {
      "result": {
        "completed": true,
        "deletedJobs": 7,
        "queueSize": 0
      },
      "errors": []
    }
  }
}

And therefore the queue is empty:

Sidekiq::Queue.new('authorized_projects').to_enum.map { |j| j['meta.user'] }
# => []

Running as non-admin gives:

{
  "data": {
    "adminSidekiqQueuesDeleteJobs": null
  },
  "errors": [
    {
      "message": "You must be an admin to use this mutation",
      "locations": [
        {
          "line": 31,
          "column": 3
        }
      ],
      "path": [
        "adminSidekiqQueuesDeleteJobs"
      ]
    }
  ]
}

For gitlab-com/gl-infra/scalability#116 (closed).

Does this MR meet the acceptance criteria?

Conformity

  • Changelog entry
  • Documentation (if required)

Availability and Testing

  • Review and add/update tests for this feature/bug. Consider all test levels. See the Test Planning Process.
Edited Jul 21, 2020 by Marcel Amirault
Assignee
Assign to
Reviewer
Request review from
12.9
Milestone
12.9 (Past due)
Assign milestone
Time tracking
Source branch: add-endpoint-to-remove-sidekiq-jobs-based-on-metadata