Skip to content

Commit

Permalink
Merge branch 'main' into task/olm-3092-trusted-app-post-port-cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ashokaditya authored Jun 29, 2022
2 parents ca5dbc1 + 111b6f4 commit d4d6d86
Show file tree
Hide file tree
Showing 113 changed files with 1,302 additions and 690 deletions.
21 changes: 13 additions & 8 deletions docs/setup/upgrade/rollback-migration.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,31 @@ WARNING: Before you roll back {kib}, ensure that the version you want to roll ba
your {es} cluster. If the version you want to roll back to is not compatible, you must also rollback {es}.
Any changes made after an upgrade are lost when you roll back to a previous version.

To roll back after a failed upgrade migration, you must also rollback the saved object indices to be compatible with the previous {kib} version.
To roll back after a failed upgrade migration, you must also roll back the {kib} feature state to be compatible with the previous {kib} version.

[float]
==== Roll back by restoring a backup snapshot
==== Roll back by restoring the {kib} feature state from a snapshot

. Before proceeding, {ref}/snapshots-take-snapshot.html[take a snapshot] that contains the `kibana` feature state.
By default, snapshots include the `kibana` feature state.
. To make sure no {kib} instances are performing an upgrade migration, shut down all {kib} instances.
. To delete all saved object indices, enter:
. {ref}/snapshots-restore-snapshot.html[Restore] the `kibana` feature state from a snapshot taken before the failed {kib} upgrade. The following {es} request will only restore the {kib} feature state
+
[source,sh]
--------------------------------------------
DELETE /.kibana*
POST _snapshot/my_repository/my_snapshot_2099.05.06/_restore
{
"indices": "-*", <1>
"feature_states": ["kibana"]
}
--------------------------------------------

. {ref}/snapshots-restore-snapshot.html[Restore] the `kibana` feature state from the snapshot.
<1> Exclude all indices and data streams from the restore operation to ensure that only the {kib} system indices included in the {kib} feature state will be restored.
. Start all {kib} instances on the older version you want to rollback to.

[float]
==== (Not recommended) Roll back without a backup snapshot
==== (Not supported) Roll back without a backup snapshot

WARNING: Rolling back without a backup snapshot is not supported and will be removed in a future version of {kib}.

. To make sure no {kib} instances are performing an upgrade migration, shut down all {kib} instances.
. {ref}/snapshots-take-snapshot.html[Take a snapshot] that includes the `kibana` feature state. By default, snapshots include the `kibana` feature state.
Expand Down Expand Up @@ -58,7 +63,7 @@ POST /.kibana_3/_aliases/.kibana
+
[source,sh]
--------------------------------------------
PPUT /.kibana,.kibana_task_manager/_settings {"index.blocks.write": false}
PUT /.kibana,.kibana_task_manager/_settings {"index.blocks.write": false}
--------------------------------------------

