Skip to content

Commit

Permalink
Closes #60173 by turning off client caching for the main service map …
Browse files Browse the repository at this point in the history
…API call (#62111) (#62212)
  • Loading branch information
ogupte authored Apr 1, 2020
1 parent df091d2 commit a1d9773
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
},
[],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function useDynamicIndexPattern(
callApmApi => {
return callApmApi({
pathname: '/api/apm/index_pattern/dynamic',
forceCache: true,
isCachable: true,
params: {
query: {
processorEvent
Expand Down
40 changes: 40 additions & 0 deletions x-pack/legacy/plugins/apm/public/services/__test__/callApi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
});
});
6 changes: 3 additions & 3 deletions x-pack/legacy/plugins/apm/public/services/rest/callApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { HttpSetup, HttpFetchOptions } from 'kibana/public';

export type FetchOptions = Omit<HttpFetchOptions, 'body'> & {
pathname: string;
forceCache?: boolean;
isCachable?: boolean;
method?: string;
body?: any;
};
Expand Down Expand Up @@ -74,8 +74,8 @@ export async function callApi<T = void>(
// 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 (
Expand Down

0 comments on commit a1d9773

Please sign in to comment.