prom-client
Advanced tools
Comparing version 3.4.4 to 3.4.5
@@ -65,3 +65,3 @@ /** | ||
Histogram.prototype.observe = function(labels, value) { | ||
observe.call(this, labels || {})(value); | ||
observe.call(this, labels === 0 ? 0 : (labels || {}))(value); | ||
}; | ||
@@ -178,3 +178,3 @@ | ||
validateLabels(histogram.labelNames, labelValuePair.labels); | ||
if(!isNumber(labelValuePair.value)) { | ||
if(!isNumber(labelValuePair.value) && labelValuePair.value > 0) { | ||
throw new Error('Value is not a valid number', labelValuePair.value); | ||
@@ -181,0 +181,0 @@ } |
'use strict'; | ||
var request = require('request'); | ||
var http = require('http'); | ||
var https = require('https'); | ||
var register = require('./register'); | ||
@@ -33,14 +34,32 @@ | ||
function useGateway(method, job, groupings, callback) { | ||
var url = [this.gatewayUrl, '/metrics/job/', encodeURIComponent(job), generateGroupings(groupings)].join(''); | ||
var path = ['/metrics/job/', encodeURIComponent(job), generateGroupings(groupings)].join(''); | ||
var httpModule = isHttps(this.gatewayUrl) ? https : http; | ||
var hostAndPort = getHostAndPort(this.gatewayUrl); | ||
var options = { | ||
body: register.metrics(), | ||
url: url, | ||
method: method | ||
method: method, | ||
hostname: hostAndPort.host, | ||
port: hostAndPort.port, | ||
path: path | ||
}; | ||
if(method === 'DELETE') { | ||
options.body = ''; | ||
var req = httpModule.request(options, function(res) { | ||
var body = ''; | ||
res.setEncoding('utf8'); | ||
res.on('data', function(chunk) { | ||
body += chunk; | ||
}); | ||
res.on('end', function() { | ||
callback(null, res, body); | ||
}); | ||
}); | ||
req.on('error', function(err) { | ||
callback(err); | ||
}); | ||
if(method !== 'DELETE') { | ||
req.write(register.metrics()); | ||
} | ||
request(options, callback); | ||
req.end(); | ||
} | ||
@@ -57,2 +76,19 @@ | ||
function getHostAndPort(url) { | ||
var host; | ||
if(url.indexOf(':') === -1) { | ||
return { host: url, port: isHttps(url) ? 443 : 80 }; | ||
} | ||
var parts = url.match(/https?:\/\/(.*):(\d*)/); | ||
return { | ||
host: parts[1], | ||
port: parts[2] | ||
}; | ||
} | ||
function isHttps(url) { | ||
return url.search(/^https/) !== -1; | ||
} | ||
module.exports = Pushgateway; |
@@ -15,3 +15,3 @@ 'use strict'; | ||
var labels = Object.keys(val.labels || {}).map(function(key) { | ||
return key + '="' + val.labels[key] + '"'; | ||
return key + '="' + escapeLabelValue(val.labels[key]) + '"'; | ||
}); | ||
@@ -35,4 +35,10 @@ | ||
function escapeString(str) { | ||
return str.replace('"', '\\"').replace('\\n', '\\\n').replace('\\', '\\\\'); | ||
return str.replace(/\n/g, '\\n').replace(/\\(?!n)/g, '\\\\'); | ||
} | ||
function escapeLabelValue(str) { | ||
if(typeof str !== 'string') { | ||
return str; | ||
} | ||
return escapeString(str).replace(/"/g, '\\"'); | ||
} | ||
@@ -39,0 +45,0 @@ var registerMetric = function registerMetric(metricFn) { |
@@ -56,3 +56,3 @@ /** | ||
Summary.prototype.observe = function(labels, value) { | ||
observe.call(this, labels || {})(value); | ||
observe.call(this, labels === 0 ? 0 : (labels || {}))(value); | ||
}; | ||
@@ -59,0 +59,0 @@ |
{ | ||
"name": "prom-client", | ||
"version": "3.4.4", | ||
"version": "3.4.5", | ||
"description": "Client for prometheus", | ||
@@ -10,3 +10,5 @@ "main": "index.js", | ||
"scripts": { | ||
"test": "eslint --ignore-pattern doc/ --ignore-path .gitignore . && mocha test/" | ||
"test": "npm run lint && npm run test-unit", | ||
"lint": "eslint --ignore-pattern doc/ --ignore-path .gitignore .", | ||
"test-unit": "mocha test/" | ||
}, | ||
@@ -27,11 +29,9 @@ "repository": { | ||
"chai": "^3.4.1", | ||
"eslint": "^1.10.1", | ||
"eslint": "^2.13.1", | ||
"express": "^4.13.3", | ||
"minami": "^1.1.1", | ||
"mocha": "^2.3.4", | ||
"nock": "^7.2.2", | ||
"nock": "^8.0.0", | ||
"sinon": "^1.17.2" | ||
}, | ||
"dependencies": { | ||
"request": "^2.69.0", | ||
"tdigest": "^0.1.1", | ||
@@ -38,0 +38,0 @@ "util-extend": "^1.0.1" |
@@ -20,2 +20,7 @@ 'use strict'; | ||
}); | ||
it('should be able to observe 0s', function() { | ||
instance.observe(0); | ||
var valuePair = getValueByLabel(0.005, instance.get().values); | ||
expect(valuePair.value).to.equal(1); | ||
}); | ||
it('should increase sum', function() { | ||
@@ -22,0 +27,0 @@ instance.observe(0.5); |
@@ -60,3 +60,3 @@ 'use strict'; | ||
return { | ||
name: 'test_"_\_\n_metric', | ||
name: 'test_"_\\_\n_metric', | ||
help: 'help_help', | ||
@@ -69,5 +69,2 @@ type: 'counter' | ||
}); | ||
it('double quote to /"', function() { | ||
expect(escapedResult).to.match(/\\"/); | ||
}); | ||
it('backslash to \\\\', function() { | ||
@@ -77,6 +74,27 @@ expect(escapedResult).to.match(/\\\\/); | ||
it('newline to \\\\n', function() { | ||
// expect(escapedResult).to.match(/\/); | ||
expect(escapedResult).to.match(/\n/); | ||
}); | ||
}); | ||
it('should escape " in label values', function() { | ||
register.registerMetric({ | ||
get: function() { | ||
return { | ||
name: 'test_metric', | ||
type: 'counter', | ||
help: 'A test metric', | ||
values: [ { | ||
value: 12, | ||
labels: { | ||
label: 'hello', | ||
code: '3"03' | ||
} | ||
}] | ||
}; | ||
} | ||
}); | ||
var escapedResult = register.metrics(); | ||
expect(escapedResult).to.match(/\\"/); | ||
}); | ||
function getMetric() { | ||
@@ -83,0 +101,0 @@ return { |
@@ -22,2 +22,7 @@ 'use strict'; | ||
it('should be able to observe 0s', function() { | ||
instance.observe(0); | ||
expect(instance.get().values[8].value).to.equal(1); | ||
}); | ||
it('should correctly calculate percentiles when more values are added to the summary', function() { | ||
@@ -24,0 +29,0 @@ instance.observe(100); |
Sorry, the diff of this file is not supported yet
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
Network access
Supply chain riskThis module accesses the network.
Found 2 instances 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
67365
2
6
1596
2
- Removedrequest@^2.69.0
- Removedajv@6.12.6(transitive)
- Removedasn1@0.2.6(transitive)
- Removedassert-plus@1.0.0(transitive)
- Removedasynckit@0.4.0(transitive)
- Removedaws-sign2@0.7.0(transitive)
- Removedaws4@1.13.2(transitive)
- Removedbcrypt-pbkdf@1.0.2(transitive)
- Removedcaseless@0.12.0(transitive)
- Removedcombined-stream@1.0.8(transitive)
- Removedcore-util-is@1.0.2(transitive)
- Removeddashdash@1.14.1(transitive)
- Removeddelayed-stream@1.0.0(transitive)
- Removedecc-jsbn@0.1.2(transitive)
- Removedextend@3.0.2(transitive)
- Removedextsprintf@1.3.0(transitive)
- Removedfast-deep-equal@3.1.3(transitive)
- Removedfast-json-stable-stringify@2.1.0(transitive)
- Removedforever-agent@0.6.1(transitive)
- Removedform-data@2.3.3(transitive)
- Removedgetpass@0.1.7(transitive)
- Removedhar-schema@2.0.0(transitive)
- Removedhar-validator@5.1.5(transitive)
- Removedhttp-signature@1.2.0(transitive)
- Removedis-typedarray@1.0.0(transitive)
- Removedisstream@0.1.2(transitive)
- Removedjsbn@0.1.1(transitive)
- Removedjson-schema@0.4.0(transitive)
- Removedjson-schema-traverse@0.4.1(transitive)
- Removedjson-stringify-safe@5.0.1(transitive)
- Removedjsprim@1.4.2(transitive)
- Removedmime-db@1.52.0(transitive)
- Removedmime-types@2.1.35(transitive)
- Removedoauth-sign@0.9.0(transitive)
- Removedperformance-now@2.1.0(transitive)
- Removedpsl@1.9.0(transitive)
- Removedpunycode@2.3.1(transitive)
- Removedqs@6.5.3(transitive)
- Removedrequest@2.88.2(transitive)
- Removedsafe-buffer@5.2.1(transitive)
- Removedsafer-buffer@2.1.2(transitive)
- Removedsshpk@1.18.0(transitive)
- Removedtough-cookie@2.5.0(transitive)
- Removedtunnel-agent@0.6.0(transitive)
- Removedtweetnacl@0.14.5(transitive)
- Removeduri-js@4.4.1(transitive)
- Removeduuid@3.4.0(transitive)
- Removedverror@1.10.0(transitive)