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

[6.6] Requires fields necessary for percent calculation (#29021) #29068

Merged
merged 1 commit into from
Jan 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion x-pack/plugins/apm/public/utils/__test__/formatters.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ describe('formatters', () => {

it('should return fallback when denominator is 0 ', () => {
expect(asPercent(3725, 0, 'n/a')).toEqual('n/a');
expect(asPercent(3725, 0)).toEqual('');
});

it('should return fallback when numerator or denominator is NaN', () => {
expect(asPercent(3725, NaN, 'n/a')).toEqual('n/a');
expect(asPercent(NaN, 10000, 'n/a')).toEqual('n/a');
});
});
});
2 changes: 1 addition & 1 deletion x-pack/plugins/apm/public/utils/formatters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export function asPercent(
denominator: number | undefined,
fallbackResult = ''
) {
if (!denominator) {
if (!denominator || isNaN(numerator)) {
return fallbackResult;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,18 @@ Array [
},
},
],
"must": Array [
Object {
"exists": Object {
"field": "system.memory.total",
},
},
Object {
"exists": Object {
"field": "system.memory.actual.free",
},
},
],
},
},
"size": 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,20 @@ const percentSystemMemoryUsedScript = {
export async function fetch(args: MetricsRequestArgs) {
return fetchMetrics<Aggs>({
...args,
bool: {
must: [
{
exists: {
field: METRIC_SYSTEM_TOTAL_MEMORY
}
},
{
exists: {
field: METRIC_SYSTEM_FREE_MEMORY
}
}
]
},
timeseriesBucketAggregations: {
averagePercentMemoryUsed: { avg: percentSystemMemoryUsedScript },
maximumPercentMemoryUsed: { max: percentSystemMemoryUsedScript }
Expand Down
4 changes: 3 additions & 1 deletion x-pack/plugins/apm/server/lib/metrics/metricsFetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ export async function fetchMetrics<T = void>({
serviceName,
setup,
timeseriesBucketAggregations = {},
totalAggregations = {}
totalAggregations = {},
bool = {}
}: MetricsRequestArgs) {
const { start, end, esFilterQuery, client, config } = setup;
const { intervalString } = getBucketSize(start, end, 'auto');
Expand Down Expand Up @@ -41,6 +42,7 @@ export async function fetchMetrics<T = void>({
size: 0,
query: {
bool: {
...bool,
filter: filters
}
},
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/apm/server/lib/metrics/query_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface MetricsRequestArgs {
setup: Setup;
timeseriesBucketAggregations?: StringMap<any>;
totalAggregations?: StringMap<any>;
bool?: StringMap<any>;
}

export interface AggValue {
Expand Down