Skip to content

Commit

Permalink
Ensure metadata is submitted as strings (#5139)
Browse files Browse the repository at this point in the history
  • Loading branch information
ofek authored and therve committed Dec 4, 2019
1 parent c742ddc commit 1158875
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from six import iteritems

from ..common import to_string
from .constants import DEFAULT_BLACKLIST
from .utils import is_primitive
from .version import parse_version
Expand All @@ -32,7 +33,7 @@ def __init__(self, check_name, check_id, logger=None, metadata_transformers=None
self.metadata_transformers.update(metadata_transformers)

def submit_raw(self, name, value):
datadog_agent.set_check_metadata(self.check_id, name, value)
datadog_agent.set_check_metadata(self.check_id, to_string(name), to_string(value))

def submit(self, name, value, options):
transformer = self.metadata_transformers.get(name)
Expand Down
21 changes: 20 additions & 1 deletion datadog_checks_base/tests/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@

import mock
import pytest
from six import PY3

from datadog_checks.base import AgentCheck
from datadog_checks.base import AgentCheck, ensure_bytes, ensure_unicode

pytestmark = pytest.mark.metadata

Expand Down Expand Up @@ -55,6 +56,24 @@ class NewAgentCheck(AgentCheck):

m.assert_called_once_with('test:123', 'foo', 'rab')

def test_encoding(self):
check = AgentCheck('test', {}, [{}])
check.check_id = 'test:123'
if PY3:
constructor = ensure_bytes
finalizer = ensure_unicode
else:
constructor = ensure_unicode
finalizer = ensure_bytes

name = constructor(u'nam\u00E9')
value = constructor(u'valu\u00E9')

with mock.patch(SET_CHECK_METADATA_METHOD) as m:
check.set_metadata(name, value)

m.assert_called_once_with('test:123', finalizer(name), finalizer(value))


class TestVersion:
def test_override_allowed(self):
Expand Down

0 comments on commit 1158875

Please sign in to comment.