datadog-checks-base 37.17.0__py2.py3-none-any.whl → 37.18.0__py2.py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
1
  # (C) Datadog, Inc. 2018-present
2
2
  # All rights reserved
3
3
  # Licensed under a 3-clause BSD style license (see LICENSE)
4
- __version__ = "37.17.0"
4
+ __version__ = "37.18.0"
@@ -0,0 +1,82 @@
1
+ # (C) Datadog, Inc. 2025-present
2
+ # All rights reserved
3
+ # Licensed under a 3-clause BSD style license (see LICENSE)
4
+ # This is the base implementation of the Agent Health reporting system.
5
+ # It provides a structure for health events and codes that can be extended by specific checks.
6
+
7
+ from __future__ import annotations
8
+
9
+ import time
10
+ from typing import TYPE_CHECKING
11
+
12
+ from datadog_checks.base.utils.serialization import json
13
+
14
+ if TYPE_CHECKING:
15
+ from datadog_checks.base import AgentCheck
16
+
17
+ try:
18
+ import datadog_agent
19
+ except ImportError:
20
+ from datadog_checks.base.stubs import datadog_agent
21
+
22
+
23
+ from enum import Enum
24
+
25
+
26
+ class HealthEvent(Enum):
27
+ """
28
+ Enum representing the health events.
29
+ """
30
+
31
+ INITIALIZATION = 'initialization'
32
+
33
+
34
+ class HealthStatus(Enum):
35
+ """
36
+ Enum representing the health statuses for a given event.
37
+ """
38
+
39
+ OK = 'ok'
40
+ WARNING = 'warning'
41
+ ERROR = 'error'
42
+
43
+
44
+ class Health:
45
+ def __init__(self, check: AgentCheck):
46
+ """
47
+ Initialize the HealthCheck instance.
48
+
49
+ :param check: AgentCheck
50
+ The check instance that will be used to submit health events.
51
+ """
52
+ self.check = check
53
+
54
+ def submit_health_event(self, name: HealthEvent, status: HealthStatus, tags: list[str] = None, **kwargs):
55
+ """
56
+ Submit a health event to the aggregator.
57
+
58
+ :param name: HealthEvent
59
+ The name of the health event.
60
+ :param status: HealthStatus
61
+ The health status to submit.
62
+ :param tags: list of str
63
+ Tags to associate with the health event.
64
+ :param kwargs: Additional keyword arguments to include in the event under `data`.
65
+ """
66
+ self.check.event_platform_event(
67
+ json.dumps(
68
+ {
69
+ 'timestamp': time.time() * 1000,
70
+ 'version': 1,
71
+ 'check_id': self.check.check_id,
72
+ 'category': self.check.__NAMESPACE__ or self.check.__class__.__name__.lower(),
73
+ 'name': name,
74
+ 'status': status,
75
+ 'tags': tags or [],
76
+ 'ddagentversion': datadog_agent.get_version(),
77
+ 'ddagenthostname': datadog_agent.get_hostname(),
78
+ 'data': {**kwargs},
79
+ }
80
+ ),
81
+ "dbm-health",
82
+ )
@@ -107,21 +107,33 @@ class ConstantRateLimiter:
107
107
  Basic rate limiter that sleeps long enough to ensure the rate limit is not exceeded. Not thread safe.
108
108
  """
109
109
 
110
- def __init__(self, rate_limit_s):
110
+ def __init__(self, rate_limit_s, max_sleep_chunk_s=5):
111
111
  """
112
112
  :param rate_limit_s: rate limit in seconds
113
+ :param max_sleep_chunk_s: maximum size of each sleep chunk while waiting for the next period
113
114
  """
114
115
  self.rate_limit_s = max(rate_limit_s, 0)
115
116
  self.period_s = 1.0 / self.rate_limit_s if self.rate_limit_s > 0 else 0
116
117
  self.last_event = 0
118
+ self.max_sleep_chunk_s = max(0, max_sleep_chunk_s)
117
119
 
118
- def update_last_time_and_sleep(self):
120
+ def update_last_time_and_sleep(self, cancel_event: Optional[threading.Event] = None):
119
121
  """
120
122
  Sleeps long enough to enforce the rate limit
