Skip to content

Commit 6c926c7

Browse files
mattkimelukasolsonkibanamachine
authored
[data views] Allow data views created on hidden and system indices - second attempt (#168882)
## Summary Previously, the 'Allow hidden and system indices' advanced option when creating a data view was only a UI convenience. It allowed you to see which hidden and system indices you were matching but they would be would be selected just the same once the data view was loaded. At some point something changed and now there are system and hidden indices that require `expandWildcards: hidden` to be passed to field caps in order to see anything. `allowHidden: boolean` is added to the DataView and DataViewSpec and passed through when field caps requests are made. This is primarily a tool for troubleshooting. For instance, instead of hitting a full data stream across a number of data tiers you can select a specific index to compare its performance. NOTE: This is a second attempt. What I learned - the whole `expand_wildcards` param is literal - you can directly query a hidden index without `expandWildcards: hidden` since its not using a wildcard. Tests now use a wildcard. Closes: #164652 --------- Co-authored-by: Lukas Olson <[email protected]> Co-authored-by: Kibana Machine <[email protected]>
1 parent 11b47c4 commit 6c926c7

File tree

26 files changed

+174
-7
lines changed

26 files changed

+174
-7
lines changed

src/plugins/data/common/search/search_source/fetch/get_search_params.test.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import { UI_SETTINGS } from '../../../constants';
1010
import { GetConfigFn } from '../../../types';
1111
import { getSearchParams, getSearchParamsFromRequest } from './get_search_params';
12+
import { createStubDataView } from '@kbn/data-views-plugin/common/data_views/data_view.stub';
1213

1314
function getConfigStub(config: any = {}): GetConfigFn {
1415
return (key) => config[key];
@@ -46,4 +47,50 @@ describe('getSearchParams', () => {
4647
query: 123,
4748
});
4849
});
50+
51+
test('sets expand_wildcards=all if data view has allowHidden=true', () => {
52+
const getConfig = getConfigStub({
53+
[UI_SETTINGS.COURIER_SET_REQUEST_PREFERENCE]: 'custom',
54+
[UI_SETTINGS.COURIER_CUSTOM_REQUEST_PREFERENCE]: 'aaa',
55+
});
56+
const index = createStubDataView({
57+
spec: {
58+
allowHidden: true,
59+
},
60+
});
61+
const searchParams = getSearchParamsFromRequest(
62+
{
63+
index,
64+
body: {
65+
query: 123,
66+
track_total_hits: true,
67+
},
68+
},
69+
{ getConfig }
70+
);
71+
expect(searchParams).toHaveProperty('expand_wildcards', 'all');
72+
});
73+
74+
test('does not set expand_wildcards if data view has allowHidden=false', () => {
75+
const getConfig = getConfigStub({
76+
[UI_SETTINGS.COURIER_SET_REQUEST_PREFERENCE]: 'custom',
77+
[UI_SETTINGS.COURIER_CUSTOM_REQUEST_PREFERENCE]: 'aaa',
78+
});
79+
const index = createStubDataView({
80+
spec: {
81+
allowHidden: false,
82+
},
83+
});
84+
const searchParams = getSearchParamsFromRequest(
85+
{
86+
index,
87+
body: {
88+
query: 123,
89+
track_total_hits: true,
90+
},
91+
},
92+
{ getConfig }
93+
);
94+
expect(searchParams).not.toHaveProperty('expand_wildcards', 'all');
95+
});
4996
});

src/plugins/data/common/search/search_source/fetch/get_search_params.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ export function getSearchParamsFromRequest(
4242
return {
4343
index: searchRequest.index.title || searchRequest.index,
4444
body,
45-
// @ts-expect-error `track_total_hits` not allowed at top level for `typesWithBodyKey`
4645
track_total_hits,
46+
...(searchRequest.index?.allowHidden && { expand_wildcards: 'all' }),
4747
...searchParams,
4848
};
4949
}

src/plugins/data_view_editor/public/components/advanced_params_content/advanced_params_content.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,16 @@ interface AdvancedParamsContentProps {
3030
disableAllowHidden: boolean;
3131
disableId: boolean;
3232
onAllowHiddenChange?: (value: boolean) => void;
33+
defaultVisible?: boolean;
3334
}
3435

