Class: Gitlab::Metrics::Subscribers::Ldap

Inherits:
ActiveSupport::Subscriber
  • Object
show all
Defined in:
lib/gitlab/metrics/subscribers/ldap.rb

Constant Summary collapse

COUNTER =
:net_ldap_count
DURATION =
:net_ldap_duration_s
OBSERVABLE_EVENTS =

Assembled from methods that are instrumented inside Net::LDAP

%i[
  open
  bind
  add
  modify
  modify_password
  rename
  delete
  search
].freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.countInteger

Returns the total number of LDAP requests.

Returns:

  • (Integer)

    the total number of LDAP requests



28
29
30
# File 'lib/gitlab/metrics/subscribers/ldap.rb', line 28

def count
  Gitlab::SafeRequestStore[COUNTER].to_i
end

.durationFloat

Returns the total duration spent on LDAP requests.

Returns:

  • (Float)

    the total duration spent on LDAP requests



33
34
35
# File 'lib/gitlab/metrics/subscribers/ldap.rb', line 33

def duration
  Gitlab::SafeRequestStore[DURATION].to_f
end

.payloadHash<Integer, Float>

Used in Gitlab::InstrumentationHelper to merge the LDAP stats into the log output

Returns:

  • (Hash<Integer, Float>)

    a hash of the stored statistics



41
42
43
44
45
46
# File 'lib/gitlab/metrics/subscribers/ldap.rb', line 41

def payload
  {
    net_ldap_count: count,
    net_ldap_duration_s: duration
  }
end

Instance Method Details

#observe_event(event) ⇒ Object

Called when an event is triggered in ActiveSupport::Notifications

This method is aliased to the various events triggered by the Net::LDAP library, as the method will be called by those names when triggered.

It stores statistics in the request for output to logs, and also resubmits the event data into Prometheus for monitoring purposes.



57
58
59
60
# File 'lib/gitlab/metrics/subscribers/ldap.rb', line 57

def observe_event(event)
  add_to_request_store(event)
  expose_metrics(event)
end