Skip to content

Commit

Permalink
addressing PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
cauemarcondes committed Feb 15, 2021
1 parent 51dec3a commit ac5f9a5
Show file tree
Hide file tree
Showing 7 changed files with 210 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export function getColumns({
{
defaultMessage: `{occurrencesCount} occ.`,
values: {
occurrencesCount: asInteger(occurrences.value),
occurrencesCount: asInteger(occurrences),
},
}
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
import { i18n } from '@kbn/i18n';
import { orderBy } from 'lodash';
import React, { useState } from 'react';
import uuid from 'uuid';
import { useApmServiceContext } from '../../../../context/apm_service/use_apm_service_context';
import { useUrlParams } from '../../../../context/url_params_context/use_url_params';
import { FETCH_STATUS, useFetcher } from '../../../../hooks/use_fetcher';
Expand All @@ -36,6 +35,10 @@ const DEFAULT_SORT = {
field: 'occurrences' as const,
};

const INITIAL_STATE = {
items: [],
};

export function ServiceOverviewErrorsTable({ serviceName }: Props) {
const {
urlParams: { start, end },
Expand All @@ -55,18 +58,11 @@ export function ServiceOverviewErrorsTable({ serviceName }: Props) {

const { pageIndex, sort } = tableOptions;

const {
data = {
items: [],
requestId: '',
},
status,
} = useFetcher(
const { data = INITIAL_STATE, status } = useFetcher(
(callApmApi) => {
if (!start || !end || !transactionType) {
return;
}

return callApmApi({
endpoint:
'GET /api/apm/services/{serviceName}/error_groups/primary_statistics',
Expand All @@ -81,23 +77,17 @@ export function ServiceOverviewErrorsTable({ serviceName }: Props) {
},
}).then((response) => {
return {
requestId: uuid(),
items: response.error_groups,
};
});
},
[start, end, serviceName, uiFilters, transactionType]
);

const { items, requestId } = data;
const { items } = data;
const currentPageErrorGroups = orderBy(
items,
(group) => {
if (sort.field === 'occurrences') {
return group.occurrences.value;
}
return group[sort.field];
},
sort.field,
sort.direction
).slice(pageIndex * PAGE_SIZE, (pageIndex + 1) * PAGE_SIZE);

Expand All @@ -109,7 +99,13 @@ export function ServiceOverviewErrorsTable({ serviceName }: Props) {
status: errorGroupComparisonStatisticsStatus,
} = useFetcher(
(callApmApi) => {
if (currentPageErrorGroups.length && start && end && transactionType) {
if (
status === FETCH_STATUS.SUCCESS &&
currentPageErrorGroups.length &&
start &&
end &&
transactionType
) {
return callApmApi({
endpoint:
'GET /api/apm/services/{serviceName}/error_groups/comparison_statistics',
Expand All @@ -127,9 +123,9 @@ export function ServiceOverviewErrorsTable({ serviceName }: Props) {
});
}
},
// only fetches agg results when requestId changes or group ids change
// only fetches agg results when status changes or group ids change
// eslint-disable-next-line react-hooks/exhaustive-deps
[requestId, groupIds],
[status, groupIds],
{ preservePreviousData: false }
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* 2.0.
*/

import { orderBy } from 'lodash';
import {
ERROR_EXC_MESSAGE,
ERROR_GROUP_ID,
Expand Down Expand Up @@ -82,21 +81,13 @@ export function getServiceErrorGroupPrimaryStatistics({
last_seen: new Date(
bucket.sample.hits.hits[0]?._source['@timestamp']
).getTime(),
occurrences: {
value: bucket.doc_count,
},
occurrences: bucket.doc_count,
})) ?? [];

const sortedErrorGroups = orderBy(
errorGroups,
(group) => group.occurrences.value,
'desc'
);

return {
is_aggregation_accurate:
(response.aggregations?.error_groups.sum_other_doc_count ?? 0) === 0,
error_groups: sortedErrorGroups,
error_groups: errorGroups,
};
});
}

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

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

Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import expect from '@kbn/expect';
import archives_metadata from '../../common/fixtures/es_archiver/archives_metadata';
import { FtrProviderContext } from '../../common/ftr_provider_context';
import { registry } from '../../common/registry';
import { APIReturnType } from '../../../../plugins/apm/public/services/rest/createCallApmApi';

type ErrorGroupsComparisonStatistics = APIReturnType<'GET /api/apm/services/{serviceName}/error_groups/comparison_statistics'>;

export default function ApiTest({ getService }: FtrProviderContext) {
const supertest = getService('supertest');
Expand Down Expand Up @@ -69,12 +72,22 @@ export default function ApiTest({ getService }: FtrProviderContext) {
);

expect(response.status).to.be(200);
expect(Object.keys(response.body).length).to.be(5);
const errorMetric = response.body[groupIds[0]];
expect(errorMetric.timeseries.length).to.be(31);

const errorGroupsComparisonStatistics = response.body as ErrorGroupsComparisonStatistics;
expect(Object.keys(errorGroupsComparisonStatistics).length).to.be.eql(groupIds.length);

groupIds.map((groupId) => {
expect(errorGroupsComparisonStatistics[groupId]).not.to.be.empty();
});

const errorgroupsComparisonStatistics = errorGroupsComparisonStatistics[groupIds[0]];
expect(
errorgroupsComparisonStatistics.timeseries.map(({ y }) => isFinite(y)).length
).to.be.greaterThan(0);
expectSnapshot(errorgroupsComparisonStatistics).toMatch();
});

it('returns empty data', async () => {
it('returns an empty list when requested groupIds are not available in the given time range', async () => {
const response = await supertest.get(
url.format({
pathname: `/api/apm/services/opbeans-java/error_groups/comparison_statistics`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ export default function ApiTest({ getService }: FtrProviderContext) {

expect(response.status).to.be(200);
expect(response.body.is_aggregation_accurate).to.eql(true);
expect(response.body.error_groups.length).to.be(5);
expect(response.body.error_groups.length).to.be.greaterThan(0);
expectSnapshot(response.body).toMatch();
});
}
);
Expand Down

0 comments on commit ac5f9a5

Please sign in to comment.