Commit 8e73c5a1 authored by charlie ablett's avatar charlie ablett

Add Prometheus metrics to ActionCable subscription events

- Add changelog
- Add to metrics docs
parent 11d8fb9f
---
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
# These are manually require'd so the classes are registered properly with
# ActiveSupport.
require_dependency 'gitlab/metrics/subscribers/action_cable'
require_dependency 'gitlab/metrics/subscribers/action_view'
require_dependency 'gitlab/metrics/subscribers/active_record'
require_dependency 'gitlab/metrics/subscribers/rails_cache'
......
......@@ -116,6 +116,10 @@ The following metrics are available:
| `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_tasks_total` | Gauge | 13.4 | Total number of tasks executed in ActionCable thread pool | `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` |
| `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_broadcasts_total` | Counter | 13.10 | The number of ActionCable broadcasts emitted | `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_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` |
......
# 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(: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
expect(::Gitlab::Metrics).to receive(:counter)
.with(Gitlab::Metrics::Subscribers::ActionCable::SINGLE_CLIENT_TRANSMISSION, /transmit/)
.and_call_original
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
expect(::Gitlab::Metrics).to receive(:counter)
.with(Gitlab::Metrics::Subscribers::ActionCable::BROADCAST, /broadcast/)
.and_call_original
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 transmit event' do
expect(::Gitlab::Metrics).to receive(:counter)
.with(Gitlab::Metrics::Subscribers::ActionCable::TRANSMIT_SUBSCRIPTION_CONFIRMATION, /confirm/)
.and_call_original
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 transmit event' do
expect(::Gitlab::Metrics).to receive(:counter)
.with(Gitlab::Metrics::Subscribers::ActionCable::TRANSMIT_SUBSCRIPTION_REJECTION, /reject/)
.and_call_original
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