From c3a0aef09715b17f43f698cb89a3da2e7fa3ab18 Mon Sep 17 00:00:00 2001 From: Kawika Avilla Date: Tue, 23 Nov 2021 10:41:30 -0800 Subject: [PATCH] [1.x][Branding] prevent logging when config not set Out of the box, the rendering service will check the config and see the default value and log an info message saying that the branding config is invalid or not set. Everytime you refresh the browser you will get those log messages. This sets it to only log error messages if the user sets the branding config and it is invalid. Include using default messages. Backport PR: https://github.com/opensearch-project/OpenSearch-Dashboards/pull/941 Signed-off-by: Kawika Avilla --- .../rendering/rendering_service.test.ts | 5 +++++ .../server/rendering/rendering_service.tsx | 19 +++++++++++++------ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/core/server/rendering/rendering_service.test.ts b/src/core/server/rendering/rendering_service.test.ts index 61a7f0ce3de..e4d52dc1364 100644 --- a/src/core/server/rendering/rendering_service.test.ts +++ b/src/core/server/rendering/rendering_service.test.ts @@ -163,6 +163,11 @@ describe('RenderingService', () => { const result = await service.isUrlValid('http://notfound.svg', 'config'); expect(result).toEqual(false); }); + + it('checks default URL returns false', async () => { + const result = await service.isUrlValid('/', 'config'); + expect(result).toEqual(false); + }); }); describe('isTitleValid()', () => { diff --git a/src/core/server/rendering/rendering_service.tsx b/src/core/server/rendering/rendering_service.tsx index efaab2b9494..5185ef6a615 100644 --- a/src/core/server/rendering/rendering_service.tsx +++ b/src/core/server/rendering/rendering_service.tsx @@ -315,8 +315,11 @@ export class RenderingService { * @returns {boolean} indicate if the URL is valid/invalid */ public isUrlValid = async (url: string, configName?: string): Promise => { + if (url === '/') { + return false; + } if (url.match(/\.(png|svg|gif|PNG|SVG|GIF)$/) === null) { - this.logger.get('branding').info(configName + ' config is not found or invalid.'); + this.logger.get('branding').error(`${configName} config is invalid. Using default branding.`); return false; } return await Axios.get(url, { adapter: AxiosHttpAdapter, maxRedirects: 0 }) @@ -324,7 +327,9 @@ export class RenderingService { return true; }) .catch(() => { - this.logger.get('branding').info(configName + ' config is not found or invalid'); + this.logger + .get('branding') + .error(`${configName} URL was not found or invalid. Using default branding.`); return false; }); }; @@ -338,12 +343,14 @@ export class RenderingService { * @returns {boolean} indicate if user input title is valid/invalid */ public isTitleValid = (title: string, configName?: string): boolean => { - if (!title || title.length > 36) { + if (!title) { + return false; + } + if (title.length > 36) { this.logger .get('branding') - .info( - configName + - ' config is not found or invalid. Title length should be between 1 to 36 characters.' + .error( + `${configName} config is not found or invalid. Title length should be between 1 to 36 characters. Using default title.` ); return false; }