-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migrate server-side ES domain to packages #136297
Changes from 34 commits
6550e9f
9d272fa
5a7f812
7d3620b
21610bf
0f4953b
a07f24d
add4b0e
fa83d21
b03557b
64c3bea
d108f7a
7892891
76a8c84
73d9556
675f1eb
d9a632f
2a3d8f2
edc8434
4b722cf
cf50cba
22b5cbc
e640dfe
a4ee98f
e7e3e8c
77aa97e
4133c84
70b2de0
01ba9b7
1f4dd07
366daa8
1988d60
5e0eddb
15e3b29
195b75b
491ecc1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
import { deepFreeze } from '@kbn/std'; | ||
|
||
/** | ||
* The current status of a service at a point in time. | ||
* | ||
* @typeParam Meta - JSON-serializable object. Plugins should export this type to allow other plugins to read the `meta` | ||
* field in a type-safe way. | ||
* @public | ||
*/ | ||
export interface ServiceStatus<Meta extends Record<string, any> | unknown = unknown> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The status calculation logic of the ES services relies on those types, however the To break the dependency I moved those things into |
||
/** | ||
* The current availability level of the service. | ||
*/ | ||
level: ServiceStatusLevel; | ||
/** | ||
* A high-level summary of the service status. | ||
*/ | ||
summary: string; | ||
/** | ||
* A more detailed description of the service status. | ||
*/ | ||
detail?: string; | ||
/** | ||
* A URL to open in a new tab about how to resolve or troubleshoot the problem. | ||
*/ | ||
documentationUrl?: string; | ||
/** | ||
* Any JSON-serializable data to be included in the HTTP API response. Useful for providing more fine-grained, | ||
* machine-readable information about the service status. May include status information for underlying features. | ||
*/ | ||
meta?: Meta; | ||
} | ||
|
||
/** | ||
* The current "level" of availability of a service. | ||
* | ||
* @remarks | ||
* The values implement `valueOf` to allow for easy comparisons between status levels with <, >, etc. Higher values | ||
* represent higher severities. Note that the default `Array.prototype.sort` implementation does not correctly sort | ||
* these values. | ||
* | ||
* A snapshot serializer is available in `src/core/server/test_utils` to ease testing of these values with Jest. | ||
* | ||
* @public | ||
*/ | ||
export const ServiceStatusLevels = deepFreeze({ | ||
/** | ||
* Everything is working! | ||
*/ | ||
available: { | ||
toString: () => 'available', | ||
valueOf: () => 0, | ||
toJSON() { | ||
return this.toString(); | ||
}, | ||
}, | ||
/** | ||
* Some features may not be working. | ||
*/ | ||
degraded: { | ||
toString: () => 'degraded', | ||
valueOf: () => 1, | ||
toJSON() { | ||
return this.toString(); | ||
}, | ||
}, | ||
/** | ||
* The service is unavailable, but other functions that do not depend on this service should work. | ||
*/ | ||
unavailable: { | ||
toString: () => 'unavailable', | ||
valueOf: () => 2, | ||
toJSON() { | ||
return this.toString(); | ||
}, | ||
}, | ||
/** | ||
* Block all user functions and display the status page, reserved for Core services only. | ||
*/ | ||
critical: { | ||
toString: () => 'critical', | ||
valueOf: () => 3, | ||
toJSON() { | ||
return this.toString(); | ||
}, | ||
}, | ||
}); | ||
|
||
/** | ||
* A convenience type that represents the union of each value in {@link ServiceStatusLevels}. | ||
* @public | ||
*/ | ||
export type ServiceStatusLevel = typeof ServiceStatusLevels[keyof typeof ServiceStatusLevels]; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
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-elasticsearch-client-server-internal" | ||
PKG_REQUIRE_NAME = "@kbn/core-elasticsearch-client-server-internal" | ||
|
||
SOURCE_FILES = glob( | ||
[ | ||
"src/**/*.ts", | ||
], | ||
exclude = [ | ||
"**/*.test.*", | ||
"**/*.stories.*", | ||
], | ||
) | ||
|
||
SRCS = SOURCE_FILES | ||
|
||
filegroup( | ||
name = "srcs", | ||
srcs = SRCS, | ||
) | ||
|
||
NPM_MODULE_EXTRA_FILES = [ | ||
"package.json", | ||
] | ||
|
||
RUNTIME_DEPS = [ | ||
"@npm//moment", | ||
"@npm//@elastic/elasticsearch", | ||
"@npm//@elastic/numeral", | ||
"//packages/kbn-std", | ||
"//packages/kbn-es-errors", | ||
"//packages/core/http/core-http-router-server-internal", | ||
### test dependencies | ||
"//packages/core/logging/core-logging-server-mocks", | ||
"//packages/core/http/core-http-server-mocks", | ||
] | ||
|
||
TYPES_DEPS = [ | ||
"@npm//@types/node", | ||
"@npm//@types/jest", | ||
"@npm//moment", | ||
"@npm//@elastic/elasticsearch", | ||
"@npm//@elastic/numeral", | ||
"//packages/kbn-utility-types:npm_module_types", | ||
"//packages/kbn-std:npm_module_types", | ||
"//packages/kbn-es-errors:npm_module_types", | ||
"//packages/kbn-logging:npm_module_types", | ||
"//packages/core/http/core-http-server:npm_module_types", | ||
"//packages/core/http/core-http-router-server-internal:npm_module_types", | ||
"//packages/core/elasticsearch/core-elasticsearch-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, | ||
declaration_map = 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,3 @@ | ||
# @kbn/core-elasticsearch-client-server-internal | ||
|
||
This package contains the internal implementation for Core's server-side elasticsearch client. |
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/elasticsearch/core-elasticsearch-client-server-internal'], | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"name": "@kbn/core-elasticsearch-client-server-internal", | ||
"private": true, | ||
"version": "1.0.0", | ||
"main": "./target_node/index.js", | ||
"license": "SSPL-1.0 OR Elastic License 2.0" | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
core-base-common
seems to be morphing into a "catch-all" I-don't-know-where-to-put-this-thing package. It's fine for now as the package is still very small. During the cleanup phase or slightly prior to that, we should audit everything incore-base-*
packages and see if we could organize the components into a domain-like structure.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, I totally agree. The intent here is to avoid the 'lets create 99 another one-file packages before the end of the migration' effect. We move all the 'misc' stuff here, and we'll revisit once everything has been moved.
Fully agree too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From a quick search through
core
, it'selasticsearch
,status
, andsavedObjects
that all use the types fromstatus
. Am I missing any othercore
domains in this list?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, AFAIK for now only the ES and SO services declare their statuses.