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
8e771f9a
Unverified
Commit
8e771f9a
authored
Jan 15, 2019
by
Daniel Lee
Committed by
GitHub
Jan 15, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #14876 from grafana/davkal/14795-annotation-step
Prometheus: Fix annotation step calculation
parents
d907b1ec
ce311750
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
79 additions
and
4 deletions
+79
-4
public/app/plugins/datasource/prometheus/datasource.ts
+6
-4
public/app/plugins/datasource/prometheus/specs/datasource.test.ts
+73
-0
No files found.
public/app/plugins/datasource/prometheus/datasource.ts
View file @
8e771f9a
...
@@ -219,8 +219,9 @@ export class PrometheusDatasource {
...
@@ -219,8 +219,9 @@ export class PrometheusDatasource {
};
};
const range = Math.ceil(end - start);
const range = Math.ceil(end - start);
// options.interval is the dynamically calculated interval
let interval = kbn.interval_to_seconds(options.interval);
let interval = kbn.interval_to_seconds(options.interval);
// Minimum interval ("Min step"), if specified for the query. or same as interval otherwise
// Minimum interval ("Min step"), if specified for the query
or datasource
. or same as interval otherwise
const minInterval = kbn.interval_to_seconds(
const minInterval = kbn.interval_to_seconds(
this.templateSrv.replace(target.interval, options.scopedVars) || options.interval
this.templateSrv.replace(target.interval, options.scopedVars) || options.interval
);
);
...
@@ -366,12 +367,13 @@ export class PrometheusDatasource {
...
@@ -366,12 +367,13 @@ export class PrometheusDatasource {
const step = annotation.step || '
60
s
';
const step = annotation.step || '
60
s
';
const start = this.getPrometheusTime(options.range.from, false);
const start = this.getPrometheusTime(options.range.from, false);
const end = this.getPrometheusTime(options.range.to, true);
const end = this.getPrometheusTime(options.range.to, true);
// Unsetting min interval
const queryOptions = {
const queryOptions = {
...options,
...options,
interval:
'
0
s
'
,
interval:
step
,
};
};
const query = this.createQuery({ expr, interval: step }, queryOptions, start, end);
// Unsetting min interval for accurate event resolution
const minStep = '
1
s
';
const query = this.createQuery({ expr, interval: minStep }, queryOptions, start, end);
const self = this;
const self = this;
return this.performTimeSeriesQuery(query, query.start, query.end).then(results => {
return this.performTimeSeriesQuery(query, query.start, query.end).then(results => {
...
...
public/app/plugins/datasource/prometheus/specs/datasource.test.ts
View file @
8e771f9a
...
@@ -577,6 +577,79 @@ describe('PrometheusDatasource', () => {
...
@@ -577,6 +577,79 @@ describe('PrometheusDatasource', () => {
expect(results[0].time).toEqual(1);
expect(results[0].time).toEqual(1);
});
});
});
});
describe('
step
parameter
', () => {
beforeEach(() => {
backendSrv.datasourceRequest = jest.fn(() => Promise.resolve(response));
ctx.ds = new PrometheusDatasource(instanceSettings, q, backendSrv as any, templateSrv, timeSrv);
});
it('
should
use
default
step
for
short
range
if
no
interval
is
given
', () => {
const query = {
...options,
range: {
from: time({ seconds: 63 }),
to: time({ seconds: 123 }),
},
};
ctx.ds.annotationQuery(query);
const req = backendSrv.datasourceRequest.mock.calls[0][0];
expect(req.url).toContain('
step
=
60
');
});
it('
should
use
custom
step
for
short
range
', () => {
const annotation = {
...options.annotation,
step: '
10
s
',
};
const query = {
...options,
annotation,
range: {
from: time({ seconds: 63 }),
to: time({ seconds: 123 }),
},
};
ctx.ds.annotationQuery(query);
const req = backendSrv.datasourceRequest.mock.calls[0][0];
expect(req.url).toContain('
step
=
10
');
});
it('
should
use
custom
step
for
short
range
', () => {
const annotation = {
...options.annotation,
step: '
10
s
',
};
const query = {
...options,
annotation,
range: {
from: time({ seconds: 63 }),
to: time({ seconds: 123 }),
},
};
ctx.ds.annotationQuery(query);
const req = backendSrv.datasourceRequest.mock.calls[0][0];
expect(req.url).toContain('
step
=
10
');
});
it('
should
use
dynamic
step
on
long
ranges
if
no
option
was
given
', () => {
const query = {
...options,
range: {
from: time({ seconds: 63 }),
to: time({ hours: 24 * 30, seconds: 63 }),
},
};
ctx.ds.annotationQuery(query);
const req = backendSrv.datasourceRequest.mock.calls[0][0];
// Range in seconds: (to - from) / 1000
// Max_datapints: 11000
// Step: range / max_datapints
const step = 236;
expect(req.url).toContain(`step=${step}`);
});
});
});
});
describe('
When
resultFormat
is
table
and
instant
=
true
', () => {
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