def receive_json(self, content: Data): msg = from_dict(WebsocketMessage, content) uid = msg.args.get("uuid", self.channel_name) self.last_uid = uid if not self.outpost: raise DenyConnection() state = OutpostState.for_instance_uid(self.outpost, uid) if self.channel_name not in state.channel_ids: state.channel_ids.append(self.channel_name) state.last_seen = datetime.now() if not self.first_msg: GAUGE_OUTPOSTS_CONNECTED.labels( outpost=self.outpost.name, uid=self.last_uid, ).inc() self.first_msg = True if msg.instruction == WebsocketMessageInstruction.HELLO: state.version = msg.args.get("version", None) state.build_hash = msg.args.get("buildHash", "") elif msg.instruction == WebsocketMessageInstruction.ACK: return GAUGE_OUTPOSTS_LAST_UPDATE.labels( outpost=self.outpost.name, uid=self.last_uid or "", version=state.version or "", ).set_to_current_time() state.save(timeout=OUTPOST_HELLO_INTERVAL * 1.5) response = WebsocketMessage( instruction=WebsocketMessageInstruction.ACK) self.send_json(asdict(response))
def disconnect(self, close_code): if self.outpost and self.last_uid: state = OutpostState.for_instance_uid(self.outpost, self.last_uid) if self.channel_name in state.channel_ids: state.channel_ids.remove(self.channel_name) state.save() LOGGER.debug( "removed outpost instance from cache", outpost=self.outpost, instance_uuid=self.last_uid, )
def disconnect(self, close_code): if self.outpost and self.last_uid: state = OutpostState.for_instance_uid(self.outpost, self.last_uid) if self.channel_name in state.channel_ids: state.channel_ids.remove(self.channel_name) state.save() GAUGE_OUTPOSTS_CONNECTED.labels( outpost=self.outpost.name, uid=self.last_uid, ).dec() LOGGER.debug( "removed outpost instance from cache", outpost=self.outpost, instance_uuid=self.last_uid, )
def disconnect(self, code): if self.outpost and self.last_uid: state = OutpostState.for_instance_uid(self.outpost, self.last_uid) if self.channel_name in state.channel_ids: state.channel_ids.remove(self.channel_name) state.save() GAUGE_OUTPOSTS_CONNECTED.labels( outpost=self.outpost.name, uid=self.last_uid, expected=self.outpost.config.kubernetes_replicas, ).dec() self.logger.debug( "removed outpost instance from cache", instance_uuid=self.last_uid, )
def receive_json(self, content: Data): msg = from_dict(WebsocketMessage, content) uid = msg.args.get("uuid", self.channel_name) self.last_uid = uid state = OutpostState.for_instance_uid(self.outpost, uid) if self.channel_name not in state.channel_ids: state.channel_ids.append(self.channel_name) state.last_seen = datetime.now() if msg.instruction == WebsocketMessageInstruction.HELLO: state.version = msg.args.get("version", None) state.build_hash = msg.args.get("buildHash", "") elif msg.instruction == WebsocketMessageInstruction.ACK: return state.save(timeout=OUTPOST_HELLO_INTERVAL * 1.5) response = WebsocketMessage( instruction=WebsocketMessageInstruction.ACK) self.send_json(asdict(response))