diff options
| author | Joshua Watt <JPEWhacker@gmail.com> | 2023-11-03 08:26:23 -0600 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2023-11-09 17:33:02 +0000 |
| commit | 4cdb0f00f9c687337bd08b97022349f4dddadcc0 (patch) | |
| tree | 6a5195e72017ae93572be7e32b920d682bf98083 /bitbake/lib | |
| parent | 8ae00cf20d510995263cfc948e73b0556ffdbf32 (diff) | |
| download | poky-4cdb0f00f9c687337bd08b97022349f4dddadcc0.tar.gz | |
bitbake: asyncrpc: Prefix log messages with client info
Adds a logging adaptor to the asyncrpc clients that prefixes log
messages with the client remote address to aid in debugging
(Bitbake rev: f4d64ce73c2449c008ff5d9b32376a2893ef7195)
Signed-off-by: Joshua Watt <JPEWhacker@gmail.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib')
| -rw-r--r-- | bitbake/lib/bb/asyncrpc/serv.py | 21 | ||||
| -rw-r--r-- | bitbake/lib/hashserv/server.py | 10 |
2 files changed, 23 insertions, 8 deletions
diff --git a/bitbake/lib/bb/asyncrpc/serv.py b/bitbake/lib/bb/asyncrpc/serv.py index dfb0377380..c99add4dd1 100644 --- a/bitbake/lib/bb/asyncrpc/serv.py +++ b/bitbake/lib/bb/asyncrpc/serv.py | |||
| @@ -12,10 +12,16 @@ import signal | |||
| 12 | import socket | 12 | import socket |
| 13 | import sys | 13 | import sys |
| 14 | import multiprocessing | 14 | import multiprocessing |
| 15 | import logging | ||
| 15 | from .connection import StreamConnection, WebsocketConnection | 16 | from .connection import StreamConnection, WebsocketConnection |
| 16 | from .exceptions import ClientError, ServerError, ConnectionClosedError | 17 | from .exceptions import ClientError, ServerError, ConnectionClosedError |
| 17 | 18 | ||
| 18 | 19 | ||
| 20 | class ClientLoggerAdapter(logging.LoggerAdapter): | ||
| 21 | def process(self, msg, kwargs): | ||
| 22 | return f"[Client {self.extra['address']}] {msg}", kwargs | ||
| 23 | |||
| 24 | |||
| 19 | class AsyncServerConnection(object): | 25 | class AsyncServerConnection(object): |
| 20 | # If a handler returns this object (e.g. `return self.NO_RESPONSE`), no | 26 | # If a handler returns this object (e.g. `return self.NO_RESPONSE`), no |
| 21 | # return message will be automatically be sent back to the client | 27 | # return message will be automatically be sent back to the client |
| @@ -27,7 +33,12 @@ class AsyncServerConnection(object): | |||
| 27 | self.handlers = { | 33 | self.handlers = { |
| 28 | "ping": self.handle_ping, | 34 | "ping": self.handle_ping, |
| 29 | } | 35 | } |
| 30 | self.logger = logger | 36 | self.logger = ClientLoggerAdapter( |
| 37 | logger, | ||
| 38 | { | ||
| 39 | "address": socket.address, | ||
| 40 | }, | ||
| 41 | ) | ||
| 31 | 42 | ||
| 32 | async def close(self): | 43 | async def close(self): |
| 33 | await self.socket.close() | 44 | await self.socket.close() |
| @@ -242,16 +253,20 @@ class AsyncServer(object): | |||
| 242 | self.server = WebsocketsServer(host, port, self._client_handler, self.logger) | 253 | self.server = WebsocketsServer(host, port, self._client_handler, self.logger) |
| 243 | 254 | ||
| 244 | async def _client_handler(self, socket): | 255 | async def _client_handler(self, socket): |
| 256 | address = socket.address | ||
| 245 | try: | 257 | try: |
| 246 | client = self.accept_client(socket) | 258 | client = self.accept_client(socket) |
| 247 | await client.process_requests() | 259 | await client.process_requests() |
| 248 | except Exception as e: | 260 | except Exception as e: |
| 249 | import traceback | 261 | import traceback |
| 250 | 262 | ||
| 251 | self.logger.error("Error from client: %s" % str(e), exc_info=True) | 263 | self.logger.error( |
| 264 | "Error from client %s: %s" % (address, str(e)), exc_info=True | ||
| 265 | ) | ||
| 252 | traceback.print_exc() | 266 | traceback.print_exc() |
| 267 | finally: | ||
| 268 | self.logger.debug("Client %s disconnected", address) | ||
| 253 | await socket.close() | 269 | await socket.close() |
| 254 | self.logger.debug("Client disconnected") | ||
| 255 | 270 | ||
| 256 | @abc.abstractmethod | 271 | @abc.abstractmethod |
| 257 | def accept_client(self, socket): | 272 | def accept_client(self, socket): |
diff --git a/bitbake/lib/hashserv/server.py b/bitbake/lib/hashserv/server.py index 13b754805b..e6a3f40577 100644 --- a/bitbake/lib/hashserv/server.py +++ b/bitbake/lib/hashserv/server.py | |||
| @@ -207,7 +207,7 @@ class ServerClient(bb.asyncrpc.AsyncServerConnection): | |||
| 207 | async def dispatch_message(self, msg): | 207 | async def dispatch_message(self, msg): |
| 208 | for k in self.handlers.keys(): | 208 | for k in self.handlers.keys(): |
| 209 | if k in msg: | 209 | if k in msg: |
| 210 | logger.debug('Handling %s' % k) | 210 | self.logger.debug('Handling %s' % k) |
| 211 | if 'stream' in k: | 211 | if 'stream' in k: |
| 212 | return await self.handlers[k](msg[k]) | 212 | return await self.handlers[k](msg[k]) |
| 213 | else: | 213 | else: |
| @@ -351,7 +351,7 @@ class ServerClient(bb.asyncrpc.AsyncServerConnection): | |||
| 351 | break | 351 | break |
| 352 | 352 | ||
| 353 | (method, taskhash) = l.split() | 353 | (method, taskhash) = l.split() |
| 354 | #logger.debug('Looking up %s %s' % (method, taskhash)) | 354 | #self.logger.debug('Looking up %s %s' % (method, taskhash)) |
| 355 | cursor = self.db.cursor() | 355 | cursor = self.db.cursor() |
| 356 | try: | 356 | try: |
| 357 | row = self.query_equivalent(cursor, method, taskhash) | 357 | row = self.query_equivalent(cursor, method, taskhash) |
| @@ -360,7 +360,7 @@ class ServerClient(bb.asyncrpc.AsyncServerConnection): | |||
| 360 | 360 | ||
| 361 | if row is not None: | 361 | if row is not None: |
| 362 | msg = row['unihash'] | 362 | msg = row['unihash'] |
| 363 | #logger.debug('Found equivalent task %s -> %s', (row['taskhash'], row['unihash'])) | 363 | #self.logger.debug('Found equivalent task %s -> %s', (row['taskhash'], row['unihash'])) |
| 364 | elif self.upstream_client is not None: | 364 | elif self.upstream_client is not None: |
| 365 | upstream = await self.upstream_client.get_unihash(method, taskhash) | 365 | upstream = await self.upstream_client.get_unihash(method, taskhash) |
| 366 | if upstream: | 366 | if upstream: |
| @@ -480,8 +480,8 @@ class ServerClient(bb.asyncrpc.AsyncServerConnection): | |||
| 480 | row = self.query_equivalent(cursor, data['method'], data['taskhash']) | 480 | row = self.query_equivalent(cursor, data['method'], data['taskhash']) |
| 481 | 481 | ||
| 482 | if row['unihash'] == data['unihash']: | 482 | if row['unihash'] == data['unihash']: |
| 483 | logger.info('Adding taskhash equivalence for %s with unihash %s', | 483 | self.logger.info('Adding taskhash equivalence for %s with unihash %s', |
| 484 | data['taskhash'], row['unihash']) | 484 | data['taskhash'], row['unihash']) |
| 485 | 485 | ||
| 486 | d = {k: row[k] for k in ('taskhash', 'method', 'unihash')} | 486 | d = {k: row[k] for k in ('taskhash', 'method', 'unihash')} |
| 487 | 487 | ||
