Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Logs UI] Support the Unified Search Bar for Query input #143222

Merged
Merged
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
00e77ef
Use Unified Search Bar for query input
Kerry350 Oct 12, 2022
d116eb7
Fix initial state quirks
Kerry350 Oct 12, 2022
8c1506a
Improve type checking
Kerry350 Oct 12, 2022
d723bf5
Merge remote-tracking branch 'upstream/main' into 142719-logs-unified…
Kerry350 Oct 13, 2022
ac3c90c
Add new showQueryMenu prop with tests / story
Kerry350 Oct 13, 2022
32d6f67
Add showQueryMenu option to Logs and the create_search_bar wrapper
Kerry350 Oct 13, 2022
fe33caa
Remove unused variables
Kerry350 Oct 13, 2022
33e494b
Update x-pack/plugins/infra/public/containers/logs/log_filter/log_fil…
Kerry350 Oct 14, 2022
09f8330
PR tweaks
Kerry350 Oct 14, 2022
140e99c
Merge branch '142719-logs-unified-search-bar-query-input' of github.c…
Kerry350 Oct 14, 2022
e0e70e8
Fix loading from URL
Kerry350 Oct 14, 2022
a7abf8f
Adjust state handling to account for invalid manager queries
Kerry350 Oct 18, 2022
ffe3e45
Merge remote-tracking branch 'upstream' into 142719-logs-unified-sear…
Kerry350 Oct 18, 2022
3147810
Show filter error within UI and block requests
Kerry350 Oct 18, 2022
a2c5024
Merge remote-tracking branch 'upstream/main' into 142719-logs-unified…
Kerry350 Oct 19, 2022
e322bbc
PR amendments
Kerry350 Oct 19, 2022
246786c
Merge branch 'main' into 142719-logs-unified-search-bar-query-input
kibanamachine Oct 19, 2022
96d17b0
Merge remote-tracking branch 'upstream/main' into 142719-logs-unified…
Kerry350 Oct 20, 2022
a395d27
Use a real DataView reference with derivedDataView
Kerry350 Oct 20, 2022
929e9df
Update x-pack/plugins/infra/public/containers/logs/log_filter/with_lo…
Kerry350 Oct 20, 2022
94b86c9
Merge branch '142719-logs-unified-search-bar-query-input' of github.c…
Kerry350 Oct 20, 2022
fd193dd
Move location of default query setting
Kerry350 Oct 20, 2022
1007c0b
Merge remote-tracking branch 'upstream/main' into 142719-logs-unified…
Kerry350 Oct 20, 2022
6cdbe6b
Respond to dataView changes
Kerry350 Oct 20, 2022
d0805d5
Merge remote-tracking branch 'upstream/main' into 142719-logs-unified…
Kerry350 Oct 24, 2022
f2ccde9
Revert "Use a real DataView reference with derivedDataView"
Kerry350 Oct 24, 2022
b484f3e
Add "type" property rather than use a "real" data view
Kerry350 Oct 24, 2022
809238b
Update x-pack/plugins/infra/public/containers/logs/log_filter/log_fil…
Kerry350 Oct 25, 2022
3d13548
Merge remote-tracking branch 'upstream/main' into 142719-logs-unified…
Kerry350 Oct 25, 2022
6256bc8
Revert "Revert "Use a real DataView reference with derivedDataView""
Kerry350 Oct 25, 2022
3595f0f
Use real dataView in resolved logView
Kerry350 Oct 25, 2022
dd161d7
Merge branch '142719-logs-unified-search-bar-query-input' of github.c…
Kerry350 Oct 25, 2022
04e7404
Merge remote-tracking branch 'upstream/main' into 142719-logs-unified…
Kerry350 Oct 31, 2022
827621d
Merge remote-tracking branch 'upstream/main' into 142719-logs-unified…
Kerry350 Oct 31, 2022
f948012
Small tweaks
Kerry350 Oct 31, 2022
8867aef
Fix tests in link_to_logs.test.tsx
Kerry350 Oct 31, 2022
3f5f8d8
Update snapshot for log_views_client.test.ts
Kerry350 Oct 31, 2022
274cec2
Merge remote-tracking branch 'upstream/main' into 142719-logs-unified…
Kerry350 Nov 1, 2022
7c99c5e
Use createStubDataView over custom object
Kerry350 Nov 1, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,15 @@ storiesOf('SearchBar', module)
query: { query: 'Test: miaou', language: 'kuery' },
} as unknown as SearchBarProps)
)
.add('with query menu off', () =>
wrapSearchBarInContext({
showDatePicker: false,
showFilterBar: false,
showQueryInput: true,
showQueryMenu: false,
query: { query: 'Test: miaou', language: 'kuery' },
} as unknown as SearchBarProps)
)
.add('with only the filter bar and the date picker on', () =>
wrapSearchBarInContext({
showDatePicker: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ export function createSearchBar({
showAutoRefreshOnly={props.showAutoRefreshOnly}
showDatePicker={props.showDatePicker}
showFilterBar={props.showFilterBar}
showQueryMenu={props.showQueryMenu}
showQueryInput={props.showQueryInput}
showSaveQuery={props.showSaveQuery}
showSubmitButton={props.showSubmitButton}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ describe('SearchBar', () => {
const FILTER_BAR = '[data-test-subj="unifiedFilterBar"]';
const QUERY_BAR = '.kbnQueryBar';
const QUERY_INPUT = '[data-test-subj="unifiedQueryInput"]';
const QUERY_MENU_BUTTON = '[data-test-subj="showQueryBarMenu"]';
const EDITOR = '[data-test-subj="unifiedTextLangEditor"]';

beforeEach(() => {
Expand Down Expand Up @@ -220,6 +221,20 @@ describe('SearchBar', () => {
expect(component.find(QUERY_INPUT).length).toBeFalsy();
});

it('Should NOT render the query menu button, if disabled', () => {
const component = mount(
wrapSearchBarInContext({
indexPatterns: [mockIndexPattern],
screenTitle: 'test screen',
onQuerySubmit: noop,
query: kqlQuery,
showQueryMenu: false,
})
);

expect(component.find(QUERY_MENU_BUTTON).length).toBeFalsy();
});

it('Should render query bar and filter bar', () => {
const component = mount(
wrapSearchBarInContext({
Expand Down
6 changes: 4 additions & 2 deletions src/plugins/unified_search/public/search_bar/search_bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export interface SearchBarOwnProps<QT extends AggregateQuery | Query = Query> {
screenTitle?: string;
dataTestSubj?: string;
// Togglers
showQueryMenu?: boolean;
showQueryInput?: boolean;
showFilterBar?: boolean;
showDatePicker?: boolean;
Expand Down Expand Up @@ -121,6 +122,7 @@ class SearchBarUI<QT extends (Query | AggregateQuery) | Query = Query> extends C
State<QT | Query>
> {
public static defaultProps = {
showQueryMenu: true,
showFilterBar: true,
showDatePicker: true,
showSubmitButton: true,
Expand Down Expand Up @@ -448,7 +450,7 @@ class SearchBarUI<QT extends (Query | AggregateQuery) | Query = Query> extends C
/>
);

const queryBarMenu = (
const queryBarMenu = this.props.showQueryMenu ? (
<QueryBarMenu
nonKqlMode={this.props.nonKqlMode}
language={
Expand Down Expand Up @@ -488,7 +490,7 @@ class SearchBarUI<QT extends (Query | AggregateQuery) | Query = Query> extends C
: undefined
}
/>
);
) : undefined;

let filterBar;
if (this.shouldRenderFilterBar()) {
Expand Down
13 changes: 13 additions & 0 deletions x-pack/plugins/infra/common/log_views/resolved_log_view.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ import { createStubDataView } from '@kbn/data-views-plugin/common/stubs';
import { defaultLogViewsStaticConfig } from './defaults';
import { ResolvedLogView, resolveLogView } from './resolved_log_view';
import { LogViewAttributes } from './types';
import { DataView, DataViewSpec } from '@kbn/data-views-plugin/common';

const dataViewMock = {
id: 'log-view-data-view-mock',
title: 'log-view-data-view-mock-title',
fields: [],
} as unknown as DataView;
Kerry350 marked this conversation as resolved.
Show resolved Hide resolved

export const createResolvedLogViewMock = (
resolvedLogViewOverrides: Partial<ResolvedLogView> = {}
Expand Down Expand Up @@ -41,15 +48,21 @@ export const createResolvedLogViewMock = (
messageColumn: { id: 'MESSAGE_COLUMN_ID' },
},
],
dataViewReference: dataViewMock,
...resolvedLogViewOverrides,
});

export const createResolvedLogViewMockFromAttributes = (logViewAttributes: LogViewAttributes) =>
resolveLogView(
'log-view-id',
logViewAttributes,
{
get: async () => createStubDataView({ spec: {} }),
getFieldsForWildcard: async () => [],
create: async (spec: DataViewSpec) =>
createStubDataView({
spec,
}),
} as unknown as DataViewsContract,
defaultLogViewsStaticConfig
);
32 changes: 20 additions & 12 deletions x-pack/plugins/infra/common/log_views/resolved_log_view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,24 @@ export interface ResolvedLogView {
fields: ResolvedLogViewField[];
runtimeMappings: estypes.MappingRuntimeFields;
columns: LogViewColumnConfiguration[];
dataViewReference: DataView;
}

export const resolveLogView = async (
logViewId: string,
logViewAttributes: LogViewAttributes,
dataViewsService: DataViewsContract,
config: LogViewsStaticConfig
): Promise<ResolvedLogView> => {
if (logViewAttributes.logIndices.type === 'index_name') {
return await resolveLegacyReference(logViewAttributes, dataViewsService, config);
return await resolveLegacyReference(logViewId, logViewAttributes, dataViewsService, config);
} else {
return await resolveDataViewReference(logViewAttributes, dataViewsService);
}
};

const resolveLegacyReference = async (
logViewId: string,
logViewAttributes: LogViewAttributes,
dataViewsService: DataViewsContract,
config: LogViewsStaticConfig
Expand All @@ -48,28 +51,32 @@ const resolveLegacyReference = async (

const indices = logViewAttributes.logIndices.indexName;

const fields = await dataViewsService
.getFieldsForWildcard({
pattern: indices,
allowNoIndex: true,
})
const dataViewReference = await dataViewsService
.create(
{
id: `log-view-${logViewId}`,
title: indices,
timeFieldName: TIMESTAMP_FIELD,
allowNoIndex: true,
},
false,
false
)
.catch((error) => {
throw new ResolveLogViewError(
`Failed to fetch fields for indices "${indices}": ${error}`,
error
);
throw new ResolveLogViewError(`Failed to create Data View reference: ${error}`, error);
});

return {
indices: logViewAttributes.logIndices.indexName,
indices,
timestampField: TIMESTAMP_FIELD,
tiebreakerField: TIEBREAKER_FIELD,
messageField: config.messageFields,
fields,
fields: dataViewReference.fields,
runtimeMappings: {},
columns: logViewAttributes.logColumns,
name: logViewAttributes.name,
description: logViewAttributes.description,
dataViewReference,
};
};

Expand Down Expand Up @@ -97,6 +104,7 @@ const resolveDataViewReference = async (
columns: logViewAttributes.logColumns,
name: logViewAttributes.name,
description: logViewAttributes.description,
dataViewReference: dataView,
};
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@

import { buildEsQuery, Filter, Query } from '@kbn/es-query';
import { JsonValue } from '@kbn/utility-types';
import { noop } from 'lodash';
import React, { useCallback, useEffect, useMemo } from 'react';
import { DataPublicPluginStart } from '@kbn/data-plugin/public';
import { euiStyled } from '@kbn/kibana-react-plugin/common';
import { useKibana } from '@kbn/kibana-react-plugin/public';
import { noop } from 'lodash';
import { LogEntryCursor } from '../../../common/log_entry';
import { defaultLogViewsStaticConfig } from '../../../common/log_views';
import { BuiltEsQuery, useLogStream } from '../../containers/logs/log_stream';
Expand Down
21 changes: 21 additions & 0 deletions x-pack/plugins/infra/public/containers/logs/log_filter/errors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* 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.
*/

/* eslint-disable max-classes-per-file */
export class UnsupportedLanguageError extends Error {
constructor(message?: string) {
super(message);
Object.setPrototypeOf(this, new.target.prototype);
}
}

export class QueryParsingError extends Error {
constructor(message?: string) {
super(message);
Object.setPrototypeOf(this, new.target.prototype);
}
}
Loading