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

Adhere to code style #3322

Merged
merged 1 commit into from
Mar 19, 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
5 changes: 1 addition & 4 deletions apache/datadog_checks/apache/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,4 @@
from .__about__ import __version__
from .apache import Apache

__all__ = [
'__version__',
'Apache'
]
__all__ = ['__version__', 'Apache']
40 changes: 21 additions & 19 deletions apache/datadog_checks/apache/apache.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# (C) Datadog, Inc. 2010-2017
# All rights reserved
# Licensed under Simplified BSD License (see LICENSE)
from six.moves.urllib.parse import urlparse

import requests
from six.moves.urllib.parse import urlparse

from datadog_checks.checks import AgentCheck

# compatability layer
try:
from config import _is_affirmative
Expand All @@ -24,6 +24,7 @@ class Apache(AgentCheck):

See http://httpd.apache.org/docs/2.2/mod/mod_status.html for more details
"""

GAUGES = {
'IdleWorkers': 'apache.performance.idle_workers',
'BusyWorkers': 'apache.performance.busy_workers',
Expand All @@ -34,13 +35,10 @@ class Apache(AgentCheck):
'ConnsTotal': 'apache.conns_total',
'ConnsAsyncWriting': 'apache.conns_async_writing',
'ConnsAsyncKeepAlive': 'apache.conns_async_keep_alive',
'ConnsAsyncClosing': 'apache.conns_async_closing'
'ConnsAsyncClosing': 'apache.conns_async_closing',
}

RATES = {
'Total kBytes': 'apache.net.bytes_per_s',
'Total Accesses': 'apache.net.request_per_s'
}
RATES = {'Total kBytes': 'apache.net.bytes_per_s', 'Total Accesses': 'apache.net.request_per_s'}

def __init__(self, name, init_config, agentConfig, instances=None):
AgentCheck.__init__(self, name, init_config, agentConfig, instances)
Expand Down Expand Up @@ -70,20 +68,24 @@ def check(self, instance):
service_check_name = 'apache.can_connect'
service_check_tags = ['host:%s' % apache_host, 'port:%s' % apache_port] + tags
try:
self.log.debug('apache check initiating request, connect timeout %d receive %d' %
(connect_timeout, receive_timeout))
r = requests.get(url, auth=auth, headers=headers(self.agentConfig),
verify=not disable_ssl_validation, timeout=(connect_timeout, receive_timeout))
self.log.debug(
'apache check initiating request, connect timeout %d receive %d' % (connect_timeout, receive_timeout)
)
r = requests.get(
url,
auth=auth,
headers=headers(self.agentConfig),
verify=not disable_ssl_validation,
timeout=(connect_timeout, receive_timeout),
)
r.raise_for_status()

except Exception as e:
self.log.warning("Caught exception %s" % str(e))
self.service_check(service_check_name, AgentCheck.CRITICAL,
tags=service_check_tags)
self.service_check(service_check_name, AgentCheck.CRITICAL, tags=service_check_tags)
raise
else:
self.service_check(service_check_name, AgentCheck.OK,
tags=service_check_tags)
self.service_check(service_check_name, AgentCheck.OK, tags=service_check_tags)
self.log.debug("apache check succeeded")
metric_count = 0
# Loop through and extract the numerical values
Expand Down Expand Up @@ -118,7 +120,7 @@ def check(self, instance):
self.warning("Assuming url was not correct. Trying to add ?auto suffix to the url")
self.check(instance)
else:
raise Exception((
"No metrics were fetched for this instance. "
"Make sure that %s is the proper url.")
% instance['apache_status_url'])
raise Exception(
("No metrics were fetched for this instance. Make sure that %s is the proper url.")
% instance['apache_status_url']
)
12 changes: 3 additions & 9 deletions apache/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
# All rights reserved
# Licensed under a 3-clause BSD style license (see LICENSE)

# Always prefer setuptools over distutils
from setuptools import setup
# To use a consistent encoding
from codecs import open
from os import path

# Always prefer setuptools over distutils
from setuptools import setup

HERE = path.abspath(path.dirname(__file__))


Expand Down Expand Up @@ -42,17 +43,13 @@ def read(*parts):
long_description=long_description,
long_description_content_type='text/markdown',
keywords='datadog agent apache check',

# The project's main homepage.
url='https://github.com/DataDog/integrations-core',

# Author details
author='Datadog',
author_email='packages@datadoghq.com',

# License
license='BSD',

# See https://pypi.python.org/pypi?%3Aaction=list_classifiers
classifiers=[
'Development Status :: 5 - Production/Stable',
Expand All @@ -63,13 +60,10 @@ def read(*parts):
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
],

# The package we're going to ship
packages=['datadog_checks.apache'],

# Run-time dependencies
install_requires=[CHECKS_BASE_REQ],

# Extra files to ship with the wheel package
include_package_data=True,
)
21 changes: 5 additions & 16 deletions apache/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,11 @@
STATUS_URL = "{0}/server-status".format(BASE_URL)
AUTO_STATUS_URL = "{0}?auto".format(STATUS_URL)

STATUS_CONFIG = {
'apache_status_url': STATUS_URL,
'tags': ['instance:first']
}
STATUS_CONFIG = {'apache_status_url': STATUS_URL, 'tags': ['instance:first']}

AUTO_CONFIG = {
'apache_status_url': AUTO_STATUS_URL,
'tags': ['instance:second']
}
AUTO_CONFIG = {'apache_status_url': AUTO_STATUS_URL, 'tags': ['instance:second']}

BAD_CONFIG = {
'apache_status_url': 'http://localhost:1234/server-status',
}
BAD_CONFIG = {'apache_status_url': 'http://localhost:1234/server-status'}

APACHE_GAUGES = [
'apache.performance.idle_workers',
Expand All @@ -37,10 +29,7 @@
'apache.conns_total',
'apache.conns_async_writing',
'apache.conns_async_keep_alive',
'apache.conns_async_closing'
'apache.conns_async_closing',
]

APACHE_RATES = [
'apache.net.bytes_per_s',
'apache.net.request_per_s'
]
APACHE_RATES = ['apache.net.bytes_per_s', 'apache.net.request_per_s']
11 changes: 3 additions & 8 deletions apache/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
from datadog_checks.dev import docker_run
from datadog_checks.dev.conditions import CheckEndpoints

from .common import (
HERE, STATUS_URL, STATUS_CONFIG, BASE_URL, CHECK_NAME
)
from .common import BASE_URL, CHECK_NAME, HERE, STATUS_CONFIG, STATUS_URL


@pytest.fixture(scope="session")
Expand All @@ -25,11 +23,8 @@ def dd_environment():
with docker_run(
compose_file=os.path.join(HERE, 'compose', 'apache.yaml'),
env_vars=env,
conditions=[
CheckEndpoints([STATUS_URL]),
generate_metrics,
],
sleep=20
conditions=[CheckEndpoints([STATUS_URL]), generate_metrics],
sleep=20,
):
yield STATUS_CONFIG

Expand Down
4 changes: 1 addition & 3 deletions apache/tests/test_apache.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@

from datadog_checks.apache import Apache

from .common import (
BAD_CONFIG, STATUS_CONFIG, APACHE_GAUGES, APACHE_RATES, HOST, PORT, AUTO_CONFIG
)
from .common import APACHE_GAUGES, APACHE_RATES, AUTO_CONFIG, BAD_CONFIG, HOST, PORT, STATUS_CONFIG


@pytest.mark.usefixtures("dd_environment")
Expand Down
1 change: 1 addition & 0 deletions apache/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ envlist =

[testenv]
usedevelop = true
dd_check_style = true
platform = linux|darwin|win32
deps =
-e../datadog_checks_base[deps]
Expand Down