Commit 7663e254 authored by charlie ablett's avatar charlie ablett

Merge branch '296845-cablett-actioncable-prometheus-metrics' into 'master'

Add Prometheus counters to subscribed ActionCable events

See merge request gitlab-org/gitlab!56157
parents 4b455de3 b2afa834
---
title: Add Prometheus metrics for ActionCable subscription events
merge_request: 56157
author:
type: added
...@@ -143,6 +143,7 @@ if Gitlab::Metrics.enabled? && !Rails.env.test? && !(Rails.env.development? && d ...@@ -143,6 +143,7 @@ if Gitlab::Metrics.enabled? && !Rails.env.test? && !(Rails.env.development? && d
# These are manually require'd so the classes are registered properly with # These are manually require'd so the classes are registered properly with
# ActiveSupport. # ActiveSupport.
require_dependency 'gitlab/metrics/subscribers/action_cable'
require_dependency 'gitlab/metrics/subscribers/action_view' require_dependency 'gitlab/metrics/subscribers/action_view'
require_dependency 'gitlab/metrics/subscribers/active_record' require_dependency 'gitlab/metrics/subscribers/active_record'
require_dependency 'gitlab/metrics/subscribers/rails_cache' require_dependency 'gitlab/metrics/subscribers/rails_cache'
......
...@@ -110,12 +110,16 @@ The following metrics are available: ...@@ -110,12 +110,16 @@ The following metrics are available:
| `auto_devops_pipelines_completed_total` | Counter | 12.7 | Counter of completed Auto DevOps pipelines, labeled by status | | | `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 | | `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` | | `action_cable_active_connections` | Gauge | 13.4 | Number of ActionCable WS clients currently connected | `server_mode` |
| `action_cable_broadcasts_total` | Counter | 13.10 | The number of ActionCable broadcasts emitted | `server_mode` |
| `action_cable_pool_min_size` | Gauge | 13.4 | Minimum number of worker threads in ActionCable thread pool | `server_mode` | | `action_cable_pool_min_size` | Gauge | 13.4 | Minimum number of worker threads in ActionCable thread pool | `server_mode` |
| `action_cable_pool_max_size` | Gauge | 13.4 | Maximum number of worker threads in ActionCable thread pool | `server_mode` | | `action_cable_pool_max_size` | Gauge | 13.4 | Maximum number of worker threads in ActionCable thread pool | `server_mode` |
| `action_cable_pool_current_size` | Gauge | 13.4 | Current number of worker threads in ActionCable thread pool | `server_mode` | | `action_cable_pool_current_size` | Gauge | 13.4 | Current number of worker threads in ActionCable thread pool | `server_mode` |
| `action_cable_pool_largest_size` | Gauge | 13.4 | Largest number of worker threads observed so far in ActionCable thread pool | `server_mode` | | `action_cable_pool_largest_size` | Gauge | 13.4 | Largest number of worker threads observed so far in ActionCable thread pool | `server_mode` |
| `action_cable_pool_pending_tasks` | Gauge | 13.4 | Number of tasks waiting to be executed in ActionCable thread pool | `server_mode` | | `action_cable_pool_pending_tasks` | Gauge | 13.4 | Number of tasks waiting to be executed in ActionCable thread pool | `server_mode` |
| `action_cable_pool_tasks_total` | Gauge | 13.4 | Total number of tasks executed in ActionCable thread pool | `server_mode` | | `action_cable_pool_tasks_total` | Gauge | 13.4 | Total number of tasks executed in ActionCable thread pool | `server_mode` |
| `action_cable_single_client_transmissions_total` | Counter | 13.10 | The number of ActionCable messages transmitted to any client in any channel | `server_mode` |
| `action_cable_subscription_confirmations_total` | Counter | 13.10 | The number of ActionCable subscriptions from clients confirmed | `server_mode` |
| `action_cable_subscription_rejections_total` | Counter | 13.10 | The number of ActionCable subscriptions from clients rejected | `server_mode` |
| `gitlab_issuable_fast_count_by_state_total` | Counter | 13.5 | Total number of row count operations on issue/merge request list pages | | | `gitlab_issuable_fast_count_by_state_total` | Counter | 13.5 | Total number of row count operations on issue/merge request list pages | |
| `gitlab_issuable_fast_count_by_state_failures_total` | Counter | 13.5 | Number of soft-failed row count operations on issue/merge request list pages | | | `gitlab_issuable_fast_count_by_state_failures_total` | Counter | 13.5 | Number of soft-failed row count operations on issue/merge request list pages | |
| `gitlab_external_http_total` | Counter | 13.8 | Total number of HTTP calls to external systems | `controller`, `action` | | `gitlab_external_http_total` | Counter | 13.8 | Total number of HTTP calls to external systems | `controller`, `action` |
......
# frozen_string_literal: true
module Gitlab
module Metrics
module Subscribers
class ActionCable < ActiveSupport::Subscriber
include Gitlab::Utils::StrongMemoize
attach_to :action_cable
SINGLE_CLIENT_TRANSMISSION = :action_cable_single_client_transmissions_total
TRANSMIT_SUBSCRIPTION_CONFIRMATION = :action_cable_subscription_confirmations_total
TRANSMIT_SUBSCRIPTION_REJECTION = :action_cable_subscription_rejections_total
BROADCAST = :action_cable_broadcasts_total
def transmit_subscription_confirmation(event)
confirm_subscription_counter.increment
end
def transmit_subscription_rejection(event)
reject_subscription_counter.increment
end
def transmit(event)
transmit_counter.increment
end
def broadcast(event)
broadcast_counter.increment
end
private
def transmit_counter
strong_memoize("transmission_counter") do
::Gitlab::Metrics.counter(
SINGLE_CLIENT_TRANSMISSION,
'The number of ActionCable messages transmitted to any client in any channel'
)
end
end
def broadcast_counter
strong_memoize("broadcast_counter") do
::Gitlab::Metrics.counter(
BROADCAST,
'The number of ActionCable broadcasts emitted'
)
end
end
def confirm_subscription_counter
strong_memoize("confirm_subscription_counter") do
::Gitlab::Metrics.counter(
TRANSMIT_SUBSCRIPTION_CONFIRMATION,
'The number of ActionCable subscriptions from clients confirmed'
)
end
end
def reject_subscription_counter
strong_memoize("reject_subscription_counter") do
::Gitlab::Metrics.counter(
TRANSMIT_SUBSCRIPTION_REJECTION,
'The number of ActionCable subscriptions from clients rejected'
)
end
end
end
end
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Gitlab::Metrics::Subscribers::ActionCable, :request_store do
let(:subscriber) { described_class.new }
let(:counter) { double(:counter) }
let(:data) { { data: { event: 'updated' } } }
let(:channel_class) { 'IssuesChannel' }
let(:event) do
double(
:event,
name: name,
payload: payload
)
end
describe '#transmit' do
let(:name) { 'transmit.action_cable' }
let(:via) { 'streamed from issues:Z2lkOi8vZs2l0bGFiL0lzc3VlLzQ0Ng' }
let(:payload) do
{
channel_class: channel_class,
via: via,
data: data
}
end
it 'tracks the transmit event' do
allow(::Gitlab::Metrics).to receive(:counter).with(
:action_cable_single_client_transmissions_total, /transmit/
).and_return(counter)
expect(counter).to receive(:increment)
subscriber.transmit(event)
end
end
describe '#broadcast' do
let(:name) { 'broadcast.action_cable' }
let(:coder) { ActiveSupport::JSON }
let(:message) do
{ event: :updated }
end
let(:broadcasting) { 'issues:Z2lkOi8vZ2l0bGFiL0lzc3VlLzQ0Ng' }
let(:payload) do
{
broadcasting: broadcasting,
message: message,
coder: coder
}
end
it 'tracks the broadcast event' do
allow(::Gitlab::Metrics).to receive(:counter).with(
:action_cable_broadcasts_total, /broadcast/
).and_return(counter)
expect(counter).to receive(:increment)
subscriber.broadcast(event)
end
end
describe '#transmit_subscription_confirmation' do
let(:name) { 'transmit_subscription_confirmation.action_cable' }
let(:channel_class) { 'IssuesChannel' }
let(:payload) do
{
channel_class: channel_class
}
end
it 'tracks the subscription confirmation event' do
allow(::Gitlab::Metrics).to receive(:counter).with(
:action_cable_subscription_confirmations_total, /confirm/
).and_return(counter)
expect(counter).to receive(:increment)
subscriber.transmit_subscription_confirmation(event)
end
end
describe '#transmit_subscription_rejection' do
let(:name) { 'transmit_subscription_rejection.action_cable' }
let(:channel_class) { 'IssuesChannel' }
let(:payload) do
{
channel_class: channel_class
}
end
it 'tracks the subscription rejection event' do
allow(::Gitlab::Metrics).to receive(:counter).with(
:action_cable_subscription_rejections_total, /reject/
).and_return(counter)
expect(counter).to receive(:increment)
subscriber.transmit_subscription_rejection(event)
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