Skip to content

Commit

Permalink
fix datadog stats
Browse files Browse the repository at this point in the history
  • Loading branch information
thehesiod committed Nov 6, 2018
1 parent 0b2fb26 commit da3b321
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion fbn/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export TMPDIR=${TMPDIR%/}
gcloud config set project santaupvote

# https://github.com/google/upvote/issues/32
python3 ./validate_certs.py
python3 "${DIR}/validate_certs.py"

# NOTE: this change is critical, or else for some reason all hosts end up getting reset to LOCKDOWN mode in the database
# see https://github.com/google/upvote/issues/21
Expand Down
14 changes: 11 additions & 3 deletions upvote/gae/shared/common/monitoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,19 @@ def _dd_get_stats():
global _dd_stats

dd_api_instance = datadog_model.DataDogApiAuth.GetInstance()
dd_api_key = dd_api_instance.api_key if dd_api_instance is not None else None

if not _dd_stats:
if not dd_api_instance:
return None

datadog.initialize(dd_api_instance.api_key)

# we can't have background threads
_dd_stats = datadog.ThreadStats()
_dd_stats.start()
_dd_stats.start(flush_in_thread=False)

# this requires an agent
# _dd_stats = datadog.statsd
return _dd_stats


Expand Down Expand Up @@ -81,6 +83,7 @@ def Set(self, value, *args):
stats = _dd_get_stats()
if stats:
stats.gauge(self._stat_format % args, value)
stats.flush()


class LatencyMetric(object):
Expand All @@ -97,6 +100,7 @@ def Record(self, value, *args):
stats = _dd_get_stats()
if stats:
stats.gauge(self._stat_format % args, value)
stats.flush()


class Counter(object):
Expand All @@ -113,10 +117,14 @@ def Increment(self, *args):
stats = _dd_get_stats()
if stats:
stats.increment(self._stat_format % args)
stats.flush()

@ContainExceptions
def IncrementBy(self, inc, *args):
_dd_get_stats().increment(self._stat_format % args, inc)
stats = _dd_get_stats()
if stats:
stats.increment(self._stat_format % args, inc)
stats.flush()


class RequestCounter(Counter):
Expand Down

0 comments on commit da3b321

Please sign in to comment.