Skip to content

Add performance logging#268

Open
cmatKhan wants to merge 8 commits intoBrentLab:devfrom
cmatKhan:add_performance_logging
Open

Add performance logging#268
cmatKhan wants to merge 8 commits intoBrentLab:devfrom
cmatKhan:add_performance_logging

Conversation

@cmatKhan
Copy link
Copy Markdown
Member

No description provided.

Copilot AI review requested due to automatic review settings April 17, 2026 22:13
@cmatKhan cmatKhan marked this pull request as draft April 17, 2026 22:13
@cmatKhan
Copy link
Copy Markdown
Member Author

This is deployed and the cloudwatch logging is nominally working

image

but this is mostly AI and needs refinement, especially in what is performance monitored

@cmatKhan
Copy link
Copy Markdown
Member Author

cmatKhan commented Apr 17, 2026

Closes #267

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds structured performance/session logging throughout the Shiny app and provisions CloudWatch metrics/alarms/dashboard to operationalize that telemetry.

Changes:

  • Introduces a profiler utility that emits single-line JSON timing spans (PROFILE) and session lifecycle records (SESSION).
  • Instruments VirtualDB initialization, query paths, and plot HTML generation across modules with profile_span(...), and threads profile_logger/session_id through module servers.
  • Adds production/ops wiring: CLI/env toggles for profiling, CloudWatch log groups + metric filters + alarms + dashboard, and Docker log routing updates.

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 13 comments.

Show a summary per file
File Description
tfbpshiny/utils/vdb_init.py Adds init-time profiling spans around expensive DB setup/lookup queries.
tfbpshiny/utils/profiler.py New JSON structured timing/session logging helpers.
tfbpshiny/modules/select_datasets/server/workspace.py Profiles key vdb.query calls used to build the matrix.
tfbpshiny/modules/perturbation/server/workspace.py Profiles correlation queries and Plotly HTML generation.
tfbpshiny/modules/comparison/server/workspace.py Profiles top-N query execution, dataframe concat, and plot build.
tfbpshiny/modules/binding/server/workspace.py Profiles correlation queries and Plotly HTML generation.
tfbpshiny/app.py Configures profiler logger, logs session START/END, passes profiler context into modules and init.
tfbpshiny/__main__.py Adds CLI flags to select profile handler and disable profiling.
configure_logger.py Adds configure_profile_logger(...) for a dedicated profiler logger format/handler.
terraform/main.tf Pins EC2 instance replacement behavior for AMI/user-data changes via ignore_changes.
terraform/cloudwatch.tf Creates log groups, metric filters, alarms, and a dashboard based on JSON profiler logs.
production.yml Adds profiler env + routes Traefik logs to its own log group/region.
docs/development.md Documents existence of profiling log (but examples need updating to JSON format).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +216 to +218
_pl = profile_logger or logging.getLogger("profiler")
with profile_span(_pl, "init.regulator_table"):
vdb._conn.execute(sql)
Comment on lines +237 to +243
_pl = profile_logger or logging.getLogger("profiler")
with profile_span(
_pl,
"vdb.execute",
dataset=_REGULATOR_DISPLAY_NAME_TABLE,
context="get_regulator_display_name",
):
:param logger: The ``"profiler"`` logger.
:param op: Operation label, e.g. ``"vdb.query"`` or ``"plot.build"``.
:param module: Shiny module name, e.g. ``"binding"``. Empty for init-time spans.
:param dataset: Dataset(s) involved, e.g. ``"harbison"`` or ``"harbisонxrossi"``.
Comment on lines 32 to 36
vdb: VirtualDB,
logger: Logger,
profile_logger: Logger,
session_id: str = "",
) -> None:
Comment thread docs/development.md
Comment on lines +50 to +60
There is both a general log and profiling log

Both loggers write to stdout/stderr, Docker's awslogs driver captures everything into the shinyapp stream under /tfbpshiny/production. To later separate PROFILE lines from main log lines when parsing:

```{python}
import pandas as pd
df = pd.read_csv("exported.log", sep="|", header=None, skipinitialspace=True,
names=["marker","timestamp","elapsed_s","op","module","dataset","context"])
profile = df[df["marker"].str.strip() == "PROFILE"]
```
Comment on lines 32 to 36
vdb: VirtualDB,
logger: Logger,
profile_logger: Logger,
session_id: str = "",
) -> None:
Comment on lines +74 to 77
profile_logger: Logger,
session_id: str = "",
) -> None:
"""Render the Top-N by Binding workspace plot."""
Comment on lines +42 to 46
profile_logger: Logger,
session_id: str = "",
) -> None:
"""Render the sample-count matrix for all active datasets."""

Comment thread docs/development.md
Comment on lines +66 to +68
fields @timestamp, @message
| filter @message like /^PROFILE/
| parse @message "PROFILE | * | * | * | * | * | *" as timestamp, elapsed_s, op, module, dataset, context
Comment thread configure_logger.py
Comment on lines 58 to 65
if level not in [logging.DEBUG, logging.INFO, logging.WARNING, logging.ERROR]:
raise ValueError("Invalid logging level")
if not isinstance(format, str):
raise ValueError("format must be a string")
if handler_type not in ["console", "file"]:
if handler_type not in ("console", "file"):
raise ValueError("handler_type must be 'console' or 'file'")
if handler_type == "file" and not log_file:
raise ValueError("log_file must be specified for file handler")
@cmatKhan cmatKhan marked this pull request as ready for review April 21, 2026 14:26
@MackLiao
Copy link
Copy Markdown
Collaborator

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants