Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
2926725b
Commit
2926725b
authored
May 01, 2018
by
Mitsuhiro Tanda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add annotation option to treat series value as timestamp
parent
e4496080
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
57 additions
and
3 deletions
+57
-3
public/app/plugins/datasource/prometheus/datasource.ts
+8
-2
public/app/plugins/datasource/prometheus/partials/annotations.editor.html
+10
-1
public/app/plugins/datasource/prometheus/specs/datasource.test.ts
+39
-0
No files found.
public/app/plugins/datasource/prometheus/datasource.ts
View file @
2926725b
...
...
@@ -487,15 +487,21 @@ export class PrometheusDatasource {
.value();
for (const value of series.values) {
if (value[1] === '
1
') {
const valueIsTrue = value[1] === '
1
'; // e.g. ALERTS
if (valueIsTrue || annotation.useValueForTime) {
const event = {
annotation: annotation,
time: Math.floor(parseFloat(value[0])) * 1000,
title: self.resultTransformer.renderTemplate(titleFormat, series.metric),
tags: tags,
text: self.resultTransformer.renderTemplate(textFormat, series.metric),
};
if (annotation.useValueForTime) {
event['
time
'] = Math.floor(parseFloat(value[1]));
} else {
event['
time
'] = Math.floor(parseFloat(value[0])) * 1000;
}
eventList.push(event);
}
}
...
...
public/app/plugins/datasource/prometheus/partials/annotations.editor.html
View file @
2926725b
...
...
@@ -10,7 +10,7 @@
</div>
<div
class=
"gf-form-group"
>
<h5
class=
"section-heading"
>
Field formats
</h
6
>
<h5
class=
"section-heading"
>
Field formats
</h
5
>
<div
class=
"gf-form-inline"
>
<div
class=
"gf-form"
>
<span
class=
"gf-form-label width-5"
>
Title
</span>
...
...
@@ -27,4 +27,13 @@
</div>
</div>
</div>
<h5
class=
"section-heading"
>
Other options
</h5>
<div
class=
"gf-form-inline"
>
<div
class=
"gf-form"
>
<gf-form-switch
class=
"gf-form"
label=
"Series value as timestamp"
label-class=
"width-14"
checked=
"ctrl.annotation.useValueForTime"
tooltip=
"The unit of timestamp is milliseconds. If the unit of the series value is seconds, multiply its range vector by 1000."
>
</gf-form-switch>
</div>
</div>
</div>
public/app/plugins/datasource/prometheus/specs/datasource.test.ts
View file @
2926725b
...
...
@@ -630,6 +630,45 @@ describe('PrometheusDatasource', () => {
expect(results[0].text).toBe('
testinstance
');
expect(results[0].time).toBe(123 * 1000);
});
it('
should
return
annotation
list
with
seriesValueAsTiemstamp
', () => {
const options = {
annotation: {
expr: '
timestamp_seconds
',
tagKeys: '
job
',
titleFormat: '
{{
job
}}
',
textFormat: '
{{
instance
}}
',
useValueForTime: true,
},
range: {
from: new Date('
2014
-
04
-
10
T05
:
20
:
10
Z
'),
to: new Date('
2014
-
05
-
20
T03
:
10
:
22
Z
'),
},
};
ctx.backendSrvMock.datasourceRequest.mockReturnValue(
Promise.resolve({
status: '
success
',
data: {
resultType: '
matrix
',
result: [
{
metric: {
__name__: '
timestamp_milliseconds
',
instance: '
testinstance
',
job: '
testjob
',
},
values: [[1443454528, '
1500000000000
']],
},
],
},
})
);
ctx.ds = new PrometheusDatasource(instanceSettings, q, ctx.backendSrvMock, ctx.templateSrvMock, ctx.timeSrvMock);
ctx.ds.annotationQuery(options).then(function (results) {
expect(results[0].time).toEqual(1500000000000);
ctx.backendSrvMock.datasourceRequest.mockReset();
});
});
});
describe('
When
resultFormat
is
table
and
instant
=
true
', () => {
...
...
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