Skip to content

Commit

Permalink
[ALERTING][APM] Fix service names with spaces are not being URL encod…
Browse files Browse the repository at this point in the history
…ed properly for {{context.viewInAppUrl}} (elastic#202890)

## Summary
It fixes elastic#184381 by encoding correctly the service name and adding tests
  • Loading branch information
fkanout authored and CAWilson94 committed Dec 9, 2024
1 parent d6da75f commit ecb125b
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* 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 { getAlertUrlErrorCount, getAlertUrlTransaction } from './alert_url';
describe('alert_url', () => {
describe('getAlertUrlErrorCount', () => {
it('return the URL where the service name is camelcase', () => {
const url = getAlertUrlErrorCount('serviceName', 'serviceEnv');
expect(url).toBe('/app/apm/services/serviceName/errors?environment=serviceEnv');
});
it('return the URL where the service name is sneak case', () => {
const url = getAlertUrlErrorCount('service_name', 'serviceEnv');
expect(url).toBe('/app/apm/services/service_name/errors?environment=serviceEnv');
});
it('return the URL encoded correctly where the service name has spaces', () => {
const url = getAlertUrlErrorCount('service name', 'serviceEnv');
expect(url).toBe('/app/apm/services/service%20name/errors?environment=serviceEnv');
});
});
describe('getAlertUrlTransaction', () => {
it('return the URL where the service name is camelcase', () => {
const url = getAlertUrlTransaction('serviceName', 'serviceEnv', 'transactionType');
expect(url).toBe(
'/app/apm/services/serviceName?transactionType=transactionType&environment=serviceEnv'
);
});
it('return the URL where the service name is sneak case', () => {
const url = getAlertUrlTransaction('service_name', 'serviceEnv', 'transactionType');
expect(url).toBe(
'/app/apm/services/service_name?transactionType=transactionType&environment=serviceEnv'
);
});
it('return the URL encoded correctly where the service name has spaces', () => {
const url = getAlertUrlTransaction('service name', 'serviceEnv', 'transactionType');
expect(url).toBe(
'/app/apm/services/service%20name?transactionType=transactionType&environment=serviceEnv'
);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const format = ({ pathname, query }: { pathname: string; query: Record<string, a

export const getAlertUrlErrorCount = (serviceName: string, serviceEnv: string | undefined) =>
format({
pathname: `/app/apm/services/${serviceName}/errors`,
pathname: `/app/apm/services/${encodeURIComponent(serviceName)}/errors`,
query: {
environment: serviceEnv ?? ENVIRONMENT_ALL.value,
},
Expand All @@ -25,7 +25,7 @@ export const getAlertUrlTransaction = (
transactionType: string
) =>
format({
pathname: `/app/apm/services/${serviceName}`,
pathname: `/app/apm/services/${encodeURIComponent(serviceName)}`,
query: {
transactionType,
environment: serviceEnv ?? ENVIRONMENT_ALL.value,
Expand Down

0 comments on commit ecb125b

Please sign in to comment.