forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ECO][Inventory v2] Ad hoc data view: Add get entities definition end…
…point using sources (elastic#203424) Closes elastic#202298⚠️ Depends on elastic#203246 ## Summary This PR changes the way we get the entity index patterns to v2. It creates an endpoint part of the inventory API which returns the index patterns by entity type. ## Testing⚠️ Currently in order to test we need to create the definition using the dev tools manually before this [PR](elastic#203246) is merged - Open Dev tools and add a definition for an existing entity type (example with host) ``` POST kbn:/internal/entities/v2/definitions/sources { "source": { "id": "host_id", "type_id": "host", "index_patterns": ["metrics-*", "metricbeat-*"], "identity_fields": ["host.name"], "metadata_fields": [], "filters": [], "timestamp_field": "@timestamp" } ``` ### Test the endpoint: - Open Dev tools and add ` GET kbn:/internal/inventory/entity/definitions/sources?type=host ` - Response: <img width="408" alt="image" src="https://github.com/user-attachments/assets/1c7416b0-50a4-4e63-8081-928ec7856ff8"> ### Test in the UI - After the previous steps add some host data (oblt cluster / metricbeat) or use synthtrace (for example use `node scripts/synthtrace infra_hosts_with_apm_hosts --scenarioOpts.numInstances=10`) - Go to Inventory and expand the host group - Click on the actions button for any host and click on the Discover link - The correct dataview should be selected based on the created definition The same can be done for other entity types https://github.com/user-attachments/assets/c9c3a7ae-daff-4d4b-b1b7-898c3f1603c6 --------- Co-authored-by: Carlos Crespo <[email protected]>
- Loading branch information
1 parent
c3f96bb
commit 5bacf1f
Showing
6 changed files
with
89 additions
and
39 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
27 changes: 0 additions & 27 deletions
27
x-pack/plugins/observability_solution/inventory/public/hooks/use_fetch_entity_definition.ts
This file was deleted.
Oops, something went wrong.
34 changes: 34 additions & 0 deletions
34
...servability_solution/inventory/public/hooks/use_fetch_entity_definition_index_patterns.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,34 @@ | ||
/* | ||
* 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 { useInventoryAbortableAsync } from './use_inventory_abortable_async'; | ||
import { useKibana } from './use_kibana'; | ||
|
||
export const useFetchEntityDefinitionIndexPattern = (type: string) => { | ||
const { | ||
services: { inventoryAPIClient }, | ||
} = useKibana(); | ||
|
||
const { value = { definitionIndexPatterns: [] }, loading } = useInventoryAbortableAsync( | ||
({ signal }) => { | ||
return inventoryAPIClient.fetch('GET /internal/inventory/entity/definitions/sources', { | ||
params: { | ||
query: { | ||
type, | ||
}, | ||
}, | ||
signal, | ||
}); | ||
}, | ||
[inventoryAPIClient] | ||
); | ||
|
||
return { | ||
entityDefinitionIndexPatterns: value?.definitionIndexPatterns, | ||
isEntityDefinitionIndexPatternsLoading: loading, | ||
}; | ||
}; |
41 changes: 41 additions & 0 deletions
41
...bservability_solution/inventory/server/routes/entity_definition/get_entity_definitions.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,41 @@ | ||
/* | ||
* 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 t from 'io-ts'; | ||
import { createInventoryServerRoute } from '../create_inventory_server_route'; | ||
|
||
export const getEntityDefinitionSourceIndexPatternsByType = createInventoryServerRoute({ | ||
endpoint: 'GET /internal/inventory/entity/definitions/sources', | ||
params: t.type({ | ||
query: t.type({ | ||
type: t.string, | ||
}), | ||
}), | ||
options: { | ||
tags: ['access:inventory'], | ||
}, | ||
async handler({ context, params, request, plugins }) { | ||
const [_coreContext, entityManagerStart] = await Promise.all([ | ||
context.core, | ||
plugins.entityManager.start(), | ||
]); | ||
const { type } = params.query; | ||
const entityManagerClient = await entityManagerStart.getScopedClient({ request }); | ||
|
||
const entityDefinitionsSource = await entityManagerClient.v2.readSourceDefinitions({ type }); | ||
|
||
return { | ||
definitionIndexPatterns: entityDefinitionsSource.map( | ||
(definition) => definition.index_patterns, | ||
[] | ||
), | ||
}; | ||
}, | ||
}); | ||
|
||
export const entityDefinitionsRoutes = { | ||
...getEntityDefinitionSourceIndexPatternsByType, | ||
}; |
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