Commit 0d0409cf authored by Sean McGivern's avatar Sean McGivern

Merge branch '217314-actioncable-prometheus' into 'master'

Export ActionCable metrics to Prometheus

See merge request gitlab-org/gitlab!41358
parents 3967f6c7 e2035b1b
---
title: Export ActionCable metrics to Prometheus
merge_request: 41358
author:
type: added
......@@ -46,6 +46,10 @@ if !Rails.env.test? && Gitlab::Metrics.prometheus_metrics_enabled?
Gitlab::Metrics::Samplers::DatabaseSampler.initialize_instance.start
Gitlab::Metrics::Samplers::ThreadsSampler.initialize_instance.start
if Gitlab::Runtime.action_cable?
Gitlab::Metrics::Samplers::ActionCableSampler.instance.start
end
if Gitlab.ee? && Gitlab::Runtime.sidekiq?
Gitlab::Metrics::Samplers::GlobalSearchSampler.instance.start
end
......
......@@ -106,6 +106,7 @@ The following metrics are available:
| `successful_login_captcha_total` | Gauge | 11.0 | Counter of successful CAPTCHA attempts during login | |
| `auto_devops_pipelines_completed_total` | Counter | 12.7 | Counter of completed Auto DevOps pipelines, labeled by status | |
| `gitlab_metrics_dashboard_processing_time_ms` | Summary | 12.10 | Metrics dashboard processing time in milliseconds | service, stages |
| `action_cable_active_connections` | Gauge | 13.4 | Number of ActionCable WS clients currently connected | `server_mode` |
## Metrics controlled by a feature flag
......
# frozen_string_literal: true
module Gitlab
module Metrics
module Samplers
class ActionCableSampler < BaseSampler
SAMPLING_INTERVAL_SECONDS = 5
def metrics
@metrics ||= {
active_connections: ::Gitlab::Metrics.gauge(
:action_cable_active_connections, 'Number of ActionCable WS clients currently connected'
)
}
end
def sample
stats = sample_stats
labels = {
server_mode: server_mode
}
metrics[:active_connections].set(labels, stats[:active_connections])
end
private
def sample_stats
{
active_connections: ::ActionCable.server.connections.size
}
end
def server_mode
Gitlab::ActionCable::Config.in_app? ? 'in-app' : 'standalone'
end
end
end
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Gitlab::Metrics::Samplers::ActionCableSampler do
subject { described_class.new }
describe '#interval' do
it 'samples every five seconds by default' do
expect(subject.interval).to eq(5)
end
it 'samples at other intervals if requested' do
expect(described_class.new(11).interval).to eq(11)
end
end
describe '#sample' do
before do
expect(::ActionCable.server.connections).to receive(:size).and_return(42)
end
context 'for in-app mode' do
it 'samples statistic with correct labels attached' do
expect(Gitlab::ActionCable::Config).to receive(:in_app?).and_return(true)
expect(subject.metrics[:active_connections]).to receive(:set).with({ server_mode: 'in-app' }, 42)
subject.sample
end
end
context 'for standalone mode' do
it 'samples statistic with correct labels attached' do
expect(Gitlab::ActionCable::Config).to receive(:in_app?).and_return(false)
expect(subject.metrics[:active_connections]).to receive(:set).with({ server_mode: 'standalone' }, 42)
subject.sample
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment