From a1d97737418d1f7a37a2a3945dfc3aac02bb1cea Mon Sep 17 00:00:00 2001 From: Oliver Gupte Date: Wed, 1 Apr 2020 14:06:34 -0700 Subject: [PATCH] Closes #60173 by turning off client caching for the main service map API call (#62111) (#62212) --- .../components/app/ServiceMap/index.tsx | 1 + .../ServicePage/ServicePage.tsx | 2 +- .../public/hooks/useDynamicIndexPattern.ts | 2 +- .../public/services/__test__/callApi.test.ts | 40 +++++++++++++++++++ .../apm/public/services/rest/callApi.ts | 6 +-- 5 files changed, 46 insertions(+), 5 deletions(-) diff --git a/x-pack/legacy/plugins/apm/public/components/app/ServiceMap/index.tsx b/x-pack/legacy/plugins/apm/public/components/app/ServiceMap/index.tsx index 8e8151e6297b..63bc1b9b8f55 100644 --- a/x-pack/legacy/plugins/apm/public/components/app/ServiceMap/index.tsx +++ b/x-pack/legacy/plugins/apm/public/components/app/ServiceMap/index.tsx @@ -36,6 +36,7 @@ export function ServiceMap({ serviceName }: ServiceMapProps) { const { start, end, environment } = urlParams; if (start && end) { return callApmApi({ + isCachable: false, pathname: '/api/apm/service-map', params: { query: { diff --git a/x-pack/legacy/plugins/apm/public/components/app/Settings/AgentConfigurations/AgentConfigurationCreateEdit/ServicePage/ServicePage.tsx b/x-pack/legacy/plugins/apm/public/components/app/Settings/AgentConfigurations/AgentConfigurationCreateEdit/ServicePage/ServicePage.tsx index b9f8fd86d067..43002c79aa2b 100644 --- a/x-pack/legacy/plugins/apm/public/components/app/Settings/AgentConfigurations/AgentConfigurationCreateEdit/ServicePage/ServicePage.tsx +++ b/x-pack/legacy/plugins/apm/public/components/app/Settings/AgentConfigurations/AgentConfigurationCreateEdit/ServicePage/ServicePage.tsx @@ -36,7 +36,7 @@ export function ServicePage({ newConfig, setNewConfig, onClickNext }: Props) { callApmApi => { return callApmApi({ pathname: '/api/apm/settings/agent-configuration/services', - forceCache: true + isCachable: true }); }, [], diff --git a/x-pack/legacy/plugins/apm/public/hooks/useDynamicIndexPattern.ts b/x-pack/legacy/plugins/apm/public/hooks/useDynamicIndexPattern.ts index 747144690bb2..ee3d2e81f259 100644 --- a/x-pack/legacy/plugins/apm/public/hooks/useDynamicIndexPattern.ts +++ b/x-pack/legacy/plugins/apm/public/hooks/useDynamicIndexPattern.ts @@ -14,7 +14,7 @@ export function useDynamicIndexPattern( callApmApi => { return callApmApi({ pathname: '/api/apm/index_pattern/dynamic', - forceCache: true, + isCachable: true, params: { query: { processorEvent diff --git a/x-pack/legacy/plugins/apm/public/services/__test__/callApi.test.ts b/x-pack/legacy/plugins/apm/public/services/__test__/callApi.test.ts index 95ebed1fcb2a..5da237b637ab 100644 --- a/x-pack/legacy/plugins/apm/public/services/__test__/callApi.test.ts +++ b/x-pack/legacy/plugins/apm/public/services/__test__/callApi.test.ts @@ -157,6 +157,46 @@ describe('callApi', () => { expect(http.get).toHaveBeenCalledTimes(1); }); + + it('should not return cached response with `isCachable: false` option', async () => { + await callApi(http, { + isCachable: false, + pathname: `/api/kibana`, + query: { start: '2010', end: '2011' } + }); + await callApi(http, { + isCachable: false, + pathname: `/api/kibana`, + query: { start: '2010', end: '2011' } + }); + await callApi(http, { + isCachable: false, + pathname: `/api/kibana`, + query: { start: '2010', end: '2011' } + }); + + expect(http.get).toHaveBeenCalledTimes(3); + }); + + it('should return cached response with `isCachable: true` option', async () => { + await callApi(http, { + isCachable: true, + pathname: `/api/kibana`, + query: { end: '2030' } + }); + await callApi(http, { + isCachable: true, + pathname: `/api/kibana`, + query: { end: '2030' } + }); + await callApi(http, { + isCachable: true, + pathname: `/api/kibana`, + query: { end: '2030' } + }); + + expect(http.get).toHaveBeenCalledTimes(1); + }); }); }); }); diff --git a/x-pack/legacy/plugins/apm/public/services/rest/callApi.ts b/x-pack/legacy/plugins/apm/public/services/rest/callApi.ts index 43ecb860a1f1..d8e3d27f042a 100644 --- a/x-pack/legacy/plugins/apm/public/services/rest/callApi.ts +++ b/x-pack/legacy/plugins/apm/public/services/rest/callApi.ts @@ -11,7 +11,7 @@ import { HttpSetup, HttpFetchOptions } from 'kibana/public'; export type FetchOptions = Omit & { pathname: string; - forceCache?: boolean; + isCachable?: boolean; method?: string; body?: any; }; @@ -74,8 +74,8 @@ export async function callApi( // only cache items that has a time range with `start` and `end` params, // and where `end` is not a timestamp in the future function isCachable(fetchOptions: FetchOptions) { - if (fetchOptions.forceCache) { - return true; + if (fetchOptions.isCachable !== undefined) { + return fetchOptions.isCachable; } if (