Skip to content

Commit

Permalink
Addressing comments pt3
Browse files Browse the repository at this point in the history
  • Loading branch information
shraykay committed Aug 31, 2018
1 parent f5f7940 commit 65b9e52
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 156 deletions.
30 changes: 3 additions & 27 deletions coredns/datadog_checks/coredns/coredns.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,6 @@ def __init__(self, name, init_config, agentConfig, instances=None):

super(CoreDNSCheck, self).__init__(name, init_config, agentConfig, instances=generic_instances)

def check(self, instance):
endpoint = instance.get('prometheus_url')
scraper_config = self.config_map[endpoint]
self.process(scraper_config)

def create_generic_instances(self, instances):
"""
Transform each CoreDNS instance into a OpenMetricsBaseCheck instance
Expand All @@ -96,32 +91,13 @@ def _create_core_dns_instance(self, instance):
if endpoint is None:
raise CheckException("Unable to find prometheus endpoint in config file.")

send_buckets = instance.get('send_histograms_buckets', True)
# By default we send the buckets.
if send_buckets is not None and str(send_buckets).lower() == 'false':
send_buckets = False
else:
send_buckets = True

send_monotonic = instance.get('send_monotonic_counter', True)
# By default we send the buckets.
if send_monotonic is not None and str(send_monotonic).lower() == 'false':
send_monotonic = False
else:
send_monotonic = True

metrics = instance.get('metrics', [])
if metrics is None:
metrics = metrics + [GO_METRICS]
else:
metrics = [DEFAULT_METRICS, GO_METRICS]
metrics = [DEFAULT_METRICS, GO_METRICS]
metrics.extend(instance.get('metrics', []))

instance.update({
'namespace': 'coredns',
'prometheus_url': endpoint,
'namespace': 'coredns',
'metrics': metrics,
'send_histograms_buckets': send_buckets,
'send_monotonic_counter': send_monotonic,
})

return instance
48 changes: 24 additions & 24 deletions coredns/datadog_checks/coredns/data/auto_conf.yaml
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
ad_identifiers:
- coredns/coredns
- coredns

init_config:

instances:
# To enable CoreDNS metrics you must specify the prometheus url and enable the plugin within coredns
# See: https://coredns.io/plugins/metrics/
## @param prometheus_url - string - required
## To enable CoreDNS metrics you must specify the prometheus url
## and enable the plugin within coredns
## See: https://coredns.io/plugins/metrics/
#
- prometheus_url: "http://%%host%%:9153/metrics"
tags:
- "dns-pod:%%host%%"

# To send the histograms bucket
send_histograms_buckets: True
## @param send_histogram_buckets - boolean - optional - default:True
#
# send_histograms_buckets: True

# To send counters as monotonic counter
send_monotonic_counter: True
## @param send_monotonic_counter - boolean - optional - default:True
## To send counters as monotonic counter
## see: https://github.com/DataDog/integrations-core/issues/1303
#
# send_monotonic_counter: True

metrics:
# metrics are being emitted from the below plugins
# to map metrics from other plugins use the format below
# https://coredns.io/plugins/metrics/
# https://coredns.io/plugins/proxy/
# https://coredns.io/plugins/cache/
- coredns_dns_response_size_bytes: response_size.bytes
- coredns_cache_hits_total: cache_hits_count
- coredns_cache_misses_total: cache_misses_count
- coredns_dns_request_count_total: request_count
- coredns_dns_request_duration_seconds: request_duration.seconds
- coredns_dns_request_size_bytes: request_size.bytes
- coredns_dns_request_type_count_total: request_type_count
- coredns_dns_response_rcode_count_total: response_code_count
- coredns_proxy_request_count_total: proxy_request_count
- coredns_proxy_request_duration_seconds: proxy_request_duration.seconds
- coredns_cache_size: cache_size.count

## Metrics from the CoreDNS plugins for 'metrics', 'proxy' and 'cache'
## are enabled by default, however in order to scrape metrics for optional
## plugins, enable the plugin in the CoreDNS corefile and then add the metric below.
## As an example, the 'template' plugin's metrics are below
#
# metrics:
# - coredns_template_matches_total: template_matches_count
# - coredns_template_template_failures_total: template_templating_failures_count
# - coredns_template_rr_failures_total: template_resource_record_failures_count
49 changes: 24 additions & 25 deletions coredns/datadog_checks/coredns/data/conf.yaml.example
Original file line number Diff line number Diff line change
@@ -1,33 +1,32 @@
init_config:
# Leave empty

instances:
# To enable CoreDNS metrics you must specify the prometheus url and enable the plugin within coredns
# See: https://coredns.io/plugins/metrics/
- prometheus_url: "http://%%host%%:9153/metrics"
tags:
- "dns-pod:%%host%%"
## @param prometheus_url - string - required
## To enable CoreDNS metrics you must specify the prometheus url
## and enable the plugin within coredns
## See: https://coredns.io/plugins/metrics/
#
# - prometheus_url: "http://%%host%%:9153/metrics"
# tags:
# - "dns-pod:%%host%%"

# To send the histograms bucket
## @param send_histogram_buckets - boolean - optional - default:True
#
# send_histograms_buckets: True

# To send counters as monotonic counter
## @param send_monotonic_counter - boolean - optional - default:True
## To send counters as monotonic counter
## see: https://github.com/DataDog/integrations-core/issues/1303
#
# send_monotonic_counter: True

metrics:
# metrics are being emitted from the below plugins
# to map metrics from other plugins use the format below
# https://coredns.io/plugins/metrics/
# https://coredns.io/plugins/proxy/
# https://coredns.io/plugins/cache/
- coredns_dns_response_size_bytes: response_size.bytes
- coredns_cache_hits_total: cache_hits_count
- coredns_cache_misses_total: cache_misses_count
- coredns_dns_request_count_total: request_count
- coredns_dns_request_duration_seconds: request_duration.seconds
- coredns_dns_request_size_bytes: request_size.bytes
- coredns_dns_request_type_count_total: request_type_count
- coredns_dns_response_rcode_count_total: response_code_count
- coredns_proxy_request_count_total: proxy_request_count
- coredns_proxy_request_duration_seconds: proxy_request_duration.seconds
- coredns_cache_size: cache_size.count

## Metrics from the CoreDNS plugins for 'metrics', 'proxy' and 'cache'
## are enabled by default, however in order to scrape metrics for optional
## plugins, enable the plugin in the CoreDNS corefile and then add the metric below.
## As an example, the 'template' plugin's metrics are below
#
# metrics:
# - coredns_template_matches_total: template_matches_count
# - coredns_template_template_failures_total: template_templating_failures_count
# - coredns_template_rr_failures_total: template_resource_record_failures_count
2 changes: 1 addition & 1 deletion coredns/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"supported_os": [
"linux"
],
"guid": "000-000",
"guid": "9b316155-fc8e-4cb0-8bd5-8af270759cfb",
"public_title": "Datadog-CoreDNS Integration",
"categories":[
"containers",
Expand Down
34 changes: 34 additions & 0 deletions coredns/metadata.csv
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,37 @@ coredns.request_size.bytes.count,count,,byte,,size of the request in bytes,0,cor
coredns.response_size.bytes.sum,gauge,,byte,,size of the request in bytes,0,coredns,response size
coredns.response_size.bytes.count,count,,byte,,size of the request in bytes,0,coredns,response size
coredns.cache_size.count,count,,entry,,,1,coredns,cache size
coredns.go.gc_duration_seconds.count,gauge,,second,,Count of the GC invocation durations.,0,coredns,
coredns.go.gc_duration_seconds.sum,gauge,,second,,Sum of the GC invocation durations.,0,coredns,
coredns.go.goroutines,gauge,,thread,,Number of goroutines that currently exist.,0,coredns,
coredns.go.info,gauge,,,,Information about the Go environment.,0,coredns,
coredns.go.memstats.alloc_bytes,gauge,,byte,,Number of bytes allocated and still in use.,0,coredns,
coredns.go.memstats.alloc_bytes_total,gauge,,byte,,Total number of bytes allocated even if freed.,0,coredns,
coredns.go.memstats.buck_hash_sys_bytes,gauge,,byte,,Number of bytes used by the profiling bucket hash table.,0,coredns,bytes used by profiling
coredns.go.memstats.frees_total,gauge,,,,Total number of frees.,0,coredns,
coredns.go.memstats.gc_cpu_fraction,gauge,,percent,,CPU taken up by GC,0,coredns,CPU taken up by gc
coredns.go.memstats.gc_sys_bytes,gauge,,byte,,Number of bytes used for garbage collection system metadata.,0,coredns,
coredns.go.memstats.heap_alloc_bytes,gauge,,byte,,Bytes allocated to the heap,0,coredns,
coredns.go.memstats.heap_idle_bytes,gauge,,byte,,Number of idle bytes in the heap,0,coredns,
coredns.go.memstats.heap_inuse_bytes,gauge,,byte,,Number of Bytes in the heap,0,coredns,
coredns.go.memstats.heap_objects,gauge,,object,,Number of objects in the heap,0,coredns,
coredns.go.memstats.heap_released_bytes,gauge,,byte,,Number of bytes released to the system in the last gc,0,coredns,
coredns.go.memstats.heap_sys_bytes,gauge,,byte,,Number of bytes used by the heap,0,coredns,
coredns.go.memstats.last_gc_time_seconds,gauge,,second,,Length of last GC,0,coredns,gc time
coredns.go.memstats.lookups_total,gauge,,operation,,Number of lookups,0,coredns,lookups total
coredns.go.memstats.mallocs_total,gauge,,operation,,Number of mallocs,0,coredns,mallocs total
coredns.go.memstats.mcache_inuse_bytes,gauge,,byte,,Number of bytes in use by mcache structures.,0,coredns,
coredns.go.memstats.mcache_sys_bytes,gauge,,byte,,Number of bytes used for mcache structures obtained from system.,0,coredns,
coredns.go.memstats.mspan_inuse_bytes,gauge,,byte,,Number of bytes in use by mspan structures.,0,coredns,
coredns.go.memstats.mspan_sys_bytes,gauge,,byte,,Number of bytes used for mspan structures obtained from system.,0,coredns,
coredns.go.memstats.next_gc_bytes,gauge,,byte,,Number of heap bytes when next garbage collection will take place,0,coredns,
coredns.go.memstats.other_sys_bytes,gauge,,byte,,Number of bytes used for other system allocations,0,coredns,
coredns.go.memstats.stack_inuse_bytes,gauge,,byte,,Number of bytes in use by the stack allocator,0,coredns,
coredns.go.memstats.stack_sys_bytes,gauge,,byte,,Number of bytes obtained from system for stack allocator,0,coredns,
coredns.go.memstats.sys_bytes,gauge,,byte,,Number of bytes obtained from system,0,coredns,
coredns.go.threads,gauge,,thread,,Number of OS threads created.,0,coredns,
coredns.process.max_fds,gauge,,file,,Maximum number of open file descriptors.,0,coredns,
coredns.process.open_fds,gauge,,file,,Number of open file descriptors.,0,coredns,
coredns.process.resident_memory_bytes,gauge,,byte,,Resident memory size in bytes.,0,coredns,
coredns.process.start_time_seconds,gauge,,second,,Start time of the process since unix epoch in seconds.,0,coredns,
coredns.process.virtual_memory_bytes,gauge,,byte,,Virtual memory size in bytes.,0,coredns,
3 changes: 0 additions & 3 deletions coredns/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,9 @@

# Run-time dependencies
install_requires=[CHECKS_BASE_REQ, ],
setup_requires=['pytest-runner', ],

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

# Extra files to ship with the wheel package
package_data={'datadog_checks.coredns': ['conf.yaml.example']},
include_package_data=True,
)
74 changes: 0 additions & 74 deletions coredns/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,87 +60,13 @@ def condition():
def dockerinstance():
return {
'prometheus_url': URL,
'send_histograms_buckets': True,
'send_monotonic_counter': True,
"metrics": [
{
"coredns_dns_response_size_bytes": "response_size.bytes"
},
{
"coredns_cache_hits_total": "cache_hits_count"
},
{
"coredns_cache_misses_total": "cache_misses_count"
},
{
"coredns_dns_request_count_total": "request_count"
},
{
"coredns_dns_request_duration_seconds": "request_duration.seconds"
},
{
"coredns_dns_request_size_bytes": "request_size.bytes"
},
{
"coredns_dns_request_type_count_total": "request_type_count"
},
{
"coredns_dns_response_rcode_count_total": "response_code_count"
},
{
"coredns_proxy_request_count_total": "proxy_request_count"
},
{
"coredns_proxy_request_duration_seconds": "proxy_request_duration.seconds"
},
{
"coredns_cache_size": "cache_size.count"
},
],
}


@pytest.fixture
def instance():
return {
'prometheus_url': 'http://localhost:9153/metrics',
'send_histograms_buckets': True,
'send_monotonic_counter': True,
"metrics": [
{
"coredns_dns_response_size_bytes": "response_size.bytes"
},
{
"coredns_cache_hits_total": "cache_hits_count"
},
{
"coredns_cache_misses_total": "cache_misses_count"
},
{
"coredns_dns_request_count_total": "request_count"
},
{
"coredns_dns_request_duration_seconds": "request_duration.seconds"
},
{
"coredns_dns_request_size_bytes": "request_size.bytes"
},
{
"coredns_dns_request_type_count_total": "request_type_count"
},
{
"coredns_dns_response_rcode_count_total": "response_code_count"
},
{
"coredns_proxy_request_count_total": "proxy_request_count"
},
{
"coredns_proxy_request_duration_seconds": "proxy_request_duration.seconds"
},
{
"coredns_cache_size": "cache_size.count"
},
],
}


Expand Down
3 changes: 1 addition & 2 deletions coredns/tests/test_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ def test_check(self, aggregator, mock_get, instance):

# check that we then get the count metrics also
check.check(instance)
for m in aggregator.metric_names:
print(m)

for metric in self.METRICS:
aggregator.assert_metric(metric)

Expand Down

0 comments on commit 65b9e52

Please sign in to comment.