Skip to content

Commit

Permalink
Merge branch 'main' into kbn-140743-notifications-api-mvp
Browse files Browse the repository at this point in the history
  • Loading branch information
gsoldevila authored Nov 2, 2022
2 parents 1467966 + 404d08f commit 091eb74
Show file tree
Hide file tree
Showing 249 changed files with 11,194 additions and 3,408 deletions.
2 changes: 2 additions & 0 deletions .buildkite/ftr_configs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -279,3 +279,5 @@ enabled:
- x-pack/performance/journeys/promotion_tracking_dashboard.ts
- x-pack/performance/journeys/web_logs_dashboard.ts
- x-pack/performance/journeys/data_stress_test_lens.ts
- x-pack/performance/journeys/ecommerce_dashboard_saved_search_only.ts
- x-pack/performance/journeys/ecommerce_dashboard_tsvb_gauge_only.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,8 @@ export const Main = (props: MainProps) => {
)}
{(guideState?.isActive === true ||
guideState?.status === 'in_progress' ||
guideState?.status === 'ready_to_complete') && (
guideState?.status === 'ready_to_complete' ||
guideState?.status === 'not_started') && (
<FormattedMessage
id="guidedOnboardingExample.guidesSelection.continueButtonLabel"
defaultMessage="Continue {guideId} guide"
Expand Down
2 changes: 1 addition & 1 deletion packages/core/node/core-node-server-internal/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
export { nodeConfig } from './src/node_config';

export { NodeService, type PrebootDeps } from './src/node_service';
export type { InternalNodeServicePreboot } from './src/node_service';
export type { InternalNodeServicePreboot, InternalNodeServiceStart } from './src/node_service';
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,62 @@ describe('NodeService', () => {
});
});
});
describe('#start()', () => {
it('returns default roles values when wildcard is provided', async () => {
configService = getMockedConfigService({ roles: ['*'] });
coreContext = mockCoreContext.create({ logger, configService });

service = new NodeService(coreContext);
await service.preboot({ loggingSystem: logger });
const { roles } = service.start();

expect(roles.backgroundTasks).toBe(true);
expect(roles.ui).toBe(true);
});

it('returns correct roles when node is configured to `background_tasks`', async () => {
configService = getMockedConfigService({ roles: ['background_tasks'] });
coreContext = mockCoreContext.create({ logger, configService });

service = new NodeService(coreContext);
await service.preboot({ loggingSystem: logger });
const { roles } = service.start();

expect(roles.backgroundTasks).toBe(true);
expect(roles.ui).toBe(false);
});

it('returns correct roles when node is configured to `ui`', async () => {
configService = getMockedConfigService({ roles: ['ui'] });
coreContext = mockCoreContext.create({ logger, configService });

service = new NodeService(coreContext);
await service.preboot({ loggingSystem: logger });
const { roles } = service.start();

expect(roles.backgroundTasks).toBe(false);
expect(roles.ui).toBe(true);
});

it('returns correct roles when node is configured to both `background_tasks` and `ui`', async () => {
configService = getMockedConfigService({ roles: ['background_tasks', 'ui'] });
coreContext = mockCoreContext.create({ logger, configService });

service = new NodeService(coreContext);
await service.preboot({ loggingSystem: logger });
const { roles } = service.start();

expect(roles.backgroundTasks).toBe(true);
expect(roles.ui).toBe(true);
});
it('throws if preboot has not been run', () => {
configService = getMockedConfigService({ roles: ['background_tasks', 'ui'] });
coreContext = mockCoreContext.create({ logger, configService });

service = new NodeService(coreContext);
expect(() => service.start()).toThrowErrorMatchingInlineSnapshot(
`"NodeService#start() can only be called after NodeService#preboot()"`
);
});
});
});
31 changes: 27 additions & 4 deletions packages/core/node/core-node-server-internal/src/node_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,20 @@ const containsWildcard = (roles: string[]) => roles.includes(NODE_WILDCARD_CHAR)
*/
export interface InternalNodeServicePreboot {
/**
* Retrieve the Kibana instance uuid.
* The Kibana process can take on specialised roles via the `node.roles` config.
*
* The roles can be used by plugins to adjust their behavior based
* on the way the Kibana process has been configured.
*/
roles: NodeRoles;
}

