Skip to content

Commit

Permalink
Merge branch 'main' into rca/hide-app
Browse files Browse the repository at this point in the history
  • Loading branch information
kdelemme authored Jul 26, 2024
2 parents 19ae164 + 7db2868 commit 68e891e
Show file tree
Hide file tree
Showing 48 changed files with 2,488 additions and 114 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ check_for_changed_files "yarn openapi:bundle:entity-analytics" true

echo -e "\n[Security Solution OpenAPI Bundling] Lists API\n"

echo -e "\n[Security Solution OpenAPI Bundling] Endpoint Management API\n"

(cd x-pack/plugins/security_solution && yarn openapi:bundle:endpoint-management)
check_for_changed_files "yarn openapi:bundle:endpoint-management" true

(cd packages/kbn-securitysolution-lists-common && yarn openapi:bundle)
check_for_changed_files "yarn openapi:bundle" true

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ export const slashRegex = /\//;
export const ampersandRegex = /&/;
export const equalsSignRegex = /=/;
export const questionMarkRegex = /\?/;
export const variableTemplateRegex = /\${(\w+)}/g;
export const urlVariableTemplateRegex = /\${(\w+)}/g;
export const dataVariableTemplateRegex = /"\${(\w+)}"/g;
export const numberStartRegex = /[-\d]/;
export const digitRegex = /[\d]/;
export const lettersRegex = /[A-Za-z]/;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ describe('requests_utils', () => {
name: 'variable2',
value: 'test2',
},
{
id: '3',
name: 'variable3',
value: '{"match_all": {}}',
},
];

