mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Elasticsearch: Remove any type from elastic_response.test.ts
This commit is contained in:
@@ -6136,7 +6136,13 @@ exports[`better eslint`] = {
|
|||||||
"public/app/plugins/datasource/elasticsearch/hooks/useStatelessReducer.ts:5381": [
|
"public/app/plugins/datasource/elasticsearch/hooks/useStatelessReducer.ts:5381": [
|
||||||
[0, 0, 0, "Do not use any type assertions.", "0"]
|
[0, 0, 0, "Do not use any type assertions.", "0"]
|
||||||
],
|
],
|
||||||
"public/app/plugins/datasource/elasticsearch/specs/elastic_response.test.ts:5381": [
|
"public/app/plugins/datasource/elasticsearch/language_provider.ts:5381": [
|
||||||
|
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
|
||||||
|
[0, 0, 0, "Unexpected any. Specify a different type.", "1"],
|
||||||
|
[0, 0, 0, "Unexpected any. Specify a different type.", "2"],
|
||||||
|
[0, 0, 0, "Unexpected any. Specify a different type.", "3"]
|
||||||
|
],
|
||||||
|
"public/app/plugins/datasource/elasticsearch/query_builder.ts:5381": [
|
||||||
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
|
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
|
||||||
[0, 0, 0, "Unexpected any. Specify a different type.", "1"],
|
[0, 0, 0, "Unexpected any. Specify a different type.", "1"],
|
||||||
[0, 0, 0, "Unexpected any. Specify a different type.", "2"],
|
[0, 0, 0, "Unexpected any. Specify a different type.", "2"],
|
||||||
@@ -6152,9 +6158,20 @@ exports[`better eslint`] = {
|
|||||||
[0, 0, 0, "Unexpected any. Specify a different type.", "12"],
|
[0, 0, 0, "Unexpected any. Specify a different type.", "12"],
|
||||||
[0, 0, 0, "Unexpected any. Specify a different type.", "13"],
|
[0, 0, 0, "Unexpected any. Specify a different type.", "13"],
|
||||||
[0, 0, 0, "Unexpected any. Specify a different type.", "14"],
|
[0, 0, 0, "Unexpected any. Specify a different type.", "14"],
|
||||||
[0, 0, 0, "Unexpected any. Specify a different type.", "15"],
|
[0, 0, 0, "Do not use any type assertions.", "15"],
|
||||||
[0, 0, 0, "Unexpected any. Specify a different type.", "16"],
|
[0, 0, 0, "Unexpected any. Specify a different type.", "16"],
|
||||||
[0, 0, 0, "Unexpected any. Specify a different type.", "17"]
|
[0, 0, 0, "Unexpected any. Specify a different type.", "17"],
|
||||||
|
[0, 0, 0, "Unexpected any. Specify a different type.", "18"]
|
||||||
|
],
|
||||||
|
"public/app/plugins/datasource/elasticsearch/specs/query_builder.test.ts:5381": [
|
||||||
|
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
|
||||||
|
[0, 0, 0, "Unexpected any. Specify a different type.", "1"],
|
||||||
|
[0, 0, 0, "Unexpected any. Specify a different type.", "2"],
|
||||||
|
[0, 0, 0, "Unexpected any. Specify a different type.", "3"],
|
||||||
|
[0, 0, 0, "Unexpected any. Specify a different type.", "4"],
|
||||||
|
[0, 0, 0, "Unexpected any. Specify a different type.", "5"],
|
||||||
|
[0, 0, 0, "Unexpected any. Specify a different type.", "6"],
|
||||||
|
[0, 0, 0, "Unexpected any. Specify a different type.", "7"]
|
||||||
],
|
],
|
||||||
"public/app/plugins/datasource/elasticsearch/test-helpers/render.tsx:5381": [
|
"public/app/plugins/datasource/elasticsearch/test-helpers/render.tsx:5381": [
|
||||||
[0, 0, 0, "Do not use any type assertions.", "0"]
|
[0, 0, 0, "Do not use any type assertions.", "0"]
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { DataFrameView, FieldCache, KeyValue, MutableDataFrame } from '@grafana/data';
|
import { Column, DataFrameView, Field, FieldCache, KeyValue, MutableDataFrame } from '@grafana/data';
|
||||||
import flatten from 'app/core/utils/flatten';
|
import flatten from 'app/core/utils/flatten';
|
||||||
|
|
||||||
import { ElasticResponse } from '../elastic_response';
|
import { ElasticResponse } from '../elastic_response';
|
||||||
@@ -7,18 +7,18 @@ import { ElasticsearchQuery } from '../types';
|
|||||||
|
|
||||||
describe('ElasticResponse', () => {
|
describe('ElasticResponse', () => {
|
||||||
let targets: ElasticsearchQuery[];
|
let targets: ElasticsearchQuery[];
|
||||||
let response: any;
|
let response: {
|
||||||
let result: any;
|
responses: unknown[];
|
||||||
|
};
|
||||||
|
let result: {
|
||||||
|
data: MockedResultData[];
|
||||||
|
};
|
||||||
|
|
||||||
describe('refId matching', () => {
|
describe('refId matching', () => {
|
||||||
// We default to the old table structure to ensure backward compatibility,
|
// We default to the old table structure to ensure backward compatibility,
|
||||||
// therefore we only process responses as DataFrames when there's at least one
|
// therefore we only process responses as DataFrames when there's at least one
|
||||||
// raw_data (new) query type.
|
// raw_data (new) query type.
|
||||||
// We should test if refId gets populated wether there's such type of query or not
|
// We should test if refId gets populated wether there's such type of query or not
|
||||||
interface MockedQueryData {
|
|
||||||
target: ElasticsearchQuery;
|
|
||||||
response: any;
|
|
||||||
}
|
|
||||||
|
|
||||||
const countQuery: MockedQueryData = {
|
const countQuery: MockedQueryData = {
|
||||||
target: {
|
target: {
|
||||||
@@ -304,7 +304,9 @@ describe('ElasticResponse', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('simple query count & avg aggregation', () => {
|
describe('simple query count & avg aggregation', () => {
|
||||||
let result: any;
|
let result: {
|
||||||
|
data: MockedResultData[];
|
||||||
|
};
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
targets = [
|
targets = [
|
||||||
@@ -356,7 +358,9 @@ describe('ElasticResponse', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('single group by query one metric', () => {
|
describe('single group by query one metric', () => {
|
||||||
let result: any;
|
let result: {
|
||||||
|
data: MockedResultData[];
|
||||||
|
};
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
targets = [
|
targets = [
|
||||||
@@ -414,7 +418,9 @@ describe('ElasticResponse', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('single group by query two metrics', () => {
|
describe('single group by query two metrics', () => {
|
||||||
let result: any;
|
let result: {
|
||||||
|
data: MockedResultData[];
|
||||||
|
};
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
targets = [
|
targets = [
|
||||||
@@ -477,7 +483,9 @@ describe('ElasticResponse', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('with percentiles ', () => {
|
describe('with percentiles ', () => {
|
||||||
let result: any;
|
let result: {
|
||||||
|
data: MockedResultData[];
|
||||||
|
};
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
targets = [
|
targets = [
|
||||||
@@ -525,7 +533,9 @@ describe('ElasticResponse', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('with extended_stats', () => {
|
describe('with extended_stats', () => {
|
||||||
let result: any;
|
let result: {
|
||||||
|
data: MockedResultData[];
|
||||||
|
};
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
targets = [
|
targets = [
|
||||||
@@ -674,7 +684,9 @@ describe('ElasticResponse', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('single group by with alias pattern', () => {
|
describe('single group by with alias pattern', () => {
|
||||||
let result: any;
|
let result: {
|
||||||
|
data: MockedResultData[];
|
||||||
|
};
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
targets = [
|
targets = [
|
||||||
@@ -744,7 +756,9 @@ describe('ElasticResponse', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('histogram response', () => {
|
describe('histogram response', () => {
|
||||||
let result: any;
|
let result: {
|
||||||
|
data: MockedResultData[];
|
||||||
|
};
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
targets = [
|
targets = [
|
||||||
@@ -780,7 +794,9 @@ describe('ElasticResponse', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('with two filters agg', () => {
|
describe('with two filters agg', () => {
|
||||||
let result: any;
|
let result: {
|
||||||
|
data: MockedResultData[];
|
||||||
|
};
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
targets = [
|
targets = [
|
||||||
@@ -952,7 +968,9 @@ describe('ElasticResponse', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('No group by time with percentiles ', () => {
|
describe('No group by time with percentiles ', () => {
|
||||||
let result: any;
|
let result: {
|
||||||
|
data: MockedResultData[];
|
||||||
|
};
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
targets = [
|
targets = [
|
||||||
@@ -1047,6 +1065,9 @@ describe('ElasticResponse', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('Raw documents query', () => {
|
describe('Raw documents query', () => {
|
||||||
|
let result: {
|
||||||
|
data: Array<MockedResultData<{ [key: string]: string | undefined }>>;
|
||||||
|
};
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
targets = [
|
targets = [
|
||||||
{
|
{
|
||||||
@@ -1092,7 +1113,9 @@ describe('ElasticResponse', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('with bucket_script ', () => {
|
describe('with bucket_script ', () => {
|
||||||
let result: any;
|
let result: {
|
||||||
|
data: MockedResultData[];
|
||||||
|
};
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
targets = [
|
targets = [
|
||||||
@@ -1159,7 +1182,9 @@ describe('ElasticResponse', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('terms with bucket_script and two scripts', () => {
|
describe('terms with bucket_script and two scripts', () => {
|
||||||
let result: any;
|
let result: {
|
||||||
|
data: MockedResultData[];
|
||||||
|
};
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
targets = [
|
targets = [
|
||||||
@@ -1380,12 +1405,7 @@ describe('ElasticResponse', () => {
|
|||||||
expect(r._id).toEqual(response.responses[0].hits.hits[i]._id);
|
expect(r._id).toEqual(response.responses[0].hits.hits[i]._id);
|
||||||
expect(r._type).toEqual(response.responses[0].hits.hits[i]._type);
|
expect(r._type).toEqual(response.responses[0].hits.hits[i]._type);
|
||||||
expect(r._index).toEqual(response.responses[0].hits.hits[i]._index);
|
expect(r._index).toEqual(response.responses[0].hits.hits[i]._index);
|
||||||
expect(r._source).toEqual(
|
expect(r._source).toEqual(flatten(response.responses[0].hits.hits[i]._source));
|
||||||
flatten(
|
|
||||||
response.responses[0].hits.hits[i]._source,
|
|
||||||
null as unknown as { delimiter?: any; maxDepth?: any; safe?: any }
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make a map from the histogram results
|
// Make a map from the histogram results
|
||||||
@@ -1398,7 +1418,7 @@ describe('ElasticResponse', () => {
|
|||||||
hist[row.Time] = row.Value;
|
hist[row.Time] = row.Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
response.responses[0].aggregations['2'].buckets.forEach((bucket: any) => {
|
response.responses[0].aggregations['2'].buckets.forEach((bucket) => {
|
||||||
expect(hist[bucket.key]).toEqual(bucket.doc_count);
|
expect(hist[bucket.key]).toEqual(bucket.doc_count);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -1469,3 +1489,41 @@ describe('ElasticResponse', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
interface MockedElasticResponse {
|
||||||
|
aggregations?: {
|
||||||
|
[key: string]: {
|
||||||
|
buckets: Array<{
|
||||||
|
doc_count?: number;
|
||||||
|
key: string | number;
|
||||||
|
[key: string]: unknown;
|
||||||
|
}>;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
hits?: {
|
||||||
|
total: number;
|
||||||
|
hits: Array<{
|
||||||
|
_id?: string;
|
||||||
|
_type?: string;
|
||||||
|
_index?: string;
|
||||||
|
_source: { sourceProp: string };
|
||||||
|
fields: { fieldProp: string };
|
||||||
|
}>;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
interface MockedQueryData {
|
||||||
|
target: ElasticsearchQuery;
|
||||||
|
response: MockedElasticResponse;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface MockedResultData<T = number[]> {
|
||||||
|
refId: string;
|
||||||
|
target: string;
|
||||||
|
datapoints: T[];
|
||||||
|
type: string;
|
||||||
|
rows: number[][];
|
||||||
|
total: number;
|
||||||
|
fields: Field[];
|
||||||
|
columns: Column[];
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user