Request: unique hash on query objects for logging
See original GitHub issueI’m trying to write a simple metrics tool to measure which queries are performing slowly so that I can evaluate my codebase over time. As a simplified example:
var knex = require('knex')({myConfig});
var runningQueries = {};
knex.on('query', function (data) {
// Generates a unique has using hash using keys like:
// ['__knexUid', 'method', 'sql', 'bindings', 'options']
var queryHash = generateHash(data);
runningQueries[queryHash] = {
sql: data.sql,
start: Date.now()
};
});
knex.on('query-response', function (response, obj, builder) {
// This hash should match the one in the function above.
var queryHash = generateHash(obj);
var runTime = Date.now() - runningQueries[queryHash].start;
// etc. etc.
delete runningQueries[queryHash];
});
The problem I’m encountering is that multiple queries with the same properties will get jumbled together - and could potentially screw up my timings or cause me to miss queries. It would be ideal if each query object had a unique hash attached to it (or the Date.now() timestamp it was created at) to identify them uniquely.
I can add the code, but before I submit a PR I’d like your input and to make sure I’m not wasting your time. 😃
Issue Analytics
- State:
- Created 7 years ago
- Comments:10 (9 by maintainers)
Top Results From Across the Web
Log request string URL with # (number sign, hash, fragment ...
The problem is that the entire Query String isn't being logged when there's a # (Number Sign) in the URL (Visiting ...
Read more >A Guide to Consistent Hashing - Toptal
Consistent Hashing is a distributed hashing scheme that operates independently of the number of servers or objects in a distributed hash table.
Read more >Build queries by using the Logging query language
This document describes how to retrieve and analyze logs when you use the Logs Explorer. You retrieve logs by writing and executing queries....
Read more >15.10 - Finding Uneven Distribution Using Hash Functions
Finding Uneven Distribution Using Hash Functions Use the following functions to identify uneven hash distribution of data.
Read more >sys.dm_exec_requests (Transact-SQL) - SQL Server
Column name Data type Description
blocking_session_id smallint
context_info varbinary(128) CONTEXT_INFO value of the session. Is nullable.
estimated_completion_time bigint Internal only. Isn't nullable.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@wubzz That’s a good idea. I’ve gone ahead and updated it to
__knexQueryUid
to fit the__knexUid
pattern.I’m using knex@0.21.2 with mssql
I’ve noticed that some queries don’t receive a __knexQueryUid. Any idea why that might be? It appears that anything using the
schema
api is missing this, for example:this type of code is resulting in query event data looking like: