mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 09:19:04 -04:00
[Synthtrace] Sanitize default value for error grouping key (#210010)
## Summary Closes #209096
This commit is contained in:
parent
9409a4364b
commit
ba5ae97569
3 changed files with 6 additions and 9 deletions
|
@ -7,7 +7,6 @@
|
|||
* License v3.0 only", or the "Server Side Public License, v 1".
|
||||
*/
|
||||
|
||||
import { createHash } from 'crypto';
|
||||
import { ApmError } from './apm_error';
|
||||
import { Entity } from '../entity';
|
||||
import { Metricset } from './metricset';
|
||||
|
@ -114,7 +113,3 @@ export class Instance extends Entity<ApmFields> {
|
|||
});
|
||||
}
|
||||
}
|
||||
|
||||
export function getErrorGroupingKey(content: string) {
|
||||
return createHash('sha256').update(content).digest('hex');
|
||||
}
|
||||
|
|
|
@ -24,7 +24,10 @@ function generateId(length: number = LONG_ID_LENGTH) {
|
|||
}
|
||||
|
||||
function generateIdWithSeed(seed: string, length: number = LONG_ID_LENGTH) {
|
||||
return seed?.padStart(length, '0');
|
||||
// this is needed to sanitize errors like "No handler for /order/{id}",
|
||||
// as encodeURIComponent is not enough and can cause errors in the client
|
||||
const encodedSeed = seed.replace(/[/]/g, '_').replace(/[{}]/g, '');
|
||||
return encodedSeed?.padStart(length, '0');
|
||||
}
|
||||
|
||||
export function generateShortId() {
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import { getErrorGroupingKey } from '@kbn/apm-synthtrace-client/src/lib/apm/instance';
|
||||
import { generateLongIdWithSeed } from '@kbn/apm-synthtrace-client/src/lib/utils/generate_id';
|
||||
|
||||
import url from 'url';
|
||||
|
@ -36,7 +35,7 @@ describe('Error details', () => {
|
|||
});
|
||||
|
||||
it('has no detectable a11y violations on load', () => {
|
||||
const errorGroupingKey = getErrorGroupingKey('Error 1');
|
||||
const errorGroupingKey = generateLongIdWithSeed('Error 1');
|
||||
const errorGroupingKeyShort = errorGroupingKey.slice(0, 5);
|
||||
const errorDetailsPageHref = url.format({
|
||||
pathname: `/app/apm/services/opbeans-java/errors/${errorGroupingKey}`,
|
||||
|
@ -54,7 +53,7 @@ describe('Error details', () => {
|
|||
|
||||
describe('when error has no occurrences', () => {
|
||||
it('shows zero occurrences', () => {
|
||||
const errorGroupingKey = getErrorGroupingKey('Error foo bar');
|
||||
const errorGroupingKey = generateLongIdWithSeed('Error foo bar');
|
||||
|
||||
cy.visitKibana(
|
||||
url.format({
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue