Skip to content

Commit

Permalink
Remove Python2 logic when loading checks (#18620)
Browse files Browse the repository at this point in the history
* Remove Python2 logic when loading checks

* remove py2 test for argocd
  • Loading branch information
iliakur authored Sep 19, 2024
1 parent 8c600ef commit 6faa14c
Show file tree
Hide file tree
Showing 25 changed files with 39 additions and 227 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
# (C) Datadog, Inc. 2013-present
# All rights reserved
# Licensed under Simplified BSD License (see LICENSE)
from six import PY3

from datadog_checks.base import PDHBaseCheck, is_affirmative

from .check import ActiveDirectoryCheckV2
from .metrics import DEFAULT_COUNTERS


class ActiveDirectoryCheck(PDHBaseCheck):
def __new__(cls, name, init_config, instances):
if PY3 and not is_affirmative(instances[0].get('use_legacy_check_version', False)):
from .check import ActiveDirectoryCheckV2

if not is_affirmative(instances[0].get('use_legacy_check_version', False)):
return ActiveDirectoryCheckV2(name, init_config, instances)
else:
return super(ActiveDirectoryCheck, cls).__new__(cls)
Expand Down
19 changes: 5 additions & 14 deletions aerospike/datadog_checks/aerospike/aerospike.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
from collections import defaultdict
from typing import List # noqa: F401

from six import PY2, iteritems

from datadog_checks.base import AgentCheck, ConfigurationError
from datadog_checks.base import AgentCheck
from datadog_checks.base.errors import CheckException

from .check import AerospikeCheckV2

try:
import aerospike
except ImportError as e:
Expand Down Expand Up @@ -78,15 +78,6 @@ def __new__(cls, name, init_config, instances):
instance = instances[0]

if 'openmetrics_endpoint' in instance:
if PY2:
raise ConfigurationError(
"This version of the integration is only available when using py3. "
"Check https://docs.datadoghq.com/agent/guide/agent-v6-python-3 "
"for more information or use the older style config."
)
# TODO: when we drop Python 2 move this import up top
from .check import AerospikeCheckV2

return AerospikeCheckV2(name, init_config, instances)

else:
Expand Down Expand Up @@ -232,7 +223,7 @@ def collect_info(self, command, metric_type, separator=';', required_keys=None,
self.log.warning('Exceeded cap `%s` for metric type `%s` - please contact support', cap, metric_type)
return

for key, value in iteritems(required_data):
for key, value in required_data.items():
self.send(metric_type, key, value, tags)

def get_namespaces(self):
Expand Down Expand Up @@ -491,7 +482,7 @@ def collect_latency(self, namespaces):

ns_latencies[ns].setdefault("metric_names", []).extend(metric_names)

for ns, v in iteritems(ns_latencies):
for ns, v in ns_latencies.items():
metric_names = v.get("metric_names", [])
metric_values = v.get("metric_values", [])
namespace_tags = ['namespace:{}'.format(ns)] if ns else []
Expand Down
11 changes: 1 addition & 10 deletions amazon_msk/datadog_checks/amazon_msk/amazon_msk.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import json

import boto3
from six import PY2

from datadog_checks.base import ConfigurationError, OpenMetricsBaseCheck, is_affirmative

from .check import AmazonMskCheckV2
from .metrics import JMX_METRICS_MAP, JMX_METRICS_OVERRIDES, NODE_METRICS_MAP, NODE_METRICS_OVERRIDES
from .utils import construct_boto_config

Expand All @@ -29,15 +29,6 @@ def __new__(cls, name, init_config, instances):
instance = instances[0]

if is_affirmative(instance.get('use_openmetrics', False)):
if PY2:
raise ConfigurationError(
"Openmetrics on this integration is only available when using py3. "
"Check https://docs.datadoghq.com/agent/guide/agent-v6-python-3 "
"for more information"
)
# TODO: when we drop Python 2 move this import up top
from .check import AmazonMskCheckV2

return AmazonMskCheckV2(name, init_config, instances)
else:
return super(AmazonMskCheck, cls).__new__(cls)
Expand Down
8 changes: 0 additions & 8 deletions argocd/datadog_checks/argocd/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
# Licensed under a 3-clause BSD style license (see LICENSE)
from collections import defaultdict

from six import PY2

from datadog_checks.base import ConfigurationError, OpenMetricsBaseCheckV2
from datadog_checks.base.constants import ServiceCheck

Expand Down Expand Up @@ -36,12 +34,6 @@ class ArgocdCheck(OpenMetricsBaseCheckV2, ConfigMixin):
DEFAULT_METRIC_LIMIT = 0

def __init__(self, name, init_config, instances):
if PY2:
raise ConfigurationError(
"This version of the integration is only available when using py3. "
"Check https://docs.datadoghq.com/agent/guide/agent-v6-python-3 "
"for more information."
)
super(ArgocdCheck, self).__init__(name, init_config, instances)
self.check_initializations.appendleft(self.parse_config)
self.check_initializations.append(self.configure_additional_transformers)
Expand Down
9 changes: 0 additions & 9 deletions argocd/tests/test_argocd.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
# Licensed under a 3-clause BSD style license (see LICENSE)

import pytest
from mock import patch

from datadog_checks.argocd import ArgocdCheck
from datadog_checks.base.constants import ServiceCheck
from datadog_checks.base.errors import ConfigurationError
from datadog_checks.dev.utils import get_metadata_metrics

from .common import (
Expand Down Expand Up @@ -96,10 +94,3 @@ def test_app_controller_service_check(dd_run_check, aggregator, mock_http_respon
ServiceCheck.UNKNOWN,
tags=['endpoint:http://app_controller:8082', 'name:faz'],
)


@patch('datadog_checks.argocd.check.PY2', True)
def test_py2():
# Test to ensure that a ConfigurationError is raised when running with Python 2.
with pytest.raises(ConfigurationError, match="This version of the integration is only available when using py3."):
ArgocdCheck('argocd', {}, [MOCKED_APP_CONTROLLER_INSTANCE])
7 changes: 2 additions & 5 deletions aspdotnet/datadog_checks/aspdotnet/aspdotnet.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
# (C) Datadog, Inc. 2013-present
# All rights reserved
# Licensed under Simplified BSD License (see LICENSE)
from six import PY3

from datadog_checks.base import PDHBaseCheck, is_affirmative

from .check import AspdotnetCheckV2
from .metrics import DEFAULT_COUNTERS

EVENT_TYPE = SOURCE_TYPE_NAME = 'aspdotnet'
Expand All @@ -13,9 +12,7 @@
class AspdotnetCheck(PDHBaseCheck):
def __new__(cls, name, init_config, instances):

if PY3 and not is_affirmative(instances[0].get('use_legacy_check_version', False)):
from .check import AspdotnetCheckV2

if not is_affirmative(instances[0].get('use_legacy_check_version', False)):
return AspdotnetCheckV2(name, init_config, instances)
else:
return super(AspdotnetCheck, cls).__new__(cls)
Expand Down
12 changes: 1 addition & 11 deletions cilium/datadog_checks/cilium/cilium.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
# (C) Datadog, Inc. 2019-present
# All rights reserved
# Licensed under a 3-clause BSD style license (see LICENSE)
from six import PY2

from datadog_checks.base import ConfigurationError, OpenMetricsBaseCheck, is_affirmative

from .check import CiliumCheckV2
from .metrics import AGENT_METRICS, OPERATOR_METRICS


Expand All @@ -19,15 +18,6 @@ def __new__(cls, name, init_config, instances):
instance = instances[0]

if is_affirmative(instance.get('use_openmetrics', False)):
if PY2:
raise ConfigurationError(
"This version of the integration is only available when using py3. "
"Check https://docs.datadoghq.com/agent/guide/agent-v6-python-3 "
"for more information or use the older style config."
)
# TODO: when we drop Python 2 move this import up top
from .check import CiliumCheckV2

return CiliumCheckV2(name, init_config, instances)
else:
return super(CiliumCheck, cls).__new__(cls)
Expand Down
14 changes: 2 additions & 12 deletions cockroachdb/datadog_checks/cockroachdb/cockroachdb.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
# (C) Datadog, Inc. 2018-present
# All rights reserved
# Licensed under a 3-clause BSD style license (see LICENSE)
from six import PY2

from datadog_checks.base import ConfigurationError, OpenMetricsBaseCheck
from datadog_checks.base import OpenMetricsBaseCheck

from .check import CockroachdbCheckV2
from .metrics import METRIC_MAP


Expand All @@ -16,15 +15,6 @@ def __new__(cls, name, init_config, instances):
instance = instances[0]

if 'openmetrics_endpoint' in instance:
if PY2:
raise ConfigurationError(
'This version of the integration is only available when using Python 3. '
'Check https://docs.datadoghq.com/agent/guide/agent-v6-python-3/ '
'for more information or use the older style config.'
)
# TODO: when we drop Python 2 move this import up top
from .check import CockroachdbCheckV2

return CockroachdbCheckV2(name, init_config, instances)
else:
return super(CockroachdbCheck, cls).__new__(cls)
Expand Down
12 changes: 1 addition & 11 deletions coredns/datadog_checks/coredns/coredns.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
# (C) Datadog, Inc. 2018-present
# All rights reserved
# Licensed under a 3-clause BSD style license (see LICENSE)
from six import PY2

from datadog_checks.base import ConfigurationError, OpenMetricsBaseCheck

from .check import CoreDNS
from .metrics import DEFAULT_METRICS, GO_METRICS


Expand All @@ -25,15 +24,6 @@ def __new__(cls, name, init_config, instances):
instance = instances[0]

if 'openmetrics_endpoint' in instance:
if PY2:
raise ConfigurationError(
"This version of the integration is only available when using py3. "
"Check https://docs.datadoghq.com/agent/guide/agent-v6-python-3 "
"for more information or use the older style config."
)
# TODO: when we drop Python 2 move this import up top
from .check import CoreDNS

return CoreDNS(name, init_config, instances)
else:
return super(CoreDNSCheck, cls).__new__(cls)
Expand Down
7 changes: 2 additions & 5 deletions dotnetclr/datadog_checks/dotnetclr/dotnetclr.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
# (C) Datadog, Inc. 2013-present
# All rights reserved
# Licensed under Simplified BSD License (see LICENSE)
from six import PY3

from datadog_checks.base import PDHBaseCheck, is_affirmative

from .check import DotnetclrCheckV2
from .metrics import DEFAULT_COUNTERS

EVENT_TYPE = SOURCE_TYPE_NAME = 'dotnetclr'


class DotnetclrCheck(PDHBaseCheck):
def __new__(cls, name, init_config, instances):
if PY3 and not is_affirmative(instances[0].get('use_legacy_check_version', False)):
from .check import DotnetclrCheckV2

if not is_affirmative(instances[0].get('use_legacy_check_version', False)):
return DotnetclrCheckV2(name, init_config, instances)
else:
return super(DotnetclrCheck, cls).__new__(cls)
Expand Down
11 changes: 1 addition & 10 deletions envoy/datadog_checks/envoy/envoy.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
from urllib.parse import urljoin

import requests
from six import PY2

from datadog_checks.base import AgentCheck, ConfigurationError, is_affirmative

from .check import EnvoyCheckV2
from .errors import UnknownMetric, UnknownTags
from .parser import parse_histogram, parse_metric
from .utils import _get_server_info
Expand All @@ -27,15 +27,6 @@ def __new__(cls, name, init_config, instances):
instance = instances[0]

if 'openmetrics_endpoint' in instance:
if PY2:
raise ConfigurationError(
"This version of the integration is only available when using py3. "
"Check https://docs.datadoghq.com/agent/guide/agent-v6-python-3 "
"for more information or use the older style config."
)
# TODO: when we drop Python 2 move this import up top
from .check import EnvoyCheckV2

return EnvoyCheckV2(name, init_config, instances)
else:
return super(Envoy, cls).__new__(cls)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
# (C) Datadog, Inc. 2013-present
# All rights reserved
# Licensed under Simplified BSD License (see LICENSE)
from six import PY3

from datadog_checks.base import PDHBaseCheck, is_affirmative

from .check import ExchangeCheckV2
from .metrics import DEFAULT_COUNTERS


class ExchangeCheck(PDHBaseCheck):
def __new__(cls, name, init_config, instances):
if PY3 and not is_affirmative(instances[0].get('use_legacy_check_version', False)):
from .check import ExchangeCheckV2

if not is_affirmative(instances[0].get('use_legacy_check_version', False)):
return ExchangeCheckV2(name, init_config, instances)
else:
return super(ExchangeCheck, cls).__new__(cls)
Expand Down
13 changes: 2 additions & 11 deletions gitlab/datadog_checks/gitlab/gitlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
from copy import deepcopy

import requests
from six import PY2

from datadog_checks.base import AgentCheck
from datadog_checks.base.checks.openmetrics import OpenMetricsBaseCheck
from datadog_checks.base.errors import CheckException, ConfigurationError
from datadog_checks.base.errors import CheckException

from .common import get_gitlab_version, get_tags
from .gitlab_v2 import GitlabCheckV2
from .metrics import METRICS_MAP


Expand Down Expand Up @@ -41,15 +41,6 @@ def __new__(cls, name, init_config, instances):
instance = instances[0]

if instance.get('openmetrics_endpoint'):
if PY2:
raise ConfigurationError(
'This version of the integration is only available when using Python 3. '
'Check https://docs.datadoghq.com/agent/guide/agent-v6-python-3/ '
'for more information or use the older style config.'
)
# TODO: when we drop Python 2 move this import up top
from .gitlab_v2 import GitlabCheckV2

return GitlabCheckV2(name, init_config, instances)

return super(GitlabCheck, cls).__new__(cls)
Expand Down
13 changes: 2 additions & 11 deletions haproxy/datadog_checks/haproxy/check.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
# (C) Datadog, Inc. 2020-present
# All rights reserved
# Licensed under a 3-clause BSD style license (see LICENSE)
from six import PY2

from datadog_checks.base import ConfigurationError, OpenMetricsBaseCheck, is_affirmative
from datadog_checks.base import OpenMetricsBaseCheck, is_affirmative

from .checkv2 import HaproxyCheckV2
from .legacy.haproxy import HAProxyCheckLegacy
from .metrics import METRIC_MAP

Expand All @@ -16,14 +15,6 @@ def __new__(cls, name, init_config, instances):
instance = instances[0]

if is_affirmative(instance.get('use_openmetrics', False)):
if PY2:
raise ConfigurationError(
"Openmetrics on this integration is only available when using py3. "
"Check https://docs.datadoghq.com/agent/guide/agent-v6-python-3 "
"for more information"
)
from .checkv2 import HaproxyCheckV2

return HaproxyCheckV2(name, init_config, instances)
elif is_affirmative(instance.get('use_prometheus', False)):
return super(HAProxyCheck, cls).__new__(cls)
Expand Down
Loading

0 comments on commit 6faa14c

Please sign in to comment.