Skip to content

Commit

Permalink
Added sidekiq stats (#368)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuri-zubov authored and asedge committed Mar 14, 2018
1 parent 2305219 commit 56f7f3a
Show file tree
Hide file tree
Showing 7 changed files with 178 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/gitlab/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class Client < API
include RepositoryFiles
include Runners
include Services
include Sidekiq
include Snippets
include SystemHooks
include Tags
Expand Down
37 changes: 37 additions & 0 deletions lib/gitlab/client/sidekiq.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
class Gitlab::Client
# Defines methods related to sidekiq metrics.
# @see https://docs.gitlab.com/ce/api/sidekiq_metrics.html
module Sidekiq
# Get the current Queue Metrics
#
# @example
# Gitlab.sidekiq_queue_metrics
def sidekiq_queue_metrics
get('/sidekiq/queue_metrics')
end

# Get the current Process Metrics
#
# @example
# Gitlab.sidekiq_process_metrics
def sidekiq_process_metrics
get('/sidekiq/process_metrics')
end

# Get the current Job Statistics
#
# @example
# Gitlab.sidekiq_job_stats
def sidekiq_job_stats
get('/sidekiq/job_stats')
end

# Get a compound response of all the previously mentioned metrics
#
# @example
# Gitlab.sidekiq_compound_metrics
def sidekiq_compound_metrics
get('/sidekiq/compound_metrics')
end
end
end
36 changes: 36 additions & 0 deletions spec/fixtures/sidekiq_compound_metrics.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"queues": {
"default": {
"backlog": 0,
"latency": 0
}
},
"processes": [
{
"hostname": "gitlab.example.com",
"pid": 5649,
"tag": "gitlab",
"started_at": "2016-06-14T10:45:07.159-05:00",
"queues": [
"post_receive",
"mailers",
"archive_repo",
"system_hook",
"project_web_hook",
"gitlab_shell",
"incoming_email",
"runner",
"common",
"default"
],
"labels": [],
"concurrency": 25,
"busy": 0
}
],
"jobs": {
"processed": 2,
"failed": 0,
"enqueued": 0
}
}
7 changes: 7 additions & 0 deletions spec/fixtures/sidekiq_job_stats.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"jobs": {
"processed": 2,
"failed": 0,
"enqueued": 0
}
}
25 changes: 25 additions & 0 deletions spec/fixtures/sidekiq_process_metrics.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"processes": [
{
"hostname": "gitlab.example.com",
"pid": 5649,
"tag": "gitlab",
"started_at": "2016-06-14T10:45:07.159-05:00",
"queues": [
"post_receive",
"mailers",
"archive_repo",
"system_hook",
"project_web_hook",
"gitlab_shell",
"incoming_email",
"runner",
"common",
"default"
],
"labels": [],
"concurrency": 25,
"busy": 0
}
]
}
8 changes: 8 additions & 0 deletions spec/fixtures/sidekiq_queue_metrics.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"queues": {
"default": {
"backlog": 0,
"latency": 0
}
}
}
64 changes: 64 additions & 0 deletions spec/gitlab/client/sidekiq_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
require 'spec_helper'

describe Gitlab::Client do
describe ".sidekiq_queue_metrics" do
before do
stub_get("/sidekiq/queue_metrics", 'sidekiq_queue_metrics')
@sidekiq_queue_metrics = Gitlab.sidekiq_queue_metrics
end

it "gets the correct resource" do
expect(a_get("/sidekiq/queue_metrics")).to have_been_made
end

it "returns a information about a sidekiq default queue" do
expect(@sidekiq_queue_metrics.queues.default.backlog).to eq 0
expect(@sidekiq_queue_metrics.queues.default.latency).to eq 0
end
end

describe ".sidekiq_process_metrics" do
before do
stub_get("/sidekiq/process_metrics", 'sidekiq_process_metrics')
@sidekiq_process_metrics = Gitlab.sidekiq_process_metrics
end

it "gets the correct resource" do
expect(a_get("/sidekiq/process_metrics")).to have_been_made
end

it "returns a information about a sidekiq process metrics" do
expect(@sidekiq_process_metrics.processes.first['busy']).to eq 0
end
end

describe ".sidekiq_job_stats" do
before do
stub_get("/sidekiq/job_stats", 'sidekiq_job_stats')
@sidekiq_job_stats = Gitlab.sidekiq_job_stats
end

it "gets the correct resource" do
expect(a_get("/sidekiq/job_stats")).to have_been_made
end

it "returns a information about a sidekiq process metrics" do
expect(@sidekiq_job_stats.jobs.processed).to eq 2
end
end

describe ".sidekiq_compound_metrics" do
before do
stub_get("/sidekiq/compound_metrics", 'sidekiq_compound_metrics')
@sidekiq_compound_metrics = Gitlab.sidekiq_compound_metrics
end

it "gets the correct resource" do
expect(a_get("/sidekiq/compound_metrics")).to have_been_made
end

it "returns a information about a sidekiq process metrics" do
expect(@sidekiq_compound_metrics.jobs.processed).to eq 2
end
end
end

0 comments on commit 56f7f3a

Please sign in to comment.