121
123
  """
122
- elapsed_s = time.time() - self.last_event
123
- sleep_amount = max(self.period_s - elapsed_s, 0)
124
- time.sleep(sleep_amount)
124
+ if self.period_s <= 0:
125
+ self.update_last_time()
126
+ return
127
+
128
+ deadline = self.last_event + self.period_s
129
+ while True:
130
+ now = time.time()
131
+ remaining = deadline - now
132
+ if remaining <= 0:
133
+ break
134
+ if cancel_event is not None and cancel_event.is_set():
135
+ break
136
+ time.sleep(min(remaining, self.max_sleep_chunk_s if self.max_sleep_chunk_s > 0 else remaining))
125
137
  self.update_last_time()
126
138
 
127
139
  def shall_execute(self):
@@ -275,6 +287,7 @@ class DBMAsyncJob(object):
275
287
  min_collection_interval=15,
276
288
  dbms="TODO",
277
289
  rate_limit=1,
290
+ max_sleep_chunk_s=1,
278
291
  run_sync=False,
279
292
  enabled=True,
280
293
  expected_db_exceptions=(),
@@ -295,7 +308,8 @@ class DBMAsyncJob(object):
295
308
  self._last_check_run = 0
296
309
  self._shutdown_callback = shutdown_callback
297
310
  self._dbms = dbms
298
- self._rate_limiter = ConstantRateLimiter(rate_limit)
311
+ self._rate_limiter = ConstantRateLimiter(rate_limit, max_sleep_chunk_s=max_sleep_chunk_s)
312
+ self._max_sleep_chunk_s = max_sleep_chunk_s
299
313
  self._run_sync = run_sync
300
314
  self._enabled = enabled
301
315
  self._expected_db_exceptions = expected_db_exceptions
@@ -387,7 +401,7 @@ class DBMAsyncJob(object):
387
401
 
388
402
  def _set_rate_limit(self, rate_limit):
389
403
  if self._rate_limiter.rate_limit_s != rate_limit:
390
- self._rate_limiter = ConstantRateLimiter(rate_limit)
404
+ self._rate_limiter = ConstantRateLimiter(rate_limit, max_sleep_chunk_s=self._max_sleep_chunk_s)
391
405
 
392
406
  def _run_sync_job_rate_limited(self):
393
407
  if self._rate_limiter.shall_execute():
@@ -401,7 +415,7 @@ class DBMAsyncJob(object):
401
415
  raise
402
416
  finally:
403
417
  if not self._cancel_event.is_set():
404
- self._rate_limiter.update_last_time_and_sleep()
418
+ self._rate_limiter.update_last_time_and_sleep(cancel_event=self._cancel_event)
405
419
  else:
406
420
  self._rate_limiter.update_last_time()
407
421
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: datadog-checks-base
3
- Version: 37.17.0
3
+ Version: 37.18.0
4
4
  Summary: The Datadog Check Toolkit
5
5
  Project-URL: Source, https://github.com/DataDog/integrations-core
6
6
  Author-email: Datadog <packages@datadoghq.com>
@@ -3,7 +3,7 @@ datadog_checks/config.py,sha256=PrAXGdlLnoV2VMQff_noSaSJJ0wg4BAiGnw7jCQLSik,196
3
3
  datadog_checks/errors.py,sha256=eFwmnrX-batIgbu-iJyseqAPNO_4rk1UuaKK89evLhg,155
4
4
  datadog_checks/log.py,sha256=orvOgMKGNEsqSTLalCAQpWP-ouorpG1A7Gn-j2mRD80,301
5
5
  datadog_checks/py.typed,sha256=la67KBlbjXN-_-DfGNcdOcjYumVpKG_Tkw-8n5dnGB4,8
6
- datadog_checks/base/__about__.py,sha256=OGNRWmqbgVQlsRuznKvzC-6tPPWiFqHVOpBqXz6TrCI,139
6
+ datadog_checks/base/__about__.py,sha256=d8C_Jbdb_6t4htu9xHzfa7q7A7J7mafa2rOZW7HXkNg,139
7
7
  datadog_checks/base/__init__.py,sha256=yWegSLE-TZWIGSvAiJj9PSrUxzlOo_UVJLt2zORZ8Ek,363
8
8
  datadog_checks/base/__init__.pyi,sha256=eH8XhrtvnD6uE6FWfEyCmKwOaaLJxNolS08D6IRHZuU,995
9
9
  datadog_checks/base/agent.py,sha256=nX9x_BYYizRKGNYfXq5z7S0FZ9xcX_wd2tuxpGe3_8k,350
@@ -138,6 +138,7 @@ datadog_checks/base/utils/concurrency/limiter.py,sha256=is2ZpUEjfsI4nBGtXG2D0Zgv
138
138
  datadog_checks/base/utils/db/__init__.py,sha256=EVTc2FtnHWLHXI3M79jyMn9ypZAMa9eqG3EKLAiMF-M,211
139
139
  datadog_checks/base/utils/db/__init__.pyi,sha256=ewmGxxyJ52wAaYxNZahi2koEUnddfvHcn3HYxQ3RUr0,240
140
140
  datadog_checks/base/utils/db/core.py,sha256=bYanwXIqBzsSxK7b-Ofb0W1WiHbFBtKyYdUBonBLe_Q,11165
141
+ datadog_checks/base/utils/db/health.py,sha256=OWdhGSUhEr8Rxr6anVxD__52wkG8kDaY7M015Y4fCkA,2361
141
142
  datadog_checks/base/utils/db/query.py,sha256=-PyxdqpbShkQ78h7sWnghQZVtjdLGVrm71n8OpHuPW4,14432
142
143
  datadog_checks/base/utils/db/sql.py,sha256=oiEzQa_vC_w3U65VFrFCoQHWj5GQLLRlSO0CfiSlp4A,2490
143
144
  datadog_checks/base/utils/db/sql_commenter.py,sha256=r_efK6TGRQxM_-Qj-ndEJdECk47J4nCFjkVyxu1XmvU,1522
@@ -145,7 +146,7 @@ datadog_checks/base/utils/db/statement_metrics.py,sha256=U7EtERkmFzfCtfyd3094fBa
145
146
  datadog_checks/base/utils/db/timed_cache.py,sha256=a9Ks5KKUvExB6GOATXTSCLamVtLD919Dn6HpweGKtFw,2114
146
147
  datadog_checks/base/utils/db/transform.py,sha256=H3JN8_MF0Pk0HaXvIZeX1A8iQrP8KBgS741MPeBiWDo,23969
147
148
  datadog_checks/base/utils/db/types.py,sha256=OLX2Oq58JQPFBD4oqUpCLkAP7ovRGN_i1vFk1E0N8Lg,267
148
- datadog_checks/base/utils/db/utils.py,sha256=f1unpvrx-iFlcD-xUAnrlq5hk-udSw0GyQKYHaPLxFM,21683
149
+ datadog_checks/base/utils/db/utils.py,sha256=6rYXjV9I7Hr_PhgkvhbTiZ0QCmyHWoZYETeUD4Qe3Js,22441
149
150
  datadog_checks/base/utils/discovery/__init__.py,sha256=vPCOdsThBcBjFJRPhDm6IsZGOwk8HlvciwCe_l8dKLk,211
150
151
  datadog_checks/base/utils/discovery/__init__.pyi,sha256=ScVLU1Njj9ekZmewltb0cULI6BylssVHfn4CcPNeyr8,173
151
152
  datadog_checks/base/utils/discovery/cache.py,sha256=f9L3A7YZpZ-mpZpFIwjsa5ab9cZMGkqdetdr9EpalbI,887
@@ -219,6 +220,6 @@ datadog_checks/utils/tracing.py,sha256=HQbQakKM-Lw75MDkItaYJYipS6YO24Z_ymDVxDsx5
219
220
  datadog_checks/utils/prometheus/__init__.py,sha256=8WwXnM9g1sfS5267QYCJX_hd8MZl5kRgBgQ_SzdNdXs,161
220
221
  datadog_checks/utils/prometheus/functions.py,sha256=4vWsTGLgujHwdYZo0tlAQkqDPHofqUJM3k9eItJqERQ,197
221
222
  datadog_checks/utils/prometheus/metrics_pb2.py,sha256=xg3UdUHe4TjeR4s13LUKZ2U1WVSt6U6zjsVRG6lX6dc,173
222
- datadog_checks_base-37.17.0.dist-info/METADATA,sha256=UaY1u0ma7GdxBAIQLtFKQPwNntPVPzLDDi8nYN434_k,4244
223
- datadog_checks_base-37.17.0.dist-info/WHEEL,sha256=tkmg4JIqwd9H8mL30xA7crRmoStyCtGp0VWshokd1Jc,105
224
- datadog_checks_base-37.17.0.dist-info/RECORD,,
223
+ datadog_checks_base-37.18.0.dist-info/METADATA,sha256=14te5AqGZkd64H3TUo-Ro0hJdsgaPGFJs4iuKM-TQFA,4244
224
+ datadog_checks_base-37.18.0.dist-info/WHEEL,sha256=tkmg4JIqwd9H8mL30xA7crRmoStyCtGp0VWshokd1Jc,105
225
+ datadog_checks_base-37.18.0.dist-info/RECORD,,