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

debuggability improvements to the CDK #37746

Conversation

stephane-airbyte
Copy link
Contributor

@stephane-airbyte stephane-airbyte commented May 1, 2024

A few changes to improve debuggability:

  1. We now print the stack trace that created an orphan thread, in addition to the current stack trace.
  2. we add the ability for a connector to tell the integration runner to not care about certain threads (by adding a thread filter)
  3. We change the log of connector containers to include the name of the test that created it (usually each test will create and close a container)
  4. We also log when the timeout timer gets triggered, to try to understand why some tests are still taking way more time than their timeout should allow

Another change that was initially in there but has been removed and might be worth thinking about:
Today, only Write checks for live threads on shutdown. We might want to do that for other operations as well

Copy link

vercel bot commented May 1, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
airbyte-docs ⬜️ Ignored (Inspect) Visit Preview May 2, 2024 9:09pm

Copy link
Contributor Author

stephane-airbyte commented May 1, 2024

@stephane-airbyte stephane-airbyte force-pushed the stephane/05-01-debuggability_improvements_to_the_cdk branch 2 times, most recently from 5b62126 to 997351f Compare May 1, 2024 22:24
Copy link
Contributor

@edgao edgao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

couple nitpicks and some questions to make sure I understand what's going on. Slightly spooky PR but I don't see a better way to do it so 🤷 :shipit:

"Junit starting {} with timeout of {}",
logLineSuffix,
DurationFormatUtils.formatDurationWords(timeout.toMillis(), true, true)
)
Timer("TimeoutTimer-" + currentThread.name, true)
.schedule(timeoutTask, timeout.toMillis())
var timer =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this var referenced anywhere? doesn't seem to be the case


class TestContext {
companion object {
val CURRENT_TEST_NAME: ThreadLocal<String?> = ThreadLocal()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Convention in kotlin is to reserve upper-case snake case to const vals. I'm surprised your IDE didn't hint about this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from the kotlin guide:
Names of constants (properties marked with const, or top-level or object val properties with no custom get function that hold deeply immutable data) should use uppercase underscore-separated (screaming snake case) names

I think this is what we're supposed to do

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL! Thanks

build.gradle Outdated
@@ -139,6 +139,9 @@ allprojects {
// This is also required, to prevent stderr spam starting with
// "OpenJDK 64-Bit Server VM warning: Sharing is only supported for boot loader cl..."
jvmArgs "-Xshare:off"
// This is required for our dangling thread checks at the end of a connector run.
// see IntegrationRunner.stopOrphanedThreads
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked at this function and I'm none the wiser as to why this --add-opens flag is required. This might be out of scope of this PR but if you do know why please take this opportunity to add some more detailed explanations.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's because we use introspection to change the access of the ThreadLocal.get(Thread)

ThreadLocal::class.java.getDeclaredMethod("get", Thread::class.java)
init {
getMethod.isAccessible = true
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fyi you can also do

private val getMethod: Method = ThreadLocal::class.java.getDeclaredMethod("get", Thread::class.java).also { isAccessible = true }

Copy link
Contributor

@postamar postamar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm happy with the changes in IntegrationRunner so this is good to go as far as I'm concerned. If it works, it works.

@stephane-airbyte stephane-airbyte force-pushed the stephane/05-01-debuggability_improvements_to_the_cdk branch 5 times, most recently from 961d513 to 55bf52e Compare May 2, 2024 20:47
@stephane-airbyte stephane-airbyte force-pushed the stephane/05-01-debuggability_improvements_to_the_cdk branch from 55bf52e to 41beb7a Compare May 2, 2024 21:09
@stephane-airbyte stephane-airbyte marked this pull request as ready for review May 3, 2024 06:01
@stephane-airbyte stephane-airbyte requested review from a team as code owners May 3, 2024 06:01
Copy link
Contributor Author

stephane-airbyte commented May 3, 2024

/publish-java-cdk

🕑 https://github.com/airbytehq/airbyte/actions/runs/8934813443
✅ Successfully published Java CDK version=0.31.6!

@stephane-airbyte stephane-airbyte merged commit c326286 into master May 3, 2024
32 checks passed
@stephane-airbyte stephane-airbyte deleted the stephane/05-01-debuggability_improvements_to_the_cdk branch May 3, 2024 13:50
aasimsani pushed a commit to taxwire/airbyte that referenced this pull request May 6, 2024
A few changes to improve debuggability:
1) We now print the stack trace that created an orphan thread, in addition to the current stack trace.
2) we add the ability for a connector to tell the integration runner to not care about certain threads (by adding a thread filter)
3) We change the log of connector containers to include the name of the test that created it (usually each test will create and close a container)
4) We also log when the timeout timer gets triggered, to try to understand why some tests are still taking way more time than their timeout should allow

Another change that was initially in there but has been removed and might be worth thinking about:
Today, only Write checks for live threads on shutdown. We might want to do that for other operations as well
clnoll pushed a commit that referenced this pull request May 10, 2024
A few changes to improve debuggability:
1) We now print the stack trace that created an orphan thread, in addition to the current stack trace.
2) we add the ability for a connector to tell the integration runner to not care about certain threads (by adding a thread filter)
3) We change the log of connector containers to include the name of the test that created it (usually each test will create and close a container)
4) We also log when the timeout timer gets triggered, to try to understand why some tests are still taking way more time than their timeout should allow

Another change that was initially in there but has been removed and might be worth thinking about:
Today, only Write checks for live threads on shutdown. We might want to do that for other operations as well
// opened method
private val getMethod: Method =
ThreadLocal::class.java.getDeclaredMethod("get", Thread::class.java).also {
it.isAccessible = true
Copy link

@mtrienis-dw-v2 mtrienis-dw-v2 May 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm getting an error here, not sure if I'm doing something silly or if there was a bug introduced here?

@stephane-airbyte

Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make private java.lang.Object java.lang.ThreadLocal.get(java.lang.Thread) accessible: module java.base does not "opens java.lang" to unnamed module @5f058f00

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how you're executing this. I've tested this when running tests from intelliJ and airbyte-ci, as well as when running a connector through the docker image

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stephane-airbyte try running this main method through Intellij IDE:

https://github.com/airbytehq/airbyte/blob/master/airbyte-integrations/connectors/destination-mysql/src/main/java/io/airbyte/integrations/destination/mysql/MySQLDestination.java#L188-L193

With the following parameters:

  • Java 21 SDK
  • Cli arguments --write --config /<my_path>/config.json --catalog /<my_path>/configured_catalog.json
  • Click Modify options -> Redirect input and then add example input message <my_path>/message.json

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you need an additional JVM parameters, --add-opens=java.base/java.lang=ALL-UNNAMED

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Roger -- thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CDK Connector Development Kit
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants