Skip to content

Commit

Permalink
Merge branch 'main' into discover-create-where-filter
Browse files Browse the repository at this point in the history
  • Loading branch information
stratoula authored May 1, 2024
2 parents 8c14396 + d887763 commit 22e5a44
Show file tree
Hide file tree
Showing 47 changed files with 900 additions and 396 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export type VersionedRouteConfig<Method extends RouteMethod> = Omit<
RouteConfig<unknown, unknown, unknown, Method>,
'validate' | 'options'
> & {
options?: Omit<RouteConfigOptions<Method>, 'access'>;
options?: Omit<RouteConfigOptions<Method>, 'access' | 'description'>;
/** See {@link RouteConfigOptions<RouteMethod>['access']} */
access: Exclude<RouteConfigOptions<Method>['access'], undefined>;
/**
Expand Down
1 change: 0 additions & 1 deletion packages/kbn-esql-utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export {
appendToESQLQuery,
appendWhereClauseToESQLQuery,
TextBasedLanguages,
getESQLQueryColumns,
} from './src';

export { ESQL_LATEST_VERSION } from './constants';
1 change: 0 additions & 1 deletion packages/kbn-esql-utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,3 @@ export {
removeDropCommandsFromESQLQuery,
} from './utils/query_parsing_helpers';
export { appendToESQLQuery, appendWhereClauseToESQLQuery } from './utils/append_to_query';
export { getESQLQueryColumns } from './utils/run_query_utils';
52 changes: 0 additions & 52 deletions packages/kbn-esql-utils/src/utils/run_query_utils.ts

This file was deleted.

4 changes: 0 additions & 4 deletions packages/kbn-esql-utils/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,8 @@
],
"kbn_references": [
"@kbn/data-views-plugin",
"@kbn/data-plugin",
"@kbn/crypto-browser",
"@kbn/data-view-utils",
"@kbn/esql-ast",
"@kbn/expressions-plugin",
"@kbn/field-types",
"@kbn/es-types",
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@ const fetchHistoricalSummaryParamsSchema = t.type({
groupBy: allOrAnyStringOrArray,
revision: t.number,
}),
t.partial({ remoteName: t.string }),
t.partial({
remoteName: t.string,
range: t.type({
from: t.string,
to: t.string,
}),
}),
])
),
}),
Expand Down
5 changes: 4 additions & 1 deletion x-pack/packages/kbn-slo-schema/src/schema/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ const groupSummarySchema = t.type({
noData: t.number,
});

const dateRangeSchema = t.type({ from: dateType, to: dateType });
const dateRangeSchema = t.type({
from: t.union([dateType, t.string]),
to: t.union([dateType, t.string]),
});

export {
ALL_VALUE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/
import { dataViewPluginMocks } from '@kbn/data-views-plugin/public/mocks';
import { getESQLQueryColumns } from '@kbn/esql-utils';
import { fetchFieldsFromESQL } from '@kbn/text-based-editor';
import type { LensPluginStartDependencies } from '../../../plugin';
import { createMockStartDependencies } from '../../../editor_frame_service/mocks';
import {
Expand All @@ -18,44 +18,45 @@ import { suggestionsApi } from '../../../lens_suggestions_api';
import { getSuggestions } from './helpers';

const mockSuggestionApi = suggestionsApi as jest.Mock;
const mockFetchData = getESQLQueryColumns as jest.Mock;
const mockFetchData = fetchFieldsFromESQL as jest.Mock;

jest.mock('../../../lens_suggestions_api', () => ({
suggestionsApi: jest.fn(() => mockAllSuggestions),
}));

jest.mock('@kbn/esql-utils', () => {
return {
getESQLQueryColumns: jest.fn().mockResolvedValue(() => [
{
name: '@timestamp',
id: '@timestamp',
meta: {
type: 'date',
jest.mock('@kbn/text-based-editor', () => ({
fetchFieldsFromESQL: jest.fn(() => {
return {
columns: [
{
name: '@timestamp',
id: '@timestamp',
meta: {
type: 'date',
},
},
},
{
name: 'bytes',
id: 'bytes',
meta: {
type: 'number',
{
name: 'bytes',
id: 'bytes',
meta: {
type: 'number',
},
},
},
{
name: 'memory',
id: 'memory',
meta: {
type: 'number',
{
name: 'memory',
id: 'memory',
meta: {
type: 'number',
},
},
},
]),
getIndexPatternFromESQLQuery: jest.fn().mockReturnValue('index1'),
};
});
],
};
}),
}));

describe('getSuggestions', () => {
const query = {
esql: 'from index1 | limit 10 | stats average = avg(bytes)',
esql: 'from index1 | limit 10 | stats average = avg(bytes',
};
const mockStartDependencies =
createMockStartDependencies() as unknown as LensPluginStartDependencies;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,39 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import {
getIndexPatternFromSQLQuery,
getIndexPatternFromESQLQuery,
getESQLAdHocDataview,
getESQLQueryColumns,
} from '@kbn/esql-utils';
import { getIndexPatternFromSQLQuery, getIndexPatternFromESQLQuery } from '@kbn/esql-utils';
import type { AggregateQuery } from '@kbn/es-query';
import { getESQLAdHocDataview } from '@kbn/esql-utils';
import { getLensAttributesFromSuggestion } from '@kbn/visualization-utils';
import { fetchFieldsFromESQL } from '@kbn/text-based-editor';
import type { DataViewSpec } from '@kbn/data-views-plugin/public';
import type { TypedLensByValueInput } from '../../../embeddable/embeddable_component';
import type { LensPluginStartDependencies } from '../../../plugin';
import type { DatasourceMap, VisualizationMap } from '../../../types';
import { suggestionsApi } from '../../../lens_suggestions_api';

export const getQueryColumns = async (
query: AggregateQuery,
deps: LensPluginStartDependencies,
abortController?: AbortController
) => {
// Fetching only columns for ES|QL for performance reasons with limit 0
// Important note: ES doesnt return the warnings for 0 limit,
// I am skipping them in favor of performance now
// but we should think another way to get them (from Lens embeddable or store)
const performantQuery = { ...query };
if ('esql' in performantQuery && performantQuery.esql) {
performantQuery.esql = `${performantQuery.esql} | limit 0`;
}
const table = await fetchFieldsFromESQL(
performantQuery,
deps.expressions,
undefined,
abortController
);
return table?.columns;
};

export const getSuggestions = async (
query: AggregateQuery,
deps: LensPluginStartDependencies,
Expand Down Expand Up @@ -46,12 +65,7 @@ export const getSuggestions = async (
if (dataView.fields.getByName('@timestamp')?.type === 'date' && !dataViewSpec) {
dataView.timeFieldName = '@timestamp';
}

const columns = await getESQLQueryColumns({
esqlQuery: 'esql' in query ? query.esql : '',
search: deps.data.search,
signal: abortController?.signal,
});
const columns = await getQueryColumns(query, deps, abortController);
const context = {
dataViewSpec: dataView?.toSpec(),
fieldName: '',
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/lens/public/editor_frame_service/mocks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export function createMockSetupDependencies() {

export function createMockStartDependencies() {
return {
data: dataPluginMock.createStartContract(),
data: dataPluginMock.createSetupContract(),
embeddable: embeddablePluginMock.createStartContract(),
expressions: expressionsPluginMock.createStartContract(),
charts: chartPluginMock.createStartContract(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
*/
import { createGetterSetter } from '@kbn/kibana-utils-plugin/common';
import type { CoreStart } from '@kbn/core/public';
import { getESQLQueryColumns } from '@kbn/esql-utils';
import { getLensAttributesFromSuggestion } from '@kbn/visualization-utils';
import { IncompatibleActionError } from '@kbn/ui-actions-plugin/public';
import { PresentationContainer } from '@kbn/presentation-containers';
import { getESQLAdHocDataview, getIndexForESQLQuery } from '@kbn/esql-utils';
import type { Datasource, Visualization } from '../../types';
import type { LensPluginStartDependencies } from '../../plugin';
import { fetchDataFromAggregateQuery } from '../../datasources/text_based/fetch_data_from_aggregate_query';
import { suggestionsApi } from '../../lens_suggestions_api';
import { generateId } from '../../id_generator';
import { executeEditAction } from './edit_action_helpers';
Expand Down Expand Up @@ -66,17 +66,21 @@ export async function executeCreateAction({
// so we are requesting them with limit 0
// this is much more performant than requesting
// all the table
const abortController = new AbortController();
const columns = await getESQLQueryColumns({
esqlQuery: `from ${defaultIndex}`,
search: deps.data.search,
signal: abortController.signal,
});
const performantQuery = {
esql: `from ${defaultIndex} | limit 0`,
};

const table = await fetchDataFromAggregateQuery(
performantQuery,
dataView,
deps.data,
deps.expressions
);

const context = {
dataViewSpec: dataView.toSpec(),
fieldName: '',
textBasedColumns: columns,
textBasedColumns: table?.columns,
query: defaultEsqlQuery,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

export const SLOS_BASE_PATH = '/app/slos';
export const SLO_PREFIX = '/slos';
export const SLOS_PATH = '/' as const;
export const SLOS_WELCOME_PATH = '/welcome' as const;
export const SLO_DETAIL_PATH = '/:sloId' as const;
export const SLO_DETAIL_PATH = '/:sloId/:tabId?' as const;
export const SLO_CREATE_PATH = '/create' as const;
export const SLO_EDIT_PATH = '/edit/:sloId' as const;
export const SLOS_OUTDATED_DEFINITIONS_PATH = '/outdated-definitions' as const;
Expand All @@ -25,10 +26,13 @@ export const paths = {
sloEdit: (sloId: string) => `${SLOS_BASE_PATH}/edit/${encodeURIComponent(sloId)}`,
sloEditWithEncodedForm: (sloId: string, encodedParams: string) =>
`${SLOS_BASE_PATH}/edit/${encodeURIComponent(sloId)}?_a=${encodedParams}`,
sloDetails: (sloId: string, instanceId?: string, remoteName?: string) => {
sloDetails: (sloId: string, instanceId?: string, remoteName?: string, tabId?: string) => {
const qs = new URLSearchParams();
if (!!instanceId) qs.append('instanceId', instanceId);
if (!!instanceId && instanceId !== '*') qs.append('instanceId', instanceId);
if (!!remoteName) qs.append('remoteName', remoteName);
if (tabId) {
return `${SLOS_BASE_PATH}/${encodeURIComponent(sloId)}/${tabId}?${qs.toString()}`;
}
return `${SLOS_BASE_PATH}/${encodeURIComponent(sloId)}?${qs.toString()}`;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { EuiButtonGroup, EuiFlexGroup, EuiFlexItem, EuiTitle } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import React from 'react';
import { SloTabId } from '../../../pages/slo_details/components/slo_details';
import { BurnRateOption } from './burn_rates';
interface Props {
burnRateOption: BurnRateOption;
setBurnRateOption: (option: BurnRateOption) => void;
burnRateOptions: BurnRateOption[];
selectedTabId: SloTabId;
}
export function BurnRateHeader({
burnRateOption,
burnRateOptions,
setBurnRateOption,
selectedTabId,
}: Props) {
const onBurnRateOptionChange = (optionId: string) => {
const selected = burnRateOptions.find((opt) => opt.id === optionId) ?? burnRateOptions[0];
setBurnRateOption(selected);
};
return (
<EuiFlexGroup justifyContent="spaceBetween">
<EuiFlexItem grow={false}>
<EuiTitle size="xs">
<h2>
{i18n.translate('xpack.slo.burnRate.title', {
defaultMessage: 'Burn rate',
})}
</h2>
</EuiTitle>
</EuiFlexItem>
{selectedTabId !== 'history' && (
<EuiFlexItem grow={false}>
<EuiButtonGroup
legend={i18n.translate('xpack.slo.burnRate.timeRangeBtnLegend', {
defaultMessage: 'Select the time range',
})}
options={burnRateOptions.map((opt) => ({ id: opt.id, label: opt.label }))}
idSelected={burnRateOption.id}
onChange={onBurnRateOptionChange}
buttonSize="compressed"
/>
</EuiFlexItem>
)}
</EuiFlexGroup>
);
}
Loading

0 comments on commit 22e5a44

Please sign in to comment.