-
Notifications
You must be signed in to change notification settings - Fork 246
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
feat: add stats logging #1204
Merged
Merged
feat: add stats logging #1204
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
should we use the url here? it is generic right
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.
url is something like
/query_execution/<int:query_execution_id>/
, which will include the parameter types.