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

[8.11] [Fleet] Replace dataviews suggestions in KQL searchboxes with internal ones (#172190) #172437

Merged
merged 3 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions x-pack/plugins/fleet/common/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,5 @@ export const FLEET_SERVER_INDICES = [
export const DATA_TIERS = ['data_hot'];

export const FLEET_ENROLLMENT_API_PREFIX = 'fleet-enrollment-api-keys';

export * from './mappings';
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

/**
* ATTENTION: New mappings for Fleet are defined in the ElasticSearch repo.
* ATTENTION: Mappings for Fleet are defined in the ElasticSearch repo.
*
* The following mappings declared here closely mirror them
* But they are only used to perform validation on the endpoints using ListWithKuery
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,20 @@
*/

import React from 'react';
import { act } from '@testing-library/react';

import type { FieldSpec } from '@kbn/data-plugin/common';

import { createFleetTestRendererMock } from '../../../mock';

import { SearchBar, filterAndConvertFields } from './search_bar';
import {
AGENTS_PREFIX,
FLEET_ENROLLMENT_API_PREFIX,
PACKAGE_POLICY_SAVED_OBJECT_TYPE,
AGENT_POLICY_SAVED_OBJECT_TYPE,
} from '../constants';

import { SearchBar, getFieldSpecs } from './search_bar';

const fields = [
{
Expand All @@ -36,39 +44,6 @@ const fields = [
},
] as FieldSpec[];

const allFields = [
{
name: 'test-index._id',
type: 'string',
esTypes: ['_id'],
},
{
name: 'test-index.api_key',
type: 'string',
esTypes: ['keyword'],
},
{
name: 'test-index.name',
type: 'string',
esTypes: ['keyword'],
},
{
name: 'another-index.version',
type: 'string',
esTypes: ['keyword'],
},
{
name: 'test2-index.name',
type: 'string',
esTypes: ['keyword'],
},
{
name: 'fleet-agents.actions',
type: 'string',
esTypes: ['keyword'],
},
] as FieldSpec[];

jest.mock('../hooks', () => {
return {
...jest.requireActual('../hooks'),
Expand All @@ -87,23 +62,6 @@ jest.mock('../hooks', () => {
},
data: {
dataViews: {
getFieldsForWildcard: jest.fn().mockResolvedValue([
{
name: '_id',
type: 'string',
esTypes: ['_id'],
},
{
name: 'api_key',
type: 'string',
esTypes: ['keyword'],
},
{
name: 'name',
type: 'string',
esTypes: ['keyword'],
},
]),
create: jest.fn().mockResolvedValue({
fields,
}),
Expand Down Expand Up @@ -197,6 +155,9 @@ describe('SearchBar', () => {
);

it('renders the search box', async () => {
await act(async () => {
result.queryByTestId('queryInput');
});
const textArea = result.queryByTestId('queryInput');
expect(textArea).not.toBeNull();
expect(textArea?.getAttribute('placeholder')).toEqual('Filter your data using KQL syntax');
Expand All @@ -207,60 +168,243 @@ describe('SearchBar', () => {
});
});

describe('filterAndConvertFields', () => {
it('leaves the fields names unchanged and does not hide any fields if fieldPrefix is not passed', async () => {
expect(filterAndConvertFields(fields, '.test-index')).toEqual({
_id: { esTypes: ['_id'], name: '_id', type: 'string' },
api_key: { esTypes: ['keyword'], name: 'api_key', type: 'string' },
name: { esTypes: ['keyword'], name: 'name', type: 'string' },
version: { esTypes: ['keyword'], name: 'version', type: 'string' },
});
describe('getFieldSpecs', () => {
it('returns fieldSpecs for fleet-agents', () => {
expect(getFieldSpecs(`.${AGENTS_PREFIX}`)).toHaveLength(57);
});

it('filters out the fields from other indices if indexPattern === .kibana-ingest', async () => {
expect(filterAndConvertFields(allFields, '.kibana_ingest', 'test-index')).toEqual({
'test-index._id': { esTypes: ['_id'], name: 'test-index._id', type: 'string' },
'test-index.api_key': { esTypes: ['keyword'], name: 'test-index.api_key', type: 'string' },
'test-index.name': { esTypes: ['keyword'], name: 'test-index.name', type: 'string' },
});
it('returns getFieldSpecs for fleet-enrollment-api-keys', () => {
const indexPattern = `.${FLEET_ENROLLMENT_API_PREFIX}`;
expect(getFieldSpecs(indexPattern)).toHaveLength(8);
expect(getFieldSpecs(indexPattern)).toEqual([
{
aggregatable: true,
esTypes: ['boolean'],
name: 'active',
searchable: true,
type: 'boolean',
},
{
aggregatable: true,
esTypes: ['keyword'],
name: 'api_key',
searchable: true,
type: 'string',
},
{
aggregatable: true,
esTypes: ['keyword'],
name: 'api_key_id',
searchable: true,
type: 'string',
},
{
aggregatable: true,
esTypes: ['date'],
name: 'created_at',
searchable: true,
type: 'date',
},
{
aggregatable: true,
esTypes: ['date'],
name: 'expire_at',
searchable: true,
type: 'date',
},
{
aggregatable: true,
esTypes: ['keyword'],
name: 'name',
searchable: true,
type: 'string',
},
{
aggregatable: true,
esTypes: ['keyword'],
name: 'policy_id',
searchable: true,
type: 'string',
},
{
aggregatable: true,
esTypes: ['date'],
name: 'updated_at',
searchable: true,
type: 'date',
},
]);
});

it('returns fields unchanged if fieldPrefix and indexPattern are not passed', async () => {
expect(filterAndConvertFields(allFields, undefined, undefined)).toEqual({
'another-index.version': {
it('returns getFieldSpecs for fleet-agent-policy', () => {
const indexPattern = `.${AGENT_POLICY_SAVED_OBJECT_TYPE}`;
expect(getFieldSpecs(indexPattern)).toHaveLength(23);
expect(getFieldSpecs(indexPattern)).toEqual([
{
aggregatable: true,
esTypes: ['keyword'],
name: 'another-index.version',
name: 'agent_features.name',
searchable: true,
type: 'string',
},
'fleet-agents.actions': {
{
aggregatable: true,
esTypes: ['boolean'],
name: 'agent_features.enabled',
searchable: true,
type: 'boolean',
},
{
aggregatable: true,
esTypes: ['keyword'],
name: 'fleet-agents.actions',
name: 'data_output_id',
searchable: true,
type: 'string',
},
'test-index._id': {
esTypes: ['_id'],
name: 'test-index._id',
{
aggregatable: true,
esTypes: ['text'],
name: 'description',
searchable: true,
type: 'string',
},
'test-index.api_key': {
{
aggregatable: true,
esTypes: ['keyword'],
name: 'test-index.api_key',
name: 'download_source_id',
searchable: true,
type: 'string',
},
'test-index.name': {
{
aggregatable: true,
esTypes: ['keyword'],
name: 'fleet_server_host_id',
searchable: true,
type: 'string',
},
{
aggregatable: true,
esTypes: ['integer'],
name: 'inactivity_timeout',
searchable: true,
type: 'number',
},
{
aggregatable: true,
esTypes: ['boolean'],
name: 'is_default',
searchable: true,
type: 'boolean',
},
{
aggregatable: true,
esTypes: ['boolean'],
name: 'is_default_fleet_server',
searchable: true,
type: 'boolean',
},
{
aggregatable: true,
esTypes: ['boolean'],
name: 'is_managed',
searchable: true,
type: 'boolean',
},
{
aggregatable: true,
esTypes: ['keyword'],
name: 'test-index.name',
name: 'is_preconfigured',
searchable: true,
type: 'string',
},
'test2-index.name': {
{
aggregatable: true,
esTypes: ['boolean'],
name: 'is_protected',
searchable: true,
type: 'boolean',
},
{
aggregatable: true,
esTypes: ['keyword'],
name: 'test2-index.name',
name: 'monitoring_enabled',
searchable: true,
type: 'string',
},
});
{
aggregatable: true,
esTypes: ['false'],
name: 'monitoring_enabled.index',
searchable: true,
type: 'false',
},
{
aggregatable: true,
esTypes: ['keyword'],
name: 'monitoring_output_id',
searchable: true,
type: 'string',
},
{
aggregatable: true,
esTypes: ['keyword'],
name: 'name',
searchable: true,
type: 'string',
},
{
aggregatable: true,
esTypes: ['keyword'],
name: 'namespace',
searchable: true,
type: 'string',
},
{
aggregatable: true,
esTypes: ['integer'],
name: 'revision',
searchable: true,
type: 'number',
},
{
aggregatable: true,
esTypes: ['version'],
name: 'schema_version',
searchable: true,
type: 'string',
},
{
aggregatable: true,
esTypes: ['keyword'],
name: 'status',
searchable: true,
type: 'string',
},
{
aggregatable: true,
esTypes: ['integer'],
name: 'unenroll_timeout',
searchable: true,
type: 'number',
},
{
aggregatable: true,
esTypes: ['date'],
name: 'updated_at',
searchable: true,
type: 'date',
},
{
aggregatable: true,
esTypes: ['keyword'],
name: 'updated_by',
searchable: true,
type: 'string',
},
]);
});
expect(getFieldSpecs(`.${PACKAGE_POLICY_SAVED_OBJECT_TYPE}`)).toHaveLength(18);

it('returns empty object if fields is empty', async () => {
expect(filterAndConvertFields([], '.kibana_ingest', 'test-index')).toEqual({});
it('returns empty array if indexPattern is not one of the previous', async () => {
expect(getFieldSpecs('.kibana_ingest')).toEqual([]);
});
});
Loading
Loading