LSST Applications g0603fd7c41+022847dfd1,g0aad566f14+f45185db35,g180d380827+40e913b07a,g2079a07aa2+86d27d4dc4,g2305ad1205+696e5f3872,g2bbee38e9b+047b288a59,g337abbeb29+047b288a59,g33d1c0ed96+047b288a59,g3a166c0a6a+047b288a59,g3d1719c13e+f45185db35,g3de15ee5c7+5201731f0d,g487adcacf7+19f9b77d7d,g50ff169b8f+96c6868917,g52b1c1532d+585e252eca,g591dd9f2cf+248b16177b,g63cd9335cc+585e252eca,g858d7b2824+f45185db35,g88963caddf+0cb8e002cc,g991b906543+f45185db35,g99cad8db69+1747e75aa3,g9b9dfce982+78139cbddb,g9ddcbc5298+9a081db1e4,ga1e77700b3+a912195c07,gae0086650b+585e252eca,gb0e22166c9+60f28cb32d,gb3a676b8dc+b4feba26a1,gb4b16eec92+f82f04eb54,gba4ed39666+c2a2e4ac27,gbb8dafda3b+215b19b0ab,gc120e1dc64+b0284b5341,gc28159a63d+047b288a59,gc3e9b769f7+dcad4ace9a,gcf0d15dbbd+78139cbddb,gdaeeff99f8+f9a426f77a,ge79ae78c31+047b288a59,w.2024.19
LSST Data Management Base Package
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
lsst.dax.apdb.monitor.MonService Class Reference
Inheritance diagram for lsst.dax.apdb.monitor.MonService:

Public Member Functions

None set_filters (self, Iterable[str] rules)
 
Iterable[MonHandlerhandlers (self)
 
None add_handler (self, MonHandler handler)
 
None remove_handler (self, MonHandler handler)
 
Iterator[None] context_tags (self, _TagsType tags)
 

Protected Member Functions

None _add_record (self, *str agent_name, str record_name, Mapping[str, Any] values, Mapping[str, str|int]|None tags=None, float|None timestamp=None)
 
_TagsType|None _add_context_tags (self, _TagsType tags)
 

Protected Attributes

 _filters
 
 _context_tags
 

Static Protected Attributes

list _handlers = []
 
_TagsType _context_tags = None
 
list _filters = []
 

Detailed Description

Class implementing monitoring service functionality.

Notes
-----
This is a singleton class which serves all client agents in an application.
It accepts records from agents, filters it based on a set of configured
rules and forwards them to one or more configured handlers. By default
there are no handlers defined which means that all records are discarded.
Default set of filtering rules is empty which accepts all agent names.

To produce a useful output from this service one has to add at least one
handler using `add_handler` method (e.g. `LoggingMonHandler` instance).
The `set_filters` methods can be used to specify the set of filtering
rules.

Definition at line 187 of file monitor.py.

Member Function Documentation

◆ _add_context_tags()

_TagsType | None lsst.dax.apdb.monitor.MonService._add_context_tags ( self,
_TagsType tags )
protected
Extend the tag context with new tags, overriding any tags that may
already exist in a current context.

Definition at line 308 of file monitor.py.

308 def _add_context_tags(self, tags: _TagsType) -> _TagsType | None:
309 """Extend the tag context with new tags, overriding any tags that may
310 already exist in a current context.
311 """
312 old_tags = self._context_tags
313 if not self._context_tags:
314 self._context_tags = tags
315 else:
316 all_tags = dict(self._context_tags)
317 all_tags.update(tags)
318 self._context_tags = all_tags
319 return old_tags
320

◆ _add_record()

None lsst.dax.apdb.monitor.MonService._add_record ( self,
*str agent_name,
str record_name,
Mapping[str, Any] values,
Mapping[str, str | int] | None tags = None,
float | None timestamp = None )
protected
Add one monitoring record, this method is for use by agents only.

Definition at line 250 of file monitor.py.

258 ) -> None:
259 """Add one monitoring record, this method is for use by agents only."""
260 if self._handlers:
261 accept: bool | None = None
262 # Check every filter, accept if none makes any decision.
263 for filter in self._filters:
264 accept = filter.accept(agent_name)
265 if accept is False:
266 return
267 if accept is True:
268 break
269 if timestamp is None:
270 timestamp = time.time()
271 if tags is None:
272 tags = self._context_tags or {}
273 else:
274 if self._context_tags:
275 all_tags = dict(self._context_tags)
276 all_tags.update(tags)
277 tags = all_tags
278 for handler in self._handlers:
279 handler.handle(record_name, timestamp, tags, values, agent_name)
280

◆ add_handler()

None lsst.dax.apdb.monitor.MonService.add_handler ( self,
MonHandler handler )
Add one monitoring handler.

Parameters
----------
handler : `MonHandler`
    Handler instance.

Definition at line 286 of file monitor.py.

286 def add_handler(self, handler: MonHandler) -> None:
287 """Add one monitoring handler.
288
289 Parameters
290 ----------
291 handler : `MonHandler`
292 Handler instance.
293 """
294 if handler not in self._handlers:
295 self._handlers.append(handler)
296

