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

Ensure metadata is submitted as strings #5139

Merged
merged 1 commit into from
Dec 4, 2019
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
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