describe('replaces variables in the url', () => {
Expand Down Expand Up @@ -96,11 +101,20 @@ describe('requests_utils', () => {
const request = {
method: 'GET',
url: '${variable1}',
data: [JSON.stringify({ '${variable1}': '${variable2}' }, null, 2)],
data: [
JSON.stringify(
{ '${variable1}': '${variable2}', '${variable2}': '${variable3}' },
null,
2
),
],
};
it('works with several variables', () => {
const result = replaceRequestVariables(request, variables);
expect(result.data[0]).toBe(JSON.stringify({ test1: 'test2' }, null, 2));
expect(JSON.parse(result.data[0])).toMatchObject({
test1: 'test2',
test2: { match_all: {} },
});
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { constructUrl } from '../../../../../lib/es';
import { MetricsTracker } from '../../../../../types';
import type { DevToolsVariable } from '../../../../components';
import type { EditorRequest } from '../types';
import { variableTemplateRegex } from './constants';
import { urlVariableTemplateRegex, dataVariableTemplateRegex } from './constants';
import { removeTrailingWhitespaces } from './tokens_utils';
import { AdjustedParsedRequest } from '../types';

Expand All @@ -38,8 +38,8 @@ export const replaceRequestVariables = (
): EditorRequest => {
return {
method,
url: replaceVariables(url, variables),
data: data.map((dataObject) => replaceVariables(dataObject, variables)),
url: replaceVariables(url, variables, false),
data: data.map((dataObject) => replaceVariables(dataObject, variables, true)),
};
};

Expand Down Expand Up @@ -118,15 +118,35 @@ export const getRequestEndLineNumber = (
return endLineNumber;
};

const isJsonString = (str: string) => {
try {
JSON.parse(str);
} catch (e) {
return false;
}
return true;
};

/*
* Internal helpers
*/
const replaceVariables = (text: string, variables: DevToolsVariable[]): string => {
if (variableTemplateRegex.test(text)) {
text = text.replaceAll(variableTemplateRegex, (match, key) => {
const replaceVariables = (
text: string,
variables: DevToolsVariable[],
isDataVariable: boolean
): string => {
const variableRegex = isDataVariable ? dataVariableTemplateRegex : urlVariableTemplateRegex;
if (variableRegex.test(text)) {
text = text.replaceAll(variableRegex, (match, key) => {
const variable = variables.find(({ name }) => name === key);
const value = variable?.value;

if (isDataVariable && value) {
// If the variable value is an object, add it as it is. Otherwise, surround it with quotes.
return isJsonString(value) ? value : `"${value}"`;
}

return variable?.value ?? match;
return value ?? match;
});
}
return text;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default function ({ getService }: FtrProviderContext) {

expect(resp.body).to.be.an('array');

expect(resp.body.length).to.be(55);
expect(resp.body.length).to.be(56);

// Test for sample data card
expect(resp.body.findIndex((c: { id: string }) => c.id === 'sample_data_all')).to.be.above(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ export default function ({ getService }: PluginFunctionalProviderContext) {
'xpack.stack_connectors.enableExperimental (array)',
'xpack.trigger_actions_ui.enableExperimental (array)',
'xpack.trigger_actions_ui.enableGeoTrackingThresholdAlert (boolean)',
'xpack.timelines.enableExperimental (array)',
'xpack.alerting.rules.run.alerts.max (number)',
'xpack.upgrade_assistant.featureSet.migrateSystemIndices (boolean)',
'xpack.upgrade_assistant.featureSet.mlSnapshots (boolean)',
Expand Down
39 changes: 30 additions & 9 deletions x-pack/plugins/data_quality/public/application.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ import ReactDOM from 'react-dom';
import { KibanaRenderContextProvider } from '@kbn/react-kibana-context-render';
import { Route, Router, Routes } from '@kbn/shared-ux-router';
import { PerformanceContextProvider } from '@kbn/ebt-tools';
import { useExecutionContext } from '@kbn/kibana-react-plugin/public';
import { KbnUrlStateStorageFromRouterProvider } from './utils/kbn_url_state_context';
import { useKibanaContextForPluginProvider } from './utils/use_kibana';
import { AppPluginStartDependencies, DataQualityPluginStart } from './types';
import { DatasetQualityRoute } from './routes';
import { PLUGIN_ID } from '../common';

export const renderApp = (
core: CoreStart,
Expand All @@ -33,6 +35,33 @@ export const renderApp = (
};
};

const AppWithExecutionContext = ({
core,
params,
}: {
core: CoreStart;
params: ManagementAppMountParams;
}) => {
const { executionContext } = core;

useExecutionContext(executionContext, {
type: 'application',
page: PLUGIN_ID,
});

return (
<KbnUrlStateStorageFromRouterProvider>
<Router history={params.history}>
<PerformanceContextProvider>
<Routes>
<Route path="/" exact={true} render={() => <DatasetQualityRoute />} />
</Routes>
</PerformanceContextProvider>
</Router>
</KbnUrlStateStorageFromRouterProvider>
);
};

interface AppProps {
core: CoreStart;
plugins: AppPluginStartDependencies;
Expand All @@ -51,15 +80,7 @@ const App = ({ core, plugins, pluginStart, params }: AppProps) => {
return (
<KibanaRenderContextProvider {...core} {...params}>
<KibanaContextProviderForPlugin>
<KbnUrlStateStorageFromRouterProvider>
<Router history={params.history}>
<PerformanceContextProvider>
<Routes>
<Route path="/" exact={true} render={() => <DatasetQualityRoute />} />
</Routes>
</PerformanceContextProvider>
</Router>
</KbnUrlStateStorageFromRouterProvider>
<AppWithExecutionContext core={core} params={params} />
</KibanaContextProviderForPlugin>
</KibanaRenderContextProvider>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function hasProperties(field: MappingProperty): field is MappingPropertyBase {
}

function isLocalModel(model: InferenceServiceSettings): model is LocalInferenceServiceSettings {
return Boolean((model as LocalInferenceServiceSettings).service_settings.model_id);
return ['elser', 'elasticsearch'].includes((model as LocalInferenceServiceSettings).service);
}

export const IndexError: React.FC<IndexErrorProps> = ({ indexName }) => {
Expand Down Expand Up @@ -124,7 +124,7 @@ export const IndexError: React.FC<IndexErrorProps> = ({ indexName }) => {
if (!modelStats || modelStats.deployment_stats?.state !== 'started') {
return {
error: i18n.translate(
'xpack.enterpriseSearch.indexOverview.indexErrors.missingModelError',
'xpack.enterpriseSearch.indexOverview.indexErrors.modelNotDeployedError',
{
defaultMessage:
'Model {modelId} for inference endpoint {inferenceId} in field {fieldName} has not been started',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@ jest.mock('../hooks', () => ({
},
},
}),
useGetAgentPolicies: jest.fn(),
useGetAgentPolicies: jest.fn().mockReturnValue({
data: {
items: [] as AgentPolicy[],
},
isLoading: false,
}),
useGetPackagePolicies: jest.fn().mockReturnValue({
data: {
items: [{ name: 'Integration 1', revision: 2, id: 'integration1', policy_ids: ['policy1'] }],
Expand All @@ -59,8 +64,7 @@ jest.mock('../hooks', () => ({
}),
}));

// FLAKY: https://github.com/elastic/kibana/issues/189004
describe.skip('ManageAgentPoliciesModal', () => {
describe('ManageAgentPoliciesModal', () => {
let testRenderer: TestRenderer;
const mockOnClose = jest.fn();
const mockPolicies = [{ name: 'Test policy', revision: 2, id: 'policy1' }] as AgentPolicy[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ export const setup = async ({
find('inferenceIdButton').simulate('click');
},
openSelectInferencePopover: () => {
expect(exists('addInferenceEndpointButton')).toBe(true);
expect(exists('learn-how-to-create-inference-endpoints')).toBe(true);
expect(exists('manageInferenceEndpointButton')).toBe(true);
},
expectDefaultInferenceModelToExists: () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@ const mockDispatch = jest.fn();
jest.mock('../../../public/application/app_context', () => ({
useAppContext: jest.fn().mockReturnValue({
core: { application: {} },
docLinks: {},
docLinks: {
links: {
enterpriseSearch: {
inferenceApiCreate: 'https://abc.com/inference-api-create',
},
},
},
plugins: {
ml: {
mlApi: {
Expand Down Expand Up @@ -93,7 +99,7 @@ describe('SelectInferenceId', () => {

it('should contain the buttons for InferenceEndpoint management', () => {
find('inferenceIdButton').simulate('click');
expect(exists('addInferenceEndpointButton')).toBe(true);
expect(exists('learn-how-to-create-inference-endpoints')).toBe(true);
expect(exists('manageInferenceEndpointButton')).toBe(true);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import {
EuiSpacer,
EuiText,
EuiTitle,
EuiIcon,
EuiLink,
} from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import React, { useEffect, useState, useCallback, useMemo } from 'react';
Expand Down Expand Up @@ -237,25 +239,6 @@ const SelectInferenceIdContent: React.FC<SelectInferenceIdContentProps> = ({
closePopover={() => setIsInferencePopoverVisible(!isInferencePopoverVisible)}
>
<EuiContextMenuPanel>
<EuiContextMenuItem
key="addInferenceEndpoint"
icon="plusInCircle"
size="s"
data-test-subj="addInferenceEndpointButton"
onClick={() => {
setIsInferenceFlyoutVisible(!isInferenceFlyoutVisible);
setInferenceEndpointError(undefined);
setIsInferencePopoverVisible(!isInferencePopoverVisible);
}}
>
{i18n.translate(
'xpack.idxMgmt.mappingsEditor.parameters.inferenceId.popover.addInferenceEndpointButton',
{
defaultMessage: 'Add Inference Endpoint',
}
)}
</EuiContextMenuItem>
<EuiHorizontalRule margin="none" />
<EuiContextMenuItem
key="manageInferenceEndpointButton"
icon="gear"
Expand Down Expand Up @@ -323,6 +306,21 @@ const SelectInferenceIdContent: React.FC<SelectInferenceIdContentProps> = ({
)}
</EuiSelectable>
</EuiPanel>
<EuiHorizontalRule margin="none" />
<EuiContextMenuItem icon={<EuiIcon type="help" color="primary" />} size="s">
<EuiLink
href={docLinks.links.enterpriseSearch.inferenceApiCreate}
target="_blank"
data-test-subj="learn-how-to-create-inference-endpoints"
>
{i18n.translate(
'xpack.idxMgmt.mappingsEditor.parameters.learnHowToCreateInferenceEndpoints',
{
defaultMessage: 'Learn how to create inference endpoints',
}
)}
</EuiLink>
</EuiContextMenuItem>
</EuiPopover>
);
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,10 @@ export const ExpressionEditor: React.FC<
<Editor {...props} />
</SourceStatusWrapper>
) : (
<LogViewProvider logViews={logsShared.logViews.client}>
<LogViewProvider
logViews={logsShared.logViews.client}
initialLogViewReference={props.ruleParams.logView}
>
<SourceStatusWrapper {...props}>
<Editor {...props} />
</SourceStatusWrapper>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
PublicAlertsClient,
RecoveredAlertData,
} from '@kbn/alerting-plugin/server/alerts_client/types';
import { type Group } from '@kbn/observability-alerting-rule-utils';
import { getEcsGroups, type Group } from '@kbn/observability-alerting-rule-utils';

import { ecsFieldMap } from '@kbn/rule-registry-plugin/common/assets/field_maps/ecs_field_map';
import { decodeOrThrow } from '@kbn/io-ts-utils';
Expand Down Expand Up @@ -191,6 +191,7 @@ export const createLogThresholdExecutor =
[ALERT_CONTEXT]: alertContext,
[ALERT_GROUP]: groups,
...flattenAdditionalContext(rootLevelContext),
...getEcsGroups(groups),
};

alertsClient.setAlertData({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"discover",
"share",
"fleet",
"security"
"security",
"customIntegrations",
],
"optionalPlugins": [
"cloud",
Expand Down
Loading

0 comments on commit 68e891e

Please sign in to comment.