-
Notifications
You must be signed in to change notification settings - Fork 37
add bucket options #17
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
Open
pmcjury
wants to merge
1
commit into
OvalMoney:master
Choose a base branch
from
pmcjury:add-bucket-options
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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 hidden or 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 |
|---|---|---|
|
|
@@ -15,3 +15,4 @@ __pycache__ | |
| htmlcov/ | ||
| dive.log | ||
| .vscode | ||
| venv | ||
This file contains hidden or 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 hidden or 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 was deleted.
Oops, something went wrong.
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -6,23 +6,39 @@ | |
|
|
||
| import celery | ||
| import celery.states | ||
| import prometheus_client | ||
|
|
||
| from .metrics import TASKS, TASKS_RUNTIME, LATENCY, WORKERS | ||
| from celery_state import CeleryState | ||
| from .utils import get_config | ||
|
|
||
| TASKS = None | ||
| WORKERS = None | ||
| TASKS_RUNTIME = None | ||
| LATENCY = None | ||
|
|
||
|
|
||
| class TaskThread(threading.Thread): | ||
| """ | ||
| MonitorThread is the thread that will collect the data that is later | ||
| exposed from Celery using its eventing system. | ||
| """ | ||
|
|
||
| def __init__(self, app, namespace, max_tasks_in_memory, *args, **kwargs): | ||
| def __init__( | ||
| self, | ||
| app, | ||
| namespace, | ||
| max_tasks_in_memory, | ||
| runtime_histogram_bucket, | ||
| latency_histogram_bucket, | ||
| *args, | ||
| **kwargs | ||
| ): | ||
| self._app = app | ||
| self._namespace = namespace | ||
| self.log = logging.getLogger("task-thread") | ||
| self._state = CeleryState(max_tasks_in_memory=max_tasks_in_memory) | ||
| self._runtime_histogram_bucket = runtime_histogram_bucket | ||
| self._latency_histogram_bucket = latency_histogram_bucket | ||
| self._known_states = set() | ||
| self._known_states_names = set() | ||
| self._tasks_started = dict() | ||
|
|
@@ -56,12 +72,22 @@ def _monitor(self): # pragma: no cover | |
| recv = self._app.events.Receiver( | ||
| conn, handlers={"*": self._process_event} | ||
| ) | ||
| setup_metrics(self._app, self._namespace) | ||
| setup_metrics( | ||
| self._app, | ||
| self._namespace, | ||
| self._runtime_histogram_bucket, | ||
| self._latency_histogram_bucket, | ||
| ) | ||
| self.log.info("Start capturing events...") | ||
| recv.capture(limit=None, timeout=None, wakeup=True) | ||
| except Exception: | ||
| self.log.exception("Connection failed") | ||
| setup_metrics(self._app, self._namespace) | ||
| setup_metrics( | ||
| self._app, | ||
| self._namespace, | ||
| self._runtime_histogram_bucket, | ||
| self._latency_histogram_bucket, | ||
| ) | ||
| time.sleep(5) | ||
|
|
||
|
|
||
|
|
@@ -109,11 +135,41 @@ def enable_events(self): | |
| self._app.control.enable_events() | ||
|
|
||
|
|
||
| def setup_metrics(app, namespace): | ||
| def setup_metrics(app, namespace, task_buckets, latency_buckets): | ||
| """ | ||
| This initializes the available metrics with default values so that | ||
| even before the first event is received, data can be exposed. | ||
| """ | ||
| global TASKS | ||
|
Author
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. I would refactor this into a class or object to extend initialization ,instead of doing it here, but I wanted to limit changes, as it's my first PR for this project |
||
| global TASKS_RUNTIME | ||
| global LATENCY | ||
| global WORKERS | ||
|
|
||
| if TASKS == None: | ||
| TASKS = prometheus_client.Counter( | ||
| "celery_tasks_total", | ||
| "Number of task events.", | ||
| ["namespace", "name", "state", "queue"], | ||
| ) | ||
| if TASKS_RUNTIME == None: | ||
| TASKS_RUNTIME = prometheus_client.Histogram( | ||
| "celery_tasks_runtime_seconds", | ||
| "Task runtime.", | ||
| ["namespace", "name", "queue"], | ||
| buckets=task_buckets, | ||
| ) | ||
| if LATENCY == None: | ||
| LATENCY = prometheus_client.Histogram( | ||
| "celery_tasks_latency_seconds", | ||
| "Time between a task is received and started.", | ||
| ["namespace", "name", "queue"], | ||
| buckets=latency_buckets, | ||
| ) | ||
| if WORKERS == None: | ||
| WORKERS = prometheus_client.Gauge( | ||
| "celery_workers", "Number of alive workers", ["namespace"] | ||
| ) | ||
|
|
||
| WORKERS.labels(namespace=namespace) | ||
| config = get_config(app) | ||
|
|
||
|
|
||
This file contains hidden or 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 hidden or 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
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.
Why does
setup_metricsneed to be called again? Same below. It was already called in core.py::start