-
Notifications
You must be signed in to change notification settings - Fork 241
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add stats logging * comments
- Loading branch information
Showing
29 changed files
with
268 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
--- | ||
id: add_stats_logger | ||
title: Stats Logging | ||
sidebar_label: Stats Logging | ||
--- | ||
|
||
Stats logging is used for monitoring and measuring the performance of an application or system. Querybook provides the support to collect metrics by adding your own stats logger, like StatsD. Here are the metrics we currently added: | ||
- Number of active users | ||
- Number of API requests | ||
- Latency of API requests | ||
- Number of websocket connections | ||
- Number of sql session failures | ||
- Number of scheduled system task failures | ||
- Number of scheduled datadoc failures | ||
- Latency of Redis operations | ||
- Number of query executions | ||
|
||
## Configure Event Logger | ||
Update `STATS_LOGGER_NAME` in the querybook config yaml file with the logger name you'd like to use. | ||
|
||
``` | ||
STATS_LOGGER_NAME: ~ | ||
``` | ||
|
||
## Add a new Stats Logger as a plugin | ||
If you'd like to actually use this feature, you need to create your own stats logger and add it as a [plugin](plugins.md). | ||
|
||
|
||
1. Locate the plugin root directory for your customized Querybook, and find the folder called `stats_logger_plugin`. | ||
2. Add your stats logger code similiar to the builtin loggers, like `ConsoleStatsLogger`, which means making sure it inherits from `BaseStatsLogger` and implements the abstract methods. | ||
3. Add the new stats logger in the variable `ALL_PLUGIN_STATS_LOGGERS` under `stats_logger_plugin/__init__.py` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ALL_PLUGIN_STATS_LOGGERS = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from env import QuerybookSettings | ||
from lib.stats_logger.all_stats_loggers import get_stats_logger_class | ||
from .base_stats_logger import BaseStatsLogger | ||
|
||
|
||
# metrics name templates | ||
API_REQUEST_COUNTER = "api.{}" | ||
API_REQUEST_LATENCY_TIMER = "api.duration.ms.{}" | ||
WS_CONNECTIONS_COUNTER = "ws.connections" | ||
SQL_SESSION_FAILURE_COUNTER = "sql.session.failure" | ||
SYSTEM_TASK_FAILURE_COUNTER = "task.failure.system" | ||
DATADOC_TASK_FAILURE_COUNTER = "task.failure.datadoc" | ||
REDIS_LATENCY_TIMER = "redis.duration.ms.{}" | ||
QUERY_EXECUTION_COUNTER = "query_execution.{}" | ||
|
||
logger_name = QuerybookSettings.STATS_LOGGER_NAME | ||
stats_logger: BaseStatsLogger = get_stats_logger_class(logger_name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from lib.utils.import_helper import import_module_with_default | ||
from .loggers.null_stats_logger import NullStatsLogger | ||
from .loggers.console_stats_logger import ConsoleStatsLogger | ||
|
||
ALL_PLUGIN_STATS_LOGGERS = import_module_with_default( | ||
"stats_logger_plugin", | ||
"ALL_PLUGIN_STATS_LOGGERS", | ||
default=[], | ||
) | ||
|
||
ALL_STATS_LOGGERS = [NullStatsLogger(), ConsoleStatsLogger()] + ALL_PLUGIN_STATS_LOGGERS | ||
|
||
|
||
def get_stats_logger_class(name: str): | ||
for logger in ALL_STATS_LOGGERS: | ||
if logger.logger_name == name: | ||
return logger | ||
raise ValueError(f"Unknown event logger name {name}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from abc import ABC, abstractmethod | ||
|
||
|
||
class BaseStatsLogger(ABC): | ||
"""Base class for logging realtime stats""" | ||
|
||
def key(self, key: str) -> str: | ||
if self.prefix: | ||
return self.prefix + key | ||
return key | ||
|
||
@property | ||
def logger_name(self) -> str: | ||
raise NotImplementedError() | ||
|
||
@property | ||
def prefix(self) -> str: | ||
return "querybook." | ||
|
||
@abstractmethod | ||
def incr(self, key: str) -> None: | ||
"""Increment a counter""" | ||
raise NotImplementedError() | ||
|
||
@abstractmethod | ||
def decr(self, key: str) -> None: | ||
"""Decrement a counter""" | ||
raise NotImplementedError() | ||
|
||
@abstractmethod | ||
def timing(self, key: str, value: float) -> None: | ||
raise NotImplementedError() | ||
|
||
@abstractmethod | ||
def gauge(self, key: str, value: float) -> None: | ||
"""Setup a gauge""" | ||
raise NotImplementedError() |
Empty file.
Oops, something went wrong.