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
0427df8f
Unverified
Commit
0427df8f
authored
Feb 02, 2021
by
Ivana Huckova
Committed by
GitHub
Feb 02, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Prometheus: Set type of labels to string (#30831)
parent
99acad44
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
2 deletions
+11
-2
public/app/plugins/datasource/prometheus/result_transformer.test.ts
+7
-1
public/app/plugins/datasource/prometheus/result_transformer.ts
+4
-1
No files found.
public/app/plugins/datasource/prometheus/result_transformer.test.ts
View file @
0427df8f
import
{
DataFrame
}
from
'@grafana/data'
;
import
{
DataFrame
,
FieldType
}
from
'@grafana/data'
;
import
{
transform
}
from
'./result_transformer'
;
jest
.
mock
(
'@grafana/runtime'
,
()
=>
({
...
...
@@ -101,15 +101,20 @@ describe('Prometheus Result Transformer', () => {
1443454531000
,
]);
expect
(
result
[
0
].
fields
[
0
].
name
).
toBe
(
'Time'
);
expect
(
result
[
0
].
fields
[
0
].
type
).
toBe
(
FieldType
.
time
);
expect
(
result
[
0
].
fields
[
1
].
values
.
toArray
()).
toEqual
([
'test'
,
'test'
,
'test2'
,
'test2'
]);
expect
(
result
[
0
].
fields
[
1
].
name
).
toBe
(
'__name__'
);
expect
(
result
[
0
].
fields
[
1
].
config
.
filterable
).
toBe
(
true
);
expect
(
result
[
0
].
fields
[
1
].
type
).
toBe
(
FieldType
.
string
);
expect
(
result
[
0
].
fields
[
2
].
values
.
toArray
()).
toEqual
([
''
,
''
,
'localhost:8080'
,
'localhost:8080'
]);
expect
(
result
[
0
].
fields
[
2
].
name
).
toBe
(
'instance'
);
expect
(
result
[
0
].
fields
[
2
].
type
).
toBe
(
FieldType
.
string
);
expect
(
result
[
0
].
fields
[
3
].
values
.
toArray
()).
toEqual
([
'testjob'
,
'testjob'
,
'otherjob'
,
'otherjob'
]);
expect
(
result
[
0
].
fields
[
3
].
name
).
toBe
(
'job'
);
expect
(
result
[
0
].
fields
[
3
].
type
).
toBe
(
FieldType
.
string
);
expect
(
result
[
0
].
fields
[
4
].
values
.
toArray
()).
toEqual
([
3846
,
3848
,
3847
,
3849
]);
expect
(
result
[
0
].
fields
[
4
].
name
).
toEqual
(
'Value'
);
expect
(
result
[
0
].
fields
[
4
].
type
).
toBe
(
FieldType
.
number
);
expect
(
result
[
0
].
refId
).
toBe
(
'A'
);
});
...
...
@@ -168,6 +173,7 @@ describe('Prometheus Result Transformer', () => {
};
const
result
=
transform
({
data
:
response
}
as
any
,
{
...
options
,
target
:
{
format
:
'table'
}
});
expect
(
result
[
0
].
fields
[
1
].
values
.
toArray
()).
toEqual
([
102
]);
expect
(
result
[
0
].
fields
[
1
].
type
).
toEqual
(
FieldType
.
number
);
});
});
...
...
public/app/plugins/datasource/prometheus/result_transformer.ts
View file @
0427df8f
...
...
@@ -299,10 +299,13 @@ function transformMetricDataToTable(md: MatrixOrVectorResult[], options: Transfo
const metricFields = Object.keys(md.reduce((acc, series) => ({ ...acc, ...series.metric }), {}))
.sort()
.map((label) => {
// Labels have string field type, otherwise table tries to figure out the type which can result in unexpected results
// Only "le" label has a number field type
const numberField = label === 'le';
return {
name: label,
config: { filterable: true },
type:
FieldType.other
,
type:
numberField ? FieldType.number : FieldType.string
,
values: new ArrayVector(),
};
});
...
...
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