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
e361a31a
Commit
e361a31a
authored
Feb 21, 2018
by
Alexander Zobnin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
prometheus: tests for heatmap format
parent
efa869bb
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
104 additions
and
0 deletions
+104
-0
public/app/plugins/datasource/prometheus/specs/datasource.jest.ts
+104
-0
No files found.
public/app/plugins/datasource/prometheus/specs/datasource.jest.ts
0 → 100644
View file @
e361a31a
import
_
from
'lodash'
;
import
moment
from
'moment'
;
import
q
from
'q'
;
import
{
PrometheusDatasource
}
from
'../datasource'
;
describe
(
'PrometheusDatasource'
,
()
=>
{
let
ctx
:
any
=
{};
let
instanceSettings
=
{
url
:
'proxied'
,
directUrl
:
'direct'
,
user
:
'test'
,
password
:
'mupp'
,
jsonData
:
{},
};
ctx
.
backendSrvMock
=
{};
ctx
.
templateSrvMock
=
{
replace
:
a
=>
a
,
};
ctx
.
timeSrvMock
=
{};
beforeEach
(()
=>
{
ctx
.
ds
=
new
PrometheusDatasource
(
instanceSettings
,
q
,
ctx
.
backendSrvMock
,
ctx
.
templateSrvMock
,
ctx
.
timeSrvMock
);
});
describe
(
'When converting prometheus histogram to heatmap format'
,
()
=>
{
beforeEach
(()
=>
{
ctx
.
query
=
{
range
:
{
from
:
moment
(
1443454528000
),
to
:
moment
(
1443454528000
)
},
targets
:
[{
expr
:
'test{job="testjob"}'
,
format
:
'heatmap'
,
legendFormat
:
'{{le}}'
}],
interval
:
'60s'
,
};
});
it
(
'should convert cumullative histogram to ordinary'
,
()
=>
{
const
resultMock
=
[
{
metric
:
{
__name__
:
'metric'
,
job
:
'testjob'
,
le
:
'10'
},
values
:
[[
1443454528.0
,
'10'
],
[
1443454528.0
,
'10'
]],
},
{
metric
:
{
__name__
:
'metric'
,
job
:
'testjob'
,
le
:
'20'
},
values
:
[[
1443454528.0
,
'20'
],
[
1443454528.0
,
'10'
]],
},
{
metric
:
{
__name__
:
'metric'
,
job
:
'testjob'
,
le
:
'30'
},
values
:
[[
1443454528.0
,
'25'
],
[
1443454528.0
,
'10'
]],
},
];
const
responseMock
=
{
data
:
{
data
:
{
result
:
resultMock
}
}
};
const
expected
=
[
{
target
:
'10'
,
datapoints
:
[[
10
,
1443454528000
],
[
10
,
1443454528000
]],
},
{
target
:
'20'
,
datapoints
:
[[
10
,
1443454528000
],
[
0
,
1443454528000
]],
},
{
target
:
'30'
,
datapoints
:
[[
5
,
1443454528000
],
[
0
,
1443454528000
]],
},
];
ctx
.
ds
.
performTimeSeriesQuery
=
jest
.
fn
().
mockReturnValue
(
responseMock
);
return
ctx
.
ds
.
query
(
ctx
.
query
).
then
(
result
=>
{
let
results
=
result
.
data
;
return
expect
(
results
).
toEqual
(
expected
);
});
});
it
(
'should sort series by label value'
,
()
=>
{
const
resultMock
=
[
{
metric
:
{
__name__
:
'metric'
,
job
:
'testjob'
,
le
:
'2'
},
values
:
[[
1443454528.0
,
'10'
],
[
1443454528.0
,
'10'
]],
},
{
metric
:
{
__name__
:
'metric'
,
job
:
'testjob'
,
le
:
'4'
},
values
:
[[
1443454528.0
,
'20'
],
[
1443454528.0
,
'10'
]],
},
{
metric
:
{
__name__
:
'metric'
,
job
:
'testjob'
,
le
:
'+Inf'
},
values
:
[[
1443454528.0
,
'25'
],
[
1443454528.0
,
'10'
]],
},
{
metric
:
{
__name__
:
'metric'
,
job
:
'testjob'
,
le
:
'1'
},
values
:
[[
1443454528.0
,
'25'
],
[
1443454528.0
,
'10'
]],
},
];
const
responseMock
=
{
data
:
{
data
:
{
result
:
resultMock
}
}
};
const
expected
=
[
'1'
,
'2'
,
'4'
,
'+Inf'
];
ctx
.
ds
.
performTimeSeriesQuery
=
jest
.
fn
().
mockReturnValue
(
responseMock
);
return
ctx
.
ds
.
query
(
ctx
.
query
).
then
(
result
=>
{
let
seriesLabels
=
_
.
map
(
result
.
data
,
'target'
);
return
expect
(
seriesLabels
).
toEqual
(
expected
);
});
});
});
});
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