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

Support Python 3 #2786

Merged
merged 2 commits into from
Dec 18, 2018
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
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ jobs:
- stage: test
env: CHECK=vsphere
- stage: test
env: CHECK=yarn
env: CHECK=yarn PYTHON3=true
- stage: test
env: CHECK=zk
before_install:
Expand Down
14 changes: 6 additions & 8 deletions yarn/datadog_checks/yarn/yarn.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,12 @@
yarn.queue.maxApplicationsPerUser The maximum number of active applications per user this queue can have
"""

# stdlib
from urlparse import urljoin, urlsplit, urlunsplit
from six.moves.urllib.parse import urljoin, urlsplit, urlunsplit
from six import iteritems

# 3rd party
from requests.exceptions import Timeout, HTTPError, InvalidURL, ConnectionError, SSLError
import requests

# Project
from datadog_checks.checks import AgentCheck
from datadog_checks.config import _is_affirmative

Expand Down Expand Up @@ -226,7 +224,7 @@ def check(self, instance):
app_tags = {}

filtered_app_tags = {}
for dd_prefix, yarn_key in app_tags.iteritems():
for dd_prefix, yarn_key in iteritems(app_tags):
if yarn_key in self._ALLOWED_APPLICATION_TAGS:
filtered_app_tags[dd_prefix] = yarn_key
app_tags = filtered_app_tags
Expand Down Expand Up @@ -292,7 +290,7 @@ def _yarn_app_metrics(self, rm_address, auth, ssl_verify, app_tags, addl_tags):
for app_json in metrics_json['apps']['app']:

tags = []
for dd_tag, yarn_key in app_tags.iteritems():
for dd_tag, yarn_key in iteritems(app_tags):
try:
val = app_json[yarn_key]
if val:
Expand Down Expand Up @@ -371,7 +369,7 @@ def _set_yarn_metrics_from_json(self, tags, metrics_json, yarn_metrics):
"""
Parse the JSON response and set the metrics
"""
for dict_path, metric in yarn_metrics.iteritems():
for dict_path, metric in iteritems(yarn_metrics):
metric_name, metric_type = metric

metric_value = self._get_value_from_json(dict_path, metrics_json)
Expand Down Expand Up @@ -424,7 +422,7 @@ def _rest_request_to_json(self, address, auth, ssl_verify, object_path, tags, *a

# Add kwargs as arguments
if kwargs:
query = '&'.join(['{}={}'.format(key, value) for key, value in kwargs.iteritems()])
query = '&'.join(['{}={}'.format(key, value) for key, value in iteritems(kwargs)])
url = urljoin(url, '?' + query)

try:
Expand Down
8 changes: 0 additions & 8 deletions yarn/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,6 @@
)


@pytest.fixture
def aggregator():
from datadog_checks.stubs import aggregator

aggregator.reset()
return aggregator


@pytest.fixture
def mocked_request():
with patch("requests.get", new=requests_get_mock):
Expand Down
11 changes: 6 additions & 5 deletions yarn/tests/test_yarn.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# (C) Datadog, Inc. 2018
# All rights reserved
# Licensed under a 3-clause BSD style license (see LICENSE)
from six import iteritems

from requests.exceptions import SSLError
from datadog_checks.yarn import YarnCheck
Expand Down Expand Up @@ -45,23 +46,23 @@ def test_check(aggregator, mocked_request):
)

# Check the YARN Cluster Metrics
for metric, value in YARN_CLUSTER_METRICS_VALUES.iteritems():
for metric, value in iteritems(YARN_CLUSTER_METRICS_VALUES):
aggregator.assert_metric(metric, value=value, tags=YARN_CLUSTER_METRICS_TAGS + CUSTOM_TAGS, count=1)

# Check the YARN App Metrics
for metric, value in YARN_APP_METRICS_VALUES.iteritems():
for metric, value in iteritems(YARN_APP_METRICS_VALUES):
aggregator.assert_metric(metric, value=value, tags=YARN_APP_METRICS_TAGS + CUSTOM_TAGS, count=1)

# Check the YARN Node Metrics
for metric, value in YARN_NODE_METRICS_VALUES.iteritems():
for metric, value in iteritems(YARN_NODE_METRICS_VALUES):
aggregator.assert_metric(metric, value=value, tags=YARN_NODE_METRICS_TAGS + CUSTOM_TAGS, count=1)

# Check the YARN Root Queue Metrics
for metric, value in YARN_ROOT_QUEUE_METRICS_VALUES.iteritems():
for metric, value in iteritems(YARN_ROOT_QUEUE_METRICS_VALUES):
aggregator.assert_metric(metric, value=value, tags=YARN_ROOT_QUEUE_METRICS_TAGS + CUSTOM_TAGS, count=1)

# Check the YARN Custom Queue Metrics
for metric, value in YARN_QUEUE_METRICS_VALUES.iteritems():
for metric, value in iteritems(YARN_QUEUE_METRICS_VALUES):
aggregator.assert_metric(metric, value=value, tags=YARN_QUEUE_METRICS_TAGS + CUSTOM_TAGS, count=1)

# Check the YARN Queue Metrics from excluded queues are absent
Expand Down
4 changes: 1 addition & 3 deletions yarn/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@
minversion = 2.0
basepython = py27
envlist =
yarn
{py27,py36}-yarn
flake8

[testenv]
usedevelop = true
platform = linux|darwin|win32

[testenv:yarn]
deps =
-e../datadog_checks_base[deps]
-rrequirements-dev.txt
Expand Down