Skip to content

Commit

Permalink
Merge branch 'main' into fix-ui-conditional-actions
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine authored Apr 26, 2023
2 parents 86a6320 + 78f625e commit 5eeeebe
Show file tree
Hide file tree
Showing 196 changed files with 4,165 additions and 5,765 deletions.
32 changes: 16 additions & 16 deletions .buildkite/scripts/steps/artifacts/docker_image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ set -euo pipefail
source .buildkite/scripts/steps/artifacts/env.sh

GIT_ABBREV_COMMIT=${BUILDKITE_COMMIT:0:12}
KIBANA_IMAGE="docker.elastic.co/kibana-ci/kibana:git-$GIT_ABBREV_COMMIT"
KIBANA_IMAGE_INPUT="docker.elastic.co/kibana-ci/kibana-serverless:git-$GIT_ABBREV_COMMIT"
KIBANA_IMAGE_OUTPUT="docker.elastic.co/kibana-ci/kibana:git-$GIT_ABBREV_COMMIT"

echo "--- Verify manifest does not already exist"
echo "$KIBANA_DOCKER_PASSWORD" | docker login -u "$KIBANA_DOCKER_USERNAME" --password-stdin docker.elastic.co
trap 'docker logout docker.elastic.co' EXIT

if docker manifest inspect $KIBANA_IMAGE &> /dev/null; then
if docker manifest inspect $KIBANA_IMAGE_OUTPUT &> /dev/null; then
echo "Manifest already exists, exiting"
exit 1
fi
Expand All @@ -32,37 +33,36 @@ node scripts/build \
--skip-docker-contexts

echo "--- Tag images"
docker rmi "$KIBANA_IMAGE"
docker rmi "$KIBANA_IMAGE_INPUT"
docker load < "target/kibana-serverless-$BASE_VERSION-docker-image.tar.gz"
docker tag "$KIBANA_IMAGE" "$KIBANA_IMAGE-amd64"
docker tag "$KIBANA_IMAGE_INPUT" "$KIBANA_IMAGE_OUTPUT-amd64"

docker rmi "$KIBANA_IMAGE"
docker rmi "$KIBANA_IMAGE_INPUT"
docker load < "target/kibana-serverless-$BASE_VERSION-docker-image-aarch64.tar.gz"
docker tag "$KIBANA_IMAGE" "$KIBANA_IMAGE-arm64"
docker tag "$KIBANA_IMAGE_INPUT" "$KIBANA_IMAGE_OUTPUT-arm64"

echo "--- Push images"
docker image push "$KIBANA_IMAGE-arm64"
docker image push "$KIBANA_IMAGE-amd64"
docker image push "$KIBANA_IMAGE_OUTPUT-arm64"
docker image push "$KIBANA_IMAGE_OUTPUT-amd64"

echo "--- Create manifest"
docker rmi "$KIBANA_IMAGE"
docker manifest create \
"$KIBANA_IMAGE" \
--amend "$KIBANA_IMAGE-arm64" \
--amend "$KIBANA_IMAGE-amd64"
"$KIBANA_IMAGE_OUTPUT" \
--amend "$KIBANA_IMAGE_OUTPUT-arm64" \
--amend "$KIBANA_IMAGE_OUTPUT-amd64"

echo "--- Push manifest"
docker manifest push "$KIBANA_IMAGE"
docker manifest push "$KIBANA_IMAGE_OUTPUT"
docker logout docker.elastic.co

