mirror of
https://github.com/grafana/grafana.git
synced 2025-02-16 18:34:52 -06:00
elasticsearch: metrics rate and top_metrics do not need xpack (#63457)
This commit is contained in:
parent
635a456fa4
commit
f925a989d3
@ -1,11 +1,11 @@
|
|||||||
import { act, fireEvent, render, screen } from '@testing-library/react';
|
import { act, fireEvent, render, screen } from '@testing-library/react';
|
||||||
import React, { ReactNode, PropsWithChildren } from 'react';
|
import React, { PropsWithChildren } from 'react';
|
||||||
import { from } from 'rxjs';
|
import { from } from 'rxjs';
|
||||||
|
|
||||||
import { getDefaultTimeRange } from '@grafana/data';
|
import { getDefaultTimeRange } from '@grafana/data';
|
||||||
|
|
||||||
import { ElasticDatasource } from '../../../datasource';
|
import { ElasticDatasource } from '../../../datasource';
|
||||||
import { defaultBucketAgg, defaultMetricAgg } from '../../../queryDef';
|
import { defaultBucketAgg } from '../../../queryDef';
|
||||||
import { ElasticsearchQuery } from '../../../types';
|
import { ElasticsearchQuery } from '../../../types';
|
||||||
import { ElasticsearchProvider } from '../ElasticsearchQueryContext';
|
import { ElasticsearchProvider } from '../ElasticsearchQueryContext';
|
||||||
|
|
||||||
@ -85,47 +85,4 @@ describe('Metric Editor', () => {
|
|||||||
expect(await screen.findByText('No options found')).toBeInTheDocument();
|
expect(await screen.findByText('No options found')).toBeInTheDocument();
|
||||||
expect(screen.queryByText('None')).not.toBeInTheDocument();
|
expect(screen.queryByText('None')).not.toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Top Metrics Aggregation', () => {
|
|
||||||
const setupTopMetricsScreen = (xpack: boolean) => {
|
|
||||||
const query: ElasticsearchQuery = {
|
|
||||||
refId: 'A',
|
|
||||||
query: '',
|
|
||||||
metrics: [defaultMetricAgg('1')],
|
|
||||||
bucketAggs: [defaultBucketAgg('2')],
|
|
||||||
};
|
|
||||||
|
|
||||||
const getFields: ElasticDatasource['getFields'] = jest.fn(() => from([[]]));
|
|
||||||
|
|
||||||
const esVersion = '7.7.0';
|
|
||||||
|
|
||||||
const wrapper = ({ children }: { children?: ReactNode }) => (
|
|
||||||
<ElasticsearchProvider
|
|
||||||
datasource={{ getFields, esVersion, xpack } as ElasticDatasource}
|
|
||||||
query={query}
|
|
||||||
range={getDefaultTimeRange()}
|
|
||||||
onChange={() => {}}
|
|
||||||
onRunQuery={() => {}}
|
|
||||||
>
|
|
||||||
{children}
|
|
||||||
</ElasticsearchProvider>
|
|
||||||
);
|
|
||||||
|
|
||||||
render(<MetricEditor value={defaultMetricAgg('1')} />, { wrapper });
|
|
||||||
|
|
||||||
act(() => {
|
|
||||||
fireEvent.click(screen.getByText('Count'));
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
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 X-Pack is disabled', () => {
|
|
||||||
setupTopMetricsScreen(false);
|
|
||||||
expect(screen.queryByText('Top Metrics')).toBe(null);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
@ -41,8 +41,7 @@ const isBasicAggregation = (metric: MetricAggregation) => !metricAggregationConf
|
|||||||
|
|
||||||
const getTypeOptions = (
|
const getTypeOptions = (
|
||||||
previousMetrics: MetricAggregation[],
|
previousMetrics: MetricAggregation[],
|
||||||
esVersion: string,
|
esVersion: string
|
||||||
xpack = false
|
|
||||||
): Array<SelectableValue<MetricAggregationType>> => {
|
): Array<SelectableValue<MetricAggregationType>> => {
|
||||||
// we'll include Pipeline Aggregations only if at least one previous metric is a "Basic" one
|
// we'll include Pipeline Aggregations only if at least one previous metric is a "Basic" one
|
||||||
const includePipelineAggregations = previousMetrics.some(isBasicAggregation);
|
const includePipelineAggregations = previousMetrics.some(isBasicAggregation);
|
||||||
@ -53,8 +52,6 @@ const getTypeOptions = (
|
|||||||
.filter(([_, { versionRange = '*' }]) => satisfies(esVersion, versionRange))
|
.filter(([_, { versionRange = '*' }]) => satisfies(esVersion, versionRange))
|
||||||
// Filtering out Pipeline Aggregations if there's no basic metric selected before
|
// Filtering out Pipeline Aggregations if there's no basic metric selected before
|
||||||
.filter(([_, config]) => includePipelineAggregations || !config.isPipelineAgg)
|
.filter(([_, config]) => includePipelineAggregations || !config.isPipelineAgg)
|
||||||
// Filtering out X-Pack plugins if X-Pack is disabled
|
|
||||||
.filter(([_, config]) => (config.xpack ? xpack : true))
|
|
||||||
.map(([key, { label }]) => ({
|
.map(([key, { label }]) => ({
|
||||||
label,
|
label,
|
||||||
value: key as MetricAggregationType,
|
value: key as MetricAggregationType,
|
||||||
@ -90,7 +87,7 @@ export const MetricEditor = ({ value }: Props) => {
|
|||||||
<InlineSegmentGroup>
|
<InlineSegmentGroup>
|
||||||
<Segment
|
<Segment
|
||||||
className={cx(styles.color, segmentStyles)}
|
className={cx(styles.color, segmentStyles)}
|
||||||
options={getTypeOptions(previousMetrics, datasource.esVersion, datasource.xpack)}
|
options={getTypeOptions(previousMetrics, datasource.esVersion)}
|
||||||
onChange={(e) => dispatch(changeMetricType({ id: value.id, type: e.value! }))}
|
onChange={(e) => dispatch(changeMetricType({ id: value.id, type: e.value! }))}
|
||||||
value={toOption(value)}
|
value={toOption(value)}
|
||||||
/>
|
/>
|
||||||
|
@ -235,7 +235,6 @@ export const metricAggregationConfig: MetricsConfiguration = {
|
|||||||
},
|
},
|
||||||
top_metrics: {
|
top_metrics: {
|
||||||
label: 'Top Metrics',
|
label: 'Top Metrics',
|
||||||
xpack: true,
|
|
||||||
requiresField: false,
|
requiresField: false,
|
||||||
isPipelineAgg: false,
|
isPipelineAgg: false,
|
||||||
supportsMissing: false,
|
supportsMissing: false,
|
||||||
@ -251,7 +250,6 @@ export const metricAggregationConfig: MetricsConfiguration = {
|
|||||||
},
|
},
|
||||||
rate: {
|
rate: {
|
||||||
label: 'Rate',
|
label: 'Rate',
|
||||||
xpack: true,
|
|
||||||
requiresField: true,
|
requiresField: true,
|
||||||
isPipelineAgg: false,
|
isPipelineAgg: false,
|
||||||
supportsMissing: false,
|
supportsMissing: false,
|
||||||
|
@ -123,7 +123,6 @@ interface MetricConfiguration<T extends MetricAggregationType> {
|
|||||||
supportsInlineScript: boolean;
|
supportsInlineScript: boolean;
|
||||||
supportsMissing: boolean;
|
supportsMissing: boolean;
|
||||||
isPipelineAgg: boolean;
|
isPipelineAgg: boolean;
|
||||||
xpack?: boolean;
|
|
||||||
/**
|
/**
|
||||||
* A valid semver range for which the metric is known to be available.
|
* A valid semver range for which the metric is known to be available.
|
||||||
* If omitted defaults to '*'.
|
* If omitted defaults to '*'.
|
||||||
|
Loading…
Reference in New Issue
Block a user