Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix type hint on prefix argument to AgentCheck.normalize() #6008

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions datadog_checks_base/datadog_checks/base/checks/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -626,12 +626,13 @@ def set_external_tags(self, external_tags):
raise

def convert_to_underscore_separated(self, name):
# type: (bytes) -> bytes
# type: (Union[str, bytes]) -> bytes
"""
Convert from CamelCase to camel_case
And substitute illegal metric characters
"""
metric_name = self.FIRST_CAP_RE.sub(br'\1_\2', ensure_bytes(name))
name = ensure_bytes(name)
metric_name = self.FIRST_CAP_RE.sub(br'\1_\2', name)
metric_name = self.ALL_CAP_RE.sub(br'\1_\2', metric_name).lower()
metric_name = self.METRIC_REPLACEMENT.sub(br'_', metric_name)
return self.DOT_UNDERSCORE_CLEANUP.sub(br'.', metric_name).strip(b'_')
Expand Down Expand Up @@ -693,7 +694,7 @@ def _format_namespace(self, s, raw=False):
return to_native_string(s)

def normalize(self, metric, prefix=None, fix_case=False):
# type: (Union[str, bytes], bytes, bool) -> str
# type: (Union[str, bytes], Union[str, bytes], bool) -> str
"""
Turn a metric into a well-formed metric name
prefix.b.c
Expand Down
4 changes: 3 additions & 1 deletion datadog_checks_base/datadog_checks/base/utils/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import re
import warnings
from decimal import ROUND_HALF_UP, Decimal
from typing import TYPE_CHECKING, Any
from typing import TYPE_CHECKING, Any, Text, Union

from six import PY3, iteritems, text_type
from six.moves.urllib.parse import urlparse
Expand All @@ -16,12 +16,14 @@


def ensure_bytes(s):
# type: (Union[Text, bytes]) -> bytes
if isinstance(s, text_type):
s = s.encode('utf-8')
return s


def ensure_unicode(s):
# type: (Union[Text, bytes]) -> Text
if isinstance(s, bytes):
s = s.decode('utf-8')
return s
Expand Down