Skip to content

Commit

Permalink
review api tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MiriamAparicio committed Apr 17, 2023
1 parent cd68c3e commit fd1bcbf
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ export class MobileDevice extends Entity<ApmFields> {
return this;
}

// FIXME synthtrace shouldn't have side-effects like this. We should use an API like .session() which returns a session
startNewSession() {
this.fields['session.id'] = generateLongId();
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export function useMobileStatisticsFetcher({
start,
end,
field,
fieldNames: JSON.stringify(
fieldValues: JSON.stringify(
data?.mainStatistics.map(({ name }) => name).sort()
),
offset:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ interface Props {
start: number;
end: number;
field: string;
fieldNames: string[];
fieldValues: string[];
offset?: string;
}

Expand All @@ -53,7 +53,7 @@ async function getMobileDetailedStatisticsByField({
kuery,
serviceName,
field,
fieldNames,
fieldValues,
apmEventClient,
start,
end,
Expand Down Expand Up @@ -94,8 +94,8 @@ async function getMobileDetailedStatisticsByField({
detailed_statistics: {
terms: {
field,
include: fieldNames,
size: fieldNames.length,
include: fieldValues,
size: fieldValues.length,
},
aggs: {
timeseries: {
Expand Down Expand Up @@ -152,7 +152,7 @@ export async function getMobileDetailedStatisticsByFieldPeriods({
kuery,
serviceName,
field,
fieldNames,
fieldValues,
apmEventClient,
start,
end,
Expand All @@ -163,7 +163,7 @@ export async function getMobileDetailedStatisticsByFieldPeriods({
kuery,
serviceName,
field,
fieldNames,
fieldValues,
apmEventClient,
start,
end,
Expand Down
6 changes: 3 additions & 3 deletions x-pack/plugins/apm/server/routes/mobile/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ const mobileDetailedStatisticsByField = createApmServerRoute({
environmentRt,
t.type({
field: t.string,
fieldNames: jsonRt.pipe(t.array(t.string)),
fieldValues: jsonRt.pipe(t.array(t.string)),
}),
]),
}),
Expand All @@ -335,7 +335,7 @@ const mobileDetailedStatisticsByField = createApmServerRoute({
const apmEventClient = await getApmEventClient(resources);
const { params } = resources;
const { serviceName } = params.path;
const { kuery, environment, start, end, field, offset, fieldNames } =
const { kuery, environment, start, end, field, offset, fieldValues } =
params.query;

return await getMobileDetailedStatisticsByFieldPeriods({
Expand All @@ -346,7 +346,7 @@ const mobileDetailedStatisticsByField = createApmServerRoute({
serviceName,
apmEventClient,
field,
fieldNames,
fieldValues,
offset,
});
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,25 @@ export async function generateMobileData({
galaxy10.startNewSession();
galaxy7.startNewSession();
huaweiP2.startNewSession();
galaxy10
.appMetrics({
'application.launch.time': 1000,
})
.timestamp(timestamp);
galaxy7
.appMetrics({
'application.launch.time': 1000,
})
.timestamp(timestamp);
huaweiP2
.appMetrics({
'application.launch.time': 1000,
})
.timestamp(timestamp);
return [
galaxy10
.transaction('Start View - View Appearing', 'Android Activity')
.errors(galaxy10.crash({ message: 'error' }).timestamp(timestamp))
.timestamp(timestamp)
.duration(500)
.success()
Expand Down Expand Up @@ -174,6 +190,7 @@ export async function generateMobileData({
),
huaweiP2
.transaction('Start View - View Appearing', 'huaweiP2 Activity')
.errors(huaweiP2.crash({ message: 'error' }).timestamp(timestamp))
.timestamp(timestamp)
.duration(20)
.success()
Expand Down Expand Up @@ -201,6 +218,7 @@ export async function generateMobileData({
),
galaxy7
.transaction('Start View - View Appearing', 'Android Activity')
.errors(galaxy7.crash({ message: 'error' }).timestamp(timestamp))
.timestamp(timestamp)
.duration(20)
.success()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,26 +80,55 @@ export default function ApiTest({ getService }: FtrProviderContext) {
environment: 'production',
field: 'service.version',
});
const fieldNames = response.mainStatistics.map((item) => item.name);
expect(fieldNames.length).to.be.equal(3);
const fieldValues = response.mainStatistics.map((item) => item.name);

expect(fieldValues).to.be.eql(['2.3', '1.1', '1.2']);

const latencyValues = response.mainStatistics.map((item) => item.latency);

expect(latencyValues).to.be.eql([400000, 20000, 20000]);

const throughputValues = response.mainStatistics.map((item) => item.throughput);
expect(throughputValues).to.be.eql([
1.800002000002222, 1.0000011111123457, 1.0000011111123457,
]);
});
it('returns the correct data for Os version', async () => {
const response = await getMobileMainStatisticsByField({
serviceName: 'synth-android',
environment: 'production',
field: 'host.os.version',
});
const fieldNames = response.mainStatistics.map((item) => item.name);
expect(fieldNames.length).to.be.equal(1);

const fieldValues = response.mainStatistics.map((item) => item.name);

expect(fieldValues).to.be.eql(['10']);

const latencyValues = response.mainStatistics.map((item) => item.latency);

expect(latencyValues).to.be.eql([210000]);

const throughputValues = response.mainStatistics.map((item) => item.throughput);
expect(throughputValues).to.be.eql([1.4000015555572838]);
});
it('returns the correct data for Devices', async () => {
const response = await getMobileMainStatisticsByField({
serviceName: 'synth-android',
environment: 'production',
field: 'device.model.identifier',
});
const fieldNames = response.mainStatistics.map((item) => item.name);
expect(fieldNames.length).to.be.equal(3);
const fieldValues = response.mainStatistics.map((item) => item.name);

expect(fieldValues).to.be.eql(['SM-G973F', 'HUAWEI P2-0000', 'SM-G930F']);

const latencyValues = response.mainStatistics.map((item) => item.latency);

expect(latencyValues).to.be.eql([400000, 20000, 20000]);

const throughputValues = response.mainStatistics.map((item) => item.throughput);
expect(throughputValues).to.be.eql([
0.6000006666674074, 0.40000044444493826, 0.40000044444493826,
]);
});
});
});
Expand Down

0 comments on commit fd1bcbf

Please sign in to comment.