Socket
Socket
Sign inDemoInstall

prom-client

Package Overview
Dependencies
Maintainers
1
Versions
84
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

prom-client - npm Package Compare versions

Comparing version 3.4.4 to 3.4.5

4

lib/histogram.js

@@ -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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc