Skip to content

Commit

Permalink
Merge branch 'main' into ftr/unify-saml-auth-service
Browse files Browse the repository at this point in the history
  • Loading branch information
dmlemeshko authored Aug 2, 2024
2 parents 40bf2c4 + 7dfe90e commit bad93a7
Show file tree
Hide file tree
Showing 158 changed files with 3,821 additions and 1,149 deletions.
2 changes: 1 addition & 1 deletion .buildkite/scripts/common/util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ check_for_changed_files() {
GIT_CHANGES="$(git status --porcelain -- . ':!:.bazelrc' ':!:config/node.options' ':!config/kibana.yml')"

if [ "$GIT_CHANGES" ]; then
if ! is_auto_commit_disabled && [[ "$SHOULD_AUTO_COMMIT_CHANGES" == "true" && "${BUILDKITE_PULL_REQUEST:-}" != "" && "${BUILDKITE_PULL_REQUEST}" != "false" ]]; then
if ! is_auto_commit_disabled && [[ "$SHOULD_AUTO_COMMIT_CHANGES" == "true" && "${BUILDKITE_PULL_REQUEST:-false}" != "false" ]]; then
NEW_COMMIT_MESSAGE="[CI] Auto-commit changed files from '$1'"
PREVIOUS_COMMIT_MESSAGE="$(git log -1 --pretty=%B)"

Expand Down
3 changes: 3 additions & 0 deletions .buildkite/scripts/steps/artifacts/publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ download "kibana-$FULL_VERSION-docker-image-aarch64.tar.gz"
download "kibana-cloud-$FULL_VERSION-docker-image.tar.gz"
download "kibana-cloud-$FULL_VERSION-docker-image-aarch64.tar.gz"
download "kibana-ubi-$FULL_VERSION-docker-image.tar.gz"
download "kibana-wolfi-$FULL_VERSION-docker-image.tar.gz"
download "kibana-wolfi-$FULL_VERSION-docker-image-aarch64.tar.gz"

download "kibana-$FULL_VERSION-arm64.deb"
download "kibana-$FULL_VERSION-amd64.deb"
Expand All @@ -33,6 +35,7 @@ download "kibana-$FULL_VERSION-docker-build-context.tar.gz"
download "kibana-cloud-$FULL_VERSION-docker-build-context.tar.gz"
download "kibana-ironbank-$FULL_VERSION-docker-build-context.tar.gz"
download "kibana-ubi-$FULL_VERSION-docker-build-context.tar.gz"
download "kibana-wolfi-$FULL_VERSION-docker-build-context.tar.gz"

download "kibana-$FULL_VERSION-linux-aarch64.tar.gz"
download "kibana-$FULL_VERSION-linux-x86_64.tar.gz"
Expand Down
3 changes: 1 addition & 2 deletions .buildkite/scripts/steps/serverless/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,7 @@ if is_pr_with_label "ci:project-deploy-observability" ; then
# Only deploy observability if the PR is targeting main
if [[ "$BUILDKITE_PULL_REQUEST_BASE_BRANCH" == "main" ]]; then
create_github_issue_oblt_test_environments
echo "--- Deploy observability with Kibana CI"
deploy "observability"
buildkite-agent annotate --context obl-test-info --style info 'See linked [Deploy Serverless Kibana] issue in pull request for project deployment information'
fi
fi
is_pr_with_label "ci:project-deploy-security" && deploy "security"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {
getMockedSearchControlFactory,
} from './mocks/factory_mocks';
import { ControlFactory } from '../types';
import { DataControlApi, DefaultDataControlState } from './types';
import { DataControlApi, DataControlFactory, DefaultDataControlState } from './types';

const mockDataViews = dataViewPluginMocks.createStartContract();
const mockDataView = createStubDataView({
Expand Down Expand Up @@ -106,13 +106,13 @@ describe('Data control editor', () => {
return controlEditor.getByTestId(testId).getAttribute('aria-pressed');
};

const mockRegistry: { [key: string]: ControlFactory<DefaultDataControlState, DataControlApi> } = {
search: getMockedSearchControlFactory({ parentApi: controlGroupApi }),
optionsList: getMockedOptionsListControlFactory({ parentApi: controlGroupApi }),
rangeSlider: getMockedRangeSliderControlFactory({ parentApi: controlGroupApi }),
};

beforeAll(() => {
const mockRegistry: { [key: string]: ControlFactory<DefaultDataControlState, DataControlApi> } =
{
search: getMockedSearchControlFactory({ parentApi: controlGroupApi }),
optionsList: getMockedOptionsListControlFactory({ parentApi: controlGroupApi }),
rangeSlider: getMockedRangeSliderControlFactory({ parentApi: controlGroupApi }),
};
(getAllControlTypes as jest.Mock).mockReturnValue(Object.keys(mockRegistry));
(getControlFactory as jest.Mock).mockImplementation((key) => mockRegistry[key]);
});
Expand All @@ -133,6 +133,50 @@ describe('Data control editor', () => {
expect(saveButton).toBeEnabled();
});

test('CompatibleControlTypesComponent respects ordering', async () => {
const tempRegistry: {
[key: string]: ControlFactory<DefaultDataControlState, DataControlApi>;
} = {
...mockRegistry,
alphabeticalFirstControl: {
type: 'alphabeticalFirst',
getIconType: () => 'lettering',
getDisplayName: () => 'Alphabetically first',
isFieldCompatible: () => true,
buildControl: jest.fn().mockReturnValue({
api: controlGroupApi,
Component: <>Should be first alphabetically</>,
}),
} as DataControlFactory,
supremeControl: {
type: 'supremeControl',
order: 100, // force it first despite alphabetical ordering
getIconType: () => 'starFilled',
getDisplayName: () => 'Supreme leader',
isFieldCompatible: () => true,
buildControl: jest.fn().mockReturnValue({
api: controlGroupApi,
Component: <>This control is forced first via the factory order</>,
}),
} as DataControlFactory,
};
(getAllControlTypes as jest.Mock).mockReturnValue(Object.keys(tempRegistry));
(getControlFactory as jest.Mock).mockImplementation((key) => tempRegistry[key]);

const controlEditor = await mountComponent({});
const menu = controlEditor.getByTestId('controlTypeMenu');
expect(menu.children.length).toEqual(5);
expect(menu.children[0].textContent).toEqual('Supreme leader'); // forced first - ignore alphabetical sorting
// the rest should be alphabetically sorted
expect(menu.children[1].textContent).toEqual('Alphabetically first');
expect(menu.children[2].textContent).toEqual('Options list');
expect(menu.children[3].textContent).toEqual('Range slider');
expect(menu.children[4].textContent).toEqual('Search');

(getAllControlTypes as jest.Mock).mockReturnValue(Object.keys(mockRegistry));
(getControlFactory as jest.Mock).mockImplementation((key) => mockRegistry[key]);
});

test('selecting a keyword field - can only create an options list control', async () => {
const controlEditor = await mountComponent({});
await selectField(controlEditor, 'machine.os.raw');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,18 @@ const CompatibleControlTypesComponent = ({
const dataControlFactories = useMemo(() => {
return getAllControlTypes()
.map((type) => getControlFactory(type))
.filter((factory) => {
return isDataControlFactory(factory);
});
.filter((factory) => isDataControlFactory(factory))
.sort(
(
{ order: orderA = 0, getDisplayName: getDisplayNameA },
{ order: orderB = 0, getDisplayName: getDisplayNameB }
) => {
const orderComparison = orderB - orderA; // sort descending by order
return orderComparison === 0
? getDisplayNameA().localeCompare(getDisplayNameB()) // if equal order, compare display names
: orderComparison;
}
);
}, []);

return (
Expand Down Expand Up @@ -283,8 +292,23 @@ export const DataControlEditor = <State extends DataControlEditorState = DataCon
dataView={selectedDataView}
onSelectField={(field) => {
setEditorState({ ...editorState, fieldName: field.name });
setSelectedControlType(fieldRegistry?.[field.name]?.compatibleControlTypes[0]);

/**
* make sure that the new field is compatible with the selected control type and, if it's not,
* reset the selected control type to the **first** compatible control type
*/
const newCompatibleControlTypes =
fieldRegistry?.[field.name]?.compatibleControlTypes ?? [];
if (
!selectedControlType ||
!newCompatibleControlTypes.includes(selectedControlType!)
) {
setSelectedControlType(newCompatibleControlTypes[0]);
}

/**
* set the control title (i.e. the one set by the user) + default title (i.e. the field display name)
*/
const newDefaultTitle = field.displayName ?? field.name;
setDefaultPanelTitle(newDefaultTitle);
const currentTitle = editorState.title;
Expand Down Expand Up @@ -365,7 +389,6 @@ export const DataControlEditor = <State extends DataControlEditorState = DataCon
{/* )} */}
</EuiDescribedFormGroup>
{CustomSettingsComponent}
{/* {!editorConfig?.hideAdditionalSettings ? CustomSettingsComponent : null} */}
{initialState.controlId && (
<>
<EuiSpacer size="l" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export const getOptionsListControlFactory = (
): DataControlFactory<OptionsListControlState, OptionsListControlApi> => {
return {
type: OPTIONS_LIST_CONTROL_TYPE,
order: 3, // should always be first, since this is the most popular control
getIconType: () => 'editorChecklist',
getDisplayName: OptionsListStrings.control.getDisplayName,
isFieldCompatible: (field) => {
Expand Down
1 change: 1 addition & 0 deletions examples/controls_example/public/react_controls/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export interface ControlFactory<
ControlApi extends DefaultControlApi = DefaultControlApi
> {
type: string;
order?: number;
getIconType: () => string;
getDisplayName: () => string;
buildControl: (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,16 @@ export function registerEluHistoryRoute(router: IRouter, metrics$: Observable<Op

router.versioned
.get({
access: 'public', // Public but needs to remain undocumented
access: 'internal',
enableQueryVersion: true,
path: '/api/_elu_history',
options: {
authRequired: false,
},
})
.addVersion(
{
version: '2023-10-31',
version: '1',
validate: false,
},
async (ctx, req, res) => {
Expand Down
2 changes: 2 additions & 0 deletions packages/kbn-doc-links/src/get_doc_links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,7 @@ export const getDocLinks = ({ kibanaBranch, buildFlavor }: GetDocLinkOptions): D
assetCriticality: `${SECURITY_SOLUTION_DOCS}asset-criticality.html`,
},
detectionEngineOverview: `${SECURITY_SOLUTION_DOCS}detection-engine-overview.html`,
aiAssistant: `${SECURITY_SOLUTION_DOCS}security-assistant.html`,
},
query: {
eql: `${ELASTICSEARCH_DOCS}eql.html`,
Expand Down Expand Up @@ -618,6 +619,7 @@ export const getDocLinks = ({ kibanaBranch, buildFlavor }: GetDocLinkOptions): D
sloBurnRateRule: isServerless
? `${SERVERLESS_OBSERVABILITY_DOCS}create-slo-burn-rate-alert-rule`
: `${OBSERVABILITY_DOCS}slo-burn-rate-alert.html`,
aiAssistant: `${OBSERVABILITY_DOCS}obs-ai-assistant.html`,
},
alerting: {
guide: isServerless
Expand Down
2 changes: 2 additions & 0 deletions packages/kbn-doc-links/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ export interface DocLinks {
readonly configureAlertSuppression: string;
};
readonly securitySolution: {
readonly aiAssistant: string;
readonly artifactControl: string;
readonly avcResults: string;
readonly trustedApps: string;
Expand Down Expand Up @@ -441,6 +442,7 @@ export interface DocLinks {
syntheticsProjectMonitors: string;
syntheticsMigrateFromIntegration: string;
sloBurnRateRule: string;
aiAssistant: string;
}>;
readonly alerting: Readonly<{
guide: string;
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-optimizer/kibana.jsonc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"type": "shared-common",
"type": "shared-server",
"id": "@kbn/optimizer",
"devOnly": true,
"owner": "@elastic/kibana-operations"
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-plugin-helpers/kibana.jsonc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"type": "shared-common",
"type": "shared-server",
"id": "@kbn/plugin-helpers",
"devOnly": true,
"owner": "@elastic/kibana-operations"
Expand Down
5 changes: 4 additions & 1 deletion src/core/server/integration_tests/metrics/elu_load.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ describe('GET /api/_elu_load', () => {
});

it('gets ELU load average', async () => {
const { body } = await supertest(listener).get('/api/_elu_history').expect(200);
const { body } = await supertest(listener)
.get('/api/_elu_history')
.query({ apiVersion: '1', elasticInternalOrigin: 'true' })
.expect(200);
expect(body).toEqual({
history: {
short: expect.any(Number),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@
import React, { createContext, useContext } from 'react';
import type { ChromeBreadcrumb } from '@kbn/core-chrome-browser';
import type { CoreStart } from '@kbn/core/public';
import type { BuildFlavor } from '@kbn/config';
import type { StartDependencies } from './plugin';

interface ContextValue extends StartDependencies {
setBreadcrumbs: (crumbs: ChromeBreadcrumb[]) => void;

capabilities: CoreStart['application']['capabilities'];
navigateToApp: CoreStart['application']['navigateToApp'];
kibanaBranch: string;
buildFlavor: BuildFlavor;
}

const AppContext = createContext<ContextValue>(null as any);
Expand Down
5 changes: 3 additions & 2 deletions src/plugins/ai_assistant_management/selection/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Side Public License, v 1.
*/

import type { PluginInitializer } from '@kbn/core/public';
import type { PluginInitializer, PluginInitializerContext } from '@kbn/core/public';
import { AIAssistantManagementPlugin } from './plugin';

import type {
Expand All @@ -24,4 +24,5 @@ export type {
export const plugin: PluginInitializer<
AIAssistantManagementSelectionPluginPublicSetup,
AIAssistantManagementSelectionPluginPublicStart
> = () => new AIAssistantManagementPlugin();
> = (initializerContext: PluginInitializerContext) =>
new AIAssistantManagementPlugin(initializerContext);
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { i18n } from '@kbn/i18n';
import type { CoreSetup } from '@kbn/core/public';
import { wrapWithTheme } from '@kbn/kibana-react-plugin/public';
import type { ManagementAppMountParams } from '@kbn/management-plugin/public';
import type { BuildFlavor } from '@kbn/config';
import type { StartDependencies, AIAssistantManagementSelectionPluginPublicStart } from '../plugin';
import { aIAssistantManagementSelectionRouter } from '../routes/config';
import { RedirectToHomeIfUnauthorized } from '../routes/components/redirect_to_home_if_unauthorized';
Expand All @@ -22,9 +23,16 @@ import { AppContextProvider } from '../app_context';
interface MountParams {
core: CoreSetup<StartDependencies, AIAssistantManagementSelectionPluginPublicStart>;
mountParams: ManagementAppMountParams;
kibanaBranch: string;
buildFlavor: BuildFlavor;
}

export const mountManagementSection = async ({ core, mountParams }: MountParams) => {
export const mountManagementSection = async ({
core,
mountParams,
kibanaBranch,
buildFlavor,
}: MountParams) => {
const [coreStart, startDeps] = await core.getStartServices();
const { element, history, setBreadcrumbs } = mountParams;
const { theme$ } = core.theme;
Expand All @@ -45,6 +53,8 @@ export const mountManagementSection = async ({ core, mountParams }: MountParams)
capabilities: coreStart.application.capabilities,
navigateToApp: coreStart.application.navigateToApp,
setBreadcrumbs,
kibanaBranch,
buildFlavor,
}}
>
<RouterProvider history={history} router={aIAssistantManagementSelectionRouter as any}>
Expand Down
13 changes: 11 additions & 2 deletions src/plugins/ai_assistant_management/selection/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
*/

import { i18n } from '@kbn/i18n';
import { type CoreSetup, Plugin, type CoreStart } from '@kbn/core/public';
import { type CoreSetup, Plugin, type CoreStart, PluginInitializerContext } from '@kbn/core/public';
import type { ManagementSetup } from '@kbn/management-plugin/public';
import type { HomePublicPluginSetup } from '@kbn/home-plugin/public';
import type { ServerlessPluginSetup } from '@kbn/serverless/public';
import { BehaviorSubject, Observable } from 'rxjs';
import type { BuildFlavor } from '@kbn/config';
import { AIAssistantType } from '../common/ai_assistant_type';
import { PREFERRED_AI_ASSISTANT_TYPE_SETTING_KEY } from '../common/ui_setting_keys';

Expand Down Expand Up @@ -40,7 +41,13 @@ export class AIAssistantManagementPlugin
StartDependencies
>
{
constructor() {}
private readonly kibanaBranch: string;
private readonly buildFlavor: BuildFlavor;

constructor(private readonly initializerContext: PluginInitializerContext) {
this.kibanaBranch = this.initializerContext.env.packageInfo.branch;
this.buildFlavor = this.initializerContext.env.packageInfo.buildFlavor;
}

public setup(
core: CoreSetup<StartDependencies, AIAssistantManagementSelectionPluginPublicStart>,
Expand Down Expand Up @@ -78,6 +85,8 @@ export class AIAssistantManagementPlugin
return mountManagementSection({
core,
mountParams,
kibanaBranch: this.kibanaBranch,
buildFlavor: this.buildFlavor,
});
},
});
Expand Down
Loading

0 comments on commit bad93a7

Please sign in to comment.