Prometheus: align exemplars check to latest api change (#32513)

This commit is contained in:
Zoltán Bedi 2021-03-30 19:34:08 +02:00 committed by GitHub
parent 37374bdecf
commit d8a83fec9d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 2 deletions

View File

@ -510,6 +510,20 @@ describe('Prometheus Result Transformer', () => {
expect(result[0].length).toBe(1); expect(result[0].length).toBe(1);
}); });
it('should return with an empty array when data is empty', () => {
const result = transform(
{
data: {
status: 'success',
data: [],
},
} as any,
options
);
expect(result).toHaveLength(0);
});
it('should remove exemplars that are too close to each other', () => { it('should remove exemplars that are too close to each other', () => {
const response = { const response = {
status: 'success', status: 'success',

View File

@ -63,7 +63,7 @@ export interface PromDataErrorResponse<T = PromData> {
data: T; data: T;
} }
export type PromData = PromMatrixData | PromVectorData | PromScalarData | PromExemplarData[] | null; export type PromData = PromMatrixData | PromVectorData | PromScalarData | PromExemplarData[];
export interface Labels { export interface Labels {
[index: string]: any; [index: string]: any;
@ -120,7 +120,7 @@ export function isExemplarData(result: PromData): result is PromExemplarData[] {
if (result == null || !Array.isArray(result)) { if (result == null || !Array.isArray(result)) {
return false; return false;
} }
return 'exemplars' in result[0]; return result.length ? 'exemplars' in result[0] : false;
} }
export type MatrixOrVectorResult = PromMatrixData['result'][0] | PromVectorData['result'][0]; export type MatrixOrVectorResult = PromMatrixData['result'][0] | PromVectorData['result'][0];