-
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
[APM] Create infraMetricsClient #141735
[APM] Create infraMetricsClient #141735
Conversation
start: number; | ||
end: number; | ||
}) => { | ||
const response = await esClient.search<unknown, { hostNames: Aggs }>({ | ||
index: [index], | ||
const response = await infraMetricsClient.search< |
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.
infraMetricsClient: await createInfraMetricsClient({ | ||
infraPlugin: plugins.infra, | ||
context, | ||
}), |
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 understand why you added it here but the idea is to split up setupRequest in separate parts, so we don't have to initialise every client when we just need one of them.
So please remove it from here and invoke it separately
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.
Yes, I completely forgot about that issue, it's almost a year old, should we prioritize it and added to 8.6?
I will add a different setupRequest for the infraMetricsClient for now
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'd love to see it split up. Your are welcome to take a stab at it after the test plan is done.
context: ApmPluginRequestHandlerContext; | ||
}) { | ||
return { | ||
search: async (opts: ESSearchRequest) => { |
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.
index
is required by default, so you need to remove it:
search: async (opts: ESSearchRequest) => { | |
search: async <TParams extends Omit<ESSearchRequest, 'index'>>( | |
opts: TParams |
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.
@dgieselaar What else is needed to ensure that aggregations are inferred correctly? Do we need to set a manual return type like InferSearchResponseOf<TDocument, TParams>
?
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 added the params type, but I still have the same errors, my errors are in the response type from the client
}), | ||
}; | ||
}); | ||
} |
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 do we need this function? Why not call createInfraMetricsClient
directly?
@@ -29,12 +30,9 @@ const infrastructureRoute = createApmServerRoute({ | |||
podNames: string[]; | |||
}> => { | |||
const setup = await setupRequest(resources); | |||
const setupInfraMetrics = await setupInfraMetricsRequest(resources); |
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 are we not calling createInfraMetricsClient
directly?
const setupInfraMetrics = await setupInfraMetricsRequest(resources); | |
const infraMetricsClient = await createInfraMetricsClient(resources); |
if (!infraMetricsClient) { | ||
return undefined; | ||
} |
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 check necessary? Isn't infraMetricsClient
required?
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, it was checking for the index before, but if the client is created we don't need to check it
...opts, | ||
}; | ||
|
||
return esClient.asCurrentUser.search(searchParams); |
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.
Try this (credits goes to @dgieselaar)
return esClient.asCurrentUser.search(searchParams); | |
const res = esClient.asCurrentUser.search( | |
searchParams | |
) as unknown as Promise<{ | |
body: any; | |
}>; | |
return unwrapEsResponse(res); |
search: async <TParams extends Omit<ESSearchRequest, 'index'>>( | ||
opts: TParams | ||
) => { |
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.
search: async <TParams extends Omit<ESSearchRequest, 'index'>>( | |
opts: TParams | |
) => { | |
async search<TDocument, TParams extends InfraMetricsSearchParams>( | |
opts: TParams | |
): Promise<InferSearchResponseOf<TDocument, TParams>> { |
Where InfraMetricsSearchParams
is:
type InfraMetricsSearchParams = Omit<ESSearchRequest, 'index'> & {
body: {
size: number;
track_total_hits: boolean | number;
};
};
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.
InfraMetricsSearchParams
is needed to make size
and track_total_hits
required.
const response = await infraMetricsClient.search< | ||
unknown, | ||
ResponseAggregations | ||
>({ |
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 shouldn't be needed
const response = await infraMetricsClient.search< | |
unknown, | |
ResponseAggregations | |
>({ | |
const response = await infraMetricsClient.search({ |
_source: [KUBERNETES, CONTAINER], | ||
size: 0, |
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: We are not using source (size: 0
) so there's no need to specify _source: [KUBERNETES, CONTAINER]
.
|
||
const { | ||
const { plugins, context } = resources; | ||
const infraMetricsClient = await createInfraMetricsClient({ |
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.
Do we need to await
createInfraMetricsClient?
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.
const infraMetricsClient = await createInfraMetricsClient({ | |
const infraMetricsClient = createInfraMetricsClient({ |
|
||
export type InfraClient = Awaited<ReturnType<typeof createInfraMetricsClient>>; | ||
|
||
export async function createInfraMetricsClient({ |
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.
Shouldn't be async afaict
export async function createInfraMetricsClient({ | |
export function createInfraMetricsClient({ |
@@ -19,6 +17,7 @@ import { | |||
KUBERNETES_REPLICASET_NAME, | |||
KUBERNETES_DEPLOYMENT_NAME, | |||
} from '../../../common/elasticsearch_fieldnames'; | |||
import { InfraClient } from '../../lib/helpers/create_es_client/create_infra_metrics_client/create_infra_metrics_client'; | |||
|
|||
type ServiceOverviewContainerMetadataDetails = | |||
| { |
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 should be inferred from the query and not explicitly typed
@@ -19,6 +17,7 @@ import { | |||
KUBERNETES_REPLICASET_NAME, | |||
KUBERNETES_DEPLOYMENT_NAME, | |||
} from '../../../common/elasticsearch_fieldnames'; | |||
import { InfraClient } from '../../lib/helpers/create_es_client/create_infra_metrics_client/create_infra_metrics_client'; |
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 you please rename this.
import { InfraClient } from '../../lib/helpers/create_es_client/create_infra_metrics_client/create_infra_metrics_client'; | |
import { InfraMetricsClient } from '../../lib/helpers/create_es_client/create_infra_metrics_client/create_infra_metrics_client'; |
Pinging @elastic/apm-ui (Team:APM) |
const { plugins, context } = resources; | ||
const infraMetricsClient = await createInfraMetricsClient({ | ||
infraPlugin: plugins.infra, | ||
context, | ||
}); |
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 think we can simplify this a bit if we just pass resources
as arg:
const { plugins, context } = resources; | |
const infraMetricsClient = await createInfraMetricsClient({ | |
infraPlugin: plugins.infra, | |
context, | |
}); | |
const infraMetricsClient = await createInfraMetricsClient(resources); |
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 leave like this, infraPlugin
is not part of the resources, so I will need to extracted somewhere else
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.
lgtm. Thanks @MiriamAparicio !
bd3de94
to
f942e61
Compare
💚 Build Succeeded
Metrics [docs]
History
To update your PR or re-run it, just comment with: |
Closes #140924