Skip to content

Commit

Permalink
addressing pr changes
Browse files Browse the repository at this point in the history
  • Loading branch information
cauemarcondes committed Oct 6, 2021
1 parent 5ef60ce commit 9489676
Show file tree
Hide file tree
Showing 3 changed files with 145 additions and 164 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export async function getThroughputChartsForBackend({
extended_bounds: { min: startWithOffset, max: endWithOffset },
},
aggs: {
sumSpanDestination: {
spanDestinationLatencySum: {
sum: {
field: SPAN_DESTINATION_SERVICE_RESPONSE_TIME_COUNT,
},
Expand All @@ -90,7 +90,7 @@ export async function getThroughputChartsForBackend({
x: bucket.key + offsetInMs,
y: calculateThroughputWithInterval({
bucketSize,
value: bucket.sumSpanDestination.value || 0,
value: bucket.spanDestinationLatencySum.value || 0,
}),
};
}) ?? []
Expand Down
190 changes: 81 additions & 109 deletions x-pack/test/apm_api_integration/tests/services/throughput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,72 +47,48 @@ export default function ApiTest({ getService }: FtrProviderContext) {
});
});

async function callThroughApis() {
const path = {
serviceName: 'opbeans-go',
};
const commonQuery = {
start: metadata.start,
end: metadata.end,
transactionType: 'request',
environment: 'ENVIRONMENT_ALL',
};
const [throughputMetricsResponse, throughputTransactionsResponse] = await Promise.all([
apmApiSupertest({
endpoint: 'GET /api/apm/services/{serviceName}/throughput',
params: {
path,
query: {
...commonQuery,
kuery: 'processor.event : "metric"',
},
async function fetchThroughput(processorEvent: 'metric' | 'transaction') {
const throughputResponse = await apmApiSupertest({
endpoint: 'GET /api/apm/services/{serviceName}/throughput',
params: {
path: { serviceName: 'opbeans-go' },
query: {
start: metadata.start,
end: metadata.end,
transactionType: 'request',
environment: 'ENVIRONMENT_ALL',
kuery: `processor.event : "${processorEvent}"`,
},
}),
apmApiSupertest({
endpoint: 'GET /api/apm/services/{serviceName}/throughput',
params: {
path,
query: {
...commonQuery,
kuery: 'processor.event : "transaction"',
},
},
}),
]);
return {
throughputMetrics: throughputMetricsResponse.body,
throughputTransactions: throughputTransactionsResponse.body,
};
},
});
return throughputResponse.body;
}

registry.when(
'Throughput when data is loaded',
{ config: 'basic', archives: [archiveName] },
() => {
let throughputMetrics: ThroughputReturn;
let throughputTransactions: ThroughputReturn;
describe('without comparisons', () => {
let throughputMetrics: ThroughputReturn;
let throughputTransactions: ThroughputReturn;

describe('compare metrics and transactions values', () => {
before(async () => {
const throughputApiResponse = await callThroughApis();
throughputMetrics = throughputApiResponse.throughputMetrics;
throughputTransactions = throughputApiResponse.throughputTransactions;
[throughputMetrics, throughputTransactions] = await Promise.all([
fetchThroughput('metric'),
fetchThroughput('transaction'),
]);
});

it('returns some transactions data', () => {
expect(throughputTransactions.currentPeriod.length).to.be.greaterThan(0);
const nonNullTransactionsDataPoints = throughputTransactions.currentPeriod.filter(
({ y }) => isFiniteNumber(y)
);
expect(nonNullTransactionsDataPoints.length).to.be.greaterThan(0);
const hasData = throughputTransactions.currentPeriod.some(({ y }) => isFiniteNumber(y));
expect(hasData).to.equal(true);
});

it('returns some metrics data', () => {
expect(throughputMetrics.currentPeriod.length).to.be.greaterThan(0);
const nonNullMetricsDataPoints = throughputTransactions.currentPeriod.filter(({ y }) =>
isFiniteNumber(y)
);
expect(nonNullMetricsDataPoints.length).to.be.greaterThan(0);
const hasData = throughputMetrics.currentPeriod.some(({ y }) => isFiniteNumber(y));
expect(hasData).to.equal(true);
});

it('has same mean value for metrics and transactions data', () => {
Expand All @@ -123,88 +99,84 @@ export default function ApiTest({ getService }: FtrProviderContext) {
expectSnapshot(metricsMean).toMatchInline(`100`);
});

it('uses 10s time interval between buckets for transactions data', () => {
it('has a bucket size of 10 seconds for transactions data', () => {
const firstTimerange = throughputTransactions.currentPeriod[0].x;
const secondTimerange = throughputTransactions.currentPeriod[1].x;
const timeIntervalAsSeconds = (secondTimerange - firstTimerange) / 1000;
expect(timeIntervalAsSeconds).to.equal(10);
});

it('uses 1m time interval between buckets for metrics data', () => {
it('has a bucket size of 1 minute for metrics data', () => {
const firstTimerange = throughputMetrics.currentPeriod[0].x;
const secondTimerange = throughputMetrics.currentPeriod[1].x;
const timeIntervalAsMinutes = (secondTimerange - firstTimerange) / 1000 / 60;
expect(timeIntervalAsMinutes).to.equal(1);
});
});
}
);

registry.when(
'Throughput when data is loaded with time comparison',
{ config: 'basic', archives: [archiveName] },
() => {
let throughputResponse: ThroughputReturn;

before(async () => {
const response = await apmApiSupertest({
endpoint: 'GET /api/apm/services/{serviceName}/throughput',
params: {
path: {
serviceName: 'opbeans-go',
},
query: {
transactionType: 'request',
start: moment(metadata.end).subtract(15, 'minutes').toISOString(),
end: metadata.end,
comparisonStart: metadata.start,
comparisonEnd: moment(metadata.start).add(15, 'minutes').toISOString(),
environment: 'ENVIRONMENT_ALL',
kuery: '',
describe('with comparisons', () => {
let throughputResponse: ThroughputReturn;

before(async () => {
const response = await apmApiSupertest({
endpoint: 'GET /api/apm/services/{serviceName}/throughput',
params: {
path: {
serviceName: 'opbeans-go',
},
query: {
transactionType: 'request',
start: moment(metadata.end).subtract(15, 'minutes').toISOString(),
end: metadata.end,
comparisonStart: metadata.start,
comparisonEnd: moment(metadata.start).add(15, 'minutes').toISOString(),
environment: 'ENVIRONMENT_ALL',
kuery: '',
},
},
},
});
});

throughputResponse = response.body;
});
throughputResponse = response.body;
});

it('returns some data', () => {
expect(throughputResponse.currentPeriod.length).to.be.greaterThan(0);
expect(throughputResponse.previousPeriod.length).to.be.greaterThan(0);
it('returns some data', () => {
expect(throughputResponse.currentPeriod.length).to.be.greaterThan(0);
expect(throughputResponse.previousPeriod.length).to.be.greaterThan(0);

const currentPeriodNonNullDataPoints = throughputResponse.currentPeriod.filter(({ y }) =>
isFiniteNumber(y)
);
const previousPeriodNonNullDataPoints = throughputResponse.previousPeriod.filter(({ y }) =>
isFiniteNumber(y)
);
const currentPeriodNonNullDataPoints = throughputResponse.currentPeriod.filter(({ y }) =>
isFiniteNumber(y)
);
const previousPeriodNonNullDataPoints = throughputResponse.previousPeriod.filter(
({ y }) => isFiniteNumber(y)
);

expect(currentPeriodNonNullDataPoints.length).to.be.greaterThan(0);
expect(previousPeriodNonNullDataPoints.length).to.be.greaterThan(0);
});
expect(currentPeriodNonNullDataPoints.length).to.be.greaterThan(0);
expect(previousPeriodNonNullDataPoints.length).to.be.greaterThan(0);
});

it('has same start time for both periods', () => {
expect(new Date(first(throughputResponse.currentPeriod)?.x ?? NaN).toISOString()).to.equal(
new Date(first(throughputResponse.previousPeriod)?.x ?? NaN).toISOString()
);
});
it('has same start time for both periods', () => {
expect(
new Date(first(throughputResponse.currentPeriod)?.x ?? NaN).toISOString()
).to.equal(new Date(first(throughputResponse.previousPeriod)?.x ?? NaN).toISOString());
});

it('has same end time for both periods', () => {
expect(new Date(last(throughputResponse.currentPeriod)?.x ?? NaN).toISOString()).to.equal(
new Date(last(throughputResponse.previousPeriod)?.x ?? NaN).toISOString()
);
});
it('has same end time for both periods', () => {
expect(new Date(last(throughputResponse.currentPeriod)?.x ?? NaN).toISOString()).to.equal(
new Date(last(throughputResponse.previousPeriod)?.x ?? NaN).toISOString()
);
});

it('returns same number of buckets for both periods', () => {
expect(throughputResponse.currentPeriod.length).to.be(
throughputResponse.previousPeriod.length
);
});
it('returns same number of buckets for both periods', () => {
expect(throughputResponse.currentPeriod.length).to.be(
throughputResponse.previousPeriod.length
);
});

it('has same mea value for both periods', () => {
const currentPeriodAvg = mean(throughputResponse.currentPeriod.map((d) => d.y));
const previousPeriodAvg = mean(throughputResponse.previousPeriod.map((d) => d.y));
expect(currentPeriodAvg).to.equal(previousPeriodAvg);
it('has same mea value for both periods', () => {
const currentPeriodAvg = mean(throughputResponse.currentPeriod.map((d) => d.y));
const previousPeriodAvg = mean(throughputResponse.previousPeriod.map((d) => d.y));
expect(currentPeriodAvg).to.equal(previousPeriodAvg);
});
});
}
);
Expand Down
Loading

0 comments on commit 9489676

Please sign in to comment.