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

Add debug logs to figure out why an event was filtered #14095

Merged
merged 5 commits into from
Oct 17, 2022

Conversation

MadLittleMods
Copy link
Contributor

@MadLittleMods MadLittleMods commented Oct 6, 2022

Spawned while investigating #13944,

Add debug logs to figure out why an event was filtered.

This way we might get some more context whenever an 403 Forbidden - body: {"errcode":"M_FORBIDDEN","error":"You don't have permission to access that event."} error is produced.

Dev notes

log_config.yaml

loggers:
    synapse:
        level: INFO

    synapse.visibility:
        level: DEBUG

Pull Request Checklist

  • Pull request is based on the develop branch
  • Pull request includes a changelog file. The entry should:
    • Be a short description of your change which makes sense to users. "Fixed a bug that prevented receiving messages from other servers." instead of "Moved X method from EventStore to EventWorkerStore.".
    • Use markdown where necessary, mostly for code blocks.
    • End with either a period (.) or an exclamation mark (!).
    • Start with a capital letter.
    • Feel free to credit yourself, by adding a sentence "Contributed by @github_username." or "Contributed by [Your Name]." to the end of the entry.
  • Pull request includes a sign off
  • Code style is correct
    (run the linters)

synapse/visibility.py Outdated Show resolved Hide resolved
To have less noise, maybe we only want to log when an event is filtered out and not why it was returned unscathed.

See #14095 (comment)
@MadLittleMods MadLittleMods force-pushed the madlittlemods/debug-log-event-filtering branch from ad5a023 to b73713f Compare October 6, 2022 20:47
@MadLittleMods MadLittleMods added the T-Task Refactoring, removal, replacement, enabling or disabling functionality, other engineering tasks. label Oct 6, 2022
@MadLittleMods MadLittleMods marked this pull request as ready for review October 7, 2022 02:32
@MadLittleMods MadLittleMods requested a review from a team as a code owner October 7, 2022 02:32
Comment on lines 89 to 94
if len(events_before_filtering) != len(events):
logger.debug(
"filter_events_for_client: Filtered out soft-failed events: Before=%s, After=%s",
[event.event_id for event in events_before_filtering],
[event.event_id for event in events],
)
Copy link
Member

Choose a reason for hiding this comment

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

This all looks fairly heavy, would it make sense to use a custom logger, like the issue_8631_logger?

Note that we also tend to guard against doing calculations we won't need:

if issue_8631_logger.isEnabledFor(logging.DEBUG):
data = {(user, device): stream_id for user, device, stream_id, _ in updates}
issue_8631_logger.debug(
"device updates need to be sent to %s: %s", destination, data
)

I don't know how important that is here though.

Copy link
Member

Choose a reason for hiding this comment

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

I guess my thought is -- do you see value in leaving these long term?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The value for me comes from seeing these in tests. Since they're debug that doesn't happen by default which sucks. We could add a custom logger and enable it to show in tests? Seems do-able for Complement tests since we can change the logging config.

It's just nice to be able to look at the CI log and figure out why an event isn't being returned. There are so many places where an event can disappear here and it's nice to know why.

Copy link
Member

Choose a reason for hiding this comment

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

For unit tests we have SYNAPSE_TEST_LOG_LEVEL=DEBUG to see debug logs, sytest doesn't have anything, complement seems to have SYNAPSE_TEST_LOG_LEVEL too?

If we only want these to debug some things, do we need to merge it or just get some CI runs going?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For unit tests we have SYNAPSE_TEST_LOG_LEVEL=DEBUG to see debug logs, sytest doesn't have anything, complement seems to have SYNAPSE_TEST_LOG_LEVEL too?

I was more talking about the default in CI and if changing the log level locally, having to choose between useful INFO and noisy DEBUG is not great. I'm thinking about having these logs shown by default 🤔. It probably doesn't make sense to have these show at the INFO level for production but I think it would in tests.

I'm also conscious of this being noise itself but I feel like these logs are one of the easy things to eliminate a bunch of possibilities. For example, if I see that a relevant event is an outlier, soft-failed, then that's a good unexpected indicator explaining it. filter_events_for_client is used in /sync, /messages, /context which are all common end-to-end assertion touch points (also notifications, relations).

I'm happy to close this PR if you're not seeing it 🙂 (the idea of it might be better than doing this)

Copy link
Member

Choose a reason for hiding this comment

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

I'll take another look (or someone else from the team can before I'm back)!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tackling the follow-up here in #14213

@clokep clokep requested a review from a team October 7, 2022 19:32
synapse/visibility.py Outdated Show resolved Hide resolved
@MadLittleMods MadLittleMods merged commit 2c63cdc into develop Oct 17, 2022
@MadLittleMods MadLittleMods deleted the madlittlemods/debug-log-event-filtering branch October 17, 2022 21:02
@MadLittleMods
Copy link
Contributor Author

Thanks for the review @clokep and @erikjohnston 🦗

MadLittleMods added a commit that referenced this pull request Jun 2, 2023
…#14213)

See #14095 (comment)

This is useful because when see that a relevant event is an `outlier` or `soft-failed`, then that's a good unexpected indicator explaining why it's not showing up. `filter_events_for_client` is used in `/sync`, `/messages`, `/context` which are all common end-to-end assertion touch points (also notifications, relations).
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
T-Task Refactoring, removal, replacement, enabling or disabling functionality, other engineering tasks.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants