Skip to content

Commit

Permalink
bug-1906113: remove eliot references
Browse files Browse the repository at this point in the history
This fixes a bunch of copy-paste errors and switches to statsd-centric
language.

This also removes LogAllMetricsKeys which we don't use.
  • Loading branch information
willkg committed Aug 19, 2024
1 parent d7e6d39 commit 9b5a4dd
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 58 deletions.
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@

# General information about the project.
project = "Tecken: Symbols at Mozilla"
copyright = "2016-2022 Mozilla Foundation"
author = "Tecken team"
copyright = "2016-2024 Mozilla Foundation"
author = "Observability Team"

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
Expand Down
2 changes: 1 addition & 1 deletion docs/exts/document_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.

"""Generates the documentation for Eliot metrics."""
"""Generates the documentation for metrics."""

import importlib
import sys
Expand Down
9 changes: 6 additions & 3 deletions docs/metrics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
Metrics
=======

Metrics in Tecken
=================
StatsD Metrics in Tecken
========================

.. autometrics:: tecken.libmarkus.TECKEN_METRICS
Tecken uses `StatsD <https://github.com/statsd/statsd>`__ with
`DogStatsD extensions <https://docs.datadoghq.com/developers/dogstatsd/?tab=hostagent>`__.

.. autometrics:: tecken.libmarkus.STATSD_METRICS
58 changes: 6 additions & 52 deletions tecken/libmarkus.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,9 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.

import json
from pathlib import Path
import time
from functools import partialmethod

import markus
from markus import INCR, GAUGE, HISTOGRAM, TIMING
from markus.backends import BackendBase
from markus.filters import AddTagFilter, RegisteredMetricsFilter
import yaml

Expand All @@ -19,17 +14,17 @@
METRICS = markus.get_metrics("tecken")


# Complete index of all Eliot metrics. This is used in documentation and to filter
# outgoing metrics.
# Complete index of all metrics. This is used in documentation and to filter outgoing
# metrics.
def _load_registered_metrics():
# Load the eliot_metrics.yaml file in this directory
path = Path(__file__).parent / "tecken_metrics.yaml"
# Load the metrics yaml file in this directory
path = Path(__file__).parent / "statsd_metrics.yaml"
with open(path) as fp:
data = yaml.safe_load(fp)
return data


TECKEN_METRICS = _load_registered_metrics()
STATSD_METRICS = _load_registered_metrics()


def set_up_markus(backends, hostname, debug=False):
Expand All @@ -43,7 +38,7 @@ def set_up_markus(backends, hostname, debug=False):
# In local dev and test environments, we want the RegisteredMetricsFilter to
# raise exceptions when metrics are used incorrectly.
metrics_filter = RegisteredMetricsFilter(
registered_metrics=TECKEN_METRICS, raise_error=True
registered_metrics=STATSD_METRICS, raise_error=True
)
METRICS.filters.append(metrics_filter)

Expand All @@ -52,44 +47,3 @@ def set_up_markus(backends, hostname, debug=False):
METRICS.filters.append(AddTagFilter(f"host:{hostname}"))

_IS_MARKUS_SETUP = True


class LogAllMetricsKeys(BackendBase): # pragma: no cover
"""A markus backend that uses the filesystem to jot down ALL keys
that ever get used.
This then becomes handy when you want to make sure that you're using
all metrics in places like Datadog.
If you're not, it's maybe time to delete the metrics key.
Don't enable this in production. Use it during local development
and/or local test running.
"""

def notice_use(self, state, type, *args, **kwargs):
filename = "all-metrics-keys.json"
try:
with open(filename) as f:
all_keys = json.load(f)
except (FileNotFoundError, json.decoder.JSONDecodeError):
# This file gets written in an not thread-safe way
# so sometimes the file is all messed up. Pretend
# it didn't exist if the exception was a JSONDecodeError.
all_keys = {
"_documentation": (
"This file was created so you can see all metrics "
"keys that get used. It won't delete keys that are no "
"longer used. Feel free to delete this file and run again."
)
}
all_keys[state] = {
"type": type,
"timestamp": time.time(),
"count": all_keys.get(state, {}).get("count", 0) + 1,
}
with open(filename, "w") as f:
json.dump(all_keys, f, sort_keys=True, indent=3)

incr = partialmethod(notice_use, type=INCR)
gauge = partialmethod(notice_use, type=GAUGE)
histogram = partialmethod(notice_use, type=HISTOGRAM)
timing = partialmethod(notice_use, type=TIMING)
File renamed without changes.

0 comments on commit 9b5a4dd

Please sign in to comment.