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
36f08994
Unverified
Commit
36f08994
authored
Jul 05, 2018
by
Alexander Zobnin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
prometheus heatmap: fix unhandled error when some points are missing
parent
240cf63b
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
48 additions
and
4 deletions
+48
-4
public/app/plugins/datasource/prometheus/result_transformer.ts
+14
-4
public/app/plugins/datasource/prometheus/specs/result_transformer.jest.ts
+30
-0
public/app/plugins/panel/heatmap/heatmap_ctrl.ts
+4
-0
No files found.
public/app/plugins/datasource/prometheus/result_transformer.ts
View file @
36f08994
...
...
@@ -28,15 +28,20 @@ export class ResultTransformer {
}
}
transformMetricData
(
m
d
,
options
,
start
,
end
)
{
transformMetricData
(
m
etricData
,
options
,
start
,
end
)
{
let
dps
=
[],
metricLabel
=
null
;
metricLabel
=
this
.
createMetricLabel
(
m
d
.
metric
,
options
);
metricLabel
=
this
.
createMetricLabel
(
m
etricData
.
metric
,
options
);
const
stepMs
=
parseInt
(
options
.
step
)
*
1000
;
let
baseTimestamp
=
start
*
1000
;
for
(
let
value
of
md
.
values
)
{
if
(
metricData
.
values
===
undefined
)
{
throw
new
Error
(
'Prometheus heatmap error: data should be a time series'
);
}
for
(
let
value
of
metricData
.
values
)
{
let
dp_value
=
parseFloat
(
value
[
1
]);
if
(
_
.
isNaN
(
dp_value
))
{
dp_value
=
null
;
...
...
@@ -164,8 +169,13 @@ export class ResultTransformer {
for
(
let
i
=
seriesList
.
length
-
1
;
i
>
0
;
i
--
)
{
let
topSeries
=
seriesList
[
i
].
datapoints
;
let
bottomSeries
=
seriesList
[
i
-
1
].
datapoints
;
if
(
!
topSeries
||
!
bottomSeries
)
{
throw
new
Error
(
'Prometheus heatmap transform error: data should be a time series'
);
}
for
(
let
j
=
0
;
j
<
topSeries
.
length
;
j
++
)
{
topSeries
[
j
][
0
]
-=
bottomSeries
[
j
][
0
];
const
bottomPoint
=
bottomSeries
[
j
]
||
[
0
];
topSeries
[
j
][
0
]
-=
bottomPoint
[
0
];
}
}
...
...
public/app/plugins/datasource/prometheus/specs/result_transformer.jest.ts
View file @
36f08994
...
...
@@ -126,6 +126,36 @@ describe('Prometheus Result Transformer', () => {
{
target
:
'3'
,
datapoints
:
[[
10
,
1445000010000
],
[
0
,
1445000020000
],
[
10
,
1445000030000
]]
},
]);
});
it
(
'should handle missing datapoints'
,
()
=>
{
const
seriesList
=
[
{
datapoints
:
[[
1
,
1000
],
[
2
,
2000
]]
},
{
datapoints
:
[[
2
,
1000
],
[
5
,
2000
],
[
1
,
3000
]]
},
{
datapoints
:
[[
3
,
1000
],
[
7
,
2000
]]
},
];
const
expected
=
[
{
datapoints
:
[[
1
,
1000
],
[
2
,
2000
]]
},
{
datapoints
:
[[
1
,
1000
],
[
3
,
2000
],
[
1
,
3000
]]
},
{
datapoints
:
[[
1
,
1000
],
[
2
,
2000
]]
},
];
const
result
=
ctx
.
resultTransformer
.
transformToHistogramOverTime
(
seriesList
);
expect
(
result
).
toEqual
(
expected
);
});
it
(
'should throw error when data in wrong format'
,
()
=>
{
const
seriesList
=
[{
rows
:
[]
},
{
datapoints
:
[]
}];
expect
(()
=>
{
ctx
.
resultTransformer
.
transformToHistogramOverTime
(
seriesList
);
}).
toThrow
();
});
it
(
'should throw error when prometheus returned non-timeseries'
,
()
=>
{
// should be { metric: {}, values: [] } for timeseries
const
metricData
=
{
metric
:
{},
value
:
[]
};
expect
(()
=>
{
ctx
.
resultTransformer
.
transformMetricData
(
metricData
,
{
step
:
1
},
1000
,
2000
);
}).
toThrow
();
});
});
describe
(
'When resultFormat is time series'
,
()
=>
{
...
...
public/app/plugins/panel/heatmap/heatmap_ctrl.ts
View file @
36f08994
...
...
@@ -302,6 +302,10 @@ export class HeatmapCtrl extends MetricsPanelCtrl {
}
seriesHandler
(
seriesData
)
{
if
(
seriesData
.
datapoints
===
undefined
)
{
throw
new
Error
(
'Heatmap error: data should be a time series'
);
}
let
series
=
new
TimeSeries
({
datapoints
:
seriesData
.
datapoints
,
alias
:
seriesData
.
target
,
...
...
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