Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[APM] Disable client caching for Service map API call #62111

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,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