datadog-checks-base 37.21.0__py2.py3-none-any.whl → 37.21.1__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.21.0"
4
+ __version__ = "37.21.1"
@@ -1094,6 +1094,9 @@ class AgentCheck(object):
1094
1094
  return entrypoint
1095
1095
 
1096
1096
  def __initialize_persistent_cache_key_prefix(self):
1097
+ if self.__persistent_cache_key_prefix:
1098
+ return
1099
+
1097
1100
  namespace = ':'.join(self.check_id.split(':')[:-1])
1098
1101
  self.__persistent_cache_key_prefix = f'{namespace}:{self.persistent_cache_id()}_'
1099
1102
 
@@ -1,6 +1,7 @@
1
1
  # (C) Datadog, Inc. 2010-present
2
2
  # All rights reserved
3
3
  # Licensed under Simplified BSD License (see LICENSE)
4
+ from typing import Any
4
5
 
5
6
 
6
7
  class _FreezeKey(object):
@@ -30,8 +31,9 @@ class _FreezeKey(object):
30
31
  if other.value is None:
31
32
  # `x < None` -> `False`
32
33
  return False
33
- # ...But we let other cases bubble through.
34
- raise
34
+
35
+ # If we get 2 types that cannot be compared, we compare the string representation of the types.
36
+ return str(type(self.value)) < str(type(other.value))
35
37
  else:
36
38
  # We're on Python 2, where `a < b` never fails (returns `False` by default), or
37
39
  # we're on Python 3 and values have the same type.
@@ -65,6 +67,17 @@ def hash_mutable(m):
65
67
  return hash(freeze(m))
66
68
 
67
69
 
70
+ def hash_mutable_stable(m: Any) -> str:
71
+ """
72
+ This method provides a way of hashing a mutable object ensuring that the same object always
73
+ provides the same hash even in different processes.
74
+ """
75
+ from datadog_checks.base.utils.hashing import HashMethod
76
+
77
+ algorithm = HashMethod.secure()
78
+ return algorithm(str(freeze(m)).encode()).hexdigest()
79
+
80
+
68
81
  def iter_unique(*iterables):
69
82
  seen = set()
70
83
 
@@ -0,0 +1,75 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import TYPE_CHECKING, Any, Protocol
4
+
5
+ if TYPE_CHECKING:
6
+ from collections.abc import Buffer
7
+
8
+
9
+ class Hash(Protocol):
10
+ def digest(self) -> bytes: ...
11
+ def hexdigest(self) -> str: ...
12
+ def update(self, obj: Buffer, /) -> None: ...
13
+ def copy(self) -> Hash: ...
14
+
15
+
16
+ class HashingAlgorithm(Protocol):
17
+ def __call__(self, data: bytes, *args: Any, **kwargs: Any) -> Hash: ...
18
+
19
+
20
+ class HashMethod:
21
+ """
22
+ Singleton class used to provide hashing algorithms
23
+ """
24
+
25
+ _architecture: str | None = None
26
+ _secure: HashingAlgorithm | None = None
27
+ _fast: HashingAlgorithm | None = None
28
+
29
+ @classmethod
30
+ def secure(cls) -> HashingAlgorithm:
31
+ """
32
+ Provides a secure hashing algorithm.
33
+
34
+ This algorithm is compliant with the FIPS 140-2 standard.
35
+ """
36
+ if cls._secure is not None:
37
+ return cls._secure
38
+
39
+ from hashlib import sha256
40
+
41
+ def secure(data: bytes, *args: Any, **kwargs: Any) -> Hash:
42
+ return sha256(data, *args, **kwargs)
43
+
44
+ cls._secure = secure
45
+ return cls._secure
46
+
47
+ @classmethod
48
+ def fast(cls) -> HashingAlgorithm:
49
+ """
50
+ Provides a fast hashing algorithm.
51
+
52
+ If the platform is 64bit, it will use the blake2b algorithm, otherwise it will use the blake2s algorithm.
53
+ """
54
+ if cls._fast is not None:
55
+ return cls._fast
56
+
57
+ from hashlib import blake2b, blake2s
58
+
59
+ selected_blake = blake2b if cls.architecture() == "64bit" else blake2s
60
+
61
+ def blake(data: bytes, *args: Any, **kwargs: Any) -> Hash:
62
+ return selected_blake(data, *args, **kwargs)
63
+
64
+ cls._fast = blake
65
+ return cls._fast
66
+
67
+ @classmethod
68
+ def architecture(cls) -> str:
69
+ if cls._architecture is not None:
70
+ return cls._architecture
71
+
72
+ from datadog_checks.base.utils.platform import Platform
73
+
74
+ cls._architecture = Platform().python_architecture()
75
+ return cls._architecture
@@ -1,7 +1,7 @@
1
1
  from collections.abc import Collection
