-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Asset Manager] Creates baseline public asset client for use in publi…
…c plugins (#167191) Closes #167075 ## Summary Adds a public asset client available in the `setup` lifecycle hook for plugins that depend on this one. `getHosts` is the only method available on this client for now. TODO, before merge: - [x] Add docs for the server client - [x] Add docs for the public client - [x] Remove REST docs from plugin docs, not needed - [x] Add unit tests for public client ### Testing this PR One way of testing this new client is to apply the attached test-assets.patch file locally, adjust the date range in the getHosts query that is added in the infra plugin, and then start Kibana and navigate to the infra app. You should see print out in the browser console. [test-assets.patch](https://github.com/elastic/kibana/files/12718693/test-assets.patch) --------- Co-authored-by: kibanamachine <[email protected]>
- Loading branch information
1 parent
424dec6
commit 859ae9e
Showing
42 changed files
with
758 additions
and
302 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,13 @@ | ||
# Asset Manager Plugin | ||
|
||
This plugin provides access to the asset data stored in assets-\* indices, primarily | ||
for inventory and topology purposes. | ||
This plugin provides access to observed asset data, such as information about hosts, pods, containers, services, and more. | ||
|
||
## Documentation | ||
|
||
See [docs for the provided APIs in the docs folder](./docs/index.md). | ||
### User Docs | ||
|
||
## Running Tests | ||
For those interested in making use of the APIs provided by this plugin, see [our API docs](./docs/api.md). | ||
|
||
There are integration tests for the endpoints implemented thus far as well as for | ||
the sample data tests. There is also a small set of tests meant to ensure that the | ||
plugin is not doing anything without the proper config value in place to enable | ||
the plugin fully. For more on enabling the plugin, see [the docs page](./docs/index.md). | ||
### Developer Docs | ||
|
||
The "not enabled" tests are run by default in CI. To run them manually, do the following: | ||
|
||
```shell | ||
$ node scripts/functional_tests_server --config x-pack/test/api_integration/apis/asset_manager/config_when_disabled.ts | ||
$ node scripts/functional_test_runner --config=x-pack/test/api_integration/apis/asset_manager/config_when_disabled.ts | ||
``` | ||
|
||
The "enabled" tests are NOT run by CI yet, to prevent blocking Kibana development for a | ||
test failure in this alpha, tech preview plugin. They will be moved into the right place | ||
to make them run for CI before the plugin is enabled by default. To run them manually: | ||
|
||
```shell | ||
$ node scripts/functional_tests_server --config x-pack/test/api_integration/apis/asset_manager/config.ts | ||
$ node scripts/functional_test_runner --config=x-pack/test/api_integration/apis/asset_manager/config.ts | ||
``` | ||
|
||
## Using Sample Data | ||
|
||
This plugin comes with a full "working set" of sample asset documents, meant | ||
to provide enough data in the correct schema format so that all of the API | ||
endpoints return expected values. | ||
|
||
To create the sample data, follow [the instructions in the REST API docs](./docs/index.md#sample-data). | ||
For those working on this plugin directly and developing it, please see [our development docs](./docs/development.md). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* 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; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { schema, TypeOf } from '@kbn/config-schema'; | ||
|
||
export const INDEX_DEFAULTS = { | ||
logs: 'filebeat-*,logs-*', | ||
}; | ||
|
||
export const configSchema = schema.object({ | ||
alphaEnabled: schema.maybe(schema.boolean()), | ||
// Designate where various types of data live. | ||
// NOTE: this should be handled in a centralized way for observability, so | ||
// that when a user configures these differently from the known defaults, | ||
// that value is propagated everywhere. For now, we duplicate the value here. | ||
sourceIndices: schema.object( | ||
{ | ||
logs: schema.string({ defaultValue: INDEX_DEFAULTS.logs }), | ||
}, | ||
{ defaultValue: INDEX_DEFAULTS } | ||
), | ||
// Choose an explicit source for asset queries. | ||
// NOTE: This will eventually need to be able to cleverly switch | ||
// between these values based on the availability of data in the | ||
// indices, and possibly for each asset kind/type value. | ||
// For now, we set this explicitly. | ||
lockedSource: schema.oneOf([schema.literal('assets'), schema.literal('signals')], { | ||
defaultValue: 'signals', | ||
}), | ||
}); | ||
|
||
export type AssetManagerConfig = TypeOf<typeof configSchema>; | ||
|
||
/** | ||
* The following map is passed to the server plugin setup under the | ||
* exposeToBrowser: option, and controls which of the above config | ||
* keys are allow-listed to be available in the browser config. | ||
* | ||
* NOTE: anything exposed here will be visible in the UI dev tools, | ||
* and therefore MUST NOT be anything that is sensitive information! | ||
*/ | ||
export const exposeToBrowserConfig = { | ||
alphaEnabled: true, | ||
} as const; | ||
|
||
type ValidKeys = keyof { | ||
[K in keyof typeof exposeToBrowserConfig as typeof exposeToBrowserConfig[K] extends true | ||
? K | ||
: never]: true; | ||
}; | ||
|
||
export type AssetManagerPublicConfig = Pick<AssetManagerConfig, ValidKeys>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* 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; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
export const ASSET_MANAGER_API_BASE = '/api/asset-manager'; | ||
|
||
function base(path: string) { | ||
return `${ASSET_MANAGER_API_BASE}${path}`; | ||
} | ||
|
||
export const GET_ASSETS = base('/assets'); | ||
export const GET_RELATED_ASSETS = base('/assets/related'); | ||
export const GET_ASSETS_DIFF = base('/assets/diff'); | ||
|
||
export const GET_HOSTS = base('/assets/hosts'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* | ||
* 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; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
export interface GetHostsOptionsPublic { | ||
from: string; | ||
to: string; | ||
} | ||
|
||
export interface GetServicesOptionsPublic { | ||
from: string; | ||
to: string; | ||
parent?: string; | ||
} |
Oops, something went wrong.