Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
06b54d87
Commit
06b54d87
authored
Nov 15, 2019
by
Tristan Read
Committed by
Tim Zallmann
Nov 15, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix Grafana chart label templates
parent
1f3f923a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
6 deletions
+18
-6
app/assets/javascripts/helpers/monitor_helper.js
app/assets/javascripts/helpers/monitor_helper.js
+7
-6
spec/frontend/helpers/monitor_helper_spec.js
spec/frontend/helpers/monitor_helper_spec.js
+11
-0
No files found.
app/assets/javascripts/helpers/monitor_helper.js
View file @
06b54d87
/* eslint-disable import/prefer-default-export */
import
_
from
'
underscore
'
;
/**
* @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
.
map
(
result
=>
{
...
...
@@ -19,10 +17,13 @@ export const makeDataSeries = (queryResults, defaultConfig) =>
if
(
name
)
{
series
.
name
=
`
${
defaultConfig
.
name
}
:
${
name
}
`
;
}
else
{
const
template
=
_
.
template
(
defaultConfig
.
name
,
{
interpolate
:
/
\{\{(
.+
?)\}\}
/g
,
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
);
});
series
.
name
=
template
(
result
.
metric
);
}
return
{
...
defaultConfig
,
...
series
};
...
...
spec/frontend/helpers/monitor_helper_spec.js
View file @
06b54d87
...
...
@@ -81,6 +81,17 @@ describe('monitor helper', () => {
expect
(
result
.
name
).
toEqual
(
'
brpop, brpop
'
);
});
it
(
'
supports hyphenated template variables
'
,
()
=>
{
const
config
=
{
...
defaultConfig
,
name
:
'
expired - {{ test-attribute }}
'
};
const
[
result
]
=
monitorHelper
.
makeDataSeries
(
[{
metric
:
{
'
test-attribute
'
:
'
test-attribute-value
'
},
values
:
series
}],
config
,
);
expect
(
result
.
name
).
toEqual
(
'
expired - test-attribute-value
'
);
});
it
(
'
updates multiple series names from templates
'
,
()
=>
{
const
config
=
{
...
defaultConfig
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment