Skip to content

Commit

Permalink
[APM] Add filter to /has_data api (#173382)
Browse files Browse the repository at this point in the history
Closes #154997

This PR adds a data tier filter to the `/has_data` api, thus limitting
the number of shards being hit by the request.
  • Loading branch information
sorenlouv committed Dec 18, 2023
1 parent 4298d65 commit e7593c0
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 421 deletions.
Expand Up @@ -8,10 +8,29 @@
import { ProcessorEvent } from '@kbn/observability-plugin/common';
import { APMEventClient } from '../../lib/helpers/create_es_client/create_apm_event_client';

// Note: this logic is duplicated in tutorials/apm/envs/on_prem
export async function hasHistoricalAgentData(apmEventClient: APMEventClient) {
const hasDataInWarmOrHotDataTiers = await hasDataRequest(apmEventClient, [
'data_hot',
'data_warm',
]);

if (hasDataInWarmOrHotDataTiers) {
return true;
}

const hasDataUnbounded = await hasDataRequest(apmEventClient);

return hasDataUnbounded;
}

type DataTier = 'data_hot' | 'data_warm' | 'data_cold' | 'data_frozen';
async function hasDataRequest(
apmEventClient: APMEventClient,
dataTiers?: DataTier[]
) {
const query = dataTiers ? { terms: { _tier: dataTiers } } : undefined;

const params = {
terminate_after: 1,
apm: {
events: [
ProcessorEvent.error,
Expand All @@ -20,8 +39,10 @@ export async function hasHistoricalAgentData(apmEventClient: APMEventClient) {
],
},
body: {
terminate_after: 1,
track_total_hits: 1,
size: 0,
query,
},
};

Expand Down

This file was deleted.

0 comments on commit e7593c0

Please sign in to comment.