aws / aws-toolkit-jetbrains

AWS Toolkit for JetBrains - a plugin for interacting with AWS from JetBrains IDEs
https://plugins.jetbrains.com/plugin/11349-aws-toolkit
Apache License 2.0
730 stars 197 forks source link

Properly resolve plugin in worker thread tasks #4590

Closed breedloj closed 2 weeks ago

breedloj commented 2 weeks ago

Types of changes

Description

This change addresses an issue where tasks run in worker threads would be unable to properly resolve the original plugin calling context since the original call stack is lost. This resulted in bad telemetry in these scenarios when running the Amazon Q plugin.

To address this, this change refactors the PluginResolver class to allow each thread to have its own PluginResolver instance, while also supporting the ability for child threads to use the instance created by the parent thread. By using ThreadLocal, each thread has its own context for storing and retrieving the PluginResolver instance. A new threading utility function, pluginAwareExecuteOnPooledThread, wraps the original pooled thread execution logic and injects a resolved PluginResolver instance from the parent thread on the worker thread. This results in the worker inheriting the parent's correctly resolved plugin identifier.

Checklist

License

I confirm that my contribution is made under the terms of the Apache 2.0 license.

sonarcloud[bot] commented 2 weeks ago

Quality Gate Passed Quality Gate passed

Issues
1 New issue
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

rbart commented 1 week ago

looks good to me! 😁