Skip to content

Commit

Permalink
Address review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
gbamparop committed Sep 22, 2022
1 parent 83a3753 commit b8679d2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
APIClientRequestParamsOf,
} from '@kbn/apm-plugin/public/services/rest/create_call_apm_api';
import { RecursivePartial } from '@kbn/apm-plugin/typings/common';
import { keyBy } from 'lodash';
import { FtrProviderContext } from '../../common/ftr_provider_context';

type StorageDetails = APIReturnType<'GET /internal/apm/services/{serviceName}/storage_details'>;
Expand Down Expand Up @@ -113,32 +114,18 @@ export default function ApiTest({ getService }: FtrProviderContext) {
it('returns correct stats for processor events', async () => {
const { status, body } = await callApi();
expect(status).to.be(200);

expect(body.processorEventStats).to.have.length(4);

const transactionStats = body.processorEventStats.find(
({ processorEvent }) => processorEvent === ProcessorEvent.transaction
);
expect(transactionStats?.docs).to.be(3);
expect(transactionStats?.size).to.be.greaterThan(0);

const spanStats = body.processorEventStats.find(
({ processorEvent }) => processorEvent === ProcessorEvent.span
);
expect(spanStats?.docs).to.be(6);
expect(spanStats?.size).to.be.greaterThan(0);

const errorStats = body.processorEventStats.find(
({ processorEvent }) => processorEvent === ProcessorEvent.error
);
expect(errorStats?.docs).to.be(9);
expect(errorStats?.size).to.be.greaterThan(0);

const metricStats = body.processorEventStats.find(
({ processorEvent }) => processorEvent === ProcessorEvent.metric
);
expect(metricStats?.docs).to.be.greaterThan(0);
expect(metricStats?.size).to.be.greaterThan(0);
const stats = keyBy(body.processorEventStats, 'processorEvent');

expect(stats[ProcessorEvent.transaction]?.docs).to.be(3);
expect(stats[ProcessorEvent.transaction]?.size).to.be.greaterThan(0);
expect(stats[ProcessorEvent.span]?.docs).to.be(6);
expect(stats[ProcessorEvent.span]?.size).to.be.greaterThan(0);
expect(stats[ProcessorEvent.error]?.docs).to.be(9);
expect(stats[ProcessorEvent.error]?.size).to.be.greaterThan(0);
expect(stats[ProcessorEvent.metric]?.docs).to.be.greaterThan(0);
expect(stats[ProcessorEvent.metric]?.size).to.be.greaterThan(0);
});

it('returns empty stats when there is no matching environment', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { IndexLifecyclePhaseSelectOption } from '@kbn/apm-plugin/common/storage_
import { apm, timerange } from '@kbn/apm-synthtrace';
import { APIClientRequestParamsOf } from '@kbn/apm-plugin/public/services/rest/create_call_apm_api';
import { RecursivePartial } from '@kbn/apm-plugin/typings/common';
import { keyBy } from 'lodash';
import { FtrProviderContext } from '../../common/ftr_provider_context';

export default function ApiTest({ getService }: FtrProviderContext) {
Expand Down Expand Up @@ -109,18 +110,16 @@ export default function ApiTest({ getService }: FtrProviderContext) {

expect(body.serviceStatistics).to.have.length(2);

const goServiceStats = body.serviceStatistics.find(
({ serviceName }) => serviceName === 'opbeans-go'
);
const stats = keyBy(body.serviceStatistics, 'serviceName');

const goServiceStats = stats[goServiceName];
expect(goServiceStats?.environments).to.have.length(1);
expect(goServiceStats?.environments).to.contain('production');
expect(goServiceStats?.agentName).to.be('go');
expect(goServiceStats?.size).to.be.greaterThan(0);
expect(goServiceStats?.sampling).to.be(1);

const nodeServiceStats = body.serviceStatistics.find(
({ serviceName }) => serviceName === 'opbeans-node'
);
const nodeServiceStats = stats[nodeServiceName];
expect(nodeServiceStats?.environments).to.have.length(2);
expect(nodeServiceStats?.environments).to.contain('staging');
expect(nodeServiceStats?.environments).to.contain('dev');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { apm, timerange } from '@kbn/apm-synthtrace';
import { APIClientRequestParamsOf } from '@kbn/apm-plugin/public/services/rest/create_call_apm_api';
import { RecursivePartial } from '@kbn/apm-plugin/typings/common';
import { FtrProviderContext } from '../../common/ftr_provider_context';
import { roundNumber } from '../../utils';

export default function ApiTest({ getService }: FtrProviderContext) {
const registry = getService('registry');
Expand Down Expand Up @@ -98,7 +99,7 @@ export default function ApiTest({ getService }: FtrProviderContext) {

expect(status).to.be(200);
expect(body.numberOfServices).to.be(2);
expect(Math.round(body.tracesPerMinute)).to.be(2);
expect(roundNumber(body.tracesPerMinute)).to.be(2);
expect(body.estimatedSize).to.be.greaterThan(0);
expect(body.dailyDataGeneration).to.be.greaterThan(0);
});
Expand All @@ -112,7 +113,7 @@ export default function ApiTest({ getService }: FtrProviderContext) {

expect(status).to.be(200);
expect(body.numberOfServices).to.be(1);
expect(Math.round(body.tracesPerMinute)).to.be(1);
expect(roundNumber(body.tracesPerMinute)).to.be(1);
expect(body.estimatedSize).to.be.greaterThan(0);
expect(body.dailyDataGeneration).to.be.greaterThan(0);
});
Expand Down Expand Up @@ -140,7 +141,7 @@ export default function ApiTest({ getService }: FtrProviderContext) {

expect(status).to.be(200);
expect(body.numberOfServices).to.be(1);
expect(Math.round(body.tracesPerMinute)).to.be(1);
expect(roundNumber(body.tracesPerMinute)).to.be(1);
expect(body.estimatedSize).to.be.greaterThan(0);
expect(body.dailyDataGeneration).to.be.greaterThan(0);
});
Expand Down

0 comments on commit b8679d2

Please sign in to comment.