Skip to content

Commit

Permalink
Merge branch 'main' into new-manifest-manager-turn-on-ff
Browse files Browse the repository at this point in the history
  • Loading branch information
szwarckonrad committed Jun 21, 2024
2 parents 4f93582 + d3897a9 commit 04c4b00
Show file tree
Hide file tree
Showing 85 changed files with 1,679 additions and 819 deletions.
60 changes: 60 additions & 0 deletions .github/workflows/bump.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Check & deploy API documentation

on:
push:
branches:
- main
paths:
- 'oas_docs/kibana.serverless.yaml'

pull_request:
branches:
- main
paths:
- 'oas_docs/kibana.serverless.yaml'

permissions:
contents: read
pull-requests: write

jobs:
deploy-doc:
if: ${{ github.event_name == 'push' }}
name: Deploy API documentation on Bump.sh
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Deploy API documentation
uses: bump-sh/github-action@v1
with:
doc: serverless
token: ${{secrets.BUMP_TOKEN}}
file: oas_docs/kibana.serverless.yaml

api-diff:
if: ${{ github.event_name == 'pull_request' }}
name: Check API diff on Bump.sh
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Create Preview
uses: bump-sh/github-action@v1
with:
doc: serverless
token: ${{secrets.BUMP_TOKEN}}
file: oas_docs/kibana.serverless.yaml
command: preview
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
- name: Comment pull request with API diff
uses: bump-sh/github-action@v1
with:
doc: serverless
token: ${{secrets.BUMP_TOKEN}}
file: oas_docs/kibana.serverless.yaml
command: diff
fail_on_breaking: true
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1055,7 +1055,7 @@
"ipaddr.js": "2.0.0",
"isbinaryfile": "4.0.2",
"joi": "^17.7.1",
"joi-to-json": "^4.2.1",
"joi-to-json": "^4.3.0",
"jquery": "^3.5.0",
"js-levenshtein": "^1.1.6",
"js-search": "^1.4.3",
Expand Down
82 changes: 79 additions & 3 deletions src/plugins/navigation/public/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { cloudExperimentsMock } from '@kbn/cloud-experiments-plugin/common/mocks
import { spacesPluginMock } from '@kbn/spaces-plugin/public/mocks';
import type { Space } from '@kbn/spaces-plugin/public';
import type { BuildFlavor } from '@kbn/config';
import type { UserSettingsData } from '@kbn/user-profile-components';
import { SOLUTION_NAV_FEATURE_FLAG_NAME } from '../common';
import { NavigationPublicPlugin } from './plugin';

