Comparing version 1.4.0 to 1.4.1
@@ -6,2 +6,5 @@ # Changelog | ||
## 1.4.1 | ||
* #15 improve the performance of hashObj() | ||
## 1.4.0 | ||
@@ -8,0 +11,0 @@ * #14 Allow for metrics in a MetricVector to be optionally expired or reset to a |
@@ -6,3 +6,3 @@ /* | ||
* | ||
* Copyright (c) 2017, Joyent, Inc. | ||
* Copyright (c) 2018, Joyent, Inc. | ||
*/ | ||
@@ -14,4 +14,2 @@ | ||
var mod_crypto = require('crypto'); | ||
/* | ||
@@ -42,4 +40,6 @@ * This is a similar regex to the one used in the golang prometheus client lib. | ||
* the metrics before they're stored. This function takes an object of labels. | ||
* The labels are sorted alphabetically, sent through stringify, and then their | ||
* md5 hash is calculated. This should be adequately unique for our case. | ||
* The labels are sorted alphabetically and returned as a string with the keys | ||
* joined together (with no separator), the values joined together (with no | ||
* separator) and the resulting two strings (keys and values) joined together | ||
* with a '/' separator. | ||
*/ | ||
@@ -49,9 +49,13 @@ function hashObj(obj) { | ||
var hash = mod_crypto.createHash('md5'); | ||
var newObj = {}; | ||
var idx; | ||
var keys = Object.keys(obj).sort(); | ||
keys.forEach(function (key) { | ||
newObj[key] = obj[key]; | ||
}); | ||
return (hash.update(JSON.stringify(newObj)).digest('hex')); | ||
var keysStr = ''; | ||
var values = ''; | ||
for (idx = 0; idx < keys.length; idx++) { | ||
keysStr += keys[idx]; | ||
values += obj[keys[idx]]; | ||
} | ||
return (keysStr + '/' + values); | ||
} | ||
@@ -58,0 +62,0 @@ |
{ | ||
"name": "artedi", | ||
"version": "1.4.0", | ||
"version": "1.4.1", | ||
"description": "a metric client library", | ||
@@ -5,0 +5,0 @@ "main": "lib/collector.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
54405
1301