Skip to content

Commit

Permalink
prometheus: fix extends from query, ensuring array fields
Browse files Browse the repository at this point in the history
  • Loading branch information
andersonba committed Oct 29, 2019
1 parent b013550 commit 007e1af
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
2 changes: 2 additions & 0 deletions constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ module.exports = {
},

ignoreAssetPattern: /(^data:)/,

arrayParams: ['labels', 'internalPatterns', 'mimeTypes', 'mimeTypePatterns', 'ignorePatterns'],
};
5 changes: 4 additions & 1 deletion prometheus/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ const promClient = require('prom-client');
const { get } = require('lodash');
const Store = require('./store');
const Settings = require('./settings');
const constants = require('../constants');
const getMetrics = require('..');
const { env, parseLabelsParam } = require('./utils');
const { env, parseLabelsParam, ensureArrayParam } = require('./utils');

const store = new Store({
cacheTTL: Settings.onDemandQueryCacheTTL,
Expand Down Expand Up @@ -253,6 +254,8 @@ app.get(Settings.path, async (req, res, next) => {

if (!cached && store.busy) throw new Error('Ops.. Busy service!');

constants.arrayParams.forEach((p) => ensureArrayParam(req.query, p));

const config = { ...Settings.defaults, ...req.query };
config.url = req.query.url;
config.labels = parseLabelsParam(req.query.labels || []);
Expand Down
10 changes: 10 additions & 0 deletions prometheus/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,20 @@ function parseLabelsParam(arr) {
: {};
}

function ensureArrayParam(query, key) {
if (key in query) {
if (!isArray(query[key])) {
// eslint-disable-next-line no-param-reassign
query[key] = [query[key]];
}
}
}

module.exports = {
env,
envArray,
envBool,
envInt,
parseLabelsParam,
ensureArrayParam,
};

0 comments on commit 007e1af

Please sign in to comment.