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

server notices on resource limit blocking #3680

Merged
merged 26 commits into from
Aug 22, 2018

Conversation

neilisfragile
Copy link
Contributor

WIP implementation, need to clarify on the shape of the event itself.

@neilisfragile neilisfragile changed the title WIP server notices on resource limit blocking server notices on resource limit blocking Aug 16, 2018
@neilisfragile
Copy link
Contributor Author

Tests needs some love, but probably good enough to get going.
I've not included any caching - it shouldn't be a problem given that only enabled servers will make extra db hits.

@@ -103,7 +103,7 @@ def maybe_send_server_notice_to_user(self, user_id):
},
)
yield self._server_notices_manager.send_notice(
user_id, content,
user_id, content
Copy link
Member

Choose a reason for hiding this comment

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

This is a spurious change, and in general we want to have trailing commas

@@ -78,6 +78,9 @@ class EventTypes(object):
Name = "m.room.name"

ServerACL = "m.room.server_acl"
Pinned = "m.room.pinned_events"

ServerNoticeLimitReached = "m.server_notice.usage_limit_reached"
Copy link
Member

Choose a reason for hiding this comment

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

Is m.server_notice.* already a thing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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


class ResourceLimitsServerNotices(object):
"""
"""
Copy link
Member

Choose a reason for hiding this comment

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

Some documentation in the docstrings would be fab.

self._server_notice_content = hs.config.user_consent_server_notice_content
self._admin_uri = hs.config.admin_uri
self._limit_usage_by_mau = hs.config.limit_usage_by_mau
self._hs_disabled = hs.config.hs_disabled
Copy link
Member

Choose a reason for hiding this comment

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

Usually we just have self.config. It doesn't really matter, but makes it easier when writing unit tests where you can then cheekily change the config and have it updated everywhere where necessary.

self._resouce_limited = False
self._message_handler = hs.get_message_handler()
self._state = hs.get_state_handler()
# Config checks?
Copy link
Member

Choose a reason for hiding this comment

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

Should this be here? Lets include the checks now if we should have them

Copy link
Contributor Author

Choose a reason for hiding this comment

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

irl discussion, noop

# Normally should always pass in user_id if you have it, but in
# this case are checking what would happen to other users if they
# were to arrive.
yield self.auth.check_auth_blocking()
Copy link
Member

Choose a reason for hiding this comment

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

This feels like a bit of an awful thing to do, but lets keep it like this for now, but write is as:

try:
    yield self.auth.check_auth_blocking()
    is_auth_blocking = False
except AuthError as e:
    is_auth_blocking = True

Rather than having nested exception, which can get weird quickly

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fair enough both branches started off very neat, much prefer suggested approach

user_id, content, EventTypes.Pinned, '',
)

except AuthError as e:
Copy link
Member

Choose a reason for hiding this comment

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

Aren't we renaming this to ResourceLimitError or whatever it was?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

PR racing :-)

referenced_events = pinned_state_event.content.get('pinned')

events = yield self._store.get_events(referenced_events)
for event_id, event in events.items():
Copy link
Member

Choose a reason for hiding this comment

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

We should always use iteritems(events), to ensure that we don't needlessly copy in py2

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did it this way for py3 compat. best I can tell iteritems is not supported in py3

Copy link
Member

Choose a reason for hiding this comment

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

There's from six import iteritems, which does it

}
event = yield self._server_notices_manager.send_notice(
user_id, content, EventTypes.ServerNoticeLimitReached
)
Copy link
Member

Choose a reason for hiding this comment

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

Err, have we actually finally decided that clients will render anything with body rather than just those with type m.room.message?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure, am following spec proposal - is there a broader conversation to be had here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@erikjohnston
Copy link
Member

In general, I'm worried that this is going to cause quite a lot of slowness on servers where this is enabled; doing this check on every sync feels excessive. I'm also unsure we only want to send the notice when a user comes back online again.

I think the correct time we'd want to do all this is when we do the transition from being open to closed, and vice versa.

@erikjohnston erikjohnston removed their assignment Aug 17, 2018
@neilisfragile
Copy link
Contributor Author

Agreed that okay to ship with perf concerns, though will refactor (rsn) to store the current room state into something cacheable

@neilisfragile
Copy link
Contributor Author

Fixing bug that prevented the server notices user sending events to the client

@erikjohnston
Copy link
Member

I'm currently waiting for the resolution of matrix-org/matrix-spec-proposals#1452 before merging

@erikjohnston
Copy link
Member

Looks like the CI failure is a flakey presence sytest

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants