Skip to content
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] Add filter to /has_data api #173382

Merged
merged 5 commits into from Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -9,9 +9,15 @@ 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) {
export async function hasHistoricalAgentData(
apmEventClient: APMEventClient,
{ limitByDataTier } = { limitByDataTier: false }
sorenlouv marked this conversation as resolved.
Show resolved Hide resolved
) {
const query = limitByDataTier
? { terms: { _tier: ['data_hot', 'data_warm'] } }
: undefined;

const params = {
terminate_after: 1,
apm: {
events: [
ProcessorEvent.error,
Expand All @@ -20,8 +26,10 @@ export async function hasHistoricalAgentData(apmEventClient: APMEventClient) {
],
},
body: {
terminate_after: 1,
cauemarcondes marked this conversation as resolved.
Show resolved Hide resolved
track_total_hits: 1,
size: 0,
query,
},
};

Expand Down
13 changes: 11 additions & 2 deletions x-pack/plugins/apm/server/routes/historical_data/route.ts
Expand Up @@ -14,8 +14,17 @@ const hasDataRoute = createApmServerRoute({
options: { tags: ['access:apm'] },
handler: async (resources): Promise<{ hasData: boolean }> => {
const apmEventClient = await getApmEventClient(resources);
const hasData = await hasHistoricalAgentData(apmEventClient);
return { hasData };
const hasDataInWarmDataTiers = await hasHistoricalAgentData(
apmEventClient,
{ limitByDataTier: true }
);

if (hasDataInWarmDataTiers) {
return { hasData: true };
}

const hasDataUnbounded = await hasHistoricalAgentData(apmEventClient);
return { hasData: hasDataUnbounded };
},
});

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.