Skip to content

Commit

Permalink
Add debugging log to language server interactions.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 599918810
Change-Id: I10be436b01a708ad6e1dba27fb5234f07eb1f241
  • Loading branch information
nttran8 authored and copybara-github committed Jan 19, 2024
1 parent 4844fa9 commit 4d6e983
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public DetectionReportList detect(
.get()
.getStatus()
.equals(HealthCheckResponse.ServingStatus.SERVING)) {
logger.atInfo().log("Detecting with language server plugins...");
return service
.runWithDeadline(
RunRequest.newBuilder().setTarget(target).addAllPlugins(pluginsToRun).build(),
Expand All @@ -83,6 +84,7 @@ public ImmutableList<PluginDefinition> getAllPlugins() {
.get()
.getStatus()
.equals(HealthCheckResponse.ServingStatus.SERVING)) {
logger.atInfo().log("Getting language server plugins...");
return ImmutableList.copyOf(
service
.listPluginsWithDeadline(ListPluginsRequest.getDefaultInstance(), DEFAULT_DEADLINE)
Expand Down
22 changes: 17 additions & 5 deletions plugin_server/py/plugin_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""Main gRPC server to execute Python Tsunami plugins."""

from concurrent import futures
import importlib
import pkgutil
Expand Down Expand Up @@ -69,11 +70,8 @@


def main(unused_argv):
logging.use_absl_handler()
logging.get_absl_handler().use_absl_log_file(
'py_plugin_server', _OUTPUT.value
)
logging.set_verbosity(logging.INFO)
_configure_log()

# Load plugins from tsunami_plugins repository.
plugin_pkg = importlib.import_module(
'py_plugins'
Expand Down Expand Up @@ -115,6 +113,20 @@ def _import_py_plugins(plugin_pkg: types.ModuleType):
logging.info('Loaded plugin module %s', full_name)


def _configure_log():
"""Store and print out log stream."""
logging.use_absl_handler()
logger = logging.get_absl_handler()
logger.use_absl_log_file(
'py_plugin_server', _OUTPUT.value
)
# Label the log record that comes from the python server for debugging.
logger.setFormatter(
logging.PythonFormatter('[Python Server] %(asctime)s %(message)s')
)
logging.set_verbosity(logging.INFO)


def _configure_plugin_service(server):
"""Configures the main plugin service for handling plugin related gRPC requests."""
http_client = (
Expand Down
15 changes: 9 additions & 6 deletions plugin_server/py/plugin_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ class PluginServiceServicer(plugin_service_pb2_grpc.PluginServiceServicer):
This class executes requests called by the Java client. All request types are
given by the plugin_service proto definition.
"""

def __init__(self, py_plugins: list[tsunami_plugin.TsunamiPlugin],
Expand All @@ -47,10 +46,11 @@ def __init__(self, py_plugins: list[tsunami_plugin.TsunamiPlugin],
self.max_workers = max_workers

def Run(
self, request: plugin_service_pb2.RunRequest,
servicer_context: plugin_service_pb2_grpc.PluginServiceServicer
self,
request: plugin_service_pb2.RunRequest,
servicer_context: plugin_service_pb2_grpc.PluginServiceServicer,
) -> RunResponse:
logging.info('Received Run request = %s', request)
logging.info('Received Run request: %s', request)
report_list = detection_pb2.DetectionReportList()

detection_futures = []
Expand All @@ -77,8 +77,11 @@ def Run(
return response

def ListPlugins(
self, request: ListPluginsRequest,
servicer_context: _PluginServiceServicer) -> ListPluginsResponse:
self,
request: ListPluginsRequest,
servicer_context: _PluginServiceServicer,
) -> ListPluginsResponse:
logging.info('Received ListPlugins request: %s', request)
response = ListPluginsResponse()
response.plugins.MergeFrom(
[plugin.GetPluginDefinition() for plugin in self.py_plugins])
Expand Down

0 comments on commit 4d6e983

Please sign in to comment.