◆ context_tags()

Iterator[None] lsst.dax.apdb.monitor.MonService.context_tags ( self,
_TagsType tags )
Context manager that adds a set of tags to all records created
inside the context.

Typically clients will be using `MonAgent.context_tags`, which forwards
to this method.

Definition at line 322 of file monitor.py.

322 def context_tags(self, tags: _TagsType) -> Iterator[None]:
323 """Context manager that adds a set of tags to all records created
324 inside the context.
325
326 Typically clients will be using `MonAgent.context_tags`, which forwards
327 to this method.
328 """
329 old_context = self._add_context_tags(tags)
330 try:
331 yield
332 finally:
333 # Restore old context.
334 self._context_tags = old_context
335
336

◆ handlers()

Iterable[MonHandler] lsst.dax.apdb.monitor.MonService.handlers ( self)
Set of handlers defined currently.

Definition at line 282 of file monitor.py.

282 def handlers(self) -> Iterable[MonHandler]:
283 """Set of handlers defined currently."""
284 return self._handlers
285

◆ remove_handler()

None lsst.dax.apdb.monitor.MonService.remove_handler ( self,
MonHandler handler )
Add one monitoring handler.

Parameters
----------
handler : `MonHandler`
    Handler instance.

Definition at line 297 of file monitor.py.

297 def remove_handler(self, handler: MonHandler) -> None:
298 """Add one monitoring handler.
299
300 Parameters
301 ----------
302 handler : `MonHandler`
303 Handler instance.
304 """
305 if handler in self._handlers:
306 self._handlers.remove(handler)
307

◆ set_filters()

None lsst.dax.apdb.monitor.MonService.set_filters ( self,
Iterable[str] rules )
Define a sequence of rules for filtering of the agent names.

Parameters
----------
rules : `~collections.abc.Iterable` [`str`]
    Ordered collection of rules.  Each string specifies filtering rule
    for a single name, or catch-all rule.  The rule consist of the
    agent name prefixed by minus or optional plus sign. Catch-all rule
    uses name "any". If the rule starts with minus sign then matching
    agent will be rejected. Otherwise matching agent is accepted.

Notes
-----
The catch-all rule (`-any`, `+any`, or `any`) can be specified in any
location in the sequence but it is always applied last. E.g.
`["-any", "+agent1"]` behaves the same as `["+agent1", "-any"]`.
If the set of rues does not include catch-all rule, filtering behaves
as if it is added implicitly as `+any`.

Filtering code evaluates each rule in order. First rule that matches
the agent name wins. Agent names are matched literally, wildcards are
not supported and there are no parent/child relations between agent
names (e.g `lsst.dax.apdb` and `lsst.dax.apdb.sql` are treated as
independent names).

Definition at line 213 of file monitor.py.

213 def set_filters(self, rules: Iterable[str]) -> None:
214 """Define a sequence of rules for filtering of the agent names.
215
216 Parameters
217 ----------
218 rules : `~collections.abc.Iterable` [`str`]
219 Ordered collection of rules. Each string specifies filtering rule
220 for a single name, or catch-all rule. The rule consist of the
221 agent name prefixed by minus or optional plus sign. Catch-all rule
222 uses name "any". If the rule starts with minus sign then matching
223 agent will be rejected. Otherwise matching agent is accepted.
224
225 Notes
226 -----
227 The catch-all rule (`-any`, `+any`, or `any`) can be specified in any
228 location in the sequence but it is always applied last. E.g.
229 `["-any", "+agent1"]` behaves the same as `["+agent1", "-any"]`.
230 If the set of rues does not include catch-all rule, filtering behaves
231 as if it is added implicitly as `+any`.
232
233 Filtering code evaluates each rule in order. First rule that matches
234 the agent name wins. Agent names are matched literally, wildcards are
235 not supported and there are no parent/child relations between agent
236 names (e.g `lsst.dax.apdb` and `lsst.dax.apdb.sql` are treated as
237 independent names).
238 """
239 match_all: MonFilter | None = None
240 self._filters = []
241 for rule in rules:
242 mon_filter = MonFilter(rule)
243 if mon_filter.is_match_all():
244 match_all = mon_filter
245 else:
246 self._filters.append(mon_filter)
247 if match_all:
248 self._filters.append(match_all)
249

Member Data Documentation

◆ _context_tags [1/2]

_TagsType lsst.dax.apdb.monitor.MonService._context_tags = None
staticprotected

Definition at line 207 of file monitor.py.

◆ _context_tags [2/2]

lsst.dax.apdb.monitor.MonService._context_tags
protected

Definition at line 314 of file monitor.py.

◆ _filters [1/2]

list lsst.dax.apdb.monitor.MonService._filters = []
staticprotected

Definition at line 210 of file monitor.py.

◆ _filters [2/2]

lsst.dax.apdb.monitor.MonService._filters
protected

Definition at line 240 of file monitor.py.

◆ _handlers

list lsst.dax.apdb.monitor.MonService._handlers = []
staticprotected

Definition at line 204 of file monitor.py.


The documentation for this class was generated from the following file: