relay_server: include 'sent' timestamp with each message
This will be used by client-side timeline instrumentation, to guide performance improvements.
This commit is contained in:
parent
e342236b7d
commit
626732b730
|
@ -78,7 +78,8 @@ class ChannelLister(RelayResource):
|
||||||
#print("LIST", appid)
|
#print("LIST", appid)
|
||||||
app = self._relay.get_app(appid)
|
app = self._relay.get_app(appid)
|
||||||
allocated = app.get_allocated()
|
allocated = app.get_allocated()
|
||||||
data = {"welcome": self._welcome, "channelids": sorted(allocated)}
|
data = {"welcome": self._welcome, "channelids": sorted(allocated),
|
||||||
|
"sent": time.time()}
|
||||||
return json_response(request, data)
|
return json_response(request, data)
|
||||||
|
|
||||||
class Allocator(RelayResource):
|
class Allocator(RelayResource):
|
||||||
|
@ -96,7 +97,8 @@ class Allocator(RelayResource):
|
||||||
if self._log_requests:
|
if self._log_requests:
|
||||||
log.msg("allocated #%d, now have %d DB channels" %
|
log.msg("allocated #%d, now have %d DB channels" %
|
||||||
(channelid, len(app.get_allocated())))
|
(channelid, len(app.get_allocated())))
|
||||||
response = {"welcome": self._welcome, "channelid": channelid}
|
response = {"welcome": self._welcome, "channelid": channelid,
|
||||||
|
"sent": time.time()}
|
||||||
return json_response(request, response)
|
return json_response(request, response)
|
||||||
|
|
||||||
def getChild(self, path, req):
|
def getChild(self, path, req):
|
||||||
|
@ -139,7 +141,8 @@ class Adder(RelayResource):
|
||||||
app = self._relay.get_app(appid)
|
app = self._relay.get_app(appid)
|
||||||
channel = app.get_channel(channelid)
|
channel = app.get_channel(channelid)
|
||||||
messages = channel.add_message(side, phase, body)
|
messages = channel.add_message(side, phase, body)
|
||||||
response = {"welcome": self._welcome, "messages": messages}
|
response = {"welcome": self._welcome, "messages": messages,
|
||||||
|
"sent": time.time()}
|
||||||
return json_response(request, response)
|
return json_response(request, response)
|
||||||
|
|
||||||
class GetterOrWatcher(RelayResource):
|
class GetterOrWatcher(RelayResource):
|
||||||
|
@ -152,7 +155,8 @@ class GetterOrWatcher(RelayResource):
|
||||||
|
|
||||||
if b"text/event-stream" not in (request.getHeader(b"accept") or b""):
|
if b"text/event-stream" not in (request.getHeader(b"accept") or b""):
|
||||||
messages = channel.get_messages()
|
messages = channel.get_messages()
|
||||||
response = {"welcome": self._welcome, "messages": messages}
|
response = {"welcome": self._welcome, "messages": messages,
|
||||||
|
"sent": time.time()}
|
||||||
return json_response(request, response)
|
return json_response(request, response)
|
||||||
|
|
||||||
request.setHeader(b"content-type", b"text/event-stream; charset=utf-8")
|
request.setHeader(b"content-type", b"text/event-stream; charset=utf-8")
|
||||||
|
@ -199,9 +203,9 @@ class Deallocator(RelayResource):
|
||||||
app = self._relay.get_app(appid)
|
app = self._relay.get_app(appid)
|
||||||
channel = app.get_channel(channelid)
|
channel = app.get_channel(channelid)
|
||||||
deleted = channel.deallocate(side, mood)
|
deleted = channel.deallocate(side, mood)
|
||||||
response = {"status": "waiting"}
|
response = {"status": "waiting", "sent": time.time()}
|
||||||
if deleted:
|
if deleted:
|
||||||
response = {"status": "deleted"}
|
response = {"status": "deleted", "sent": time.time()}
|
||||||
return json_response(request, response)
|
return json_response(request, response)
|
||||||
|
|
||||||
|
|
||||||
|
@ -244,7 +248,7 @@ class Channel:
|
||||||
self._listeners.discard(ep)
|
self._listeners.discard(ep)
|
||||||
|
|
||||||
def broadcast_message(self, phase, body):
|
def broadcast_message(self, phase, body):
|
||||||
data = json.dumps({"phase": phase, "body": body})
|
data = json.dumps({"phase": phase, "body": body, "sent": time.time()})
|
||||||
for ep in self._listeners:
|
for ep in self._listeners:
|
||||||
ep.sendEvent(data)
|
ep.sendEvent(data)
|
||||||
|
|
||||||
|
|
|
@ -90,6 +90,7 @@ class API(ServerBase, unittest.TestCase):
|
||||||
d.addCallback(lambda _: self.post("allocate", {"appid": "app1",
|
d.addCallback(lambda _: self.post("allocate", {"appid": "app1",
|
||||||
"side": "abc"}))
|
"side": "abc"}))
|
||||||
def _allocated(data):
|
def _allocated(data):
|
||||||
|
data.pop("sent", None)
|
||||||
self.failUnlessEqual(set(data.keys()),
|
self.failUnlessEqual(set(data.keys()),
|
||||||
set(["welcome", "channelid"]))
|
set(["welcome", "channelid"]))
|
||||||
self.failUnlessIsInstance(data["channelid"], int)
|
self.failUnlessIsInstance(data["channelid"], int)
|
||||||
|
@ -294,6 +295,7 @@ class API(ServerBase, unittest.TestCase):
|
||||||
def _check_msg1(ev):
|
def _check_msg1(ev):
|
||||||
eventtype, data = ev
|
eventtype, data = ev
|
||||||
self.failUnlessEqual(eventtype, "message")
|
self.failUnlessEqual(eventtype, "message")
|
||||||
|
data.pop("sent", None)
|
||||||
self.failUnlessEqual(data, {"phase": "1", "body": "msg1A"})
|
self.failUnlessEqual(data, {"phase": "1", "body": "msg1A"})
|
||||||
d.addCallback(_check_msg1)
|
d.addCallback(_check_msg1)
|
||||||
|
|
||||||
|
@ -303,12 +305,14 @@ class API(ServerBase, unittest.TestCase):
|
||||||
def _check_msg2(ev):
|
def _check_msg2(ev):
|
||||||
eventtype, data = ev
|
eventtype, data = ev
|
||||||
self.failUnlessEqual(eventtype, "message")
|
self.failUnlessEqual(eventtype, "message")
|
||||||
|
data.pop("sent", None)
|
||||||
self.failUnlessEqual(data, {"phase": "1", "body": "msg1B"})
|
self.failUnlessEqual(data, {"phase": "1", "body": "msg1B"})
|
||||||
d.addCallback(_check_msg2)
|
d.addCallback(_check_msg2)
|
||||||
d.addCallback(lambda _: self.o.wait_for_next_event())
|
d.addCallback(lambda _: self.o.wait_for_next_event())
|
||||||
def _check_msg3(ev):
|
def _check_msg3(ev):
|
||||||
eventtype, data = ev
|
eventtype, data = ev
|
||||||
self.failUnlessEqual(eventtype, "message")
|
self.failUnlessEqual(eventtype, "message")
|
||||||
|
data.pop("sent", None)
|
||||||
self.failUnlessEqual(data, {"phase": "2", "body": "msg2A"})
|
self.failUnlessEqual(data, {"phase": "2", "body": "msg2A"})
|
||||||
d.addCallback(_check_msg3)
|
d.addCallback(_check_msg3)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user