-
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
[Security Solution] add new GET endpoint metadata list api #118968
Conversation
@@ -161,6 +167,83 @@ export const getMetadataListRequestHandler = function ( | |||
}; | |||
}; | |||
|
|||
export function getMetadataListRequestHandlerV2( |
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.
will remove the V2 naming across the board when we get rid of the POST API.
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.
most of the code is purposely duplicated so that the POST API and associated code can be easily removed in later PR.
endpointAppContextService.start({ ...startContract, packageService: mockPackageService }); | ||
mockAgentService = startContract.agentService!; | ||
mockAgentPolicyService = startContract.agentPolicyService!; | ||
describe('POST list endpoints route', () => { |
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.
most of this is actually untouched, I just moved/nested some stuff. also duplicated POST API tests then modified them for the new GET API.
expect(body.request_page_size).to.eql(10); | ||
expect(body.request_page_index).to.eql(0); | ||
}); | ||
describe('test metadata apis', () => { |
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.
same as other tests, mostly just nesting/moving tests around followed by duplicating POST API tests and modifying for the new GET API.
f396033
to
4096bca
Compare
Pinging @elastic/security-onboarding-and-lifecycle-mgt (Team:Onboarding and Lifecycle Mgt) |
💚 Build Succeeded
Metrics [docs]
History
To update your PR or re-run it, just comment with: |
} | ||
|
||
// If no unified Index present, then perform a search using the legacy approach | ||
if (!doesUnitedIndexExist || didUnitedIndexError) { |
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.
nit: move this and the next one to another method,. e.g. getMetadataListRequestHandlerLegacy()
💚 Backport successful
This backport PR will be merged automatically after passing CI. |
…119099) Co-authored-by: Joey F. Poon <[email protected]>
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.
@joeypoon
Just taking a look at this - thank you for taking this on. I left several comments. Let me know if you have any questions.
/** | ||
* Returned by the server via GET /api/endpoint/metadata | ||
*/ | ||
export interface MetadataListResponse extends BaseListResponse { |
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.
You could hve also made BaseListResonse
a generic, like:
export interface BaseListResponse<D = unknown> {
data: D[];
page: number;
pageSize: number;
total: number;
sort?: string;
sortOrder?: 'asc' | 'desc';
}
Which would make it easier to defined more domain specific types:
export type MetadataListResponse = BaseListResponse<HostInfo>
pageSize: number; | ||
total: number; | ||
sort?: string; | ||
sortOrder?: 'asc' | 'desc'; |
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.
❓ Q. Do we support sort/sort order on the metadata API currently? (or maybe this new API does?)
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.
no to both :(. this was just preemptive.
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.
cool. best to remove it for now (don't forget to adjust the schema
pageSize: pagingProperties.pageSize, | ||
filters: request.body?.filters || {}, | ||
hostStatuses: request.body?.filters.host_status || [], |
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.
oh crap - was this a bug I introduced during the refactor?
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.
nah, I'm just flatting things here for the new route so had to change some of the methods.
total, | ||
request_page_size: pageSize, | ||
request_page_index: pagingProperties.pageIndex * pagingProperties.pageSize, |
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.
is this correct?
request_page_index
is suppose to be the page index that the user requested, correct? This does not look right to me.
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.
the naming here is a bit confusing, this was actually the index of the document since it was being pulled directly from the esQuery.from
. I changed everything to be index of the page so this is the last place where we're using index of doc (for endpoint list apis at least), which we can then delete together with the route.
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.
😱 🙀 - So happy we are deleting this API.
> { | ||
return async (context, request, response) => { | ||
const endpointMetadataService = endpointAppContext.service.getEndpointMetadataService(); | ||
if (!endpointMetadataService) { |
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.
is this needed?
I would move it to the service.getEndpointMetadataService()
instead if you see that it is actually needed
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.
this is needed here but I hesitate to move the exception up since isn't there a possibility that this might not be a required service for a consumer?
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.
I don't think so. I think that EndpointAppContext
is always initialized "fully" so this service will (?should?) be available always
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.
misunderstood you here. will just remove the null check.
body = { | ||
data, | ||
total, | ||
page: request.query.page, |
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.
you could just use the return value from getHostMetadataList()
method right (I think it has the same signature as far as the data structure.
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.
I changed to this because I removed page
and pageSize
from getHostMetadataList
since it just returns those directly from the received params anyways.
endpointAppContext: EndpointAppContext, | ||
logger: Logger, | ||
endpointPolicies: PackagePolicy[] | ||
endpointPolicies: PackagePolicy[], | ||
queryOptions: TypeOf<typeof GetMetadataListRequestSchemaV2.query> |
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.
We probably should create a type for this in security_solution/common/
because the UI will need it as well.
@@ -60,27 +65,54 @@ export const GetMetadataListRequestSchema = { | |||
), | |||
}; | |||
|
|||
export const GetMetadataListRequestSchemaV2 = { | |||
query: schema.object({ |
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.
can we make all of this optional? A consumer of the list api should not be required to define all of this. It should be optional and schema assign defaults.
Also - I suggest you move it to security_solution/common/endpoint/schema
, so that the Types that we create from it can be re-used on the UI side. You should also add some tests against the schema (case we ever change to io-ts
we have tests in place to ensure it still works as we expected it)
service: new EndpointAppContextService(), | ||
config: () => Promise.resolve(createMockConfig()), | ||
experimentalFeatures: parseExperimentalConfigValue(createMockConfig().enableExperimental), | ||
const query = await kibanaRequestToMetadataListESQuery({ |
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.
If you make the query
optional, please a test for it.
@@ -36,7 +36,7 @@ export function buildStatusesKuery(statusesToFilter: string[]): string | undefin | |||
export async function findAgentIdsByStatus( | |||
agentService: AgentService, | |||
esClient: ElasticsearchClient, | |||
statuses: string[], | |||
statuses: string[] = [], |
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.
why make it optional? the method's purpose is to get agents by statuses, so the consumer of this method must define them on input.
(I see below there is not much harm, as it exits if it finds an empty array, but still I think we should not be invoking this method without statuses
)
Summary
Creates a new GET endpoint metadata list API. It returns the same data as the existing POST endpoint metadata list API but in a more standardized format. POST API removal and frontend change to use new API will be addressed in separate PRs.
Checklist
For maintainers