-
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
Get the assetClient ready for building inventory prototype #167692
Merged
jasonrhodes
merged 13 commits into
elastic:main
from
jasonrhodes:asset-client_inventory-ready
Oct 4, 2023
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
7654bfc
Adds getServices method, tests, and docs
jasonrhodes fb298e3
Fixes types and adds EAN parsing for getServices
jasonrhodes 7f4c183
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine 5c7b12c
Adds unit tests for server client
jasonrhodes 27894e8
Removes binary source switching from asset client methods
jasonrhodes 213232e
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine 96f6715
Removes locked source fork from API integration tests
jasonrhodes 0976491
Merge branch 'main' into asset-client_inventory-ready
jasonrhodes 760ee60
Merge branch 'main' into asset-client_inventory-ready
jasonrhodes 9025078
Merge branch 'main' into asset-client_inventory-ready
jasonrhodes 8938f91
Troubleshooting failed FTR tests
jasonrhodes 34c6d1a
Improvements to assets server client unit tests
jasonrhodes 98c0e7f
Defaults validation error to 400 status, per review suggestion
jasonrhodes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
27 changes: 0 additions & 27 deletions
27
x-pack/plugins/asset_manager/server/lib/accessors/hosts/get_hosts_by_assets.ts
This file was deleted.
Oops, something went wrong.
19 changes: 0 additions & 19 deletions
19
x-pack/plugins/asset_manager/server/lib/accessors/hosts/index.ts
This file was deleted.
Oops, something went wrong.
19 changes: 0 additions & 19 deletions
19
x-pack/plugins/asset_manager/server/lib/accessors/index.ts
This file was deleted.
Oops, something went wrong.
59 changes: 59 additions & 0 deletions
59
x-pack/plugins/asset_manager/server/lib/accessors/services/get_services.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,59 @@ | ||
/* | ||
* 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 { Asset } from '../../../../common/types_api'; | ||
import { collectServices } from '../../collectors/services'; | ||
import { parseEan } from '../../parse_ean'; | ||
import { GetServicesOptionsPublic } from '../../../../common/types_client'; | ||
import { | ||
AssetClientDependencies, | ||
AssetClientOptionsWithInjectedValues, | ||
} from '../../asset_client_types'; | ||
|
||
export type GetServicesOptions = GetServicesOptionsPublic & AssetClientDependencies; | ||
export type GetServicesOptionsInjected = AssetClientOptionsWithInjectedValues<GetServicesOptions>; | ||
|
||
export async function getServices( | ||
options: GetServicesOptionsInjected | ||
): Promise<{ services: Asset[] }> { | ||
const filters = []; | ||
|
||
if (options.parent) { | ||
const { kind, id } = parseEan(options.parent); | ||
|
||
if (kind === 'host') { | ||
filters.push({ | ||
bool: { | ||
should: [{ term: { 'host.name': id } }, { term: { 'host.hostname': id } }], | ||
minimum_should_match: 1, | ||
}, | ||
}); | ||
} | ||
|
||
if (kind === 'container') { | ||
filters.push({ | ||
bool: { | ||
should: [{ term: { 'container.id': id } }], | ||
minimum_should_match: 1, | ||
}, | ||
}); | ||
} | ||
} | ||
|
||
const apmIndices = await options.getApmIndices(options.savedObjectsClient); | ||
const { assets } = await collectServices({ | ||
client: options.elasticsearchClient, | ||
from: options.from, | ||
to: options.to || 'now', | ||
sourceIndices: { | ||
apm: apmIndices, | ||
}, | ||
filters, | ||
}); | ||
|
||
return { services: assets }; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
should we validate
kind
value as part ofparseEan
(caller can pass the supported types to the function), or here, maybe with a switch ? thinking the api consumer should know if the parameter was ignoredThere 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.
Good point. I think I'll explore this more as I develop the UI built on top of it, and see what makes the most sense.