Skip to content

Commit

Permalink
Support flush_first_value flag for monotonic counts
Browse files Browse the repository at this point in the history
  • Loading branch information
ofek committed Oct 31, 2020
1 parent f166aa6 commit 9610db2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
26 changes: 20 additions & 6 deletions datadog_checks_base/datadog_checks/base/checks/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,8 +415,10 @@ def submit_histogram_bucket(self, name, value, lower_bound, upper_bound, monoton
self, self.check_id, name, value, lower_bound, upper_bound, monotonic, hostname, tags
)

def _submit_metric(self, mtype, name, value, tags=None, hostname=None, device_name=None, raw=False):
# type: (int, str, float, Sequence[str], str, str, bool) -> None
def _submit_metric(
self, mtype, name, value, tags=None, hostname=None, device_name=None, raw=False, flush_first_value=False
):
# type: (int, str, float, Sequence[str], str, str, bool, bool) -> None
if value is None:
# ignore metric sample
return
Expand Down Expand Up @@ -447,7 +449,9 @@ def _submit_metric(self, mtype, name, value, tags=None, hostname=None, device_na
self.warning(err_msg)
return

aggregator.submit_metric(self, self.check_id, mtype, self._format_namespace(name, raw), value, tags, hostname)
aggregator.submit_metric(
self, self.check_id, mtype, self._format_namespace(name, raw), value, tags, hostname, flush_first_value
)

def gauge(self, name, value, tags=None, hostname=None, device_name=None, raw=False):
# type: (str, float, Sequence[str], str, str, bool) -> None
Expand Down Expand Up @@ -483,8 +487,10 @@ def count(self, name, value, tags=None, hostname=None, device_name=None, raw=Fal
aggregator.COUNT, name, value, tags=tags, hostname=hostname, device_name=device_name, raw=raw
)

def monotonic_count(self, name, value, tags=None, hostname=None, device_name=None, raw=False):
# type: (str, float, Sequence[str], str, str, bool) -> None
def monotonic_count(
self, name, value, tags=None, hostname=None, device_name=None, raw=False, flush_first_value=False
):
# type: (str, float, Sequence[str], str, str, bool, bool) -> None
"""Sample an increasing counter metric.
- **name** (_str_) - the name of the metric
Expand All @@ -494,9 +500,17 @@ def monotonic_count(self, name, value, tags=None, hostname=None, device_name=Non
- **device_name** (_str_) - **deprecated** add a tag in the form `device:<device_name>` to the `tags`
list instead.
- **raw** (_bool_) - whether to ignore any defined namespace prefix
- **flush_first_value** (_bool_) - whether to sample the first value
"""
self._submit_metric(
aggregator.MONOTONIC_COUNT, name, value, tags=tags, hostname=hostname, device_name=device_name, raw=raw
aggregator.MONOTONIC_COUNT,
name,
value,
tags=tags,
hostname=hostname,
device_name=device_name,
raw=raw,
flush_first_value=flush_first_value,
)

def rate(self, name, value, tags=None, hostname=None, device_name=None, raw=False):
Expand Down
4 changes: 2 additions & 2 deletions datadog_checks_base/datadog_checks/base/stubs/aggregator.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ def is_aggregate(cls, mtype):
def ignore_metric(cls, name):
return name in cls.IGNORED_METRICS

def submit_metric(self, check, check_id, mtype, name, value, tags, hostname):
def submit_metric(self, check, check_id, mtype, name, value, tags, hostname, flush_first_value):
if not self.ignore_metric(name):
self._metrics[name].append(MetricStub(name, mtype, value, tags, hostname, None))

def submit_metric_e2e(self, check, check_id, mtype, name, value, tags, hostname, device=None):
def submit_metric_e2e(self, check, check_id, mtype, name, value, tags, hostname, device=None, flush_first_value=False):
# Device is only present in metrics read from the real agent in e2e tests. Normally it is submitted as a tag
if not self.ignore_metric(name):
self._metrics[name].append(MetricStub(name, mtype, value, tags, hostname, device))
Expand Down

0 comments on commit 9610db2

Please sign in to comment.