3536
export const AdvancedParamsContent = ({
3637
disableAllowHidden,
3738
disableId,
3839
onAllowHiddenChange,
40+
defaultVisible = false,
3941
}: AdvancedParamsContentProps) => (
40-
<AdvancedParamsSection>
42+
<AdvancedParamsSection defaultVisible={defaultVisible}>
4143
<EuiFlexGroup>
4244
<EuiFlexItem>
4345
<UseField<boolean, IndexPatternConfig>

src/plugins/data_view_editor/public/components/advanced_params_content/advanced_params_section.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ import { EuiButtonEmpty, EuiSpacer } from '@elastic/eui';
1313

1414
interface Props {
1515
children: React.ReactNode;
16+
defaultVisible: boolean;
1617
}
1718

18-
export const AdvancedParamsSection = ({ children }: Props) => {
19-
const [isVisible, setIsVisible] = useState<boolean>(false);
19+
export const AdvancedParamsSection = ({ children, defaultVisible = false }: Props) => {
20+
const [isVisible, setIsVisible] = useState<boolean>(defaultVisible);
2021

2122
const toggleIsVisible = useCallback(() => {
2223
setIsVisible(!isVisible);

src/plugins/data_view_editor/public/components/data_view_editor_flyout_content.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ const IndexPatternEditorFlyoutContentComponent = ({
105105
title: editData.getIndexPattern(),
106106
id: editData.id,
107107
name: editData.name,
108+
allowHidden: editData.getAllowHidden(),
108109
...(editData.timeFieldName
109110
? {
110111
timestampField: { label: editData.timeFieldName, value: editData.timeFieldName },
@@ -124,6 +125,7 @@ const IndexPatternEditorFlyoutContentComponent = ({
124125
timeFieldName: formData.timestampField?.value,
125126
id: formData.id,
126127
name: formData.name,
128+
allowHidden: formData.allowHidden,
127129
};
128130

129131
if (type === INDEX_PATTERN_TYPE.ROLLUP && rollupIndex) {
@@ -293,6 +295,7 @@ const IndexPatternEditorFlyoutContentComponent = ({
293295
onAllowHiddenChange={() => {
294296
form.getFields().title.validate();
295297
}}
298+
defaultVisible={editData?.getAllowHidden()}
296299
/>
297300
</Form>
298301
<Footer

src/plugins/data_view_editor/public/components/data_view_flyout_content_container.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,11 @@ const DataViewFlyoutContentContainer = ({
5050
try {
5151
let saveResponse;
5252
if (editData) {
53-
const { name = '', timeFieldName, title = '' } = dataViewSpec;
53+
const { name = '', timeFieldName, title = '', allowHidden = false } = dataViewSpec;
5454
editData.setIndexPattern(title);
5555
editData.name = name;
5656
editData.timeFieldName = timeFieldName;
57+
editData.setAllowHidden(allowHidden);
5758
saveResponse = editData.isPersisted()
5859
? await dataViews.updateSavedObject(editData)
5960
: editData;

src/plugins/data_view_editor/public/data_view_editor_service.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ export class DataViewEditorService {
342342

343343
const getFieldsOptions: GetFieldsOptions = {
344344
pattern: this.indexPattern,
345+
allowHidden: this.allowHidden,
345346
};
346347
if (this.type === INDEX_PATTERN_TYPE.ROLLUP) {
347348
getFieldsOptions.type = INDEX_PATTERN_TYPE.ROLLUP;

src/plugins/data_views/common/content_management/v1/cm_services.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ const dataViewAttributesSchema = schema.object(
4646
allowNoIndex: schema.maybe(schema.boolean()),
4747
runtimeFieldMap: schema.maybe(schema.any()),
4848
name: schema.maybe(schema.string()),
49+
allowHidden: schema.maybe(schema.boolean()),
4950
},
5051
{ unknowns: 'forbid' }
5152
);

src/plugins/data_views/common/data_views/__snapshots__/data_view.test.ts.snap

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/plugins/data_views/common/data_views/__snapshots__/data_views.test.ts.snap

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)