[DataViews] Use 'rollup' data view type constant (#177524)

## Summary

Resolves https://github.com/elastic/kibana/issues/158410.

### Checklist

Delete any items that are not applicable to this PR.

- [ ] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)
- [ ]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [ ] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [ ] [Flaky Test
Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was
used on any tests changed
- [ ] Any UI touched in this PR is usable by keyboard only (learn more
about [keyboard accessibility](https://webaim.org/techniques/keyboard/))
- [ ] Any UI touched in this PR does not create any new axe failures
(run axe in browser:
[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),
[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))
- [ ] If a plugin configuration key changed, check if it needs to be
allowlisted in the cloud and added to the [docker
list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)
- [ ] This renders correctly on smaller devices using a responsive
layout. (You can test this [in your
browser](https://www.browserstack.com/guide/responsive-testing-on-local-server))
- [ ] This was checked for [cross-browser
compatibility](https://www.elastic.co/support/matrix#matrix_browsers)


### Risk Matrix

Delete this section if it is not applicable to this PR.

Before closing this PR, invite QA, stakeholders, and other developers to
identify risks that should be tested prior to the change/feature
release.

When forming the risk matrix, consider some of the following examples
and how they may potentially impact the change:

| Risk | Probability | Severity | Mitigation/Notes |

|---------------------------|-------------|----------|-------------------------|
| Multiple Spaces—unexpected behavior in non-default Kibana Space.
| Low | High | Integration tests will verify that all features are still
supported in non-default Kibana Space and when user switches between
spaces. |
| Multiple nodes—Elasticsearch polling might have race conditions
when multiple Kibana nodes are polling for the same tasks. | High | Low
| Tasks are idempotent, so executing them multiple times will not result
in logical error, but will degrade performance. To test for this case we
add plenty of unit tests around this logic and document manual testing
procedure. |
| Code should gracefully handle cases when feature X or plugin Y are
disabled. | Medium | High | Unit tests will verify that any feature flag
or plugin combination still results in our service operational. |
| [See more potential risk
examples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx) |


### For maintainers

- [ ] This was checked for breaking API changes and was [labeled
appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)
This commit is contained in:
Lukas Olson 2024-03-05 20:46:41 +01:00 committed by GitHub
parent 1f032eb138
commit 555b7b62b5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
18 changed files with 46 additions and 31 deletions

View file

@ -16,6 +16,7 @@ import { SearchStrategyDependencies } from '../../types';
import { enhancedEsSearchStrategyProvider } from './ese_search_strategy';
import { createSearchSessionsClientMock } from '../../mocks';
import { getMockSearchConfig } from '../../../../config.mock';
import { DataViewType } from '@kbn/data-views-plugin/common';
const mockAsyncResponse = {
body: {
@ -246,7 +247,7 @@ describe('ES search strategy', () => {
await esSearch
.search(
{
indexType: 'rollup',
indexType: DataViewType.ROLLUP,
params,
},
{},
@ -274,7 +275,7 @@ describe('ES search strategy', () => {
await esSearch
.search(
{
indexType: 'rollup',
indexType: DataViewType.ROLLUP,
params,
},
{},

View file

@ -21,7 +21,7 @@ import type {
IEsSearchResponse,
ISearchOptions,
} from '../../../../common';
import { pollSearch } from '../../../../common';
import { DataViewType, pollSearch } from '../../../../common';
import {
getDefaultAsyncGetParams,
getDefaultAsyncSubmitParams,
@ -171,7 +171,7 @@ export const enhancedEsSearchStrategyProvider = (
search: (request, options: IAsyncSearchOptions, deps) => {
logger.debug(`search ${JSON.stringify(request.params) || request.id}`);
if (request.indexType === 'rollup' && deps.rollupsEnabled) {
if (request.indexType === DataViewType.ROLLUP && deps.rollupsEnabled) {
return from(rollupSearch(request, options, deps));
} else {
return asyncSearch(request, options, deps);

View file

@ -21,7 +21,7 @@ import {
} from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n-react';
import { DataView, DataViewField, RuntimeField } from '@kbn/data-views-plugin/public';
import { DataView, DataViewField, DataViewType, RuntimeField } from '@kbn/data-views-plugin/public';
import { DATA_VIEW_SAVED_OBJECT_TYPE } from '@kbn/data-views-plugin/public';
import { useKibana } from '@kbn/kibana-react-plugin/public';
import {
@ -170,7 +170,7 @@ export const EditIndexPattern = withRouter(
});
const isRollup =
new URLSearchParams(useLocation().search).get('type') === 'rollup' &&
new URLSearchParams(useLocation().search).get('type') === DataViewType.ROLLUP &&
dataViews.getRollupsEnabled();
const displayIndexPatternEditor = showEditDialog ? (
<IndexPatternEditor

View file

@ -27,6 +27,7 @@ import useObservable from 'react-use/lib/useObservable';
import { reactRouterNavigate, useKibana } from '@kbn/kibana-react-plugin/public';
import { NoDataViewsPromptComponent } from '@kbn/shared-ux-prompt-no-data-views';
import type { SpacesContextProps } from '@kbn/spaces-plugin/public';
import { DataViewType } from '@kbn/data-views-plugin/public';
import type { IndexPatternManagmentContext } from '../../types';
import { getListBreadcrumbs } from '../breadcrumbs';
import { type RemoveDataViewProps, removeDataView } from '../edit_index_pattern';
@ -169,7 +170,7 @@ export const IndexPatternTable = ({
chrome.docTitle.change(title);
const isRollup =
new URLSearchParams(useLocation().search).get('type') === 'rollup' &&
new URLSearchParams(useLocation().search).get('type') === DataViewType.ROLLUP &&
dataViews.getRollupsEnabled();
const ContextWrapper = useMemo(

View file

@ -11,6 +11,7 @@ import {
DataView,
DataViewField,
DataViewListItem,
DataViewType,
} from '@kbn/data-views-plugin/public';
import { i18n } from '@kbn/i18n';
@ -29,7 +30,7 @@ const rollupIndexPatternListName = i18n.translate(
);
export const isRollup = (indexPatternType: string = '') => {
return indexPatternType === 'rollup';
return indexPatternType === DataViewType.ROLLUP;
};
export async function getIndexPatterns(defaultIndex: string, dataViewsService: DataViewsContract) {
@ -76,14 +77,14 @@ export const getTags = (
const tags = [];
if (isDefault) {
tags.push({
key: 'default',
key: DataViewType.DEFAULT,
name: defaultIndexPatternListName,
'data-test-subj': 'default-tag',
});
}
if (isRollup(indexPattern.type) && rollupsEnabled) {
tags.push({
key: 'rollup',
key: DataViewType.ROLLUP,
name: rollupIndexPatternListName,
'data-test-subj': 'rollup-tag',
});

View file

@ -16,12 +16,13 @@ import {
createResultSchema,
searchOptionsSchemas,
} from '@kbn/content-management-utils';
import { DataViewType } from '../..';
import { serializedFieldFormatSchema, fieldSpecSchema } from '../../schemas';
const dataViewAttributesSchema = schema.object(
{
title: schema.string(),
type: schema.maybe(schema.literal('rollup')),
type: schema.maybe(schema.literal(DataViewType.ROLLUP)),
timeFieldName: schema.maybe(schema.string()),
sourceFilters: schema.maybe(
schema.arrayOf(

View file

@ -9,7 +9,7 @@
import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import { IndexPatternsFetcher } from '.';
import { elasticsearchServiceMock } from '@kbn/core/server/mocks';
import { DataViewMissingIndices } from '../../common';
import { DataViewMissingIndices, DataViewType } from '../../common';
const rollupResponse = {
foo: {
@ -51,7 +51,7 @@ describe('Index Pattern Fetcher - server', () => {
indexPatterns = new IndexPatternsFetcher(esClient, true, true);
await indexPatterns.getFieldsForWildcard({
pattern: patternList,
type: 'rollup',
type: DataViewType.ROLLUP,
rollupIndex: 'foo',
});
expect(esClient.rollup.getRollupIndexCaps).toHaveBeenCalledTimes(1);
@ -64,7 +64,7 @@ describe('Index Pattern Fetcher - server', () => {
indexPatterns = new IndexPatternsFetcher(esClient, true, false);
await indexPatterns.getFieldsForWildcard({
pattern: patternList,
type: 'rollup',
type: DataViewType.ROLLUP,
rollupIndex: 'foo',
});
expect(esClient.rollup.getRollupIndexCaps).toHaveBeenCalledTimes(0);

View file

@ -18,6 +18,7 @@ import {
getCapabilitiesForRollupIndices,
mergeCapabilitiesWithFields,
} from './lib';
import { DataViewType } from '../../common/types';
export interface FieldDescriptor {
aggregatable: boolean;
@ -105,7 +106,7 @@ export class IndexPatternsFetcher {
includeEmptyFields,
});
if (this.rollupsEnabled && type === 'rollup' && rollupIndex) {
if (this.rollupsEnabled && type === DataViewType.ROLLUP && rollupIndex) {
const rollupFields: FieldDescriptor[] = [];
const capabilityCheck = getCapabilitiesForRollupIndices(
await this.elasticsearchClient.rollup.getRollupIndexCaps({

View file

@ -12,6 +12,7 @@ import { isRunningResponse, ISearchSource } from '@kbn/data-plugin/public';
import { buildDataTableRecordList } from '@kbn/discover-utils';
import type { EsHitRecord } from '@kbn/discover-utils/types';
import type { SearchResponseWarning } from '@kbn/search-response-warnings';
import { DataViewType } from '@kbn/data-views-plugin/public';
import type { RecordsFetchResponse } from '../../types';
import { getAllowedSampleSize } from '../../../utils/get_allowed_sample_size';
import { FetchDeps } from './fetch_all';
@ -29,7 +30,7 @@ export const fetchDocuments = (
searchSource.setField('trackTotalHits', false);
searchSource.setField('highlightAll', true);
searchSource.setField('version', true);
if (searchSource.getField('index')?.type === 'rollup') {
if (searchSource.getField('index')?.type === DataViewType.ROLLUP) {
// We treat that data view as "normal" even if it was a rollup data view,
// since the rollup endpoint does not support querying individual documents, but we
// can get them from the regular _search API that will be used if the data view

View file

@ -8,6 +8,7 @@
import { getCapabilitiesForRollupIndices } from '@kbn/data-plugin/server';
import type { DataViewsService } from '@kbn/data-views-plugin/common';
import { DataViewType } from '@kbn/data-views-plugin/common';
import { AbstractSearchStrategy, EsSearchRequest } from './abstract_search_strategy';
import { RollupSearchCapabilities } from '../capabilities/rollup_search_capabilities';
@ -30,7 +31,7 @@ export class RollupSearchStrategy extends AbstractSearchStrategy {
esRequests: EsSearchRequest[],
trackedEsSearches?: TrackedEsSearches
) {
return super.search(requestContext, req, esRequests, trackedEsSearches, 'rollup');
return super.search(requestContext, req, esRequests, trackedEsSearches, DataViewType.ROLLUP);
}
async getRollupData(
@ -60,7 +61,7 @@ export class RollupSearchStrategy extends AbstractSearchStrategy {
if (
indexPatternString &&
((!indexPattern && !isIndexPatternContainsWildcard(indexPatternString)) ||
indexPattern?.type === 'rollup')
indexPattern?.type === DataViewType.ROLLUP)
) {
const rollupData = await this.getRollupData(requestContext, indexPatternString);
const rollupIndices = getRollupIndices(rollupData);
@ -96,7 +97,7 @@ export class RollupSearchStrategy extends AbstractSearchStrategy {
capabilities?: unknown
) {
return super.getFieldsForWildcard(fetchedIndexPattern, indexPatternsService, capabilities, {
type: 'rollup',
type: DataViewType.ROLLUP,
rollupIndex: fetchedIndexPattern.indexPatternString,
});
}

View file

@ -13,6 +13,7 @@ import {
type FieldId,
EVENT_RATE_FIELD_ID,
} from '@kbn/ml-anomaly-utils';
import { DataViewType } from '@kbn/data-views-plugin/public';
import { getGeoFields, filterCategoryFields } from '../../../../common/util/fields_utils';
import { ml, type MlApiServices } from '../ml_api_service';
import { processTextAndKeywordFields, NewJobCapabilitiesServiceBase } from './new_job_capabilities';
@ -57,7 +58,7 @@ export class NewJobCapsService extends NewJobCapabilitiesServiceBase {
const resp = await this._mlApiService.jobs.newJobCaps(
dataView.getIndexPattern(),
dataView.type === 'rollup'
dataView.type === DataViewType.ROLLUP
);
const { fields: allFields, aggs } = createObjects(resp, dataView.getIndexPattern());

View file

@ -6,7 +6,7 @@
*/
import { ES_FIELD_TYPES, KBN_FIELD_TYPES } from '@kbn/field-types';
import { DataView } from '@kbn/data-views-plugin/public';
import { DataView, DataViewType } from '@kbn/data-views-plugin/public';
import type { Field, NewJobCapsResponse } from '@kbn/ml-anomaly-utils';
import {
getDependentVar,
@ -63,7 +63,7 @@ class NewJobCapsServiceAnalytics extends NewJobCapabilitiesServiceBase {
try {
const resp: NewJobCapsResponse = await ml.dataFrameAnalytics.newJobCapsAnalytics(
dataView.getIndexPattern(),
dataView.type === 'rollup'
dataView.type === DataViewType.ROLLUP
);
const allFields = removeNestedFieldChildren(resp, dataView.getIndexPattern());

View file

@ -9,6 +9,7 @@ import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import type { IScopedClusterClient } from '@kbn/core/server';
import type { DataViewsService, DataView } from '@kbn/data-views-plugin/common';
import type { RollupFields } from '@kbn/ml-anomaly-utils';
import { DataViewType } from '@kbn/data-views-plugin/common';
export interface RollupJob {
job_id: string;
@ -67,7 +68,8 @@ async function loadRollupIndexPattern(
): Promise<DataView | null> {
const resp = await dataViewsService.find('*', 10000);
const obj = resp.find(
(dv) => dv.type === 'rollup' && dv.title === indexPattern && dv.typeMeta !== undefined
(dv) =>
dv.type === DataViewType.ROLLUP && dv.title === indexPattern && dv.typeMeta !== undefined
);
return obj ?? null;

View file

@ -7,6 +7,7 @@
import { get } from 'lodash';
import { ElasticsearchClient } from '@kbn/core/server';
import { estypes } from '@elastic/elasticsearch';
import { DataViewType } from '@kbn/data-views-plugin/common';
// elasticsearch index.max_result_window default value
const ES_MAX_RESULT_WINDOW_DEFAULT_VALUE = 1000;
@ -40,7 +41,7 @@ export async function fetchRollupIndexPatterns(kibanaIndex: string, esClient: El
bool: {
filter: {
term: {
'index-pattern.type': 'rollup',
'index-pattern.type': DataViewType.ROLLUP,
},
},
},

View file

@ -12,6 +12,7 @@ import expect from '@kbn/expect';
import { stringify } from 'query-string';
import { registerHelpers } from './rollup.test_helpers';
import { getRandomString } from './lib';
import { DataViewType } from '@kbn/data-views-plugin/common';
export default function ({ getService }) {
const supertest = getService('supertest');
@ -40,7 +41,7 @@ export default function ({ getService }) {
uri = `${BASE_URI}?${stringify(
{
pattern: 'foo',
type: 'rollup',
type: DataViewType.ROLLUP,
rollup_index: 'bar',
},
{ sort: false }
@ -63,7 +64,7 @@ export default function ({ getService }) {
// Query for wildcard
const params = {
pattern: indexName,
type: 'rollup',
type: DataViewType.ROLLUP,
rollup_index: rollupIndex,
};
const uri = `${BASE_URI}?${stringify(params, { sort: false })}`;

View file

@ -8,6 +8,7 @@
import expect from '@kbn/expect';
import { parse as parseCookie } from 'tough-cookie';
import { ELASTIC_HTTP_VERSION_HEADER } from '@kbn/core-http-common';
import { DataViewType } from '@kbn/data-views-plugin/common';
import { FtrProviderContext } from '../../ftr_provider_context';
import { verifyErrorResponse } from '../../../../../test/api_integration/apis/search/verify_error';
@ -384,7 +385,7 @@ export default function ({ getService }: FtrProviderContext) {
.set(ELASTIC_HTTP_VERSION_HEADER, '1')
.set('kbn-xsrf', 'foo')
.send({
indexType: 'rollup',
indexType: DataViewType.ROLLUP,
params: {
body: {
query: {
@ -403,7 +404,7 @@ export default function ({ getService }: FtrProviderContext) {
.set(ELASTIC_HTTP_VERSION_HEADER, '1')
.set('kbn-xsrf', 'foo')
.send({
indexType: 'rollup',
indexType: DataViewType.ROLLUP,
params: {
index: 'banana',
body: {
@ -424,7 +425,7 @@ export default function ({ getService }: FtrProviderContext) {
.set(ELASTIC_HTTP_VERSION_HEADER, '1')
.set('kbn-xsrf', 'foo')
.send({
indexType: 'rollup',
indexType: DataViewType.ROLLUP,
params: {
index: 'rollup_logstash',
size: 0,

View file

@ -10,6 +10,7 @@ import { ELASTIC_HTTP_VERSION_HEADER } from '@kbn/core-http-common';
import { INITIAL_REST_VERSION_INTERNAL } from '@kbn/data-views-plugin/server/constants';
import { X_ELASTIC_INTERNAL_ORIGIN_REQUEST } from '@kbn/core-http-common/src/constants';
import { FIELDS_FOR_WILDCARD_PATH as BASE_URI } from '@kbn/data-views-plugin/common/constants';
import { DataViewType } from '@kbn/data-views-plugin/common';
import { FtrProviderContext } from '../../../ftr_provider_context';
export default function ({ getService }: FtrProviderContext) {
@ -31,7 +32,7 @@ export default function ({ getService }: FtrProviderContext) {
.get(BASE_URI)
.query({
pattern: 'basic_index',
type: 'rollup',
type: DataViewType.ROLLUP,
rollup_index: 'bar',
})
.set(ELASTIC_HTTP_VERSION_HEADER, INITIAL_REST_VERSION_INTERNAL)

View file

@ -9,6 +9,7 @@ import expect from 'expect';
import { DATA_VIEW_PATH } from '@kbn/data-views-plugin/server';
import { ELASTIC_HTTP_VERSION_HEADER } from '@kbn/core-http-common';
import { INITIAL_REST_VERSION } from '@kbn/data-views-plugin/server/constants';
import { DataViewType } from '@kbn/data-views-plugin/common';
import { FtrProviderContext } from '../../../../ftr_provider_context';
const archivePath = 'test/api_integration/fixtures/es_archiver/index_patterns/basic_index';
@ -70,7 +71,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
.send({
data_view: {
title: 'basic_index',
type: 'rollup',
type: DataViewType.ROLLUP,
},
override: true,
})