Kitura / Swift-Kuery

SQL database abstraction layer
Apache License 2.0
426 stars 41 forks source link

Provide support for monitoring queries #12

Open seabaylea opened 7 years ago

seabaylea commented 7 years ago

In order to be able to do complete monitoring of a deployed application, its also important to be able to monitor database calls for to understand their performance and whether errors are occurring.

The basic data that would be needed is the equivalent for what we collect for MySQL queries on Node.js in 'appmetrics': https://www.npmjs.com/package/appmetrics

Event: 'mysql'
Emitted when a MySQL query is made using the mysql module.

* data (Object) the data from the MySQL query:
  * time (Number) the milliseconds when the MySQL query was made. This can be converted to a Date using new Date(data.time).
  * query (String) the query made of the MySQL database.
  * duration (Number) the time taken for the MySQL query to be responded to in ms.

Additionally in the future we may also want the ability to be able to insert fault injection, and circuit breaking functionality, etc.

ianpartridge commented 7 years ago

We'd probably provide two callbacks: at the start and end of execute(). The start would provide the raw query string.

By "end" I mean just before the callback is invoked - we don't want to monitor how long the resulting business logic takes.

rfdickerson commented 7 years ago

I'm not sure if I like the API to work by passing in callback functions as arguments. Maybe instead just provide a delegate protocol- that various monitoring components can plug in to the database Swift client driver?

ianpartridge commented 7 years ago

Sorry, that's exactly what I meant. Like we're doing in Kitura-net for Request start/end.