summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/helpers/monitor_helper.js
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-11-19 22:11:55 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2019-11-19 22:11:55 +0000
commit5a8431feceba47fd8e1804d9aa1b1730606b71d5 (patch)
treee5df8e0ceee60f4af8093f5c4c2f934b8abced05 /app/assets/javascripts/helpers/monitor_helper.js
parent4d477238500c347c6553d335d920bedfc5a46869 (diff)
downloadgitlab-ce-5a8431feceba47fd8e1804d9aa1b1730606b71d5.tar.gz
Add latest changes from gitlab-org/gitlab@12-5-stable-ee
Diffstat (limited to 'app/assets/javascripts/helpers/monitor_helper.js')
-rw-r--r--app/assets/javascripts/helpers/monitor_helper.js44
1 files changed, 29 insertions, 15 deletions
diff --git a/app/assets/javascripts/helpers/monitor_helper.js b/app/assets/javascripts/helpers/monitor_helper.js
index 2c2a04d5b5e..d172aa8a444 100644
--- a/app/assets/javascripts/helpers/monitor_helper.js
+++ b/app/assets/javascripts/helpers/monitor_helper.js
@@ -1,17 +1,31 @@
-/* eslint-disable import/prefer-default-export */
-
+/**
+ * @param {Array} queryResults - Array of Result objects
+ * @param {Object} defaultConfig - Default chart config values (e.g. lineStyle, name)
+ * @returns {Array} The formatted values
+ */
+// eslint-disable-next-line import/prefer-default-export
export const makeDataSeries = (queryResults, defaultConfig) =>
- queryResults.reduce((acc, result) => {
- const data = result.values.filter(([, value]) => !Number.isNaN(value));
- if (!data.length) {
- return acc;
- }
- const relevantMetric = defaultConfig.name.toLowerCase().replace(' ', '_');
- const name = result.metric[relevantMetric];
- const series = { data };
- if (name) {
- series.name = `${defaultConfig.name}: ${name}`;
- }
+ queryResults
+ .map(result => {
+ const data = result.values.filter(([, value]) => !Number.isNaN(value));
+ if (!data.length) {
+ return null;
+ }
+ const relevantMetric = defaultConfig.name.toLowerCase().replace(' ', '_');
+ const name = result.metric[relevantMetric];
+ const series = { data };
+ if (name) {
+ series.name = `${defaultConfig.name}: ${name}`;
+ } else {
+ series.name = defaultConfig.name;
+ Object.keys(result.metric).forEach(templateVar => {
+ const value = result.metric[templateVar];
+ const regex = new RegExp(`{{\\s*${templateVar}\\s*}}`, 'g');
+
+ series.name = series.name.replace(regex, value);
+ });
+ }
- return acc.concat({ ...defaultConfig, ...series });
- }, []);
+ return { ...defaultConfig, ...series };
+ })
+ .filter(series => series !== null);