mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Elasticsearch: remove already-disabled code (#52932)
* elastic: removed unused code from go-part * elastic: removed unused code from js-part
This commit is contained in:
@@ -87,7 +87,7 @@ describe('Metric Editor', () => {
|
||||
});
|
||||
|
||||
describe('Top Metrics Aggregation', () => {
|
||||
const setupTopMetricsScreen = (esVersion: string, xpack: boolean) => {
|
||||
const setupTopMetricsScreen = (xpack: boolean) => {
|
||||
const query: ElasticsearchQuery = {
|
||||
refId: 'A',
|
||||
query: '',
|
||||
@@ -97,6 +97,8 @@ describe('Metric Editor', () => {
|
||||
|
||||
const getFields: ElasticDatasource['getFields'] = jest.fn(() => from([[]]));
|
||||
|
||||
const esVersion = '7.7.0';
|
||||
|
||||
const wrapper = ({ children }: { children?: ReactNode }) => (
|
||||
<ElasticsearchProvider
|
||||
datasource={{ getFields, esVersion, xpack } as ElasticDatasource}
|
||||
@@ -116,18 +118,13 @@ describe('Metric Editor', () => {
|
||||
});
|
||||
};
|
||||
|
||||
it('Should include top metrics aggregation when esVersion is 77 and X-Pack is enabled', () => {
|
||||
setupTopMetricsScreen('7.7.0', true);
|
||||
it('Should include top metrics aggregation when X-Pack is enabled', () => {
|
||||
setupTopMetricsScreen(true);
|
||||
expect(screen.getByText('Top Metrics')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('Should NOT include top metrics aggregation where esVersion is 77 and X-Pack is disabled', () => {
|
||||
setupTopMetricsScreen('7.7.0', false);
|
||||
expect(screen.queryByText('Top Metrics')).toBe(null);
|
||||
});
|
||||
|
||||
it('Should NOT include top metrics aggregation when esVersion is 70 and X-Pack is enabled', () => {
|
||||
setupTopMetricsScreen('7.0.0', true);
|
||||
it('Should NOT include top metrics aggregation where X-Pack is disabled', () => {
|
||||
setupTopMetricsScreen(false);
|
||||
expect(screen.queryByText('Top Metrics')).toBe(null);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -113,7 +113,7 @@ export const metricAggregationConfig: MetricsConfiguration = {
|
||||
label: 'Moving Average',
|
||||
requiresField: true,
|
||||
isPipelineAgg: true,
|
||||
versionRange: '>=2.0.0 <8.0.0',
|
||||
versionRange: '<8.0.0',
|
||||
supportsMissing: false,
|
||||
supportsMultipleBucketPaths: false,
|
||||
hasSettings: true,
|
||||
@@ -136,14 +136,12 @@ export const metricAggregationConfig: MetricsConfiguration = {
|
||||
supportsMissing: false,
|
||||
hasMeta: false,
|
||||
hasSettings: true,
|
||||
versionRange: '>=7.0.0',
|
||||
defaults: {},
|
||||
},
|
||||
derivative: {
|
||||
label: 'Derivative',
|
||||
requiresField: true,
|
||||
isPipelineAgg: true,
|
||||
versionRange: '>=2.0.0',
|
||||
supportsMissing: false,
|
||||
supportsMultipleBucketPaths: false,
|
||||
hasSettings: true,
|
||||
@@ -155,7 +153,6 @@ export const metricAggregationConfig: MetricsConfiguration = {
|
||||
label: 'Serial Difference',
|
||||
requiresField: true,
|
||||
isPipelineAgg: true,
|
||||
versionRange: '>=2.0.0',
|
||||
supportsMissing: false,
|
||||
supportsMultipleBucketPaths: false,
|
||||
hasSettings: true,
|
||||
@@ -171,7 +168,6 @@ export const metricAggregationConfig: MetricsConfiguration = {
|
||||
label: 'Cumulative Sum',
|
||||
requiresField: true,
|
||||
isPipelineAgg: true,
|
||||
versionRange: '>=2.0.0',
|
||||
supportsMissing: false,
|
||||
supportsMultipleBucketPaths: false,
|
||||
hasSettings: true,
|
||||
@@ -185,7 +181,6 @@ export const metricAggregationConfig: MetricsConfiguration = {
|
||||
isPipelineAgg: true,
|
||||
supportsMissing: false,
|
||||
supportsMultipleBucketPaths: true,
|
||||
versionRange: '>=2.0.0',
|
||||
hasSettings: true,
|
||||
supportsInlineScript: false,
|
||||
hasMeta: false,
|
||||
@@ -250,7 +245,6 @@ export const metricAggregationConfig: MetricsConfiguration = {
|
||||
supportsMultipleBucketPaths: false,
|
||||
hasSettings: true,
|
||||
supportsInlineScript: false,
|
||||
versionRange: '>=7.7.0',
|
||||
hasMeta: false,
|
||||
defaults: {
|
||||
settings: {
|
||||
@@ -261,7 +255,6 @@ export const metricAggregationConfig: MetricsConfiguration = {
|
||||
rate: {
|
||||
label: 'Rate',
|
||||
xpack: true,
|
||||
versionRange: '>=7.10.0',
|
||||
requiresField: true,
|
||||
isPipelineAgg: false,
|
||||
supportsMissing: false,
|
||||
|
||||
@@ -35,7 +35,7 @@ describe('ConfigEditor', () => {
|
||||
onOptionsChange={(options) => {
|
||||
expect(options.jsonData.esVersion).toBe('5.0.0');
|
||||
expect(options.jsonData.timeField).toBe('@timestamp');
|
||||
expect(options.jsonData.maxConcurrentShardRequests).toBe(256);
|
||||
expect(options.jsonData.maxConcurrentShardRequests).toBe(5);
|
||||
}}
|
||||
options={options}
|
||||
/>
|
||||
|
||||
@@ -7,15 +7,10 @@ import { createDefaultConfigOptions } from './mocks';
|
||||
|
||||
describe('ElasticDetails', () => {
|
||||
describe('Max concurrent Shard Requests', () => {
|
||||
it('should render "Max concurrent Shard Requests" if version >= 5.6.0', () => {
|
||||
render(<ElasticDetails onChange={() => {}} value={createDefaultConfigOptions({ esVersion: '5.6.0' })} />);
|
||||
it('should render "Max concurrent Shard Requests" ', () => {
|
||||
render(<ElasticDetails onChange={() => {}} value={createDefaultConfigOptions({ esVersion: '8.2.0' })} />);
|
||||
expect(screen.getByLabelText('Max concurrent Shard Requests')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('should not render "Max concurrent Shard Requests" if version < 5.6.0', () => {
|
||||
render(<ElasticDetails onChange={() => {}} value={createDefaultConfigOptions({ esVersion: '5.0.0' })} />);
|
||||
expect(screen.queryByLabelText('Max concurrent Shard Requests')).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
it('should change database on interval change when not set explicitly', async () => {
|
||||
@@ -51,31 +46,29 @@ describe('ElasticDetails', () => {
|
||||
});
|
||||
|
||||
describe('version change', () => {
|
||||
const testCases = [{ version: '7.10+', maxConcurrentShardRequests: 6, expectedMaxConcurrentShardRequests: 6 }];
|
||||
const tc = { version: '7.10+', maxConcurrentShardRequests: 6, expectedMaxConcurrentShardRequests: 6 };
|
||||
|
||||
testCases.forEach((tc) => {
|
||||
const onChangeMock = jest.fn();
|
||||
it(`sets maxConcurrentShardRequests=${tc.expectedMaxConcurrentShardRequests} if version=${tc.version},`, async () => {
|
||||
render(
|
||||
<ElasticDetails
|
||||
onChange={onChangeMock}
|
||||
value={createDefaultConfigOptions({
|
||||
maxConcurrentShardRequests: tc.maxConcurrentShardRequests,
|
||||
esVersion: '7.0.0',
|
||||
})}
|
||||
/>
|
||||
);
|
||||
const onChangeMock = jest.fn();
|
||||
it(`sets maxConcurrentShardRequests=${tc.expectedMaxConcurrentShardRequests} if version=${tc.version},`, async () => {
|
||||
render(
|
||||
<ElasticDetails
|
||||
onChange={onChangeMock}
|
||||
value={createDefaultConfigOptions({
|
||||
maxConcurrentShardRequests: tc.maxConcurrentShardRequests,
|
||||
esVersion: '7.0.0',
|
||||
})}
|
||||
/>
|
||||
);
|
||||
|
||||
const selectEl = screen.getByLabelText('ElasticSearch version');
|
||||
const selectEl = screen.getByLabelText('ElasticSearch version');
|
||||
|
||||
await selectEvent.select(selectEl, tc.version, { container: document.body });
|
||||
await selectEvent.select(selectEl, tc.version, { container: document.body });
|
||||
|
||||
expect(onChangeMock).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
jsonData: expect.objectContaining({ maxConcurrentShardRequests: tc.expectedMaxConcurrentShardRequests }),
|
||||
})
|
||||
);
|
||||
});
|
||||
expect(onChangeMock).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
jsonData: expect.objectContaining({ maxConcurrentShardRequests: tc.expectedMaxConcurrentShardRequests }),
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import React from 'react';
|
||||
import { gte, lt, valid } from 'semver';
|
||||
import { valid } from 'semver';
|
||||
|
||||
import { DataSourceSettings, SelectableValue } from '@grafana/data';
|
||||
import { FieldSet, InlineField, Input, Select, InlineSwitch } from '@grafana/ui';
|
||||
@@ -82,8 +82,7 @@ export const ElasticDetails = ({ value, onChange }: Props) => {
|
||||
options={[customOption, ...esVersions].filter(isTruthy)}
|
||||
onChange={(option) => {
|
||||
const maxConcurrentShardRequests = getMaxConcurrenShardRequestOrDefault(
|
||||
value.jsonData.maxConcurrentShardRequests,
|
||||
option.value!
|
||||
value.jsonData.maxConcurrentShardRequests
|
||||
);
|
||||
onChange({
|
||||
...value,
|
||||
@@ -99,16 +98,14 @@ export const ElasticDetails = ({ value, onChange }: Props) => {
|
||||
/>
|
||||
</InlineField>
|
||||
|
||||
{gte(value.jsonData.esVersion, '5.6.0') && (
|
||||
<InlineField label="Max concurrent Shard Requests" labelWidth={26}>
|
||||
<Input
|
||||
id="es_config_shardRequests"
|
||||
value={value.jsonData.maxConcurrentShardRequests || ''}
|
||||
onChange={jsonDataChangeHandler('maxConcurrentShardRequests', value, onChange)}
|
||||
width={24}
|
||||
/>
|
||||
</InlineField>
|
||||
)}
|
||||
<InlineField label="Max concurrent Shard Requests" labelWidth={26}>
|
||||
<Input
|
||||
id="es_config_shardRequests"
|
||||
value={value.jsonData.maxConcurrentShardRequests || ''}
|
||||
onChange={jsonDataChangeHandler('maxConcurrentShardRequests', value, onChange)}
|
||||
width={24}
|
||||
/>
|
||||
</InlineField>
|
||||
|
||||
<InlineField
|
||||
label="Min time interval"
|
||||
@@ -139,7 +136,7 @@ export const ElasticDetails = ({ value, onChange }: Props) => {
|
||||
/>
|
||||
</InlineField>
|
||||
|
||||
{gte(value.jsonData.esVersion, '6.6.0') && value.jsonData.xpack && (
|
||||
{value.jsonData.xpack && (
|
||||
<InlineField label="Include Frozen Indices" labelWidth={26}>
|
||||
<InlineSwitch
|
||||
id="es_config_frozenIndices"
|
||||
@@ -224,18 +221,14 @@ const intervalHandler =
|
||||
}
|
||||
};
|
||||
|
||||
function getMaxConcurrenShardRequestOrDefault(maxConcurrentShardRequests: number | undefined, version: string): number {
|
||||
if (maxConcurrentShardRequests === 5 && lt(version, '7.0.0')) {
|
||||
return 256;
|
||||
}
|
||||
|
||||
if (maxConcurrentShardRequests === 256 && gte(version, '7.0.0')) {
|
||||
function getMaxConcurrenShardRequestOrDefault(maxConcurrentShardRequests: number | undefined): number {
|
||||
if (maxConcurrentShardRequests === 256) {
|
||||
return 5;
|
||||
}
|
||||
|
||||
return maxConcurrentShardRequests || defaultMaxConcurrentShardRequests(version);
|
||||
return maxConcurrentShardRequests || defaultMaxConcurrentShardRequests();
|
||||
}
|
||||
|
||||
export function defaultMaxConcurrentShardRequests(version: string) {
|
||||
return gte(version, '7.0.0') ? 5 : 256;
|
||||
export function defaultMaxConcurrentShardRequests() {
|
||||
return 5;
|
||||
}
|
||||
|
||||
@@ -18,8 +18,7 @@ export const coerceOptions = (
|
||||
...options.jsonData,
|
||||
timeField: options.jsonData.timeField || '@timestamp',
|
||||
esVersion,
|
||||
maxConcurrentShardRequests:
|
||||
options.jsonData.maxConcurrentShardRequests || defaultMaxConcurrentShardRequests(esVersion),
|
||||
maxConcurrentShardRequests: options.jsonData.maxConcurrentShardRequests || defaultMaxConcurrentShardRequests(),
|
||||
logMessageField: options.jsonData.logMessageField || '',
|
||||
logLevelField: options.jsonData.logLevelField || '',
|
||||
includeFrozen: options.jsonData.includeFrozen ?? false,
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { cloneDeep, find, first as _first, isNumber, isObject, isString, map as _map } from 'lodash';
|
||||
import { generate, lastValueFrom, Observable, of, throwError } from 'rxjs';
|
||||
import { catchError, first, map, mergeMap, skipWhile, throwIfEmpty } from 'rxjs/operators';
|
||||
import { gte, lt, satisfies } from 'semver';
|
||||
|
||||
import {
|
||||
DataFrame,
|
||||
@@ -113,7 +112,6 @@ export class ElasticDatasource
|
||||
this.maxConcurrentShardRequests = settingsData.maxConcurrentShardRequests;
|
||||
this.queryBuilder = new ElasticQueryBuilder({
|
||||
timeField: this.timeField,
|
||||
esVersion: this.esVersion,
|
||||
});
|
||||
this.logMessageField = settingsData.logMessageField || '';
|
||||
this.logLevelField = settingsData.logLevelField || '';
|
||||
@@ -297,11 +295,6 @@ export class ElasticDatasource
|
||||
size: 10000,
|
||||
};
|
||||
|
||||
// fields field not supported on ES 5.x
|
||||
if (lt(this.esVersion, '5.0.0')) {
|
||||
data['fields'] = [timeField, '_source'];
|
||||
}
|
||||
|
||||
const header: any = {
|
||||
search_type: 'query_then_fetch',
|
||||
ignore_unavailable: true,
|
||||
@@ -461,10 +454,6 @@ export class ElasticDatasource
|
||||
index: this.indexPattern.getIndexList(timeFrom, timeTo),
|
||||
};
|
||||
|
||||
if (satisfies(this.esVersion, '>=5.6.0 <7.0.0')) {
|
||||
queryHeader['max_concurrent_shard_requests'] = this.maxConcurrentShardRequests;
|
||||
}
|
||||
|
||||
return JSON.stringify(queryHeader);
|
||||
}
|
||||
|
||||
@@ -519,13 +508,8 @@ export class ElasticDatasource
|
||||
return text;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method checks to ensure the user is running a 5.0+ cluster. This is
|
||||
* necessary bacause the query being used for the getLogRowContext relies on the
|
||||
* search_after feature.
|
||||
*/
|
||||
showContextToggle(): boolean {
|
||||
return gte(this.esVersion, '5.0.0');
|
||||
return true;
|
||||
}
|
||||
|
||||
getLogRowContext = async (row: LogRowModel, options?: RowContextOptions): Promise<{ data: DataFrame[] }> => {
|
||||
@@ -687,7 +671,7 @@ export class ElasticDatasource
|
||||
|
||||
const esQuery = JSON.stringify(queryObj);
|
||||
|
||||
const searchType = queryObj.size === 0 && lt(this.esVersion, '5.0.0') ? 'count' : 'query_then_fetch';
|
||||
const searchType = 'query_then_fetch';
|
||||
const header = this.getQueryHeader(searchType, options.range.from, options.range.to);
|
||||
payload += header + '\n';
|
||||
|
||||
@@ -804,15 +788,8 @@ export class ElasticDatasource
|
||||
if (index && index.mappings) {
|
||||
const mappings = index.mappings;
|
||||
|
||||
if (lt(this.esVersion, '7.0.0')) {
|
||||
for (const typeName in mappings) {
|
||||
const properties = mappings[typeName].properties;
|
||||
getFieldsRecursively(properties);
|
||||
}
|
||||
} else {
|
||||
const properties = mappings.properties;
|
||||
getFieldsRecursively(properties);
|
||||
}
|
||||
const properties = mappings.properties;
|
||||
getFieldsRecursively(properties);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -825,7 +802,7 @@ export class ElasticDatasource
|
||||
}
|
||||
|
||||
getTerms(queryDef: TermsQuery, range = getDefaultTimeRange()): Observable<MetricFindValue[]> {
|
||||
const searchType = gte(this.esVersion, '5.0.0') ? 'query_then_fetch' : 'count';
|
||||
const searchType = 'query_then_fetch';
|
||||
const header = this.getQueryHeader(searchType, range.from, range.to);
|
||||
let esQuery = JSON.stringify(this.queryBuilder.getTermsQuery(queryDef));
|
||||
|
||||
@@ -855,11 +832,11 @@ export class ElasticDatasource
|
||||
getMultiSearchUrl() {
|
||||
const searchParams = new URLSearchParams();
|
||||
|
||||
if (gte(this.esVersion, '7.0.0') && this.maxConcurrentShardRequests) {
|
||||
if (this.maxConcurrentShardRequests) {
|
||||
searchParams.append('max_concurrent_shard_requests', `${this.maxConcurrentShardRequests}`);
|
||||
}
|
||||
|
||||
if (gte(this.esVersion, '6.6.0') && this.xpack && this.includeFrozen) {
|
||||
if (this.xpack && this.includeFrozen) {
|
||||
searchParams.append('ignore_throttled', 'false');
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import { gte, lt } from 'semver';
|
||||
|
||||
import { InternalTimeZones } from '@grafana/data';
|
||||
|
||||
import {
|
||||
@@ -23,11 +21,9 @@ import { convertOrderByToMetricId, getScriptValue } from './utils';
|
||||
|
||||
export class ElasticQueryBuilder {
|
||||
timeField: string;
|
||||
esVersion: string;
|
||||
|
||||
constructor(options: { timeField: string; esVersion: string }) {
|
||||
constructor(options: { timeField: string }) {
|
||||
this.timeField = options.timeField;
|
||||
this.esVersion = options.esVersion;
|
||||
}
|
||||
|
||||
getRangeFilter() {
|
||||
@@ -54,7 +50,7 @@ export class ElasticQueryBuilder {
|
||||
|
||||
if (aggDef.settings.orderBy !== void 0) {
|
||||
queryNode.terms.order = {};
|
||||
if (aggDef.settings.orderBy === '_term' && gte(this.esVersion, '6.0.0')) {
|
||||
if (aggDef.settings.orderBy === '_term') {
|
||||
queryNode.terms.order['_key'] = aggDef.settings.order;
|
||||
} else {
|
||||
queryNode.terms.order[aggDef.settings.orderBy] = aggDef.settings.order;
|
||||
@@ -153,11 +149,6 @@ export class ElasticQueryBuilder {
|
||||
},
|
||||
];
|
||||
|
||||
// fields field not supported on ES 5.x
|
||||
if (lt(this.esVersion, '5.0.0')) {
|
||||
query.fields = ['*', '_source'];
|
||||
}
|
||||
|
||||
query.script_fields = {};
|
||||
return query;
|
||||
}
|
||||
@@ -415,13 +406,7 @@ export class ElasticQueryBuilder {
|
||||
}
|
||||
|
||||
private buildScript(script: string) {
|
||||
if (gte(this.esVersion, '5.6.0')) {
|
||||
return script;
|
||||
}
|
||||
|
||||
return {
|
||||
inline: script,
|
||||
};
|
||||
return script;
|
||||
}
|
||||
|
||||
private toNumber(stringValue: unknown): unknown | number {
|
||||
@@ -480,7 +465,7 @@ export class ElasticQueryBuilder {
|
||||
switch (orderBy) {
|
||||
case 'key':
|
||||
case 'term':
|
||||
const keyname = gte(this.esVersion, '6.0.0') ? '_key' : '_term';
|
||||
const keyname = '_key';
|
||||
query.aggs['1'].terms.order[keyname] = order;
|
||||
break;
|
||||
case 'doc_count':
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,4 +1,4 @@
|
||||
import { removeEmpty } from './utils';
|
||||
import { removeEmpty, coerceESVersion } from './utils';
|
||||
|
||||
describe('removeEmpty', () => {
|
||||
it('Should remove all empty', () => {
|
||||
@@ -33,4 +33,25 @@ describe('removeEmpty', () => {
|
||||
|
||||
expect(removeEmpty(original)).toStrictEqual(expectedResult);
|
||||
});
|
||||
|
||||
it('should correctly coerce the version info', () => {
|
||||
// valid string
|
||||
expect(coerceESVersion('8.1.3')).toBe('8.1.3');
|
||||
|
||||
// invalid string
|
||||
expect(coerceESVersion('haha')).toBe('5.0.0');
|
||||
|
||||
// known number
|
||||
expect(coerceESVersion(2)).toBe('2.0.0');
|
||||
expect(coerceESVersion(5)).toBe('5.0.0');
|
||||
expect(coerceESVersion(56)).toBe('5.6.0');
|
||||
expect(coerceESVersion(60)).toBe('6.0.0');
|
||||
expect(coerceESVersion(70)).toBe('7.0.0');
|
||||
|
||||
// unknown number
|
||||
expect(coerceESVersion(42)).toBe('5.0.0');
|
||||
|
||||
// undefined
|
||||
expect(coerceESVersion(undefined)).toBe('5.0.0');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -95,11 +95,11 @@ export const getScriptValue = (metric: MetricAggregationWithInlineScript) =>
|
||||
(typeof metric.settings?.script === 'object' ? metric.settings?.script?.inline : metric.settings?.script) || '';
|
||||
|
||||
/**
|
||||
* Coerces the a version string/number to a valid semver string.
|
||||
* Coerces the version to a valid semver string.
|
||||
* It takes care of also converting from the legacy format (numeric) to the new one.
|
||||
* @param version
|
||||
*/
|
||||
export const coerceESVersion = (version: string | number): string => {
|
||||
export const coerceESVersion = (version: string | number | undefined): string => {
|
||||
if (typeof version === 'string') {
|
||||
return valid(version) || '5.0.0';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user