Class: Datadog::DI::ProbeRepository Private

Inherits:
Object
  • Object
show all
Defined in:
lib/datadog/di/probe_repository.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Thread-safe repository for storing probes in various states.

Probes are stored in three collections based on their state:

  • installed_probes: Successfully instrumented probes

  • pending_probes: Probes waiting for their target to be defined

  • failed_probes: Probes that failed to instrument (stores error messages, not probes)

This class is shared between ProbeManager and ProbeNotifierWorker, allowing ProbeNotifierWorker to look up probes for error handling.

Instance Method Summary collapse

Constructor Details

#initializeProbeRepository

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of ProbeRepository.



19
20
21
22
23
24
# File 'lib/datadog/di/probe_repository.rb', line 19

def initialize
  @installed_probes = {}
  @pending_probes = {}
  @failed_probes = {}
  @lock = Monitor.new
end

Instance Method Details

#add_failed(probe_id, message) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Records a probe installation failure.

Failed probes are tracked by ID with their error message to prevent repeated installation attempts that would fail again.

Parameters:

  • probe_id (String)

    The probe ID

  • message (String)

    The error message describing why the probe failed



153
154
155
156
157
# File 'lib/datadog/di/probe_repository.rb', line 153

def add_failed(probe_id, message)
  @lock.synchronize do
    @failed_probes[probe_id] = message
  end
end

#add_installed(probe) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Adds a probe to the installed probes collection.

Parameters:

  • probe (Probe)

    The probe to add



63
64
65
66
67
# File 'lib/datadog/di/probe_repository.rb', line 63

def add_installed(probe)
  @lock.synchronize do
    @installed_probes[probe.id] = probe
  end
end

#add_pending(probe) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Adds a probe to the pending probes collection.

Parameters:

  • probe (Probe)

    The probe to add



101
102
103
104
105
# File 'lib/datadog/di/probe_repository.rb', line 101

def add_pending(probe)
  @lock.synchronize do
    @pending_probes[probe.id] = probe
  end
end

#clear_all {|probe| ... } ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Clears all probes from all collections.

If a block is given, yields each installed probe after clearing to allow cleanup (e.g., unhooking instrumentation).

The yield happens outside the lock to avoid blocking other operations if the cleanup callback is slow.

Yields:

  • (probe)

    Yields each installed probe after clearing (for cleanup)



181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/datadog/di/probe_repository.rb', line 181

def clear_all
  probes_to_cleanup = @lock.synchronize do
    probes = @installed_probes.values
    @installed_probes.clear
    @pending_probes.clear
    @failed_probes.clear
    probes
  end

  if block_given?
    probes_to_cleanup.each do |probe|
      yield probe
    end
  end
end

#clear_pendingvoid

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Clears all pending probes.



120
121
122
123
124
# File 'lib/datadog/di/probe_repository.rb', line 120

def clear_pending
  @lock.synchronize do
    @pending_probes.clear
  end
end

#failed_probesHash<String, String>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the failed probes hash. Values are error message strings, not Probe objects.

Returns:

  • (Hash<String, String>)

    map of probe ID to error message



130
131
132
133
134
# File 'lib/datadog/di/probe_repository.rb', line 130

def failed_probes
  @lock.synchronize do
    @failed_probes
  end
end

#find_failed(probe_id) ⇒ String?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Finds a failed probe error message by probe ID.

Parameters:

  • probe_id (String)

    The probe ID to look up

Returns:

  • (String, nil)

    The error message if found, nil otherwise



140
141
142
143
144
# File 'lib/datadog/di/probe_repository.rb', line 140

def find_failed(probe_id)
  @lock.synchronize do
    @failed_probes[probe_id]
  end
end

#find_installed(probe_id) ⇒ Probe?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Finds an installed probe by ID.

Parameters:

  • probe_id (String)

    The probe ID to look up

Returns:

  • (Probe, nil)

    The probe if found, nil otherwise



54
55
56
57
58
# File 'lib/datadog/di/probe_repository.rb', line 54

def find_installed(probe_id)
  @lock.synchronize do
    @installed_probes[probe_id]
  end
end

#find_pending(probe_id) ⇒ Probe?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Finds a pending probe by ID.

Parameters:

  • probe_id (String)

    The probe ID to look up

Returns:

  • (Probe, nil)

    The probe if found, nil otherwise



92
93
94
95
96
# File 'lib/datadog/di/probe_repository.rb', line 92

def find_pending(probe_id)
  @lock.synchronize do
    @pending_probes[probe_id]
  end
end

#installed_probesHash<String, Probe>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the installed probes hash. Note: Returns the actual hash for backward compatibility with existing code.

Returns:

  • (Hash<String, Probe>)

    map of probe ID to installed probe



44
45
46
47
48
# File 'lib/datadog/di/probe_repository.rb', line 44

def installed_probes
  @lock.synchronize do
    @installed_probes
  end
end

#pending_probesHash<String, Probe>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the pending probes hash.

Returns:

  • (Hash<String, Probe>)

    map of probe ID to pending probe



82
83
84
85
86
# File 'lib/datadog/di/probe_repository.rb', line 82

def pending_probes
  @lock.synchronize do
    @pending_probes
  end
end

#remove_failed(probe_id) ⇒ String?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Removes a probe failure record from the collection.

Called when remote configuration removes a probe that previously failed to install, cleaning up the failure tracking.

Parameters:

  • probe_id (String)

    The ID of the probe to remove

Returns:

  • (String, nil)

    The removed error message if found, nil otherwise



166
167
168
169
170
# File 'lib/datadog/di/probe_repository.rb', line 166

def remove_failed(probe_id)
  @lock.synchronize do
    @failed_probes.delete(probe_id)
  end
end

#remove_installed(probe_id) ⇒ Probe?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Removes a probe from the installed probes collection.

Parameters:

  • probe_id (String)

    The ID of the probe to remove

Returns:

  • (Probe, nil)

    The removed probe if found, nil otherwise



73
74
75
76
77
# File 'lib/datadog/di/probe_repository.rb', line 73

def remove_installed(probe_id)
  @lock.synchronize do
    @installed_probes.delete(probe_id)
  end
end

#remove_pending(probe_id) ⇒ Probe?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Removes a probe from the pending probes collection.

Parameters:

  • probe_id (String)

    The ID of the probe to remove

Returns:

  • (Probe, nil)

    The removed probe if found, nil otherwise



111
112
113
114
115
# File 'lib/datadog/di/probe_repository.rb', line 111

def remove_pending(probe_id)
  @lock.synchronize do
    @pending_probes.delete(probe_id)
  end
end

#synchronize { ... } ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Executes the block while holding the repository lock.

Use this for compound operations that need to atomically check and modify multiple collections (e.g., check-then-install). Individual methods already acquire the lock internally; since the lock is a Monitor (reentrant), calling them from within this block is safe.

Yields:

  • Block to execute while holding the lock

Returns:

  • The return value of the block



36
37
38
# File 'lib/datadog/di/probe_repository.rb', line 36

def synchronize(&block)
  @lock.synchronize(&block)
end