-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Infrastructure UI] Implement Metrics explorer views CRUD endpoints (#…
…155621) ## 📓 Summary Part of #152617 Closes #155111 This PR implements the CRUD endpoints for the metrics explorer views. Following the approach used for the InventoryView service, it exposes a client that abstracts all the logic concerned to the `metrics-explorer-view` saved objects. It also follows the guideline provided for [Versioning interfaces](https://docs.elastic.dev/kibana-dev-docs/versioning-interfaces) and [Versioning HTTP APIs](https://docs.elastic.dev/kibana-dev-docs/versioning-http-apis), preparing for the serverless. ## 🤓 Tips for the reviewer You can open the Kibana dev tools and play with the following snippet to test the create APIs, or you can perform the same requests with your preferred client: ``` // Get all GET kbn:/api/infra/metrics_explorer_views // Create one POST kbn:/api/infra/metrics_explorer_views { "attributes": { "name": "My view" } } // Get one GET kbn:/api/infra/metrics_explorer_views/<switch-with-id> // Update one PUT kbn:/api/infra/metrics_explorer_views/<switch-with-id> { "attributes": { "name": "My view 2" } } // Delete one DELETE kbn:/api/infra/metrics_explorer_views/<switch-with-id> ``` --------- Co-authored-by: Marco Antonio Ghiani <[email protected]> Co-authored-by: kibanamachine <[email protected]>
- Loading branch information
1 parent
202f13f
commit 61bb52c
Showing
38 changed files
with
1,528 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ | |
*/ | ||
|
||
export * from './inventory_views/v1'; | ||
export * from './metrics_explorer_views/v1'; |
68 changes: 68 additions & 0 deletions
68
x-pack/plugins/infra/common/http_api/metrics_explorer_views/v1/common.ts
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,68 @@ | ||
/* | ||
* 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 { nonEmptyStringRt } from '@kbn/io-ts-utils'; | ||
import * as rt from 'io-ts'; | ||
import { either } from 'fp-ts/Either'; | ||
|
||
export const METRICS_EXPLORER_VIEW_URL = '/api/infra/metrics_explorer_views'; | ||
export const METRICS_EXPLORER_VIEW_URL_ENTITY = `${METRICS_EXPLORER_VIEW_URL}/{metricsExplorerViewId}`; | ||
export const getMetricsExplorerViewUrl = (metricsExplorerViewId?: string) => | ||
[METRICS_EXPLORER_VIEW_URL, metricsExplorerViewId].filter(Boolean).join('/'); | ||
|
||
const metricsExplorerViewIdRT = new rt.Type<string, string, unknown>( | ||
'MetricsExplorerViewId', | ||
rt.string.is, | ||
(u, c) => | ||
either.chain(rt.string.validate(u, c), (id) => { | ||
return id === '0' | ||
? rt.failure(u, c, `The metrics explorer view with id ${id} is not configurable.`) | ||
: rt.success(id); | ||
}), | ||
String | ||
); | ||
|
||
export const metricsExplorerViewRequestParamsRT = rt.type({ | ||
metricsExplorerViewId: metricsExplorerViewIdRT, | ||
}); | ||
|
||
export type MetricsExplorerViewRequestParams = rt.TypeOf<typeof metricsExplorerViewRequestParamsRT>; | ||
|
||
export const metricsExplorerViewRequestQueryRT = rt.partial({ | ||
sourceId: rt.string, | ||
}); | ||
|
||
export type MetricsExplorerViewRequestQuery = rt.TypeOf<typeof metricsExplorerViewRequestQueryRT>; | ||
|
||
const metricsExplorerViewAttributesResponseRT = rt.intersection([ | ||
rt.strict({ | ||
name: nonEmptyStringRt, | ||
isDefault: rt.boolean, | ||
isStatic: rt.boolean, | ||
}), | ||
rt.UnknownRecord, | ||
]); | ||
|
||
const metricsExplorerViewResponseRT = rt.exact( | ||
rt.intersection([ | ||
rt.type({ | ||
id: rt.string, | ||
attributes: metricsExplorerViewAttributesResponseRT, | ||
}), | ||
rt.partial({ | ||
updatedAt: rt.number, | ||
version: rt.string, | ||
}), | ||
]) | ||
); | ||
|
||
export const metricsExplorerViewResponsePayloadRT = rt.type({ | ||
data: metricsExplorerViewResponseRT, | ||
}); | ||
|
||
export type GetMetricsExplorerViewResponsePayload = rt.TypeOf< | ||
typeof metricsExplorerViewResponsePayloadRT | ||
>; |
29 changes: 29 additions & 0 deletions
29
...k/plugins/infra/common/http_api/metrics_explorer_views/v1/create_metrics_explorer_view.ts
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,29 @@ | ||
/* | ||
* 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 { nonEmptyStringRt } from '@kbn/io-ts-utils'; | ||
import * as rt from 'io-ts'; | ||
|
||
export const createMetricsExplorerViewAttributesRequestPayloadRT = rt.intersection([ | ||
rt.type({ | ||
name: nonEmptyStringRt, | ||
}), | ||
rt.UnknownRecord, | ||
rt.exact(rt.partial({ isDefault: rt.undefined, isStatic: rt.undefined })), | ||
]); | ||
|
||
export type CreateMetricsExplorerViewAttributesRequestPayload = rt.TypeOf< | ||
typeof createMetricsExplorerViewAttributesRequestPayloadRT | ||
>; | ||
|
||
export const createMetricsExplorerViewRequestPayloadRT = rt.type({ | ||
attributes: createMetricsExplorerViewAttributesRequestPayloadRT, | ||
}); | ||
|
||
export type CreateMetricsExplorerViewRequestPayload = rt.TypeOf< | ||
typeof createMetricsExplorerViewRequestPayloadRT | ||
>; |
36 changes: 36 additions & 0 deletions
36
x-pack/plugins/infra/common/http_api/metrics_explorer_views/v1/find_metrics_explorer_view.ts
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,36 @@ | ||
/* | ||
* 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 { nonEmptyStringRt } from '@kbn/io-ts-utils'; | ||
import * as rt from 'io-ts'; | ||
|
||
export const findMetricsExplorerViewAttributesResponseRT = rt.strict({ | ||
name: nonEmptyStringRt, | ||
isDefault: rt.boolean, | ||
isStatic: rt.boolean, | ||
}); | ||
|
||
const findMetricsExplorerViewResponseRT = rt.exact( | ||
rt.intersection([ | ||
rt.type({ | ||
id: rt.string, | ||
attributes: findMetricsExplorerViewAttributesResponseRT, | ||
}), | ||
rt.partial({ | ||
updatedAt: rt.number, | ||
version: rt.string, | ||
}), | ||
]) | ||
); | ||
|
||
export const findMetricsExplorerViewResponsePayloadRT = rt.type({ | ||
data: rt.array(findMetricsExplorerViewResponseRT), | ||
}); | ||
|
||
export type FindMetricsExplorerViewResponsePayload = rt.TypeOf< | ||
typeof findMetricsExplorerViewResponsePayloadRT | ||
>; |
16 changes: 16 additions & 0 deletions
16
x-pack/plugins/infra/common/http_api/metrics_explorer_views/v1/get_metrics_explorer_view.ts
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,16 @@ | ||
/* | ||
* 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 * as rt from 'io-ts'; | ||
|
||
export const getMetricsExplorerViewRequestParamsRT = rt.type({ | ||
metricsExplorerViewId: rt.string, | ||
}); | ||
|
||
export type GetMetricsExplorerViewRequestParams = rt.TypeOf< | ||
typeof getMetricsExplorerViewRequestParamsRT | ||
>; |
12 changes: 12 additions & 0 deletions
12
x-pack/plugins/infra/common/http_api/metrics_explorer_views/v1/index.ts
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,12 @@ | ||
/* | ||
* 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 * from './common'; | ||
export * from './get_metrics_explorer_view'; | ||
export * from './find_metrics_explorer_view'; | ||
export * from './create_metrics_explorer_view'; | ||
export * from './update_metrics_explorer_view'; |
29 changes: 29 additions & 0 deletions
29
...k/plugins/infra/common/http_api/metrics_explorer_views/v1/update_metrics_explorer_view.ts
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,29 @@ | ||
/* | ||
* 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 { nonEmptyStringRt } from '@kbn/io-ts-utils'; | ||
import * as rt from 'io-ts'; | ||
|
||
export const updateMetricsExplorerViewAttributesRequestPayloadRT = rt.intersection([ | ||
rt.type({ | ||
name: nonEmptyStringRt, | ||
}), | ||
rt.UnknownRecord, | ||
rt.exact(rt.partial({ isDefault: rt.undefined, isStatic: rt.undefined })), | ||
]); | ||
|
||
export type UpdateMetricsExplorerViewAttributesRequestPayload = rt.TypeOf< | ||
typeof updateMetricsExplorerViewAttributesRequestPayloadRT | ||
>; | ||
|
||
export const updateMetricsExplorerViewRequestPayloadRT = rt.type({ | ||
attributes: updateMetricsExplorerViewAttributesRequestPayloadRT, | ||
}); | ||
|
||
export type UpdateMetricsExplorerViewRequestPayload = rt.TypeOf< | ||
typeof updateMetricsExplorerViewRequestPayloadRT | ||
>; |
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 |
---|---|---|
|
@@ -5,4 +5,5 @@ | |
* 2.0. | ||
*/ | ||
|
||
export * from './defaults'; | ||
export * from './types'; |
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
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
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
Oops, something went wrong.