Skip to content
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 usageData service to packages #139844

Merged
merged 8 commits into from
Sep 5, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,8 @@
"@kbn/core-ui-settings-common": "link:bazel-bin/packages/core/ui-settings/core-ui-settings-common",
"@kbn/core-usage-data-base-server-internal": "link:bazel-bin/packages/core/usage-data/core-usage-data-base-server-internal",
"@kbn/core-usage-data-server": "link:bazel-bin/packages/core/usage-data/core-usage-data-server",
"@kbn/core-usage-data-server-internal": "link:bazel-bin/packages/core/usage-data/core-usage-data-server-internal",
"@kbn/core-usage-data-server-mocks": "link:bazel-bin/packages/core/usage-data/core-usage-data-server-mocks",
"@kbn/crypto": "link:bazel-bin/packages/kbn-crypto",
"@kbn/crypto-browser": "link:bazel-bin/packages/kbn-crypto-browser",
"@kbn/datemath": "link:bazel-bin/packages/kbn-datemath",
Expand Down Expand Up @@ -952,6 +954,8 @@
"@types/kbn__core-ui-settings-common": "link:bazel-bin/packages/core/ui-settings/core-ui-settings-common/npm_module_types",
"@types/kbn__core-usage-data-base-server-internal": "link:bazel-bin/packages/core/usage-data/core-usage-data-base-server-internal/npm_module_types",
"@types/kbn__core-usage-data-server": "link:bazel-bin/packages/core/usage-data/core-usage-data-server/npm_module_types",
"@types/kbn__core-usage-data-server-internal": "link:bazel-bin/packages/core/usage-data/core-usage-data-server-internal/npm_module_types",
"@types/kbn__core-usage-data-server-mocks": "link:bazel-bin/packages/core/usage-data/core-usage-data-server-mocks/npm_module_types",
"@types/kbn__crypto": "link:bazel-bin/packages/kbn-crypto/npm_module_types",
"@types/kbn__crypto-browser": "link:bazel-bin/packages/kbn-crypto-browser/npm_module_types",
"@types/kbn__datemath": "link:bazel-bin/packages/kbn-datemath/npm_module_types",
Expand Down
4 changes: 4 additions & 0 deletions packages/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ filegroup(
"//packages/core/ui-settings/core-ui-settings-common:build",
"//packages/core/usage-data/core-usage-data-base-server-internal:build",
"//packages/core/usage-data/core-usage-data-server:build",
"//packages/core/usage-data/core-usage-data-server-internal:build",
"//packages/core/usage-data/core-usage-data-server-mocks:build",
"//packages/home/sample_data_card:build",
"//packages/home/sample_data_tab:build",
"//packages/home/sample_data_types:build",
Expand Down Expand Up @@ -433,6 +435,8 @@ filegroup(
"//packages/core/ui-settings/core-ui-settings-common:build_types",
"//packages/core/usage-data/core-usage-data-base-server-internal:build_types",
"//packages/core/usage-data/core-usage-data-server:build_types",
"//packages/core/usage-data/core-usage-data-server-internal:build_types",
"//packages/core/usage-data/core-usage-data-server-mocks:build_types",
"//packages/home/sample_data_card:build_types",
"//packages/home/sample_data_tab:build_types",
"//packages/kbn-ace:build_types",
Expand Down
130 changes: 130 additions & 0 deletions packages/core/usage-data/core-usage-data-server-internal/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
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-usage-data-server-internal"
PKG_REQUIRE_NAME = "@kbn/core-usage-data-server-internal"

SOURCE_FILES = glob(
[
"**/*.ts",
],
exclude = [
"**/*.config.js",
"**/*.mock.*",
"**/*.test.*",
"**/*.stories.*",
"**/__snapshots__/**",
"**/integration_tests/**",
"**/mocks/**",
"**/scripts/**",
"**/storybook/**",
"**/test_fixtures/**",
"**/test_helpers/**",
],
)

SRCS = SOURCE_FILES

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

NPM_MODULE_EXTRA_FILES = [
"package.json",
]

RUNTIME_DEPS = [
"@npm//lodash",
"@npm//rxjs",
"@npm//@elastic/elasticsearch",
"//packages/kbn-config",
"//packages/core/saved-objects/core-saved-objects-base-server-internal",
"//packages/core/saved-objects/core-saved-objects-utils-server",
"//packages/core/usage-data/core-usage-data-base-server-internal",
]

TYPES_DEPS = [
"@npm//@types/node",
"@npm//@types/jest",
"@npm//lodash",
"@npm//rxjs",
"@npm//@elastic/elasticsearch",
"//packages/kbn-config:npm_module_types",
"//packages/kbn-logging:npm_module_types",
"//packages/core/base/core-base-server-internal:npm_module_types",
"//packages/core/logging/core-logging-server-internal:npm_module_types",
"//packages/core/http/core-http-server:npm_module_types",
"//packages/core/http/core-http-server-internal:npm_module_types",
"//packages/core/elasticsearch/core-elasticsearch-server:npm_module_types",
"//packages/core/elasticsearch/core-elasticsearch-server-internal:npm_module_types",
"//packages/core/metrics/core-metrics-server:npm_module_types",
"//packages/core/saved-objects/core-saved-objects-server:npm_module_types",
"//packages/core/saved-objects/core-saved-objects-api-server:npm_module_types",
"//packages/core/saved-objects/core-saved-objects-base-server-internal:npm_module_types",
"//packages/core/saved-objects/core-saved-objects-utils-server:npm_module_types",
"//packages/core/usage-data/core-usage-data-server:npm_module_types",
"//packages/core/usage-data/core-usage-data-base-server-internal: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",
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-usage-data-server-internal

This package contains the internal types and implementation for Core's server-side `usage-data` domain.
10 changes: 10 additions & 0 deletions packages/core/usage-data/core-usage-data-server-internal/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* 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.
*/

export { CoreUsageDataService, CoreUsageStatsClient } from './src';
export type { InternalCoreUsageDataSetup } from '@kbn/core-usage-data-base-server-internal';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-exporting the internal contract type from the base package for consistency, given all other domains allow to import the service impl and the associated contracts from the same package.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: external exports/imports first?

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/usage-data/core-usage-data-server-internal'],
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "@kbn/core-usage-data-server-internal",
"private": true,
"version": "1.0.0",
"main": "./target_node/index.js",
"author": "Kibana Core",
"license": "SSPL-1.0 OR Elastic License 2.0"
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import type { SavedObjectTypeRegistry } from '@kbn/core-saved-objects-base-serve
import type { SavedObjectsServiceStart } from '@kbn/core-saved-objects-server';

import { isConfigured } from './is_configured';
import { coreUsageStatsType } from './core_usage_stats';
import { coreUsageStatsType } from './saved_objects';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved the stats SO type to a saved_objects subfolder, as that's our recommended approach

import { CoreUsageStatsClient } from './core_usage_stats_client';

export type ExposedConfigsToUsage = Map<string, Record<string, boolean>>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
* Side Public License, v 1.
*/

import { httpServerMock, httpServiceMock, savedObjectsRepositoryMock } from '../mocks';
import { httpServerMock, httpServiceMock } from '@kbn/core-http-server-mocks';
import { savedObjectsRepositoryMock } from '@kbn/core-saved-objects-api-server-mocks';
import {
CORE_USAGE_STATS_TYPE,
CORE_USAGE_STATS_ID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
* Side Public License, v 1.
*/

import type { KibanaRequest, IBasePath } from '@kbn/core-http-server';
import type { ISavedObjectsRepository } from '@kbn/core-saved-objects-api-server';
import { DEFAULT_NAMESPACE_STRING } from '@kbn/core-saved-objects-utils-server';
import type { CoreUsageStats } from '@kbn/core-usage-data-server';
import {
Expand All @@ -18,7 +20,6 @@ import {
CORE_USAGE_STATS_ID,
REPOSITORY_RESOLVE_OUTCOME_STATS,
} from '@kbn/core-usage-data-base-server-internal';
import { ISavedObjectsRepository, KibanaRequest, IBasePath } from '..';

export const BULK_CREATE_STATS_PREFIX = 'apiCalls.savedObjectsBulkCreate';
export const BULK_GET_STATS_PREFIX = 'apiCalls.savedObjectsBulkGet';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* 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.
*/

export { CoreUsageDataService } from './core_usage_data_service';
export { CoreUsageStatsClient } from './core_usage_stats_client';
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* 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.
*/

export { coreUsageStatsType } from './core_usage_stats';
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"extends": "../../../../tsconfig.bazel.json",
"compilerOptions": {
"declaration": true,
"declarationMap": true,
"emitDeclarationOnly": true,
"outDir": "target_types",
"stripInternal": false,
"types": [
"jest",
"node"
]
},
"include": [
"**/*.ts",
]
}
110 changes: 110 additions & 0 deletions packages/core/usage-data/core-usage-data-server-mocks/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
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-usage-data-server-mocks"
PKG_REQUIRE_NAME = "@kbn/core-usage-data-server-mocks"

SOURCE_FILES = glob(
[
"**/*.ts",
],
exclude = [
"**/*.config.js",
"**/*.test.*",
"**/*.stories.*",
"**/__snapshots__/**",
"**/integration_tests/**",
"**/mocks/**",
"**/scripts/**",
"**/storybook/**",
"**/test_fixtures/**",
"**/test_helpers/**",
],
)

SRCS = SOURCE_FILES

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

NPM_MODULE_EXTRA_FILES = [
"package.json",
]

RUNTIME_DEPS = [
"@npm//rxjs",
]

TYPES_DEPS = [
"@npm//@types/node",
"@npm//@types/jest",
"@npm//rxjs",
"//packages/kbn-utility-types:npm_module_types",
"//packages/core/usage-data/core-usage-data-server:npm_module_types",
"//packages/core/usage-data/core-usage-data-base-server-internal:npm_module_types",
"//packages/core/usage-data/core-usage-data-server-internal: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",
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,5 @@
# @kbn/core-usage-data-server-mocks

This package contains mocks for Core's server-side `usage-data` domain.
- `coreUsageDataServiceMock`
- `coreUsageStatsClientMock`
Loading