awslabs / disco

A suite of tools including a framework for creating Java Agents, for aspect-oriented tooling for distributed systems.
Apache License 2.0
55 stars 12 forks source link

Added additional JDBC interceptor for Connections #16

Closed willarmiros closed 3 years ago

willarmiros commented 3 years ago

Description of changes: This PR expands the functionality of the DiSCo SQL library by adding an interceptor for the Connection class. We are interested in capturing methods called on the Connection object that send a pre-formatted SQL query with parameters to the server (via either prepareStatement or prepareCall), which will then be actually executed later on.

The Advices we use are quite simple, we just capture the pre-formatted query string from the target methods' arguments, and send it in a ServiceDownstreamEvent which is formatted similarly to the existing events emitted for SQL queries. However, because the request & response objects are different than queries, and they generally model different interactions with a SQL server, I made a new origin for these events.

The integ tests still have the problem of not being able to be mocked and intercepted at once, so I had to implement a full fake MyConnectionImpl class like I did for the Statements earlier. We should be able to revisit this once the changes to Disco which are "in the pipeline" are released.

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