Skip to content

Commit 6846561

Browse files
committed
Closes #60173 by turning off client caching for the main service map API call
1 parent aab5a0c commit 6846561

5 files changed

Lines changed: 46 additions & 5 deletions

File tree

x-pack/legacy/plugins/apm/public/components/app/ServiceMap/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export function ServiceMap({ serviceName }: ServiceMapProps) {
4242
const { start, end, environment } = urlParams;
4343
if (start && end) {
4444
return callApmApi({
45+
isCachable: false,
4546
pathname: '/api/apm/service-map',
4647
params: {
4748
query: {

x-pack/legacy/plugins/apm/public/components/app/Settings/AgentConfigurations/AgentConfigurationCreateEdit/ServicePage/ServicePage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export function ServicePage({ newConfig, setNewConfig, onClickNext }: Props) {
3636
callApmApi => {
3737
return callApmApi({
3838
pathname: '/api/apm/settings/agent-configuration/services',
39-
forceCache: true
39+
isCachable: true
4040
});
4141
},
4242
[],

x-pack/legacy/plugins/apm/public/hooks/useDynamicIndexPattern.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export function useDynamicIndexPattern(
1414
callApmApi => {
1515
return callApmApi({
1616
pathname: '/api/apm/index_pattern/dynamic',
17-
forceCache: true,
17+
isCachable: true,
1818
params: {
1919
query: {
2020
processorEvent

x-pack/legacy/plugins/apm/public/services/__test__/callApi.test.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,46 @@ describe('callApi', () => {
157157

158158
expect(http.get).toHaveBeenCalledTimes(1);
159159
});
160+
161+
it('should not return cached response with `isCachable: false` option', async () => {
162+
await callApi(http, {
163+
isCachable: false,
164+
pathname: `/api/kibana`,
165+
query: { start: '2010', end: '2011' }
166+
});
167+
await callApi(http, {
168+
isCachable: false,
169+
pathname: `/api/kibana`,
170+
query: { start: '2010', end: '2011' }
171+
});
172+
await callApi(http, {
173+
isCachable: false,
174+
pathname: `/api/kibana`,
175+
query: { start: '2010', end: '2011' }
176+
});
177+
178+
expect(http.get).toHaveBeenCalledTimes(3);
179+
});
180+
181+
it('should return cached response with `isCachable: true` option', async () => {
182+
await callApi(http, {
183+
isCachable: true,
184+
pathname: `/api/kibana`,
185+
query: { end: '2030' }
186+
});
187+
await callApi(http, {
188+
isCachable: true,
189+
pathname: `/api/kibana`,
190+
query: { end: '2030' }
191+
});
192+
await callApi(http, {
193+
isCachable: true,
194+
pathname: `/api/kibana`,
195+
query: { end: '2030' }
196+
});
197+
198+
expect(http.get).toHaveBeenCalledTimes(1);
199+
});
160200
});
161201
});
162202
});

x-pack/legacy/plugins/apm/public/services/rest/callApi.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { HttpSetup, HttpFetchOptions } from 'kibana/public';
1111

1212
export type FetchOptions = Omit<HttpFetchOptions, 'body'> & {
1313
pathname: string;
14-
forceCache?: boolean;
14+
isCachable?: boolean;
1515
method?: string;
1616
body?: any;
1717
};
@@ -74,8 +74,8 @@ export async function callApi<T = void>(
7474
// only cache items that has a time range with `start` and `end` params,
7575
// and where `end` is not a timestamp in the future
7676
function isCachable(fetchOptions: FetchOptions) {
77-
if (fetchOptions.forceCache) {
78-
return true;
77+
if (fetchOptions.isCachable !== undefined) {
78+
return fetchOptions.isCachable;
7979
}
8080

8181
if (

0 commit comments

Comments
 (0)