-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Performance monitoring #3658
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
Merged
Merged
Performance monitoring #3658
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
bf8100c
Initial scaffolding for metrics
Weves 7708874
iterate
Weves 498d353
more
Weves 2920ae0
More metrics + SyncRecord concept
Weves 896fd18
Add indices, standardize timing
Weves 5c0ccab
Small cleanup
Weves d95a00d
Address comments
Weves 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 |
---|---|---|
@@ -0,0 +1,72 @@ | ||
"""Add SyncRecord | ||
|
||
Revision ID: 97dbb53fa8c8 | ||
Revises: 369644546676 | ||
Create Date: 2025-01-11 19:39:50.426302 | ||
|
||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "97dbb53fa8c8" | ||
down_revision = "be2ab2aa50ee" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade() -> None: | ||
op.create_table( | ||
"sync_record", | ||
sa.Column("id", sa.Integer(), nullable=False), | ||
sa.Column("entity_id", sa.Integer(), nullable=False), | ||
sa.Column( | ||
"sync_type", | ||
sa.Enum( | ||
"DOCUMENT_SET", | ||
"USER_GROUP", | ||
"CONNECTOR_DELETION", | ||
name="synctype", | ||
native_enum=False, | ||
length=40, | ||
), | ||
nullable=False, | ||
), | ||
sa.Column( | ||
"sync_status", | ||
sa.Enum( | ||
"IN_PROGRESS", | ||
"SUCCESS", | ||
"FAILED", | ||
"CANCELED", | ||
name="syncstatus", | ||
native_enum=False, | ||
length=40, | ||
), | ||
nullable=False, | ||
), | ||
sa.Column("num_docs_synced", sa.Integer(), nullable=False), | ||
sa.Column("sync_start_time", sa.DateTime(timezone=True), nullable=False), | ||
sa.Column("sync_end_time", sa.DateTime(timezone=True), nullable=True), | ||
sa.PrimaryKeyConstraint("id"), | ||
) | ||
|
||
# Add index for fetch_latest_sync_record query | ||
op.create_index( | ||
"ix_sync_record_entity_id_sync_type_sync_start_time", | ||
"sync_record", | ||
["entity_id", "sync_type", "sync_start_time"], | ||
) | ||
|
||
# Add index for cleanup_sync_records query | ||
op.create_index( | ||
"ix_sync_record_entity_id_sync_type_sync_status", | ||
"sync_record", | ||
["entity_id", "sync_type", "sync_status"], | ||
) | ||
|
||
|
||
def downgrade() -> None: | ||
op.drop_index("ix_sync_record_entity_id_sync_type_sync_status") | ||
op.drop_index("ix_sync_record_entity_id_sync_type_sync_start_time") | ||
op.drop_table("sync_record") |
41 changes: 41 additions & 0 deletions
41
backend/alembic/versions/fec3db967bf7_add_time_updated_to_usergroup_and_.py
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
"""Add time_updated to UserGroup and DocumentSet | ||
Revision ID: fec3db967bf7 | ||
Revises: 97dbb53fa8c8 | ||
Create Date: 2025-01-12 15:49:02.289100 | ||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "fec3db967bf7" | ||
down_revision = "97dbb53fa8c8" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade() -> None: | ||
op.add_column( | ||
"document_set", | ||
sa.Column( | ||
"time_updated", | ||
sa.DateTime(timezone=True), | ||
nullable=False, | ||
server_default=sa.func.now(), | ||
), | ||
) | ||
op.add_column( | ||
"user_group", | ||
sa.Column( | ||
"time_updated", | ||
sa.DateTime(timezone=True), | ||
nullable=False, | ||
server_default=sa.func.now(), | ||
), | ||
) | ||
|
||
|
||
def downgrade() -> None: | ||
op.drop_column("user_group", "time_updated") | ||
op.drop_column("document_set", "time_updated") |
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 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 |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import multiprocessing | ||
from typing import Any | ||
|
||
from celery import Celery | ||
from celery import signals | ||
from celery import Task | ||
from celery.signals import celeryd_init | ||
from celery.signals import worker_init | ||
from celery.signals import worker_ready | ||
from celery.signals import worker_shutdown | ||
|
||
import onyx.background.celery.apps.app_base as app_base | ||
from onyx.configs.constants import POSTGRES_CELERY_WORKER_MONITORING_APP_NAME | ||
from onyx.db.engine import SqlEngine | ||
from onyx.utils.logger import setup_logger | ||
from shared_configs.configs import MULTI_TENANT | ||
|
||
|
||
logger = setup_logger() | ||
|
||
celery_app = Celery(__name__) | ||
celery_app.config_from_object("onyx.background.celery.configs.monitoring") | ||
|
||
|
||
@signals.task_prerun.connect | ||
def on_task_prerun( | ||
sender: Any | None = None, | ||
task_id: str | None = None, | ||
task: Task | None = None, | ||
args: tuple | None = None, | ||
kwargs: dict | None = None, | ||
**kwds: Any, | ||
) -> None: | ||
app_base.on_task_prerun(sender, task_id, task, args, kwargs, **kwds) | ||
|
||
|
||
@signals.task_postrun.connect | ||
def on_task_postrun( | ||
sender: Any | None = None, | ||
task_id: str | None = None, | ||
task: Task | None = None, | ||
args: tuple | None = None, | ||
kwargs: dict | None = None, | ||
retval: Any | None = None, | ||
state: str | None = None, | ||
**kwds: Any, | ||
) -> None: | ||
app_base.on_task_postrun(sender, task_id, task, args, kwargs, retval, state, **kwds) | ||
|
||
|
||
@celeryd_init.connect | ||
def on_celeryd_init(sender: Any = None, conf: Any = None, **kwargs: Any) -> None: | ||
app_base.on_celeryd_init(sender, conf, **kwargs) | ||
|
||
|
||
@worker_init.connect | ||
def on_worker_init(sender: Any, **kwargs: Any) -> None: | ||
logger.info("worker_init signal received.") | ||
logger.info(f"Multiprocessing start method: {multiprocessing.get_start_method()}") | ||
|
||
SqlEngine.set_app_name(POSTGRES_CELERY_WORKER_MONITORING_APP_NAME) | ||
SqlEngine.init_engine(pool_size=sender.concurrency, max_overflow=8) | ||
|
||
|
||
app_base.wait_for_redis(sender, **kwargs) | ||
app_base.wait_for_db(sender, **kwargs) | ||
|
||
# Less startup checks in multi-tenant case | ||
if MULTI_TENANT: | ||
return | ||
|
||
app_base.on_secondary_worker_init(sender, **kwargs) | ||
|
||
|
||
@worker_ready.connect | ||
def on_worker_ready(sender: Any, **kwargs: Any) -> None: | ||
app_base.on_worker_ready(sender, **kwargs) | ||
|
||
|
||
@worker_shutdown.connect | ||
def on_worker_shutdown(sender: Any, **kwargs: Any) -> None: | ||
app_base.on_worker_shutdown(sender, **kwargs) | ||
|
||
|
||
@signals.setup_logging.connect | ||
def on_setup_logging( | ||
loglevel: Any, logfile: Any, format: Any, colorize: Any, **kwargs: Any | ||
) -> None: | ||
app_base.on_setup_logging(loglevel, logfile, format, colorize, **kwargs) | ||
|
||
|
||
celery_app.autodiscover_tasks( | ||
[ | ||
"onyx.background.celery.tasks.monitoring", | ||
] | ||
) |
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import onyx.background.celery.configs.base as shared_config | ||
|
||
broker_url = shared_config.broker_url | ||
broker_connection_retry_on_startup = shared_config.broker_connection_retry_on_startup | ||
broker_pool_limit = shared_config.broker_pool_limit | ||
broker_transport_options = shared_config.broker_transport_options | ||
|
||
redis_socket_keepalive = shared_config.redis_socket_keepalive | ||
redis_retry_on_timeout = shared_config.redis_retry_on_timeout | ||
redis_backend_health_check_interval = shared_config.redis_backend_health_check_interval | ||
|
||
result_backend = shared_config.result_backend | ||
result_expires = shared_config.result_expires # 86400 seconds is the default | ||
|
||
task_default_priority = shared_config.task_default_priority | ||
task_acks_late = shared_config.task_acks_late | ||
|
||
# Monitoring worker specific settings | ||
worker_concurrency = 1 # Single worker is sufficient for monitoring | ||
worker_pool = "threads" | ||
Weves marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
worker_prefetch_multiplier = 1 |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.