export interface InternalNodeServiceStart {
/**
* The Kibana process can take on specialised roles via the `node.roles` config.
*
* The roles can be used by plugins to adjust their behavior based
* on the way the Kibana process has been configured.
*/
roles: NodeRoles;
}
Expand All @@ -41,6 +54,7 @@ export interface PrebootDeps {
export class NodeService {
private readonly configService: IConfigService;
private readonly log: Logger;
private roles?: NodeRoles;

constructor(core: CoreContext) {
this.configService = core.configService;
Expand All @@ -52,13 +66,22 @@ export class NodeService {
loggingSystem.setGlobalContext({ service: { node: { roles } } });
this.log.info(`Kibana process configured with roles: [${roles.join(', ')}]`);

this.roles = NODE_ACCEPTED_ROLES.reduce((acc, curr) => {
return { ...acc, [camelCase(curr)]: roles.includes(curr) };
}, {} as NodeRoles);

return {
roles: NODE_ACCEPTED_ROLES.reduce((acc, curr) => {
return { ...acc, [camelCase(curr)]: roles.includes(curr) };
}, {} as NodeRoles),
roles: this.roles,
};
}

public start(): InternalNodeServiceStart {
if (this.roles == null) {
throw new Error('NodeService#start() can only be called after NodeService#preboot()');
}
return { roles: this.roles };
}

public stop() {
// nothing to do here yet
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
*/

import type { PublicMethodsOf } from '@kbn/utility-types';
import type { NodeService, InternalNodeServicePreboot } from '@kbn/core-node-server-internal';
import type {
NodeService,
InternalNodeServicePreboot,
InternalNodeServiceStart,
} from '@kbn/core-node-server-internal';

const createInternalPrebootContractMock = () => {
const prebootContract: jest.Mocked<InternalNodeServicePreboot> = {
Expand All @@ -19,17 +23,38 @@ const createInternalPrebootContractMock = () => {
return prebootContract;
};

const createInternalStartContractMock = (
{
ui,
backgroundTasks,
}: {
ui: boolean;
backgroundTasks: boolean;
} = { ui: true, backgroundTasks: true }
) => {
const startContract: jest.Mocked<InternalNodeServiceStart> = {
roles: {
backgroundTasks,
ui,
},
};
return startContract;
};

type NodeServiceContract = PublicMethodsOf<NodeService>;
const createMock = () => {
const mocked: jest.Mocked<NodeServiceContract> = {
preboot: jest.fn(),
start: jest.fn(),
stop: jest.fn(),
};
mocked.preboot.mockResolvedValue(createInternalPrebootContractMock());
mocked.start.mockReturnValue(createInternalStartContractMock());
return mocked;
};

export const nodeServiceMock = {
create: createMock,
createInternalPrebootContract: createInternalPrebootContractMock,
createInternalStartContract: createInternalStartContractMock,
};
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,19 @@ the same version could have plugins enabled at any time that would introduce
new transforms or mappings.
`OUTDATED_DOCUMENTS_SEARCH`

3. If the `.kibana` alias exists we’re migrating from either a v1 or v2 index
3. If `waitForMigrations` was set we're running on a background-tasks node and
we should not participate in the migration but instead wait for the ui node(s)
to complete the migration.
`WAIT_FOR_MIGRATION_COMPLETION`

4. If the `.kibana` alias exists we’re migrating from either a v1 or v2 index
and the migration source index is the index the `.kibana` alias points to.
`WAIT_FOR_YELLOW_SOURCE`

4. If `.kibana` is a concrete index, we’re migrating from a legacy index
5. If `.kibana` is a concrete index, we’re migrating from a legacy index
`LEGACY_SET_WRITE_BLOCK`

5. If there are no `.kibana` indices, this is a fresh deployment. Initialize a
6. If there are no `.kibana` indices, this is a fresh deployment. Initialize a
new saved objects index
`CREATE_NEW_TARGET`

Expand Down Expand Up @@ -259,6 +264,15 @@ new `.kibana` alias that points to `.kibana_pre6.5.0_001`.
`index_not_found_exception` another instance has already completed this step.
`SET_SOURCE_WRITE_BLOCK`

## WAIT_FOR_MIGRATION_COMPLETION
### Next action
`fetchIndices`
### New control state
1. If the ui node finished the migration
`DONE`
2. Otherwise wait 2s and check again
→ WAIT_FOR_MIGRATION_COMPLETION

## WAIT_FOR_YELLOW_SOURCE
### Next action
`waitForIndexStatus` (status='yellow')
Expand Down Expand Up @@ -417,6 +431,13 @@ update the mappings and then use an update_by_query to ensure that all fields ar

## UPDATE_TARGET_MAPPINGS_WAIT_FOR_TASK
### Next action
`waitForPickupUpdatedMappingsTask`

### New control state
`MARK_VERSION_INDEX_READY`

## MARK_VERSION_INDEX_READY
### Next action
`updateAliases`

Atomically apply the `versionIndexReadyActions` using the _alias actions API. By performing the following actions we guarantee that if multiple versions of Kibana started the upgrade in parallel, only one version will succeed.
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 091eb74

Please sign in to comment.