-
Notifications
You must be signed in to change notification settings - Fork 224
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
bug-1898341, bug-1898345: add "host" tag, fix metrics key prefix #6623
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,19 +12,19 @@ | |
|
||
LOGGING_LEVEL = CONFIG("LOGGING_LEVEL", "INFO") | ||
LOCAL_DEV_ENV = CONFIG("LOCAL_DEV_ENV", False, cast=bool) | ||
HOST_ID = socket.gethostname() | ||
HOSTNAME = CONFIG("HOSTNAME", default=socket.gethostname()) | ||
|
||
|
||
class AddHostID(logging.Filter): | ||
class AddHostname(logging.Filter): | ||
def filter(self, record): | ||
record.host_id = HOST_ID | ||
record.hostname = HOSTNAME | ||
return True | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Once we've switched to GCP, we can remove There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why won't we need it anymore? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. because logs in gcp are already tagged with pod and container name? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When we did Eliot, I remember that Harold and I talked about this but I don't remember what we covered. I had this bug where I removed the logging filter from Eliot logging: https://bugzilla.mozilla.org/show_bug.cgi?id=1815981 It doesn't talk about why, though. Eliot app log entries look like this:
That includes a "hostname" field as well as a pod_name and container_name. The "hostname" field gets added by the python-dockerflow mozlog formatter: |
||
|
||
|
||
logconfig_dict = { | ||
"version": 1, | ||
"disable_existing_loggers": False, | ||
"filters": {"add_hostid": {"()": AddHostID}}, | ||
"filters": {"add_hostname": {"()": AddHostname}}, | ||
"handlers": { | ||
"console": { | ||
"level": LOGGING_LEVEL, | ||
|
@@ -35,7 +35,7 @@ def filter(self, record): | |
"level": LOGGING_LEVEL, | ||
"class": "logging.StreamHandler", | ||
"formatter": "mozlog", | ||
"filters": ["add_hostid"], | ||
"filters": ["add_hostname"], | ||
}, | ||
}, | ||
"formatters": { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,8 +5,6 @@ | |
import json | ||
import logging | ||
|
||
import markus | ||
|
||
from socorro.external.crashstorage_base import ( | ||
CrashStorageBase, | ||
CrashIDNotFound, | ||
|
@@ -98,8 +96,6 @@ def __init__( | |
self.bucket = bucket | ||
self.dump_file_suffix = dump_file_suffix | ||
|
||
self.metrics = markus.get_metrics(metrics_prefix) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This never got used in the crashstorage classes except for |
||
|
||
@classmethod | ||
def build_connection(cls, region, access_key, secret_access_key, endpoint_url): | ||
""" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# This Source Code Form is subject to the terms of the Mozilla Public | ||
# 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/. | ||
|
||
"""Holds Markus utility functions and global state.""" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is effectively a copy from Antenna with some minor adjustments. |
||
|
||
import logging | ||
import os | ||
|
||
import markus | ||
from markus.filters import AddTagFilter | ||
|
||
|
||
_IS_MARKUS_SETUP = False | ||
|
||
# NOTE(willkg): this checks the CLOUD_PROVIDER environ directly here because this can't | ||
# import socorro.settings; this is temporary--once we finish the GCP migration, we can | ||
# remove this | ||
_CLOUD_PROVIDER = os.environ.get("CLOUD_PROVIDER", "AWS").upper() | ||
|
||
LOGGER = logging.getLogger(__name__) | ||
# NOTE(willkg): we need to set the prefix selectively because in AWS we don't have the | ||
# "socorro" key prefix, but in GCP we want one | ||
if _CLOUD_PROVIDER == "GCP": | ||
METRICS = markus.get_metrics("socorro") | ||
else: | ||
METRICS = markus.get_metrics() | ||
|
||
|
||
def set_up_metrics(statsd_host, statsd_port, hostname, debug=False): | ||
"""Initialize and configures the metrics system. | ||
:arg statsd_host: the statsd host to send metrics to | ||
:arg statsd_port: the port on the host to send metrics to | ||
:arg hostname: the host name | ||
:arg debug: whether or not to additionally log metrics to the logger | ||
""" | ||
global _IS_MARKUS_SETUP, METRICS | ||
if _IS_MARKUS_SETUP: | ||
return | ||
|
||
markus_backends = [ | ||
{ | ||
"class": "markus.backends.datadog.DatadogMetrics", | ||
"options": { | ||
"statsd_host": statsd_host, | ||
"statsd_port": statsd_port, | ||
}, | ||
} | ||
] | ||
if debug: | ||
markus_backends.append( | ||
{ | ||
"class": "markus.backends.logging.LoggingMetrics", | ||
"options": { | ||
"logger_name": "markus", | ||
"leader": "METRICS", | ||
}, | ||
} | ||
) | ||
|
||
if _CLOUD_PROVIDER == "GCP" and hostname: | ||
METRICS.filters.append(AddTagFilter(f"host:{hostname}")) | ||
|
||
markus.configure(markus_backends) | ||
|
||
_IS_MARKUS_SETUP = True | ||
|
||
|
||
def build_prefix(*parts): | ||
new_prefix = [] | ||
for part in parts: | ||
part = part.strip() | ||
if part: | ||
new_prefix.append(part) | ||
|
||
return ".".join(parts) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're switching from
HOST_ID
toHOSTNAME
everywhere. It's interesting that this didn't originally pull theHOST_ID
from the environment--it only usedsocket.gethostname()
.