Expand All @@ -32,10 +31,8 @@ const setup = (
},
{
buildFlavor = 'traditional',
userSettings = {},
}: {
buildFlavor?: BuildFlavor;
userSettings?: UserSettingsData;
} = {}
) => {
const initializerContext = coreMock.createPluginInitializerContext({}, { buildFlavor });
Expand Down Expand Up @@ -219,6 +216,85 @@ describe('Navigation Plugin', () => {
});

describe('isSolutionNavEnabled$', () => {
// This test will need to be changed when we remove the feature flag
it('should be off by default', async () => {
const { plugin, coreStart, unifiedSearch, cloud } = setup({ featureOn });

const { isSolutionNavEnabled$ } = plugin.start(coreStart, {
unifiedSearch,
cloud,
});
await new Promise((resolve) => setTimeout(resolve));

const isEnabled = await firstValueFrom(isSolutionNavEnabled$);
expect(isEnabled).toBe(false);
});

it('should be off if feature flag if "ON" but space solution is "classic" or "undefined"', async () => {
const { plugin, coreStart, unifiedSearch, cloud, cloudExperiments, spaces } = setup({
featureOn,
});

cloudExperiments.getVariation.mockResolvedValue(true); // Feature flag ON

{
spaces.getActiveSpace$ = jest
.fn()
.mockReturnValue(of({ solution: undefined } as Pick<Space, 'solution'>));

const { isSolutionNavEnabled$ } = plugin.start(coreStart, {
unifiedSearch,
cloud,
cloudExperiments,
spaces,
});
await new Promise((resolve) => setTimeout(resolve));

const isEnabled = await firstValueFrom(isSolutionNavEnabled$);
expect(isEnabled).toBe(false);
}

{
spaces.getActiveSpace$ = jest
.fn()
.mockReturnValue(of({ solution: 'classic' } as Pick<Space, 'solution'>));

const { isSolutionNavEnabled$ } = plugin.start(coreStart, {
unifiedSearch,
cloud,
cloudExperiments,
spaces,
});
await new Promise((resolve) => setTimeout(resolve));

const isEnabled = await firstValueFrom(isSolutionNavEnabled$);
expect(isEnabled).toBe(false);
}
});

it('should be on if feature flag if "ON" and space solution is set', async () => {
const { plugin, coreStart, unifiedSearch, cloud, cloudExperiments, spaces } = setup({
featureOn,
});

cloudExperiments.getVariation.mockResolvedValue(true); // Feature flag ON

spaces.getActiveSpace$ = jest
.fn()
.mockReturnValue(of({ solution: 'es' } as Pick<Space, 'solution'>));

const { isSolutionNavEnabled$ } = plugin.start(coreStart, {
unifiedSearch,
cloud,
cloudExperiments,
spaces,
});
await new Promise((resolve) => setTimeout(resolve));

const isEnabled = await firstValueFrom(isSolutionNavEnabled$);
expect(isEnabled).toBe(true);
});

it('on serverless should flag must be disabled', async () => {
const { plugin, coreStart, unifiedSearch, cloud, cloudExperiments } = setup(
{ featureOn },
Expand Down
32 changes: 24 additions & 8 deletions src/plugins/navigation/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,16 @@
* Side Public License, v 1.
*/
import React from 'react';
import { firstValueFrom, from, of, ReplaySubject, shareReplay, take, combineLatest } from 'rxjs';
import {
firstValueFrom,
from,
of,
ReplaySubject,
shareReplay,
take,
combineLatest,
map,
} from 'rxjs';
import { PluginInitializerContext, CoreSetup, CoreStart, Plugin } from '@kbn/core/public';
import type { UnifiedSearchPublicPluginStart } from '@kbn/unified-search-plugin/public';
import type { Space } from '@kbn/spaces-plugin/public';
Expand Down Expand Up @@ -119,7 +128,14 @@ export class NavigationPublicPlugin
this.addSolutionNavigation(solutionNavigation);
});
},
isSolutionNavEnabled$: this.isSolutionNavExperiementEnabled$,
isSolutionNavEnabled$: combineLatest([
this.isSolutionNavExperiementEnabled$,
activeSpace$,
]).pipe(
map(([isFeatureEnabled, activeSpace]) => {
return getIsProjectNav(isFeatureEnabled, activeSpace?.solution) && !isServerless;
})
),
};
}

Expand Down Expand Up @@ -169,11 +185,7 @@ export class NavigationPublicPlugin
}: { isFeatureEnabled: boolean; isServerless: boolean; activeSpace?: Space }
) {
const solutionView = activeSpace?.solution;
const isProjectNav =
isFeatureEnabled &&
Boolean(solutionView) &&
isKnownSolutionView(solutionView) &&
solutionView !== 'classic';
const isProjectNav = getIsProjectNav(isFeatureEnabled, solutionView) && !isServerless;

// On serverless the chrome style is already set by the serverless plugin
if (!isServerless) {
Expand All @@ -186,6 +198,10 @@ export class NavigationPublicPlugin
}
}

function getIsProjectNav(isFeatureEnabled: boolean, solutionView?: string) {
return isFeatureEnabled && Boolean(solutionView) && isKnownSolutionView(solutionView);
}

