-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🌊 Data generation and fixes (#200783)
This PR adds a synthtrace scenario for the main logs streams endpoint called `slash_logs`. It can be invoked like this: ``` node scripts/synthtrace.js slash_logs --live --kibana=http://elastic:changeme@localhost:5601 --target=http://elastic:changeme@localhost:9200 --liveBucketSize=1000 ``` ## Changes on synthtrace I had to adapt a couple things: * Add the `--liveBucketSize` flag because it's really annoying to wait for a minute to see whether data gets processed correctly * Extend the existing log mock module that's also used for the unstructured logs scenario in a couple ways * Add the ability to route directly to an index by adding `_index` to a document (otherwise it will use the DSNS) ## Changes on streams I fixed a couple things I realized were broken: * Check whether a field exists before accessing it in the routing condition (otherwise it rejects the document) * Update ES objects in the right order - if the routing is put in place before the receiving child data stream is ready, it will auto-create an index with the wrong mapping * Allow to not specify a condition for a child - in this case it's not routing to this child * Set `subobjects: true` for now - otherwise fields are not indexed properly, I think this is an Elasticsearch bug, I will follow up on this with the Elasticsearch team * Set `dynamic: false` - that somehow got lost in refactorings
- Loading branch information
Showing
15 changed files
with
582 additions
and
63 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
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
372 changes: 361 additions & 11 deletions
372
packages/kbn-apm-synthtrace/src/scenarios/helpers/logs_mock_data.ts
Large diffs are not rendered by default.
Oops, something went wrong.
137 changes: 137 additions & 0 deletions
137
packages/kbn-apm-synthtrace/src/scenarios/slash_logs.ts
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,137 @@ | ||
/* | ||
* 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", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
import { LogDocument, generateShortId, log } from '@kbn/apm-synthtrace-client'; | ||
import { Scenario } from '../cli/scenario'; | ||
import { withClient } from '../lib/utils/with_client'; | ||
import { | ||
getAgentName, | ||
getCloudProvider, | ||
getCloudRegion, | ||
getIpAddress, | ||
getJavaLogs, | ||
getServiceName, | ||
getWebLogs, | ||
getKubernetesMessages, | ||
getLinuxMessages, | ||
KUBERNETES_SERVICES, | ||
getStableShortId, | ||
getRandomRange, | ||
} from './helpers/logs_mock_data'; | ||
import { getAtIndexOrRandom } from './helpers/get_at_index_or_random'; | ||
|
||
const LINUX_PROCESSES = ['cron', 'sshd', 'systemd', 'nginx', 'apache2']; | ||
|
||
const scenario: Scenario<LogDocument> = async (runOptions) => { | ||
const constructCommonMetadata = () => ({ | ||
'agent.name': getAgentName(), | ||
'cloud.provider': getCloudProvider(), | ||
'cloud.region': getCloudRegion(Math.floor(Math.random() * 3)), | ||
'cloud.availability_zone': `${getCloudRegion(0)}a`, | ||
'cloud.instance.id': generateShortId(), | ||
'cloud.project.id': generateShortId(), | ||
}); | ||
|
||
const generateNginxLogs = (timestamp: number) => { | ||
return getWebLogs().map((message) => { | ||
return log | ||
.createForIndex('logs') | ||
.setHostIp(getIpAddress()) | ||
.message(message) | ||
.defaults({ | ||
...constructCommonMetadata(), | ||
'log.file.path': `/var/log/nginx/access-${getStableShortId()}.log`, | ||
}) | ||
.timestamp(timestamp); | ||
}); | ||
}; | ||
|
||
const generateSyslogData = (timestamp: number) => { | ||
const messages: Record<string, string[]> = getLinuxMessages(); | ||
|
||
return getRandomRange().map(() => { | ||
const processName = getAtIndexOrRandom(LINUX_PROCESSES); | ||
const message = getAtIndexOrRandom(messages[processName]); | ||
return log | ||
.createForIndex('logs') | ||
.message(message) | ||
.setHostIp(getIpAddress()) | ||
.defaults({ | ||
...constructCommonMetadata(), | ||
'process.name': processName, | ||
'log.file.path': `/var/log/${processName}.log`, | ||
}) | ||
.timestamp(timestamp); | ||
}); | ||
}; | ||
|
||
const generateKubernetesLogs = (timestamp: number) => { | ||
const messages: Record<string, string[]> = getKubernetesMessages(); | ||
|
||
return getRandomRange().map(() => { | ||
const service = getAtIndexOrRandom(KUBERNETES_SERVICES); | ||
const isStringifiedJSON = Math.random() > 0.5; | ||
const message = isStringifiedJSON | ||
? JSON.stringify({ | ||
serviceName: service, | ||
message: getAtIndexOrRandom(messages[service]), | ||
}) | ||
: getAtIndexOrRandom(messages[service]); | ||
return log | ||
.createForIndex('logs') | ||
.message(message) | ||
.setHostIp(getIpAddress()) | ||
.defaults({ | ||
...constructCommonMetadata(), | ||
'kubernetes.namespace': 'default', | ||
'kubernetes.pod.name': `${service}-pod-${getStableShortId()}`, | ||
'kubernetes.container.name': `${service}-container`, | ||
'orchestrator.resource.name': service, | ||
}) | ||
.timestamp(timestamp); | ||
}); | ||
}; | ||
|
||
const generateUnparsedJavaLogs = (timestamp: number) => { | ||
return getJavaLogs().map((message) => { | ||
const serviceName = getServiceName(Math.floor(Math.random() * 3)); | ||
return log | ||
.createForIndex('logs') | ||
.message(message) | ||
.defaults({ | ||
...constructCommonMetadata(), | ||
'service.name': serviceName, | ||
}) | ||
.timestamp(timestamp); | ||
}); | ||
}; | ||
|
||
return { | ||
generate: ({ range, clients: { logsEsClient } }) => { | ||
const { logger } = runOptions; | ||
|
||
const nginxLogs = range.interval('1m').generator(generateNginxLogs); | ||
const syslogData = range.interval('1m').generator(generateSyslogData); | ||
const kubernetesLogs = range.interval('1m').generator(generateKubernetesLogs); | ||
const unparsedJavaLogs = range.interval('1m').generator(generateUnparsedJavaLogs); | ||
|
||
return withClient( | ||
logsEsClient, | ||
logger.perf('generating_messy_logs', () => [ | ||
nginxLogs, | ||
syslogData, | ||
kubernetesLogs, | ||
unparsedJavaLogs, | ||
]) | ||
); | ||
}, | ||
}; | ||
}; | ||
|
||
export default scenario; |
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
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
Oops, something went wrong.