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

Deprecate service tag #5545

Merged
merged 1 commit into from
Jan 24, 2020
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 @@ -14,6 +14,12 @@ instances:
- <SERVICE_NAME_1>
- <SERVICE_NAME_2>

## @param disable_legacy_service_tag - boolean - optional - default: false
## Whether or not to stop submitting the tag `service` that has been renamed
## to `windows_service` and disable the associated deprecation warning.
#
# disable_legacy_service_tag: false

## @param tags - list of key:value element - optional
## List of tags to attach to every service check emitted by this integration.
##
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,26 @@ def check(self, instance):
state = service_status[1]
status = self.STATE_TO_STATUS.get(state, self.UNKNOWN)

tags = ['service:{}'.format(short_name)]
tags = ['windows_service:{}'.format(short_name)]
tags.extend(custom_tags)

if not instance.get('disable_legacy_service_tag', False):
self._log_deprecation('service_tag', 'windows_service')
tags.append('service:{}'.format(short_name))

self.service_check(self.SERVICE_CHECK_NAME, status, tags=tags)
self.log.debug('service state for %s %s', short_name, status)

if 'ALL' not in services:
for service in services_unseen:
status = self.CRITICAL

tags = ['service:{}'.format(service)]
tags = ['windows_service:{}'.format(service)]
tags.extend(custom_tags)

if not instance.get('disable_legacy_service_tag', False):
self._log_deprecation('service_tag', 'windows_service')
tags.append('service:{}'.format(service))

self.service_check(self.SERVICE_CHECK_NAME, status, tags=tags)
self.log.debug('service state for %s %s', service, status)
5 changes: 5 additions & 0 deletions windows_service/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,10 @@
# All rights reserved
# Licensed under a 3-clause BSD style license (see LICENSE)
INSTANCE_BASIC = {'services': ['eventlog', 'Dnscache', 'NonExistentService'], 'tags': ['optional:tag1']}
INSTANCE_BASIC_DISABLE_SERVICE_TAG = {
'services': ['eventlog', 'Dnscache', 'NonExistentService'],
'tags': ['optional:tag1'],
'disable_legacy_service_tag': True,
}
INSTANCE_WILDCARD = {'host': '.', 'services': ['Event.*', 'Dns%']}
INSTANCE_ALL = {'services': ['ALL']}
5 changes: 5 additions & 0 deletions windows_service/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ def instance_basic():
return deepcopy(common.INSTANCE_BASIC)


@pytest.fixture
def instance_basic_disable_service_tag():
return deepcopy(common.INSTANCE_BASIC_DISABLE_SERVICE_TAG)


@pytest.fixture
def instance_wildcard():
return deepcopy(common.INSTANCE_WILDCARD)
Expand Down
55 changes: 45 additions & 10 deletions windows_service/tests/test_windows_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,65 @@ def test_basic(aggregator, check, instance_basic):
c = check(instance_basic)
c.check(instance_basic)
aggregator.assert_service_check(
c.SERVICE_CHECK_NAME, status=c.OK, tags=['service:EventLog', 'optional:tag1'], count=1
c.SERVICE_CHECK_NAME,
status=c.OK,
tags=['service:EventLog', 'windows_service:EventLog', 'optional:tag1'],
count=1,
)
aggregator.assert_service_check(
c.SERVICE_CHECK_NAME, status=c.OK, tags=['service:Dnscache', 'optional:tag1'], count=1
c.SERVICE_CHECK_NAME,
status=c.OK,
tags=['service:Dnscache', 'windows_service:Dnscache', 'optional:tag1'],
count=1,
)
aggregator.assert_service_check(
c.SERVICE_CHECK_NAME, status=c.CRITICAL, tags=['service:NonExistentService', 'optional:tag1'], count=1
c.SERVICE_CHECK_NAME,
status=c.CRITICAL,
tags=['service:NonExistentService', 'windows_service:NonExistentService', 'optional:tag1'],
count=1,
)


def test_wildcard(aggregator, check, instance_wildcard):
c = check(instance_wildcard)
c.check(instance_wildcard)
aggregator.assert_service_check(c.SERVICE_CHECK_NAME, status=c.OK, tags=['service:EventLog'], count=1)
aggregator.assert_service_check(c.SERVICE_CHECK_NAME, status=c.OK, tags=['service:EventSystem'], count=1)
aggregator.assert_service_check(c.SERVICE_CHECK_NAME, status=c.OK, tags=['service:Dnscache'], count=1)
aggregator.assert_service_check(
c.SERVICE_CHECK_NAME, status=c.OK, tags=['service:EventLog', 'windows_service:EventLog'], count=1
)
aggregator.assert_service_check(
c.SERVICE_CHECK_NAME, status=c.OK, tags=['service:EventSystem', 'windows_service:EventSystem'], count=1
)
aggregator.assert_service_check(
c.SERVICE_CHECK_NAME, status=c.OK, tags=['service:Dnscache', 'windows_service:Dnscache'], count=1
)


def test_all(aggregator, check, instance_all):
c = check(instance_all)
c.check(instance_all)
aggregator.assert_service_check(c.SERVICE_CHECK_NAME, status=c.OK, tags=['service:EventLog'], count=1)
aggregator.assert_service_check(c.SERVICE_CHECK_NAME, status=c.OK, tags=['service:Dnscache'], count=1)
aggregator.assert_service_check(c.SERVICE_CHECK_NAME, status=c.OK, tags=['service:EventSystem'], count=1)
aggregator.assert_service_check(
c.SERVICE_CHECK_NAME, status=c.OK, tags=['service:EventLog', 'windows_service:EventLog'], count=1
)
aggregator.assert_service_check(
c.SERVICE_CHECK_NAME, status=c.OK, tags=['service:Dnscache', 'windows_service:Dnscache'], count=1
)
aggregator.assert_service_check(
c.SERVICE_CHECK_NAME, status=c.OK, tags=['service:EventSystem', 'windows_service:EventSystem'], count=1
)


def test_basic_disable_service_tag(aggregator, check, instance_basic_disable_service_tag):
c = check(instance_basic_disable_service_tag)
c.check(instance_basic_disable_service_tag)
aggregator.assert_service_check(
c.SERVICE_CHECK_NAME, status=c.OK, tags=['windows_service:EventLog', 'optional:tag1'], count=1
)
aggregator.assert_service_check(
c.SERVICE_CHECK_NAME, status=c.OK, tags=['windows_service:Dnscache', 'optional:tag1'], count=1
)
aggregator.assert_service_check(
c.SERVICE_CHECK_NAME, status=c.CRITICAL, tags=['windows_service:NonExistentService', 'optional:tag1'], count=1
)


@pytest.mark.e2e
Expand All @@ -55,6 +90,6 @@ def test_basic_e2e(dd_agent_check, check, instance_basic):
aggregator.assert_service_check(
WindowsService.SERVICE_CHECK_NAME,
status=WindowsService.CRITICAL,
tags=['service:NonExistentService', 'optional:tag1'],
tags=['service:NonExistentService', 'windows_service:NonExistentService', 'optional:tag1'],
count=1,
)