cat << EOF | buildkite-agent annotate --style "info" --context image
### Container Images
Manifest: \`$KIBANA_IMAGE\`
Manifest: \`$KIBANA_IMAGE_OUTPUT\`
AMD64: \`$KIBANA_IMAGE-amd64\`
AMD64: \`$KIBANA_IMAGE_OUTPUT-amd64\`
ARM64: \`$KIBANA_IMAGE-arm64\`
ARM64: \`$KIBANA_IMAGE_OUTPUT-arm64\`
EOF

echo "--- Build dependencies report"
Expand Down
3 changes: 3 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,9 @@ packages/core/usage-data/core-usage-data-base-server-internal @elastic/kibana-co
packages/core/usage-data/core-usage-data-server @elastic/kibana-core
packages/core/usage-data/core-usage-data-server-internal @elastic/kibana-core
packages/core/usage-data/core-usage-data-server-mocks @elastic/kibana-core
packages/core/user-settings/core-user-settings-server @elastic/platform-security
packages/core/user-settings/core-user-settings-server-internal @elastic/platform-security
packages/core/user-settings/core-user-settings-server-mocks @elastic/platform-security
x-pack/plugins/cross_cluster_replication @elastic/platform-deployment-management
packages/kbn-crypto @elastic/kibana-security
packages/kbn-crypto-browser @elastic/kibana-core
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,9 @@
"@kbn/core-usage-data-base-server-internal": "link:packages/core/usage-data/core-usage-data-base-server-internal",
"@kbn/core-usage-data-server": "link:packages/core/usage-data/core-usage-data-server",
"@kbn/core-usage-data-server-internal": "link:packages/core/usage-data/core-usage-data-server-internal",
"@kbn/core-user-settings-server": "link:packages/core/user-settings/core-user-settings-server",
"@kbn/core-user-settings-server-internal": "link:packages/core/user-settings/core-user-settings-server-internal",
"@kbn/core-user-settings-server-mocks": "link:packages/core/user-settings/core-user-settings-server-mocks",
"@kbn/cross-cluster-replication-plugin": "link:x-pack/plugins/cross_cluster_replication",
"@kbn/crypto": "link:packages/kbn-crypto",
"@kbn/crypto-browser": "link:packages/kbn-crypto-browser",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import type { InternalStatusServiceSetup } from '@kbn/core-status-server-interna
import type { InternalUiSettingsServiceSetup } from '@kbn/core-ui-settings-server-internal';
import type { InternalCoreUsageDataSetup } from '@kbn/core-usage-data-base-server-internal';
import type { InternalCustomBrandingSetup } from '@kbn/core-custom-branding-server-internal';
import type { InternalUserSettingsServiceSetup } from '@kbn/core-user-settings-server-internal';

/** @internal */
export interface InternalCoreSetup {
Expand All @@ -47,4 +48,5 @@ export interface InternalCoreSetup {
deprecations: InternalDeprecationsServiceSetup;
coreUsageData: InternalCoreUsageDataSetup;
customBranding: InternalCustomBrandingSetup;
userSettings: InternalUserSettingsServiceSetup;
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
"@kbn/core-usage-data-base-server-internal",
"@kbn/core-usage-data-server",
"@kbn/core-custom-branding-server-internal",
"@kbn/core-custom-branding-server"
"@kbn/core-custom-branding-server",
"@kbn/core-user-settings-server-internal"
],
"exclude": [
"target/**/*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { executionContextServiceMock } from '@kbn/core-execution-context-server-
import { coreUsageDataServiceMock } from '@kbn/core-usage-data-server-mocks';
import { customBrandingServiceMock } from '@kbn/core-custom-branding-server-mocks';
import { createCoreStartMock } from './core_start.mock';
import { userSettingsServiceMock } from '@kbn/core-user-settings-server-mocks';

type CoreSetupMockType = MockedKeys<CoreSetup> & {
elasticsearch: ReturnType<typeof elasticsearchServiceMock.createSetup>;
Expand Down Expand Up @@ -53,6 +54,7 @@ export function createCoreSetupMock({
analytics: analyticsServiceMock.createAnalyticsServiceSetup(),
capabilities: capabilitiesServiceMock.createSetupContract(),
customBranding: customBrandingServiceMock.createSetupContract(),
userSettings: userSettingsServiceMock.createSetupContract(),
docLinks: docLinksServiceMock.createSetupContract(),
elasticsearch: elasticsearchServiceMock.createSetup(),
http: httpMock,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { statusServiceMock } from '@kbn/core-status-server-mocks';
import { uiSettingsServiceMock } from '@kbn/core-ui-settings-server-mocks';
import { coreUsageDataServiceMock } from '@kbn/core-usage-data-server-mocks';
import { customBrandingServiceMock } from '@kbn/core-custom-branding-server-mocks';
import { userSettingsServiceMock } from '@kbn/core-user-settings-server-mocks';

export function createInternalCoreSetupMock() {
const setupDeps = {
Expand All @@ -47,6 +48,7 @@ export function createInternalCoreSetupMock() {
executionContext: executionContextServiceMock.createInternalSetupContract(),
coreUsageData: coreUsageDataServiceMock.createSetupContract(),
customBranding: customBrandingServiceMock.createSetupContract(),
userSettings: userSettingsServiceMock.createSetupContract(),
};
return setupDeps;
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"@kbn/core-http-request-handler-context-server",
"@kbn/core-logging-server-mocks",
"@kbn/core-custom-branding-server-mocks",
"@kbn/core-user-settings-server-mocks",
],
"exclude": [
"target/**/*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { StatusServiceSetup } from '@kbn/core-status-server';
import { UiSettingsServiceSetup } from '@kbn/core-ui-settings-server';
import { CoreUsageDataSetup } from '@kbn/core-usage-data-server';
import { CustomBrandingSetup } from '@kbn/core-custom-branding-server';
import { UserSettingsServiceSetup } from '@kbn/core-user-settings-server';
import { CoreStart } from './core_start';

/**
Expand Down Expand Up @@ -64,6 +65,8 @@ export interface CoreSetup<TPluginsStart extends object = object, TStart = unkno
status: StatusServiceSetup;
/** {@link UiSettingsServiceSetup} */
uiSettings: UiSettingsServiceSetup;
/** {@link UserSettingsServiceSetup} */
userSettings: UserSettingsServiceSetup;
/** {@link DeprecationsServiceSetup} */
deprecations: DeprecationsServiceSetup;
/** {@link StartServicesAccessor} */
Expand Down
3 changes: 2 additions & 1 deletion packages/core/lifecycle/core-lifecycle-server/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"@kbn/core-status-server",
"@kbn/core-ui-settings-server",
"@kbn/core-usage-data-server",
"@kbn/core-custom-branding-server"
"@kbn/core-custom-branding-server",
"@kbn/core-user-settings-server"
],
"exclude": [
"target/**/*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,9 @@ export function createPluginSetupContext<TPlugin, TPluginDependencies>(
register: deps.uiSettings.register,
registerGlobal: deps.uiSettings.registerGlobal,
},
userSettings: {
setUserProfileSettings: deps.userSettings.setUserProfileSettings,
},
getStartServices: () => plugin.startDependencies,
deprecations: deps.deprecations.getRegistry(plugin.name),
coreUsageData: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import type { UiPlugins } from '@kbn/core-plugins-base-server-internal';
import { httpServiceMock, httpServerMock } from '@kbn/core-http-server-mocks';
import { uiSettingsServiceMock } from '@kbn/core-ui-settings-server-mocks';
import { bootstrapRendererFactory, BootstrapRenderer } from './bootstrap_renderer';
import { userSettingsServiceMock } from '@kbn/core-user-settings-server-mocks';

const createPackageInfo = (parts: Partial<PackageInfo> = {}): PackageInfo => ({
branch: 'master',
Expand All @@ -41,12 +42,14 @@ describe('bootstrapRenderer', () => {
let renderer: BootstrapRenderer;
let uiPlugins: UiPlugins;
let packageInfo: PackageInfo;
let userSettingsService: ReturnType<typeof userSettingsServiceMock.createSetupContract>;

beforeEach(() => {
auth = httpServiceMock.createAuth();
uiSettingsClient = uiSettingsServiceMock.createClient();
uiPlugins = createUiPlugins();
packageInfo = createPackageInfo();
userSettingsService = userSettingsServiceMock.createSetupContract();

getThemeTagMock.mockReturnValue('v8light');
getPluginsBundlePathsMock.mockReturnValue(new Map());
Expand Down Expand Up @@ -88,7 +91,7 @@ describe('bootstrapRenderer', () => {
expect(uiSettingsClient.get).toHaveBeenCalledWith('theme:darkMode');
});

it('calls getThemeTag with the correct parameters', async () => {
it('calls getThemeTag with the values from the UiSettingsClient when the UserSettingsService is not provided', async () => {
uiSettingsClient.get.mockResolvedValue(true);

const request = httpServerMock.createKibanaRequest();
Expand All @@ -104,6 +107,58 @@ describe('bootstrapRenderer', () => {
darkMode: true,
});
});

it('calls getThemeTag with values from the UserSettingsService when provided', async () => {
userSettingsService.getUserSettingDarkMode.mockReturnValueOnce(true);

renderer = bootstrapRendererFactory({
auth,
packageInfo,
uiPlugins,
serverBasePath: '/base-path',
userSettingsService,
});

uiSettingsClient.get.mockResolvedValue(false);
const request = httpServerMock.createKibanaRequest();

await renderer({
request,
uiSettingsClient,
});

expect(getThemeTagMock).toHaveBeenCalledTimes(1);
expect(getThemeTagMock).toHaveBeenCalledWith({
themeVersion: 'v8',
darkMode: true,
});
});

it('calls getThemeTag with values from the UiSettingsClient when values from UserSettingsService are `undefined`', async () => {
userSettingsService.getUserSettingDarkMode.mockReturnValueOnce(undefined);

renderer = bootstrapRendererFactory({
auth,
packageInfo,
uiPlugins,
serverBasePath: '/base-path',
userSettingsService,
});

uiSettingsClient.get.mockResolvedValue(false);
const request = httpServerMock.createKibanaRequest();

await renderer({
request,
uiSettingsClient,
});

expect(getThemeTagMock).toHaveBeenCalledTimes(1);
expect(getThemeTagMock).toHaveBeenCalledWith({
themeVersion: 'v8',
darkMode: false,
});
});
});

describe('when the auth status is `unknown`', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { ThemeVersion } from '@kbn/ui-shared-deps-npm';
import type { KibanaRequest, HttpAuth } from '@kbn/core-http-server';
import type { IUiSettingsClient } from '@kbn/core-ui-settings-server';
import type { UiPlugins } from '@kbn/core-plugins-base-server-internal';
import { InternalUserSettingsServiceSetup } from '@kbn/core-user-settings-server-internal';
import { getPluginsBundlePaths } from './get_plugin_bundle_paths';
import { getJsDependencyPaths } from './get_js_dependency_paths';
import { getThemeTag } from './get_theme_tag';
Expand All @@ -25,6 +26,7 @@ interface FactoryOptions {
packageInfo: PackageInfo;
uiPlugins: UiPlugins;
auth: HttpAuth;
userSettingsService?: InternalUserSettingsServiceSetup;
}

interface RenderedOptions {
Expand All @@ -43,6 +45,7 @@ export const bootstrapRendererFactory: BootstrapRendererFactory = ({
serverBasePath,
uiPlugins,
auth,
userSettingsService,
}) => {
const isAuthenticated = (request: KibanaRequest) => {
const { status: authStatus } = auth.get(request);
Expand All @@ -56,7 +59,16 @@ export const bootstrapRendererFactory: BootstrapRendererFactory = ({

try {
const authenticated = isAuthenticated(request);
darkMode = authenticated ? await uiSettingsClient.get('theme:darkMode') : false;

if (authenticated) {
const userSettingDarkMode = await userSettingsService?.getUserSettingDarkMode(request);

if (userSettingDarkMode) {
darkMode = userSettingDarkMode;
} else {
darkMode = await uiSettingsClient.get('theme:darkMode');
}
}
} catch (e) {
// just use the default values in case of connectivity issues with ES
}
Expand Down
Loading

0 comments on commit 5eeeebe

Please sign in to comment.