Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: emit openjd_* log messages without any log formatting #16

Merged
merged 1 commit into from
Oct 17, 2023

Conversation

jericht
Copy link
Contributor

@jericht jericht commented Oct 17, 2023

What was the problem/requirement? (What/Why)

The adaptor runtime is currently printing openjd_* messages with log formatting enabled, meaning they are prefixed with the log level. This prevents these messages from being captured by OpenJD since they do not meet the spec of requiring the line start with openjd_*.

This manifests in two ways:

  1. In "regular" mode (non-background/daemon), if an adaptor fails one of its on_* methods (e.g. on_run), we are currently emitting an ERROR level log message in the AdaptorRunner class (code). Our log formatter will print this with an ERROR: prefix to the message.
  2. In background/daemon mode, all adaptor stdout/stderr is emitted under the log level ADAPTOR_OUTPUT. Our log formatter will print this with an ADAPTOR_OUTPUT: prefix to the message

What was the solution? (How)

Added a conditional log formatter which does not apply formatting to any log messages that begin with openjd_*

What is the impact of this change?

Any openjd_* message emitted by the adaptor runtime will no longer have log formatting applied to it, allowing it to be captured by OpenJD

How was this change tested?

  • Added unit test
  • Manual E2E test with an example adaptor that always raises an "Oops" exception on_run (logs below)

Was this change documented?

No

Is this a breaking change?

No

E2E testing logs

BEFORE - Regular mode

$ HelloWorldAdaptor
In HelloWorldAdaptor main
INFO: Applying user-level configuration: /home/jericht/.openjd/worker/adaptors/runtime/configuration.json
INFO: Applying user-level configuration: /home/jericht/.openjd/adaptors/HelloWorldAdaptor/HelloWorldAdaptor.json
INFO: Running command: /local/home/jericht/.local/share/hatch/env/virtual/openjd-adaptor-example/4ErhphO-/openjd-adaptor-example/bin/python /local/home/jericht/.local/share/hatch/env/virtual/openjd-adaptor-example/4ErhphO-/openjd-adaptor-example/lib/python3.9/site-packages/hello_world_adaptor/client.py /home/jericht/.openjd/adaptors/sockets/dcc/6775
 - - [17/Oct/2023 18:48:45] "GET /action HTTP/1.1" 200 -
STDOUT: Performing action: {"name": "print", "args": {"message": "on_start"}}
STDOUT: HelloWorld: on_start
ERROR: openjd_fail: Error encountered while running adaptor: Oops
ERROR: Error running the adaptor: Oops
 - - [17/Oct/2023 18:49:05] "GET /action HTTP/1.1" 200 -
STDOUT: Performing action: {"name": "close", "args": null}
STDOUT: closing
Entrypoint failed: Oops

AFTER - Regular Mode

$ HelloWorldAdaptor 
In HelloWorldAdaptor main
INFO: Applying user-level configuration: /home/jericht/.openjd/worker/adaptors/runtime/configuration.json
INFO: Applying user-level configuration: /home/jericht/.openjd/adaptors/HelloWorldAdaptor/HelloWorldAdaptor.json
INFO: Running command: /local/home/jericht/.local/share/hatch/env/virtual/openjd-adaptor-example/4ErhphO-/openjd-adaptor-example/bin/python /local/home/jericht/.local/share/hatch/env/virtual/openjd-adaptor-example/4ErhphO-/openjd-adaptor-example/lib/python3.9/site-packages/hello_world_adaptor/client.py /home/jericht/.openjd/adaptors/sockets/dcc/12498
 - - [17/Oct/2023 19:33:57] "GET /action HTTP/1.1" 200 -
STDOUT: Performing action: {"name": "print", "args": {"message": "on_start"}}
STDOUT: HelloWorld: on_start
openjd_fail: Error encountered while running adaptor: Oops
ERROR: Error running the adaptor: Oops
 - - [17/Oct/2023 19:34:17] "GET /action HTTP/1.1" 200 -
STDOUT: Performing action: {"name": "close", "args": null}
STDOUT: closing
Entrypoint failed: Oops

BEFORE - Background Mode

$ HelloWorldAdaptor daemon run --connection-file /tmp/HelloWorldAdaptor.json
In HelloWorldAdaptor main
INFO: Applying user-level configuration: /home/jericht/.openjd/worker/adaptors/runtime/configuration.json
INFO: Applying user-level configuration: /home/jericht/.openjd/adaptors/HelloWorldAdaptor/HelloWorldAdaptor.json
ADAPTOR_OUTPUT: 
ADAPTOR_OUTPUT: ERROR: openjd_fail: Error encountered while running adaptor: Oops
Entrypoint failed: 
ERROR: openjd_fail: Error encountered while running adaptor: Oops

AFTER - Background Mode

$ HelloWorldAdaptor daemon run --connection-file /tmp/HelloWorldAdaptor.json
In HelloWorldAdaptor main
INFO: Applying user-level configuration: /home/jericht/.openjd/worker/adaptors/runtime/configuration.json
INFO: Applying user-level configuration: /home/jericht/.openjd/adaptors/HelloWorldAdaptor/HelloWorldAdaptor.json
ADAPTOR_OUTPUT: 
openjd_fail: Error encountered while running adaptor: Oops
Entrypoint failed: 
openjd_fail: Error encountered while running adaptor: Oops

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@jericht jericht marked this pull request as ready for review October 17, 2023 20:11
@jericht jericht requested a review from a team as a code owner October 17, 2023 20:11
@jericht jericht merged commit 52bc173 into mainline Oct 17, 2023
6 checks passed
@jericht jericht deleted the jericht/openjd_msg branch October 17, 2023 20:40
Honglichenn pushed a commit that referenced this pull request Jan 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants