Skip to content

Commit

Permalink
Generate data after now in test and wait for documents in metric thre…
Browse files Browse the repository at this point in the history
…shold test.
  • Loading branch information
maryam-saeidi committed Mar 13, 2024
1 parent 796fd58 commit aceaf5f
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ export default function ({ getService }: FtrProviderContext) {
schedule: [
{
template: 'good',
start: 'now-15m',
end: 'now',
start: 'now-10m',
end: 'now+5m',
metrics: [
{ name: 'system.cpu.user.pct', method: 'linear', start: 2.5, end: 2.5 },
{ name: 'system.cpu.total.pct', method: 'linear', start: 0.5, end: 0.5 },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ export default function ({ getService }: FtrProviderContext) {
schedule: [
{
template: 'good',
start: 'now-15m',
end: 'now',
start: 'now-10m',
end: 'now+5m',
metrics: [
{ name: 'system.cpu.user.pct', method: 'linear', start: 2.5, end: 2.5 },
{ name: 'system.cpu.total.pct', method: 'linear', start: 0.5, end: 0.5 },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ export default function ({ getService }: FtrProviderContext) {
schedule: [
{
template: 'good',
start: 'now-15m',
end: 'now',
start: 'now-10m',
end: 'now+5m',
metrics: [
{ name: 'system.cpu.user.pct', method: 'linear', start: 2.5, end: 2.5 },
{ name: 'system.cpu.total.pct', method: 'linear', start: 0.5, end: 0.5 },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ export default function ({ getService }: FtrProviderContext) {
schedule: [
{
template: 'good',
start: 'now-15m',
end: 'now',
start: 'now-10m',
end: 'now+5m',
metrics: [{ name: 'system.cpu.user.pct', method: 'linear', start: 2.5, end: 2.5 }],
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export async function waitForDocumentInIndex<T>({
logger.debug(`Returned document: ${JSON.stringify(response.hits.hits[0])}`);
return response;
},
utilityName: 'fetching rule',
utilityName: `waiting for documents in ${indexName} index`,
logger,
retryService,
timeout: TIMEOUT,
Expand Down Expand Up @@ -117,7 +117,7 @@ export async function waitForAlertInIndex<T>({
}
return response;
},
utilityName: 'fetching rule',
utilityName: `waiting for alerting document in the alerting index (${indexName})`,
logger,
retryService,
timeout: TIMEOUT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,24 @@ export default function ({ getService }: FtrProviderContext) {
name: 'Default',
});
dataForgeConfig = {
schedule: [{ template: 'good', start: 'now-15m', end: 'now' }],
schedule: [
{
template: 'good',
start: 'now-10m',
end: 'now+5m',
metrics: [{ name: 'system.cpu.user.pct', method: 'linear', start: 0.9, end: 0.9 }],
},
],
indexing: { dataset: 'fake_hosts' as Dataset },
};
dataForgeIndices = await generate({ client: esClient, config: dataForgeConfig, logger });
await waitForDocumentInIndex({
esClient,
indexName: dataForgeIndices.join(','),
docCountTarget: 45,
retryService,
logger,
});
actionId = await createIndexConnector({
supertest,
name: 'Index Connector: Metric threshold API test',
Expand Down Expand Up @@ -91,6 +105,7 @@ export default function ({ getService }: FtrProviderContext) {
{
ruleType: '{{rule.type}}',
alertDetailsUrl: '{{context.alertDetailsUrl}}',
reason: '{{context.reason}}',
},
],
},
Expand Down Expand Up @@ -206,6 +221,9 @@ export default function ({ getService }: FtrProviderContext) {
expect(resp.hits.hits[0]._source?.alertDetailsUrl).eql(
`https://localhost:5601/app/observability/alerts?_a=(kuery:%27kibana.alert.uuid:%20%22${alertId}%22%27%2CrangeFrom:%27${rangeFrom}%27%2CrangeTo:now%2Cstatus:all)`
);
expect(resp.hits.hits[0]._source?.reason).eql(
`system.cpu.user.pct is 90% in the last 5 mins. Alert when > 50%.`
);
});
});
});
Expand Down

0 comments on commit aceaf5f

Please sign in to comment.