Skip to content

Profiling middleware - #1228

Open
LDiazN wants to merge 8 commits into
masterfrom
profiling-middleware
Open

Profiling middleware#1228
LDiazN wants to merge 8 commits into
masterfrom
profiling-middleware

Conversation

@LDiazN

@LDiazN LDiazN commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Adds a profiling middleware that generates HTML reports of the specified endpoints, using pyinstrument

Some examples:
image
image

This is specially useful for diagnosing performance issues, particularly the new submission path that has been showing poor performance

Usage

We have now exposed two new environment variables:

  • PROFILING_ACTIVE = (default: false) Sets profiling active or unactive
  • PROFILE_REPORT_PATH = (default: empty string) The path where the HTML report will be saved to

To specify what endpoints should be profiled, use the whitelist list of accepted prefixes:

whitelist = ("/api/v1/submit_measurement",)

@LDiazN
LDiazN requested a review from aagbsn July 22, 2026 10:28
@LDiazN LDiazN self-assigned this Jul 22, 2026

@aagbsn aagbsn left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this looks useful. I am wondering if the ProfileMiddleware should get added via app_middleware only if profiling is enabled, rather than always adding it to the stack and doing lazy import on each request.

@LDiazN

LDiazN commented Jul 23, 2026

Copy link
Copy Markdown
Contributor Author

this looks useful. I am wondering if the ProfileMiddleware should get added via app_middleware only if profiling is enabled, rather than always adding it to the stack and doing lazy import on each request.

Yeah it would be slightly more efficient but it makes it a bit harder to test, bc then the middleware wouldn't be available on tests if the environment to activate it is not properly set in the host machine.

A possible solution is to add a fixture that adds and removes the middleware to the app, what do you think?

@aagbsn

aagbsn commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

yes, if the profiling feature is intended for profiling during testing using a fixture to selectively install the middleware seems like the best solution

# wasn't possible to send msmnt to fastpath, try to send it to s3
ts_prefix = now.strftime("%Y%m%d%H")
s3_key = f"postcans/{ts_prefix}/{ts_prefix}_{cc}_{tn}/{msmt_uid}.post"
s3_key = f"postcans/{ts_prefix}/{ts_prefix}_{cc}_{test_name}/{msmt_uid}.post"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Does this impact how the s3 reprocessor will handle files?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No, actually the tn variable didn't even exist. It was a silent bug that hasn't triggered bc the fastpath has been quite stable lately. test_name is the new name of the same variable

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