Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

HTTPStatus.* have started to appear in Processed request log lines instead of an integer #11812

Closed
anoadragon453 opened this issue Jan 24, 2022 · 7 comments · Fixed by #11827
Closed
Labels
S-Major Major functionality / product severely impaired, no satisfactory workaround. T-Defect Bugs, crashes, hangs, security vulnerabilities, or other reported issues.

Comments

@anoadragon453
Copy link
Member

An example log line from matrix.org:

2022-01-24 08:10:36,396 - synapse.access.http.8080 - 445 - INFO - GET-7050353 - xxx.xxx.xxx.xxx - 8080 - {@redacted:matrix.org} Processed request: 0.296sec/0.003sec (0.007sec, 0.000sec) (0.002sec/0.288sec/2) 36141B HTTPStatus.OK "GET /_synapse/admin/v1/event_reports HTTP/1.1" "aiohttp/0.2.1" [0 dbevts]

This seems to currently happening for EventReportsRestServlet, RoomStateRestServlet and RoomRestServlet. Perhaps other endpoints are affected, but none observed in the recent logs on matrix.org.

Notice the HTTPStatus.OK in the logs, whereas one would expect 200. This seems to happen as we simply cast the return code to a str:

code = str(self.code)

However, str(HTTPStatus.OK) unhelpfully resolves to the str "HTTPStatus.OK"...

This could have implications for scripts that parse Synapse logs.

@anoadragon453 anoadragon453 added S-Major Major functionality / product severely impaired, no satisfactory workaround. T-Defect Bugs, crashes, hangs, security vulnerabilities, or other reported issues. labels Jan 24, 2022
@DMRobertson
Copy link
Contributor

Sorry, this has my fingerprints all over it.

@DMRobertson
Copy link
Contributor

code = str(int(self.code)) would work when self.code: int or self.code: HTTPStatus. Or maybe it's just easier to ditch the status enum unilaterally?

@anoadragon453
Copy link
Member Author

I do like using HTTPStatus, but perhaps we should int(HTTPStatus) before returning from servlets?

@babolivier
Copy link
Contributor

If we're starting to lean towards using HTTPStatus, we probably should fix the logging code rather than each individual servlet?

@anoadragon453
Copy link
Member Author

ServletCallback is currently defined as returning and int when returning a status code:

# Type of a callback method for processing requests
# it is actually called with a SynapseRequest and a kwargs dict for the params,
# but I can't figure out how to represent that.
ServletCallback = Callable[
..., Union[None, Awaitable[None], Tuple[int, Any], Awaitable[Tuple[int, Any]]]
]

We could extend this to include HTTPStatus, and then update all code that interacts with it to process both correctly.

@babolivier I agree that that would probably be less things to update (and to remember) than doing int(HTTPStatus.*) everywhere.

@DMRobertson
Copy link
Contributor

ServletCallback is currently defined as returning and int when returning a status code:

FWIW note that IntEnum instances will inherit from int:

>>> import http
>>> isinstance(http.HTTPStatus.OK, int)
True

@richvdh
Copy link
Member

richvdh commented Jan 24, 2022

we've had this before, btw: #7017

DMRobertson pushed a commit that referenced this issue Jan 25, 2022
DMRobertson pushed a commit that referenced this issue Jan 26, 2022
* Don't print HTTPStatus.* in "Processed..." logs

Fixes #11812. See also #7118 and
#7188 (comment) in
particular.

Co-authored-by: Brendan Abolivier <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
S-Major Major functionality / product severely impaired, no satisfactory workaround. T-Defect Bugs, crashes, hangs, security vulnerabilities, or other reported issues.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants