forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🌊 Streams: Enrichment integration tests (elastic#201771)
Adds some basic tests for enrichment and makes the `_enable` endpoint idempotent.
- Loading branch information
1 parent
6a92173
commit 2cb11a3
Showing
6 changed files
with
182 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import expect from '@kbn/expect'; | ||
import { JsonObject } from '@kbn/utility-types'; | ||
import { SearchTotalHits } from '@elastic/elasticsearch/lib/api/types'; | ||
import { enableStreams, fetchDocument, indexDocument, putStream } from './helpers/requests'; | ||
import { FtrProviderContext } from '../../ftr_provider_context'; | ||
import { waitForDocumentInIndex } from '../../../alerting_api_integration/observability/helpers/alerting_wait_for_helpers'; | ||
import { cleanUpRootStream } from './helpers/cleanup'; | ||
|
||
export default function ({ getService }: FtrProviderContext) { | ||
const supertest = getService('supertest'); | ||
const esClient = getService('es'); | ||
const retryService = getService('retry'); | ||
const logger = getService('log'); | ||
|
||
describe('Enrichment', () => { | ||
after(async () => { | ||
await cleanUpRootStream(esClient); | ||
}); | ||
|
||
before(async () => { | ||
await enableStreams(supertest); | ||
}); | ||
|
||
it('Place processing steps', async () => { | ||
const body = { | ||
fields: [ | ||
{ | ||
name: '@timestamp', | ||
type: 'date', | ||
}, | ||
{ | ||
name: 'message', | ||
type: 'match_only_text', | ||
}, | ||
{ | ||
name: 'message2', | ||
type: 'match_only_text', | ||
}, | ||
{ | ||
name: 'host.name', | ||
type: 'keyword', | ||
}, | ||
{ | ||
name: 'log.level', | ||
type: 'keyword', | ||
}, | ||
], | ||
processing: [ | ||
{ | ||
config: { | ||
type: 'grok', | ||
field: 'message', | ||
patterns: [ | ||
'%{TIMESTAMP_ISO8601:inner_timestamp} %{LOGLEVEL:log.level} %{GREEDYDATA:message2}', | ||
], | ||
}, | ||
} as JsonObject, | ||
{ | ||
config: { | ||
type: 'dissect', | ||
field: 'message2', | ||
pattern: '%{log.logger} %{message3}', | ||
}, | ||
condition: { | ||
field: 'log.level', | ||
operator: 'eq', | ||
value: 'info', | ||
}, | ||
} as JsonObject, | ||
], | ||
children: [], | ||
}; | ||
const response = await putStream(supertest, 'logs', body); | ||
expect(response).to.have.property('acknowledged', true); | ||
}); | ||
|
||
it('Index doc not matching condition', async () => { | ||
const doc = { | ||
'@timestamp': '2024-01-01T00:00:10.000Z', | ||
message: '2023-01-01T00:00:10.000Z error test', | ||
}; | ||
const response = await indexDocument(esClient, 'logs', doc); | ||
expect(response.result).to.eql('created'); | ||
await waitForDocumentInIndex({ esClient, indexName: 'logs', retryService, logger }); | ||
|
||
const result = await fetchDocument(esClient, 'logs', response._id); | ||
expect(result._source).to.eql({ | ||
'@timestamp': '2024-01-01T00:00:10.000Z', | ||
message: '2023-01-01T00:00:10.000Z error test', | ||
inner_timestamp: '2023-01-01T00:00:10.000Z', | ||
message2: 'test', | ||
log: { | ||
level: 'error', | ||
}, | ||
}); | ||
}); | ||
|
||
it('Index doc matching condition', async () => { | ||
const doc = { | ||
'@timestamp': '2024-01-01T00:00:11.000Z', | ||
message: '2023-01-01T00:00:10.000Z info mylogger this is the message', | ||
}; | ||
const response = await indexDocument(esClient, 'logs', doc); | ||
expect(response.result).to.eql('created'); | ||
await waitForDocumentInIndex({ | ||
esClient, | ||
indexName: 'logs', | ||
retryService, | ||
logger, | ||
docCountTarget: 2, | ||
}); | ||
|
||
const result = await fetchDocument(esClient, 'logs', response._id); | ||
expect(result._source).to.eql({ | ||
'@timestamp': '2024-01-01T00:00:11.000Z', | ||
message: '2023-01-01T00:00:10.000Z info mylogger this is the message', | ||
inner_timestamp: '2023-01-01T00:00:10.000Z', | ||
log: { | ||
level: 'info', | ||
logger: 'mylogger', | ||
}, | ||
message2: 'mylogger this is the message', | ||
message3: 'this is the message', | ||
}); | ||
}); | ||
|
||
it('Doc is searchable', async () => { | ||
const response = await esClient.search({ | ||
index: 'logs', | ||
body: { | ||
query: { | ||
match: { | ||
message2: 'mylogger', | ||
}, | ||
}, | ||
}, | ||
}); | ||
expect((response.hits.total as SearchTotalHits).value).to.eql(1); | ||
}); | ||
|
||
it('Non-indexed field is not searchable', async () => { | ||
const response = await esClient.search({ | ||
index: 'logs', | ||
body: { | ||
query: { | ||
match: { | ||
'log.logger': 'mylogger', | ||
}, | ||
}, | ||
}, | ||
}); | ||
expect((response.hits.total as SearchTotalHits).value).to.eql(0); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters