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
dc608483
Unverified
Commit
dc608483
authored
Aug 21, 2018
by
Marcus Efraimsson
Committed by
GitHub
Aug 21, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #12876 from grafana/davkal/explore-rate-hinting
Explore: still show rate hint if query is complex
parents
c970e1e4
75db4d8e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
9 deletions
+39
-9
public/app/plugins/datasource/prometheus/datasource.ts
+15
-9
public/app/plugins/datasource/prometheus/specs/datasource.test.ts
+24
-0
No files found.
public/app/plugins/datasource/prometheus/datasource.ts
View file @
dc608483
...
...
@@ -110,10 +110,9 @@ export function determineQueryHints(series: any[], datasource?: any): any[] {
// Check for monotony
const
datapoints
:
[
number
,
number
][]
=
s
.
datapoints
;
const
simpleMetric
=
query
.
trim
().
match
(
/^
\w
+$/
);
if
(
simpleMetric
&&
datapoints
.
length
>
1
)
{
if
(
datapoints
.
length
>
1
)
{
let
increasing
=
false
;
const
monotonic
=
datapoints
.
every
((
dp
,
index
)
=>
{
const
monotonic
=
datapoints
.
filter
(
dp
=>
dp
[
0
]
!==
null
).
every
((
dp
,
index
)
=>
{
if
(
index
===
0
)
{
return
true
;
}
...
...
@@ -122,18 +121,25 @@ export function determineQueryHints(series: any[], datasource?: any): any[] {
return
dp
[
0
]
>=
datapoints
[
index
-
1
][
0
];
});
if
(
increasing
&&
monotonic
)
{
const
label
=
'Time series is monotonously increasing.'
;
return
{
label
,
index
,
fix
:
{
const
simpleMetric
=
query
.
trim
().
match
(
/^
\w
+$/
)
;
let
label
=
'Time series is monotonously increasing.'
;
let
fix
;
if
(
simpleMetric
)
{
fix
=
{
label
:
'Fix by adding rate().'
,
action
:
{
type
:
'ADD_RATE'
,
query
,
index
,
},
},
};
}
else
{
label
=
`
${
label
}
Try applying a rate() function.`
;
}
return
{
label
,
index
,
fix
,
};
}
}
...
...
public/app/plugins/datasource/prometheus/specs/datasource.test.ts
View file @
dc608483
...
...
@@ -213,6 +213,30 @@ describe('PrometheusDatasource', () => {
});
});
it
(
'returns a rate hint w/o action for a complex monotonously increasing series'
,
()
=>
{
const
series
=
[{
datapoints
:
[[
23
,
1000
],
[
24
,
1001
]],
query
:
'sum(metric)'
,
responseIndex
:
0
}];
const
hints
=
determineQueryHints
(
series
);
expect
(
hints
.
length
).
toBe
(
1
);
expect
(
hints
[
0
].
label
).
toContain
(
'rate()'
);
expect
(
hints
[
0
].
fix
).
toBeUndefined
();
});
it
(
'returns a rate hint for a monotonously increasing series with missing data'
,
()
=>
{
const
series
=
[{
datapoints
:
[[
23
,
1000
],
[
null
,
1001
],
[
24
,
1002
]],
query
:
'metric'
,
responseIndex
:
0
}];
const
hints
=
determineQueryHints
(
series
);
expect
(
hints
.
length
).
toBe
(
1
);
expect
(
hints
[
0
]).
toMatchObject
({
label
:
'Time series is monotonously increasing.'
,
index
:
0
,
fix
:
{
action
:
{
type
:
'ADD_RATE'
,
query
:
'metric'
,
},
},
});
});
it
(
'returns a histogram hint for a bucket series'
,
()
=>
{
const
series
=
[{
datapoints
:
[[
23
,
1000
]],
query
:
'metric_bucket'
,
responseIndex
:
0
}];
const
hints
=
determineQueryHints
(
series
);
...
...
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