. Start {kib} on the older version you want to roll back to.
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@
"@kbn/core-execution-context-browser-internal": "link:bazel-bin/packages/core/execution-context/core-execution-context-browser-internal",
"@kbn/core-execution-context-browser-mocks": "link:bazel-bin/packages/core/execution-context/core-execution-context-browser-mocks",
"@kbn/core-execution-context-common": "link:bazel-bin/packages/core/execution-context/core-execution-context-common",
"@kbn/core-execution-context-server": "link:bazel-bin/packages/core/execution-context/core-execution-context-server",
"@kbn/core-execution-context-server-internal": "link:bazel-bin/packages/core/execution-context/core-execution-context-server-internal",
"@kbn/core-execution-context-server-mocks": "link:bazel-bin/packages/core/execution-context/core-execution-context-server-mocks",
"@kbn/core-fatal-errors-browser": "link:bazel-bin/packages/core/fatal-errors/core-fatal-errors-browser",
"@kbn/core-fatal-errors-browser-internal": "link:bazel-bin/packages/core/fatal-errors/core-fatal-errors-browser-internal",
"@kbn/core-fatal-errors-browser-mocks": "link:bazel-bin/packages/core/fatal-errors/core-fatal-errors-browser-mocks",
Expand Down Expand Up @@ -709,6 +712,9 @@
"@types/kbn__core-execution-context-browser-internal": "link:bazel-bin/packages/core/execution-context/core-execution-context-browser-internal/npm_module_types",
"@types/kbn__core-execution-context-browser-mocks": "link:bazel-bin/packages/core/execution-context/core-execution-context-browser-mocks/npm_module_types",
"@types/kbn__core-execution-context-common": "link:bazel-bin/packages/core/execution-context/core-execution-context-common/npm_module_types",
"@types/kbn__core-execution-context-server": "link:bazel-bin/packages/core/execution-context/core-execution-context-server/npm_module_types",
"@types/kbn__core-execution-context-server-internal": "link:bazel-bin/packages/core/execution-context/core-execution-context-server-internal/npm_module_types",
"@types/kbn__core-execution-context-server-mocks": "link:bazel-bin/packages/core/execution-context/core-execution-context-server-mocks/npm_module_types",
"@types/kbn__core-fatal-errors-browser": "link:bazel-bin/packages/core/fatal-errors/core-fatal-errors-browser/npm_module_types",
"@types/kbn__core-fatal-errors-browser-internal": "link:bazel-bin/packages/core/fatal-errors/core-fatal-errors-browser-internal/npm_module_types",
"@types/kbn__core-fatal-errors-browser-mocks": "link:bazel-bin/packages/core/fatal-errors/core-fatal-errors-browser-mocks/npm_module_types",
Expand Down
6 changes: 6 additions & 0 deletions packages/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ filegroup(
"//packages/core/execution-context/core-execution-context-browser-mocks:build",
"//packages/core/execution-context/core-execution-context-browser:build",
"//packages/core/execution-context/core-execution-context-common:build",
"//packages/core/execution-context/core-execution-context-server-internal:build",
"//packages/core/execution-context/core-execution-context-server-mocks:build",
"//packages/core/execution-context/core-execution-context-server:build",
"//packages/core/fatal-errors/core-fatal-errors-browser-internal:build",
"//packages/core/fatal-errors/core-fatal-errors-browser-mocks:build",
"//packages/core/fatal-errors/core-fatal-errors-browser:build",
Expand Down Expand Up @@ -211,6 +214,9 @@ filegroup(
"//packages/core/execution-context/core-execution-context-browser-mocks:build_types",
"//packages/core/execution-context/core-execution-context-browser:build_types",
"//packages/core/execution-context/core-execution-context-common:build_types",
"//packages/core/execution-context/core-execution-context-server-internal:build_types",
"//packages/core/execution-context/core-execution-context-server-mocks:build_types",
"//packages/core/execution-context/core-execution-context-server:build_types",
"//packages/core/fatal-errors/core-fatal-errors-browser-internal:build_types",
"//packages/core/fatal-errors/core-fatal-errors-browser-mocks:build_types",
"//packages/core/fatal-errors/core-fatal-errors-browser:build_types",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
load("@npm//@bazel/typescript:index.bzl", "ts_config")
load("@build_bazel_rules_nodejs//:index.bzl", "js_library")
load("//src/dev/bazel:index.bzl", "jsts_transpiler", "pkg_npm", "pkg_npm_types", "ts_project")

PKG_DIRNAME = "core-execution-context-server-internal"
PKG_REQUIRE_NAME = "@kbn/core-execution-context-server-internal"

SOURCE_FILES = glob(
[
"src/**/*.ts",
],
exclude = [
"**/*.test.*",
],
)

SRCS = SOURCE_FILES

filegroup(
name = "srcs",
srcs = SRCS,
)

NPM_MODULE_EXTRA_FILES = [
"package.json",
]

RUNTIME_DEPS = [
"@npm//lodash",
"@npm//rxjs",
"//packages/kbn-config-schema",
]

TYPES_DEPS = [
"@npm//@types/node",
"@npm//@types/jest",
"@npm//@types/lodash",
"@npm//rxjs",
"@npm//elastic-apm-node",
"//packages/kbn-config-schema:npm_module_types",
"//packages/kbn-logging:npm_module_types",
"//packages/core/base/core-base-server-internal:npm_module_types",
"//packages/core/execution-context/core-execution-context-common:npm_module_types",
"//packages/core/execution-context/core-execution-context-server:npm_module_types",
]

jsts_transpiler(
name = "target_node",
srcs = SRCS,
build_pkg_name = package_name(),
)

ts_config(
name = "tsconfig",
src = "tsconfig.json",
deps = [
"//:tsconfig.base.json",
"//:tsconfig.bazel.json",
],
)

ts_project(
name = "tsc_types",
args = ['--pretty'],
srcs = SRCS,
deps = TYPES_DEPS,
declaration = True,
emit_declaration_only = True,
out_dir = "target_types",
root_dir = "src",
tsconfig = ":tsconfig",
)

js_library(
name = PKG_DIRNAME,
srcs = NPM_MODULE_EXTRA_FILES,
deps = RUNTIME_DEPS + [":target_node"],
package_name = PKG_REQUIRE_NAME,
visibility = ["//visibility:public"],
)

pkg_npm(
name = "npm_module",
deps = [":" + PKG_DIRNAME],
)

filegroup(
name = "build",
srcs = [":npm_module"],
visibility = ["//visibility:public"],
)

pkg_npm_types(
name = "npm_module_types",
srcs = SRCS,
deps = [":tsc_types"],
package_name = PKG_REQUIRE_NAME,
tsconfig = ":tsconfig",
visibility = ["//visibility:public"],
)

filegroup(
name = "build_types",
srcs = [":npm_module_types"],
visibility = ["//visibility:public"],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# @kbn/core-execution-context-server-internal

This package contains the internal types and implementation for Core's server-side execution context service.

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

module.exports = {
preset: '@kbn/test/jest_node',
rootDir: '../../../..',
roots: ['<rootDir>/packages/core/execution-context/core-execution-context-server-internal'],
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "@kbn/core-execution-context-server-internal",
"private": true,
"version": "1.0.0",
"main": "./target_node/index.js",
"license": "SSPL-1.0 OR Elastic License 2.0"
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Side Public License, v 1.
*/

import { TypeOf, schema } from '@kbn/config-schema';
import { schema } from '@kbn/config-schema';
import type { ServiceConfigDescriptor } from '@kbn/core-base-server-internal';

const configSchema = schema.object({
Expand All @@ -16,9 +16,11 @@ const configSchema = schema.object({
/**
* @internal
*/
export type ExecutionContextConfigType = TypeOf<typeof configSchema>;
export interface ExecutionContextConfigType {
enabled: boolean;
}

export const config: ServiceConfigDescriptor<ExecutionContextConfigType> = {
export const executionContextConfig: ServiceConfigDescriptor<ExecutionContextConfigType> = {
path: 'execution_context',
schema: configSchema,
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import { Blob } from 'buffer';
import type { KibanaExecutionContext } from '../../types';
import type { KibanaExecutionContext } from '@kbn/core-execution-context-common';

import {
ExecutionContextContainer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import type { KibanaExecutionContext } from '../../types';

import type { KibanaExecutionContext } from '@kbn/core-execution-context-common';
import type { IExecutionContextContainer } from '@kbn/core-execution-context-server';

// Switch to the standard Baggage header. blocked by
// https://github.com/elastic/apm-agent-nodejs/issues/2102
Expand Down Expand Up @@ -41,14 +43,6 @@ function enforceMaxLength(header: string): string {
return header.slice(0, MAX_BAGGAGE_LENGTH);
}

/**
* @public
*/
export interface IExecutionContextContainer {
toString(): string;
toJSON(): Readonly<KibanaExecutionContext>;
}

function stringify(ctx: KibanaExecutionContext): string {
const encodeURIComponentIfNotEmpty = (val?: string) => encodeURIComponent(val || '');
const stringifiedCtx = `${encodeURIComponentIfNotEmpty(ctx.type)}:${encodeURIComponentIfNotEmpty(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
} from './execution_context_service';

const delay = (ms: number = 100) => new Promise((resolve) => setTimeout(resolve, ms));

describe('ExecutionContextService', () => {
describe('setup', () => {
let service: InternalExecutionContextSetup;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,27 @@
* Side Public License, v 1.
*/
import { AsyncLocalStorage } from 'async_hooks';
import apm from 'elastic-apm-node';
import type apm from 'elastic-apm-node';
import { isUndefined, omitBy } from 'lodash';
import type { Subscription } from 'rxjs';

import type { Logger } from '@kbn/logging';
import type { CoreContext, CoreService } from '@kbn/core-base-server-internal';
import type { KibanaExecutionContext } from '../../types';
import type { KibanaExecutionContext } from '@kbn/core-execution-context-common';
import type { IExecutionContextContainer } from '@kbn/core-execution-context-server';
import type { ExecutionContextConfigType } from './execution_context_config';

import {
ExecutionContextContainer,
IExecutionContextContainer,
getParentContextFrom,
} from './execution_context_container';
import { ExecutionContextContainer, getParentContextFrom } from './execution_context_container';

/**
* @internal
*/
export interface IExecutionContext {
getParentContextFrom(headers: Record<string, string>): KibanaExecutionContext | undefined;

setRequestId(requestId: string): void;

set(context: KibanaExecutionContext): void;

/**
* The sole purpose of this imperative internal API is to be used by the http service.
* The event-based nature of Hapi server doesn't allow us to wrap a request handler with "withContext".
Expand All @@ -36,11 +35,14 @@ export interface IExecutionContext {
* https://nodejs.org/api/async_context.html#async_context_asynclocalstorage_enterwith_store
*/
get(): IExecutionContextContainer | undefined;

withContext<R>(context: KibanaExecutionContext | undefined, fn: () => R): R;

/**
* returns serialized representation to send as a header
**/
getAsHeader(): string | undefined;

/**
* returns apm labels
**/
Expand All @@ -57,24 +59,6 @@ export type InternalExecutionContextSetup = IExecutionContext;
*/
export type InternalExecutionContextStart = IExecutionContext;

/**
* @public
*/
export interface ExecutionContextSetup {
/**
* Keeps track of execution context while the passed function is executed.
* Data are carried over all async operations spawned by the passed function.
* The nested calls stack the registered context on top of each other.
**/
withContext<R>(context: KibanaExecutionContext | undefined, fn: (...args: any[]) => R): R;
getAsLabels(): apm.Labels;
}

/**
* @public
*/
export type ExecutionContextStart = ExecutionContextSetup;

export class ExecutionContextService
implements CoreService<InternalExecutionContextSetup, InternalExecutionContextStart>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,10 @@
* Side Public License, v 1.
*/

export type { KibanaExecutionContext } from '../../types';
export { ExecutionContextService } from './execution_context_service';
export type {
InternalExecutionContextSetup,
InternalExecutionContextStart,
ExecutionContextSetup,
ExecutionContextStart,
IExecutionContext,
} from './execution_context_service';
export type { IExecutionContextContainer } from './execution_context_container';
export { config } from './execution_context_config';
export { executionContextConfig } from './execution_context_config';
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"extends": "../../../../tsconfig.bazel.json",
"compilerOptions": {
"declaration": true,
"emitDeclarationOnly": true,
"outDir": "target_types",
"rootDir": "src",
"stripInternal": false,
"types": [
"jest",
"node"
]
},
"include": [
"src/**/*"
]
}
Loading

0 comments on commit d4d6d86

Please sign in to comment.