Skip to content

Commit

Permalink
Merge remote-tracking branch upstream/master
Browse files Browse the repository at this point in the history
  • Loading branch information
YulNaumenko committed Mar 2, 2021
2 parents 1ba5829 + fd3b3eb commit dd4acdd
Show file tree
Hide file tree
Showing 19 changed files with 168 additions and 158 deletions.
2 changes: 2 additions & 0 deletions docs/developer/plugin-list.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ as uiSettings within the code.
|{kib-repo}blob/{branch}/src/plugins/apm_oss/README.asciidoc[apmOss]
|undefined
|{kib-repo}blob/{branch}/src/plugins/bfetch/README.md[bfetch]
|bfetch allows to batch HTTP requests and streams responses back.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ function* printPlugins(plugins: Plugins, includes: string[]) {
yield `|{kib-repo}blob/{branch}/${path}[${plugin.id}]`;
}

if (!plugin.relativeReadmePath || plugin.readmeSnippet) {
yield plugin.readmeSnippet ? `|${plugin.readmeSnippet}` : '|WARNING: Missing README.';
yield '';
}
yield plugin.relativeReadmePath === undefined
? '|WARNING: Missing README.'
: `|${plugin.readmeSnippet}`;

yield '';
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
} from '../../../common/elasticsearch_fieldnames';
import { APM_ML_JOB_GROUP, ML_MODULE_ID_APM_TRANSACTION } from './constants';
import { withApmSpan } from '../../utils/with_apm_span';
import { getAnomalyDetectionJobs } from './get_anomaly_detection_jobs';

