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

Add count type to go_expvar #5097

Merged
merged 2 commits into from
Nov 27, 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
2 changes: 1 addition & 1 deletion go_expvar/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ If your service doesn't already listen for HTTP requests (with the http package)
- path: my_func_counter
# if you don't want it named my_go_app.my_func_counter
#alias: my_go_app.preferred_counter_name
type: counter # other valid options: rate, gauge
type: count # other valid options: rate, gauge
#tags:
# - "tag_name1:tag_value1"
```
Expand Down
4 changes: 2 additions & 2 deletions go_expvar/datadog_checks/go_expvar/data/conf.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ instances:
## Note: You can use a regex when you want to report for all elements matching a certain pattern
##
## You can also specify a `type` for the metrics. One of:
## * counter
## * count
## * gauge (the default)
## * rate (note that this shows up as a gauge in Datadog that is meant to be seen as a "per second rate")
#
Expand All @@ -72,7 +72,7 @@ instances:
# - path: memstats/Lookups
# type: rate
# - path: memstats/Mallocs
# type: counter
# type: count
# - path: memstats/Frees
# type: rate
# - path: memstats/BySize/1/Mallocs
Expand Down
6 changes: 4 additions & 2 deletions go_expvar/datadog_checks/go_expvar/go_expvar.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,17 @@

GAUGE = "gauge"
RATE = "rate"
COUNTER = "counter"
COUNT = "count"
COUNTER = "counter" # Deprecated
MONOTONIC_COUNTER = "monotonic_counter"
DEFAULT_TYPE = GAUGE


SUPPORTED_TYPES = {
GAUGE: AgentCheck.gauge,
RATE: AgentCheck.rate,
COUNTER: AgentCheck.increment,
COUNT: AgentCheck.count,
COUNTER: AgentCheck.increment, # Deprecated
MONOTONIC_COUNTER: AgentCheck.monotonic_count,
}

Expand Down
37 changes: 28 additions & 9 deletions go_expvar/tests/test_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
]

# this is a histogram
CHECK_GAUGES_DEFAULT = ['{}.memstats.pause_ns']
CHECK_HISTOGRAM_DEFAULT = ['{}.memstats.pause_ns']

CHECK_RATES = [
'{}.memstats.frees',
Expand All @@ -41,6 +41,8 @@

CHECK_RATES_CUSTOM_MOCK = ['{}.gc.pause']

CHECK_COUNT_CUSTOM_MOCK = ['{}.gc.pause.count']


MOCK_CONFIG = {
"expvar_url": common.URL_WITH_PATH,
Expand All @@ -57,6 +59,7 @@
"type": "gauge",
"tags": ["metric_tag1:metric_value1", "metric_tag2:metric_value2"],
},
{"path": "memstats/NumGC", "alias": "go_expvar.gc.pause.count", "type": "count"},
],
}

Expand All @@ -69,19 +72,35 @@ def test_go_expvar_mocked(go_expvar_mock, check, aggregator):

shared_tags = ['optionaltag1', 'optionaltag2', 'expvar_url:{0}'.format(common.URL_WITH_PATH)]

for gauge in CHECK_GAUGES_DEFAULT:
aggregator.assert_metric(gauge.format(common.CHECK_NAME), count=2, tags=shared_tags)
for gauge in CHECK_HISTOGRAM_DEFAULT:
aggregator.assert_metric(
gauge.format(common.CHECK_NAME), metric_type=aggregator.HISTOGRAM, count=2, tags=shared_tags
)

for gauge in CHECK_GAUGES:
aggregator.assert_metric(gauge.format(common.CHECK_NAME), count=1, tags=shared_tags)
aggregator.assert_metric(
gauge.format(common.CHECK_NAME), metric_type=aggregator.GAUGE, count=1, tags=shared_tags
)
for gauge, tags in iteritems(CHECK_GAUGES_CUSTOM_MOCK):
aggregator.assert_metric(gauge.format(common.CHECK_NAME), count=1, tags=shared_tags + tags)
aggregator.assert_metric(
gauge.format(common.CHECK_NAME), metric_type=aggregator.GAUGE, count=1, tags=shared_tags + tags
)

for rate in CHECK_RATES:
aggregator.assert_metric(rate.format(common.CHECK_NAME), count=1, tags=shared_tags)
aggregator.assert_metric(rate.format(common.CHECK_NAME), metric_type=aggregator.RATE, count=1, tags=shared_tags)
for rate in CHECK_RATES_CUSTOM_MOCK:
aggregator.assert_metric(
rate.format(common.CHECK_NAME), count=1, tags=shared_tags + ['path:memstats.PauseTotalNs']
rate.format(common.CHECK_NAME),
count=1,
metric_type=aggregator.RATE,
tags=shared_tags + ['path:memstats.PauseTotalNs'],
)
for count in CHECK_COUNT_CUSTOM_MOCK:
aggregator.assert_metric(
count.format(common.CHECK_NAME),
count=1,
metric_type=aggregator.COUNT,
tags=shared_tags + ['path:memstats.NumGC'],
)

aggregator.assert_all_metrics_covered()
Expand Down Expand Up @@ -115,7 +134,7 @@ def test_go_expvar_mocked_namespace(go_expvar_mock, check, aggregator):

shared_tags = ['optionaltag1', 'optionaltag2', 'expvar_url:{0}'.format(common.URL_WITH_PATH)]

for gauge in CHECK_GAUGES_DEFAULT:
for gauge in CHECK_HISTOGRAM_DEFAULT:
aggregator.assert_metric(gauge.format(metric_namespace), count=2, tags=shared_tags)

for gauge in CHECK_GAUGES:
Expand Down Expand Up @@ -143,7 +162,7 @@ def test_max_metrics(go_expvar_mock, check, aggregator):
shared_tags = ['optionaltag1', 'optionaltag2', 'expvar_url:{0}'.format(common.URL_WITH_PATH)]

# Default metrics
for gauge in CHECK_GAUGES_DEFAULT:
for gauge in CHECK_HISTOGRAM_DEFAULT:
aggregator.assert_metric(gauge.format(common.CHECK_NAME), count=2, tags=shared_tags)

# And then check limitation, will fail at the coverage_report if incorrect
Expand Down