function isKnownSolutionView(solution?: string) {
return solution && ['oblt', 'es', 'security'].includes(solution);
return Boolean(solution) && ['oblt', 'es', 'security'].includes(solution!);
}
1 change: 0 additions & 1 deletion src/plugins/navigation/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
"@kbn/shared-ux-chrome-navigation",
"@kbn/cloud-plugin",
"@kbn/config",
"@kbn/user-profile-components",
"@kbn/cloud-experiments-plugin",
"@kbn/spaces-plugin",
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,10 @@ describe('<IndexDetailsPage />', () => {
});
describe('Add Semantic text field', () => {
const customInferenceModel = 'my-elser-model';
const mockLicense = {
isActive: true,
hasAtLeast: jest.fn((type) => true),
};
beforeEach(async () => {
httpRequestsMockHelpers.setInferenceModels({
data: [
Expand Down Expand Up @@ -674,7 +678,18 @@ describe('<IndexDetailsPage />', () => {
enterpriseSearch: '',
},
},
core: {
application: { capabilities: { ml: { canGetTrainedModels: true } } },
},
plugins: {
licensing: {
license$: {
subscribe: jest.fn((callback) => {
callback(mockLicense);
return { unsubscribe: jest.fn() };
}),
},
},
ml: {
mlApi: {
trainedModels: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('When semantic_text is enabled', () => {
getItemSpy = jest.spyOn(Storage.prototype, 'getItem');
setItemSpy = jest.spyOn(Storage.prototype, 'setItem');
const setup = registerTestBed(SemanticTextBanner, {
defaultProps: { isSemanticTextEnabled: true },
defaultProps: { isSemanticTextEnabled: true, isPlatinumLicense: true },
memoryRouter: { wrapComponent: false },
});
const testBed = setup();
Expand Down Expand Up @@ -56,6 +56,21 @@ describe('When semantic_text is enabled', () => {
});
});

describe('when user does not have ML permissions', () => {
const setupWithNoMlPermission = registerTestBed(SemanticTextBanner, {
defaultProps: { isSemanticTextEnabled: true, isPlatinumLicense: false },
memoryRouter: { wrapComponent: false },
});

const { find } = setupWithNoMlPermission();

it('should contain content related to semantic_text', () => {
expect(find('indexDetailsMappingsSemanticTextBanner').text()).toContain(
'Semantic text now available for platinum license'
);
});
});

describe('When semantic_text is disabled', () => {
const setup = registerTestBed(SemanticTextBanner, {
defaultProps: { isSemanticTextEnabled: false },
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/index_management/kibana.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"browser": true,
"configPath": ["xpack", "index_management"],
"requiredPlugins": ["home", "management", "features", "share"],
"optionalPlugins": ["security", "usageCollection", "fleet", "cloud", "ml", "console"],
"optionalPlugins": ["security", "usageCollection", "fleet", "cloud", "ml", "console","licensing"],
"requiredBundles": ["kibanaReact", "esUiShared", "runtimeFields"]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import type { CloudSetup } from '@kbn/cloud-plugin/public';
import type { ConsolePluginStart } from '@kbn/console-plugin/public';

import { EuiBreadcrumb } from '@elastic/eui';
import { LicensingPluginStart } from '@kbn/licensing-plugin/public';
import { ExtensionsService } from '../services';
import { HttpService, NotificationService, UiMetricService } from './services';
import { IndexManagementBreadcrumb } from './services/breadcrumbs';
Expand All @@ -48,6 +49,7 @@ export interface AppDependencies {
share: SharePluginStart;
cloud?: CloudSetup;
console?: ConsolePluginStart;
licensing?: LicensingPluginStart;
ml?: MlPluginStart;
};
services: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export function getIndexManagementDependencies({
cloud,
console: startDependencies.console,
ml: startDependencies.ml,
licensing: startDependencies.licensing,
},
services: {
httpService,
Expand Down
Loading

0 comments on commit 04c4b00

Please sign in to comment.