export async function createAnomalyDetectionJobs(
setup: Setup,
Expand All @@ -38,14 +39,19 @@ export async function createAnomalyDetectionJobs(
throw Boom.forbidden(ML_ERRORS.ML_NOT_AVAILABLE_IN_SPACE);
}

const uniqueMlJobEnvs = await getUniqueMlJobEnvs(setup, environments, logger);
if (uniqueMlJobEnvs.length === 0) {
return [];
}

return withApmSpan('create_anomaly_detection_jobs', async () => {
logger.info(
`Creating ML anomaly detection jobs for environments: [${environments}].`
`Creating ML anomaly detection jobs for environments: [${uniqueMlJobEnvs}].`
);

const indexPatternName = indices['apm_oss.transactionIndices'];
const responses = await Promise.all(
environments.map((environment) =>
uniqueMlJobEnvs.map((environment) =>
createAnomalyDetectionJob({ ml, environment, indexPatternName })
)
);
Expand Down Expand Up @@ -105,3 +111,24 @@ async function createAnomalyDetectionJob({
});
});
}

async function getUniqueMlJobEnvs(
setup: Setup,
environments: string[],
logger: Logger
) {
// skip creation of duplicate ML jobs
const jobs = await getAnomalyDetectionJobs(setup, logger);
const existingMlJobEnvs = jobs.map(({ environment }) => environment);
const requestedExistingMlJobEnvs = environments.filter((env) =>
existingMlJobEnvs.includes(env)
);

if (requestedExistingMlJobEnvs.length) {
logger.warn(
`Skipping creation of existing ML jobs for environments: [${requestedExistingMlJobEnvs}]}`
);
}

return environments.filter((env) => !existingMlJobEnvs.includes(env));
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export const createAnomalyDetectionJobsRoute = createRoute({
}

await createAnomalyDetectionJobs(setup, environments, context.logger);

notifyFeatureUsage({
licensingPlugin: context.licensing,
featureName: 'ml',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ export const DEFAULT_INITIAL_APP_DATA = {
},
},
},
access: {
hasAppSearchAccess: true,
hasWorkplaceSearchAccess: true,
},
appSearch: {
accountId: 'some-id-string',
onboardingComplete: true,
Expand Down
10 changes: 6 additions & 4 deletions x-pack/plugins/enterprise_search/common/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ export interface InitialAppData {
ilmEnabled?: boolean;
isFederatedAuth?: boolean;
configuredLimits?: ConfiguredLimits;
access?: {
hasAppSearchAccess: boolean;
hasWorkplaceSearchAccess: boolean;
};
access?: ProductAccess;
appSearch?: AppSearchAccount;
workplaceSearch?: WorkplaceSearchInitialData;
}
Expand All @@ -32,6 +29,11 @@ export interface ConfiguredLimits {
workplaceSearch: WorkplaceSearchConfiguredLimits;
}

export interface ProductAccess {
hasAppSearchAccess: boolean;
hasWorkplaceSearchAccess: boolean;
}

export interface MetaPage {
current: number;
size: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,74 +6,68 @@
*/

import { DEFAULT_INITIAL_APP_DATA } from '../../../common/__mocks__';
import { LogicMounter } from '../__mocks__';

import { resetContext } from 'kea';

import { AppLogic } from './app_logic';

describe('AppLogic', () => {
const { mount } = new LogicMounter(AppLogic);

beforeEach(() => {
mount();
});

const DEFAULT_VALUES = {
hasInitialized: false,
account: {},
configuredLimits: {},
ilmEnabled: false,
myRole: {},
const mount = (props = {}) => {
AppLogic({ ...DEFAULT_INITIAL_APP_DATA, ...props });
AppLogic.mount();
};

it('has expected default values', () => {
expect(AppLogic.values).toEqual(DEFAULT_VALUES);
beforeEach(() => {
jest.clearAllMocks();
resetContext({});
});

describe('initializeAppData()', () => {
it('sets values based on passed props', () => {
AppLogic.actions.initializeAppData(DEFAULT_INITIAL_APP_DATA);
it('sets values from props', () => {
mount();

expect(AppLogic.values).toEqual({
hasInitialized: true,
ilmEnabled: true,
configuredLimits: {
engine: {
maxDocumentByteSize: 102400,
maxEnginesPerMetaEngine: 15,
},
},
account: {
accountId: 'some-id-string',
onboardingComplete: true,
role: DEFAULT_INITIAL_APP_DATA.appSearch.role,
expect(AppLogic.values).toEqual({
ilmEnabled: true,
configuredLimits: {
engine: {
maxDocumentByteSize: 102400,
maxEnginesPerMetaEngine: 15,
},
myRole: expect.objectContaining({
id: 'account_id:somestring|user_oid:somestring',
roleType: 'owner',
availableRoleTypes: ['owner', 'admin'],
credentialTypes: ['admin', 'private', 'search'],
canAccessAllEngines: true,
canViewAccountCredentials: true,
// Truncated for brevity - see utils/role/index.test.ts for full output
}),
});
},
account: {
accountId: 'some-id-string',
onboardingComplete: true,
role: DEFAULT_INITIAL_APP_DATA.appSearch.role,
},
myRole: expect.objectContaining({
id: 'account_id:somestring|user_oid:somestring',
roleType: 'owner',
availableRoleTypes: ['owner', 'admin'],
credentialTypes: ['admin', 'private', 'search'],
canAccessAllEngines: true,
canViewAccountCredentials: true,
// Truncated for brevity - see utils/role/index.test.ts for full output
}),
});
});

it('gracefully handles missing initial data', () => {
AppLogic.actions.initializeAppData({});
describe('actions', () => {
describe('setOnboardingComplete()', () => {
it('sets true', () => {
mount({ appSearch: { onboardingComplete: false } });

expect(AppLogic.values).toEqual({
...DEFAULT_VALUES,
hasInitialized: true,
AppLogic.actions.setOnboardingComplete();
expect(AppLogic.values.account.onboardingComplete).toEqual(true);
});
});
});

describe('setOnboardingComplete()', () => {
it('sets true', () => {
expect(AppLogic.values.account.onboardingComplete).toBeFalsy();
AppLogic.actions.setOnboardingComplete();
expect(AppLogic.values.account.onboardingComplete).toEqual(true);
describe('selectors', () => {
describe('myRole', () => {
it('falls back to an empty object if role is missing', () => {
mount({ appSearch: {} });

expect(AppLogic.values.myRole).toEqual({});
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -14,53 +14,33 @@ import { ConfiguredLimits, Account, Role } from './types';
import { getRoleAbilities } from './utils/role';

interface AppValues {
hasInitialized: boolean;
ilmEnabled: boolean;
configuredLimits: Partial<ConfiguredLimits>;
account: Partial<Account>;
myRole: Partial<Role>;
configuredLimits: ConfiguredLimits;
account: Account;
myRole: Role;
}
interface AppActions {
initializeAppData(props: InitialAppData): Required<InitialAppData>;
setOnboardingComplete(): boolean;
}

export const AppLogic = kea<MakeLogicType<AppValues, AppActions>>({
export const AppLogic = kea<MakeLogicType<AppValues, AppActions, Required<InitialAppData>>>({
path: ['enterprise_search', 'app_search', 'app_logic'],
actions: {
initializeAppData: (props) => props,
setOnboardingComplete: () => true,
},
reducers: {
hasInitialized: [
false,
{
initializeAppData: () => true,
},
],
reducers: ({ props }) => ({
account: [
{},
props.appSearch,
{
initializeAppData: (_, { appSearch: account }) => account || {},
setOnboardingComplete: (account) => ({
...account,
onboardingComplete: true,
}),
},
],
configuredLimits: [
{},
{
initializeAppData: (_, { configuredLimits }) => configuredLimits?.appSearch || {},
},
],
ilmEnabled: [
false,
{
initializeAppData: (_, { ilmEnabled }) => !!ilmEnabled,
},
],
},
configuredLimits: [props.configuredLimits.appSearch, {}],
ilmEnabled: [props.ilmEnabled, {}],
}),
selectors: {
myRole: [
(selectors) => [selectors.account],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,11 @@ export const FlyoutHeader: React.FC = () => {
};

export const FlyoutBody: React.FC = () => {
const { configuredLimits } = useValues(AppLogic);
const maxDocumentByteSize = configuredLimits?.engine?.maxDocumentByteSize;
const {
configuredLimits: {
engine: { maxDocumentByteSize },
},
} = useValues(AppLogic);

const { textInput, errors } = useValues(DocumentCreationLogic);
const { setTextInput } = useActions(DocumentCreationLogic);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,11 @@ export const FlyoutHeader: React.FC = () => {
};

export const FlyoutBody: React.FC = () => {
const { configuredLimits } = useValues(AppLogic);
const maxDocumentByteSize = configuredLimits?.engine?.maxDocumentByteSize;
const {
configuredLimits: {
engine: { maxDocumentByteSize },
},
} = useValues(AppLogic);

const { isUploading, errors } = useValues(DocumentCreationLogic);
const { setFileInput } = useActions(DocumentCreationLogic);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const comboBoxOptionToEngineName = (option: EuiComboBoxOptionOption<string>): st
export const MetaEngineCreation: React.FC = () => {
const {
configuredLimits: {
engine: { maxEnginesPerMetaEngine } = { maxEnginesPerMetaEngine: Infinity },
engine: { maxEnginesPerMetaEngine },
},
} = useValues(AppLogic);

Expand Down
Loading

0 comments on commit dd4acdd

Please sign in to comment.