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
9155f463
Unverified
Commit
9155f463
authored
Nov 05, 2020
by
Zoltán Bedi
Committed by
GitHub
Nov 05, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Prometheus: fix missing labels from value (#28842)
parent
574553ec
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
12 deletions
+52
-12
public/app/plugins/datasource/prometheus/result_transformer.test.ts
+27
-0
public/app/plugins/datasource/prometheus/result_transformer.ts
+25
-12
No files found.
public/app/plugins/datasource/prometheus/result_transformer.test.ts
View file @
9155f463
...
...
@@ -248,6 +248,33 @@ describe('Prometheus Result Transformer', () => {
});
describe
(
'When the response is a matrix'
,
()
=>
{
it
(
'should have labels with the value field'
,
()
=>
{
const
response
=
{
status
:
'success'
,
data
:
{
resultType
:
'matrix'
,
result
:
[
{
metric
:
{
__name__
:
'test'
,
job
:
'testjob'
,
instance
:
'testinstance'
},
values
:
[
[
0
,
'10'
],
[
1
,
'10'
],
[
2
,
'0'
],
],
},
],
},
};
const
result
:
DataFrame
[]
=
transform
({
data
:
response
}
as
any
,
{
...
options
,
});
expect
(
result
[
0
].
fields
[
1
].
labels
).
toBeDefined
();
expect
(
result
[
0
].
fields
[
1
].
labels
?.
instance
).
toBe
(
'testinstance'
);
expect
(
result
[
0
].
fields
[
1
].
labels
?.
job
).
toBe
(
'testjob'
);
});
it
(
'should transform into a data frame'
,
()
=>
{
const
response
=
{
status
:
'success'
,
...
...
public/app/plugins/datasource/prometheus/result_transformer.ts
View file @
9155f463
...
...
@@ -4,6 +4,7 @@ import {
Field
,
FieldType
,
formatLabels
,
Labels
,
MutableField
,
ScopedVars
,
TIME_SERIES_TIME_FIELD_NAME
,
...
...
@@ -71,7 +72,7 @@ export function transform(
meta
:
options
.
meta
,
refId
:
options
.
refId
,
length
:
1
,
fields
:
[
getTimeField
([
prometheusResult
.
result
]),
getValueField
(
[
prometheusResult
.
result
]
)],
fields
:
[
getTimeField
([
prometheusResult
.
result
]),
getValueField
(
{
data
:
[
prometheusResult
.
result
]
}
)],
},
];
}
...
...
@@ -109,7 +110,7 @@ function getPreferredVisualisationType(isInstantQuery?: boolean, mixedQueries?:
* Transforms matrix and vector result from Prometheus result to DataFrame
*/
function
transformToDataFrame
(
data
:
MatrixOrVectorResult
,
options
:
TransformOptions
):
DataFrame
{
const
{
name
}
=
createLabelInfo
(
data
.
metric
,
options
);
const
{
name
,
labels
}
=
createLabelInfo
(
data
.
metric
,
options
);
const
fields
:
Field
[]
=
[];
...
...
@@ -138,10 +139,10 @@ function transformToDataFrame(data: MatrixOrVectorResult, options: TransformOpti
dps
.
push
([
t
,
null
]);
}
fields
.
push
(
getTimeField
(
dps
,
true
));
fields
.
push
(
getValueField
(
dps
,
undefined
,
false
));
fields
.
push
(
getValueField
(
{
data
:
dps
,
parseValue
:
false
,
labels
,
displayName
:
name
}
));
}
else
{
fields
.
push
(
getTimeField
([
data
.
value
]));
fields
.
push
(
getValueField
(
[
data
.
value
]
));
fields
.
push
(
getValueField
(
{
data
:
[
data
.
value
],
labels
,
displayName
:
name
}
));
}
return
{
...
...
@@ -176,7 +177,7 @@ function transformMetricDataToTable(md: MatrixOrVectorResult[], options: Transfo
values
:
new
ArrayVector
(),
};
});
const
valueField
=
getValueField
(
[],
valueText
);
const
valueField
=
getValueField
(
{
data
:
[],
valueName
:
valueText
}
);
md
.
forEach
(
d
=>
{
if
(
isMatrixData
(
d
))
{
...
...
@@ -218,16 +219,28 @@ function getTimeField(data: PromValue[], isMs = false): MutableField {
values
:
new
ArrayVector
<
number
>
(
data
.
map
(
val
=>
(
isMs
?
val
[
0
]
:
val
[
0
]
*
1000
))),
};
}
function
getValueField
(
data
:
PromValue
[],
valueName
:
string
=
TIME_SERIES_VALUE_FIELD_NAME
,
parseValue
=
true
):
MutableField
{
type
ValueFieldOptions
=
{
data
:
PromValue
[];
valueName
?:
string
;
parseValue
?:
boolean
;
labels
?:
Labels
;
displayName
?:
string
;
};
function
getValueField
({
data
,
valueName
=
TIME_SERIES_VALUE_FIELD_NAME
,
parseValue
=
true
,
labels
,
displayName
,
}:
ValueFieldOptions
):
MutableField
{
return
{
name
:
valueName
,
type
:
FieldType
.
number
,
config
:
{},
config
:
{
displayName
,
},
labels
,
values
:
new
ArrayVector
<
number
|
null
>
(
data
.
map
(
val
=>
(
parseValue
?
parseSampleValue
(
val
[
1
])
:
val
[
1
]))),
};
}
...
...
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