Skip to content

Commit

Permalink
Deprecate service tag
Browse files Browse the repository at this point in the history
  • Loading branch information
ofek committed Jan 24, 2020
1 parent 8b1cd68 commit 046aac1
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 12 deletions.
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
12 changes: 10 additions & 2 deletions windows_service/datadog_checks/windows_service/windows_service.py
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,
)

0 comments on commit 046aac1

Please sign in to comment.