2
2
 
3
3
  from datadog_checks.base import AgentCheck
4
- from datadog_checks.base.utils.containers import hash_mutable
4
+ from datadog_checks.base.utils.containers import hash_mutable_stable
5
5
 
6
6
 
7
7
  def config_set_persistent_cache_id(
@@ -30,4 +30,5 @@ def config_set_persistent_cache_id(
30
30
  instance_config_values = tuple(value for key, value in check.instance.items() if key in set_instance_config_options)
31
31
 
32
32
  selected_values = init_config_values + instance_config_values
33
- return str(hash_mutable(selected_values)).replace("-", "")
33
+
34
+ return hash_mutable_stable(selected_values)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: datadog-checks-base
3
- Version: 37.21.0
3
+ Version: 37.21.1
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=pvycJFU0hkYwQYew20pwmnwFDOFZoWPr3etBDGeoKzI,139
6
+ datadog_checks/base/__about__.py,sha256=zY9yrvpmsQJIlSMC9LByfIb_KGfdfnD6iYbUnIQNZBo,139
7
7
  datadog_checks/base/__init__.py,sha256=yWegSLE-TZWIGSvAiJj9PSrUxzlOo_UVJLt2zORZ8Ek,363
8
8
  datadog_checks/base/__init__.pyi,sha256=a4Y1JIcPJ8pz9tRkBAvjWdtvSQwZxbMZBuRmIiSs_4E,1031
9
9
  datadog_checks/base/agent.py,sha256=nX9x_BYYizRKGNYfXq5z7S0FZ9xcX_wd2tuxpGe3_8k,350
@@ -15,7 +15,7 @@ datadog_checks/base/types.py,sha256=anajZS0W0TsxUHJQw-JHOP2NSeuC9BisXSy9mAStlxQ,
15
15
  datadog_checks/base/checks/__init__.py,sha256=q7V6v-FwQWkQC1QWaVzKaPjZMaxPJHJcLd71C0uM7bA,211
16
16
  datadog_checks/base/checks/__init__.pyi,sha256=ydetl6kEFCSChppYQhs8mvIP5l6vnZD5AbLABGhbFcM,309
17
17
  datadog_checks/base/checks/_config_ast.py,sha256=v1rAhwORF80b3kfZKhf6zXZ7S5D3A2QPUK4tSo8eo-Y,3268
18
- datadog_checks/base/checks/base.py,sha256=xP56kjtCvW-CMWrdVN3ZC1yAhQr4jad9ORPDuOdz-eM,60654
18
+ datadog_checks/base/checks/base.py,sha256=mnh61HRvHFisSP4IvUtoDPswxB3_ybX-nWkfXMyzWJE,60721
19
19
  datadog_checks/base/checks/db.py,sha256=HzEOH4uZaMDAaUTJYy0K5wV9FryNQDXsSMAOHXPVaf4,794
20
20
  datadog_checks/base/checks/network.py,sha256=UkgqkVHaoX7Hqi0WKEx-TvaFiF6-37VyF9A3m2aSaJM,1966
21
21
  datadog_checks/base/checks/kube_leader/__init__.py,sha256=q7V6v-FwQWkQC1QWaVzKaPjZMaxPJHJcLd71C0uM7bA,211
@@ -109,15 +109,16 @@ datadog_checks/base/utils/_http_utils.py,sha256=w8whzycmGzVKlCUv703rgg2qMAF0T3d5
109
109
  datadog_checks/base/utils/aws.py,sha256=wxFLWlVFtv5_EURdsXzDhORcTpM0jBlAokcMiPV1xD8,1945
110
110
  datadog_checks/base/utils/common.py,sha256=OtmKd5FKjlwJwRbhE4aImOBWPOzNPVqfXXmHXk4MMIw,3803
111
111
  datadog_checks/base/utils/constants.py,sha256=QwTey4CWB0NAxm2rcD-wPYRkEyglekQIrAzFMabEa38,306
112
- datadog_checks/base/utils/containers.py,sha256=LBqUzERHxx5TdgcWVQTq1A1WaGCMhzXT9k4Gn0fX3J8,2753
112
+ datadog_checks/base/utils/containers.py,sha256=S6c9kvmDJuiHh9hO62Pbdqrnhm6e2R3O5gGH3l5jtNo,3243
113
113
  datadog_checks/base/utils/date.py,sha256=JJmqP84CgVcFJ0cvAmMu8EtM6v96tIESucQNm9eKeEc,2780
114
114
  datadog_checks/base/utils/diagnose.py,sha256=eLMe0tISpkzS3yxVR83IHxorQJfHT_Xi6Cq4zzRNxVI,5285
115
115
  datadog_checks/base/utils/fips.py,sha256=vxm3K7wTQKYenP1LbXk7pmJ8WA6l367BTJGBNO0DkvQ,2490
116
116
  datadog_checks/base/utils/functions.py,sha256=iGlybxR6aPPElNxNb2ELOzbk328j9OVBAxredJxdCRw,695
117
+ datadog_checks/base/utils/hashing.py,sha256=dNAe3RUvd7TE3WmcDX6SYQhTaMXsxxDHue4fPkFuL5Q,2015
117
118
  datadog_checks/base/utils/headers.py,sha256=0SSdC71jwaB61BODfusahCVr1c56GvT9iwt7cidcHP0,1779
118
119
  datadog_checks/base/utils/http.py,sha256=ePSzL7x_xsb1dnXJyU2fBXIgOU0p5UFZIpG2AX_jZZA,44651
119
120
  datadog_checks/base/utils/limiter.py,sha256=YRTrPCX1S5EtHLVcP_-GEfzRots_LTcy1f_uHZVs90g,3027
120
- datadog_checks/base/utils/persistent_cache.py,sha256=i5I9BKIb5V2BFEs0sVTf8bBQUIH21G2nL_tRQHC9GMk,1538
121
+ datadog_checks/base/utils/persistent_cache.py,sha256=1Tk0dkWZH8yH4I_bMZgnhhz2jcZcIyu85dNpBvy5lsM,1531
121
122
  datadog_checks/base/utils/platform.py,sha256=wW8f6XKo4JHxvu1sN0DpLDmYjS_cCu8GoKvfTjIj4yM,2499
122
123
  datadog_checks/base/utils/secrets.py,sha256=Tj5MBOoyGXXDWB3Hr-7UKDy5GV1NZJkFPY4T4v9PHHg,551
123
124
  datadog_checks/base/utils/serialization.py,sha256=pcRUzZIUZkOsfnGDGbxeUwGXrSsFl_9rLhA0ekD_AZ8,975
@@ -222,6 +223,6 @@ datadog_checks/utils/tracing.py,sha256=HQbQakKM-Lw75MDkItaYJYipS6YO24Z_ymDVxDsx5
222
223
  datadog_checks/utils/prometheus/__init__.py,sha256=8WwXnM9g1sfS5267QYCJX_hd8MZl5kRgBgQ_SzdNdXs,161
223
224
  datadog_checks/utils/prometheus/functions.py,sha256=4vWsTGLgujHwdYZo0tlAQkqDPHofqUJM3k9eItJqERQ,197
224
225
  datadog_checks/utils/prometheus/metrics_pb2.py,sha256=xg3UdUHe4TjeR4s13LUKZ2U1WVSt6U6zjsVRG6lX6dc,173
225
- datadog_checks_base-37.21.0.dist-info/METADATA,sha256=RngK4W5OJrfoUb7udQ1t_kuEqdSP0_6Mk6FecbRTVyo,4245
226
- datadog_checks_base-37.21.0.dist-info/WHEEL,sha256=tkmg4JIqwd9H8mL30xA7crRmoStyCtGp0VWshokd1Jc,105
227
- datadog_checks_base-37.21.0.dist-info/RECORD,,
226
+ datadog_checks_base-37.21.1.dist-info/METADATA,sha256=W1zsqHGVigXb-0R8vJOUv2kxuRDn0S02dYFWEfggkHQ,4245
227
+ datadog_checks_base-37.21.1.dist-info/WHEEL,sha256=tkmg4JIqwd9H8mL30xA7crRmoStyCtGp0VWshokd1Jc,105
228
+ datadog_checks_base-37.21.1.dist-info/RECORD,,