Report recent requests in management view, for easy visibility.

migration-testing
Ryan Kelly 4 years ago
parent 8bfe371045
commit 3ec996582a
No known key found for this signature in database
GPG Key ID: FB70C973A037D258

@ -32,7 +32,7 @@ $(ENV)/COMPLETE: requirements.txt
.PHONY: serve .PHONY: serve
serve: | $(ENV)/COMPLETE serve: | $(ENV)/COMPLETE
$(ENV)/bin/gunicorn --paste ./syncserver.ini $(ENV)/bin/gunicorn --paste ./syncserver.ini --workers 1
.PHONY: clean .PHONY: clean
clean: clean:

@ -15,5 +15,9 @@
<input type="hidden" name="cmd" value="reset" /> <input type="hidden" name="cmd" value="reset" />
<input type="submit" value="Reset" /> <input type="submit" value="Reset" />
</form> </form>
<p>
Most recent server requests:<br/>
{recent_requests}
</p>
</body> </body>
</html> </html>

@ -2,11 +2,16 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this file, # License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/. # You can obtain one at http://mozilla.org/MPL/2.0/.
import collections
from pyramid import httpexceptions from pyramid import httpexceptions
import syncserver.migration import syncserver.migration
RECENT_REQUESTS = collections.deque(maxlen=30)
def interpose_migration_state_errors(handler, registry): def interpose_migration_state_errors(handler, registry):
"""Tween to send errors from storage endpoint based on migration state. """Tween to send errors from storage endpoint based on migration state.
@ -37,6 +42,25 @@ def interpose_migration_state_errors(handler, registry):
return interpose_migration_state_errors_tween return interpose_migration_state_errors_tween
def log_recent_requests_in_memory(handler, registry):
"""Keep a log of recent requests in memory, for easy visibility.
This is a little debugging aid for folks using the server to test
client behaviour, they can see the recent requests without having
to trawl through the server logs.
This only really works if you have a single worker, but that's
fine for our purposes here.
"""
def log_recent_requests_in_memory_tween(request):
RECENT_REQUESTS.appendleft("{} {}".format(request.method, request.path))
return handler(request)
return log_recent_requests_in_memory_tween
def includeme(config): def includeme(config):
"""Include all the SyncServer tweens into the given config.""" """Include all the SyncServer tweens into the given config."""
config.add_tween("syncserver.tweens.interpose_migration_state_errors") config.add_tween("syncserver.tweens.interpose_migration_state_errors")
config.add_tween("syncserver.tweens.log_recent_requests_in_memory")

@ -33,6 +33,7 @@ from pyramid.response import Response
from pyramid.interfaces import IAuthenticationPolicy from pyramid.interfaces import IAuthenticationPolicy
import syncserver.migration import syncserver.migration
import syncserver.tweens
# A GET on / returns a simple management interface, # A GET on / returns a simple management interface,
# while POST requests control the state of the server. # while POST requests control the state of the server.
@ -46,7 +47,8 @@ def _management(request):
with open(src) as f: with open(src) as f:
content = f.read() content = f.read()
content = content.format( content = content.format(
migration_state=request.registry["MigrationStateManager"].current_state_name() migration_state=request.registry["MigrationStateManager"].current_state_name(),
recent_requests="<br/>".join(syncserver.tweens.RECENT_REQUESTS),
) )
return Response(content, content_type="text/html") return Response(content, content_type="text/html")

Loading…
Cancel
Save