Skip to content

Commit

Permalink
Do not modify original instance
Browse files Browse the repository at this point in the history
  • Loading branch information
mfpierre committed Aug 31, 2018
1 parent 347ba60 commit 1381cd9
Showing 1 changed file with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import re
import time
from collections import defaultdict, Counter
from copy import deepcopy

from datadog_checks.errors import CheckException
from datadog_checks.checks.openmetrics import OpenMetricsBaseCheck
Expand Down Expand Up @@ -100,14 +101,15 @@ def _create_kubernetes_state_prometheus_instance(self, instance):
"""
Set up the kubernetes_state instance so it can be used in OpenMetricsBaseCheck
"""
ksm_instance = deepcopy(instance)
endpoint = instance.get('kube_state_url')
if endpoint is None:
raise CheckException("Unable to find kube_state_url in config file.")

extra_labels = instance.get('label_joins', {})
hostname_override = is_affirmative(instance.get('hostname_override', True))
extra_labels = ksm_instance.get('label_joins', {})
hostname_override = is_affirmative(ksm_instance.get('hostname_override', True))

instance.update({
ksm_instance.update({
'namespace': 'kubernetes_state',
'metrics': [{
'kube_daemonset_status_current_number_scheduled': 'daemonset.scheduled',
Expand Down Expand Up @@ -237,18 +239,18 @@ def _create_kubernetes_state_prometheus_instance(self, instance):
}
},
# Defaults that were set when kubernetes_state was based on PrometheusCheck
'send_monotonic_counter': instance.get('send_monotonic_counter', False),
'health_service_check': instance.get('health_service_check', False)
'send_monotonic_counter': ksm_instance.get('send_monotonic_counter', False),
'health_service_check': ksm_instance.get('health_service_check', False)
})

instance['prometheus_url'] = endpoint
instance['label_joins'].update(extra_labels)
instance['label_to_hostname'] = 'node' if hostname_override else None
ksm_instance['prometheus_url'] = endpoint
ksm_instance['label_joins'].update(extra_labels)
ksm_instance['label_to_hostname'] = 'node' if hostname_override else None

if 'labels_mapper' in instance and not isinstance(instance['labels_mapper'], dict):
if 'labels_mapper' in ksm_instance and not isinstance(ksm_instance['labels_mapper'], dict):
self.log.warning("Option labels_mapper should be a dictionary for {}".format(endpoint))

return instance
return ksm_instance

def _condition_to_service_check(self, sample, sc_name, mapping, tags=None):
"""
Expand Down

0 comments on commit 1381cd9

Please sign in to comment.