Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
c2b9198
Fixes #5003: suppress toast on error via option to axios request conf…
ulischulte Feb 6, 2026
31ee137
Merge branch 'master' into fix/5003-suppress-toasts-on-missing-metric
ulischulte Feb 9, 2026
10ddaa9
Merge branch 'master' into fix/5003-suppress-toasts-on-missing-metric
ulischulte Feb 10, 2026
51ea5a2
#5003: Suppress toast on cache.size not found
ulischulte Feb 11, 2026
b2efcdb
#5003: Suppress toast only on cache.size not found
ulischulte Feb 11, 2026
b077297
Merge branch 'master' into fix/5003-suppress-toasts-on-missing-metric
ulischulte Feb 11, 2026
f9e6ef0
Merge branch 'master' into fix/5003-suppress-toasts-on-missing-metric
ulischulte Feb 13, 2026
3b1fe2a
Merge remote-tracking branch 'origin/master' into fix/5003-suppress-t…
ulischulte Feb 15, 2026
aca0657
Fixes #5003: address changes from default branch to tests
ulischulte Feb 15, 2026
a0c0a39
Merge branch 'master' into fix/5003-suppress-toasts-on-missing-metric
ulischulte Feb 15, 2026
931bd35
Merge branch 'master' into fix/5003-suppress-toasts-on-missing-metric
SteKoe Feb 17, 2026
9cccc85
Fix lint errors
ulischulte Feb 18, 2026
4e9dfdb
Merge branch 'master' into fix/5003-suppress-toasts-on-missing-metric
ulischulte Feb 18, 2026
cd7e2b0
Merge branch 'master' into fix/5003-suppress-toasts-on-missing-metric
ulischulte Feb 18, 2026
2deea5e
Merge branch 'master' into fix/5003-suppress-toasts-on-missing-metric
ulischulte Feb 22, 2026
f84086e
Merge remote-tracking branch 'origin/master' into fix/5003-suppress-t…
ulischulte Mar 6, 2026
ad1b6ae
Fix npm audit
ulischulte Mar 6, 2026
1d6592a
#5003: Fix test setup
ulischulte Mar 6, 2026
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
361 changes: 224 additions & 137 deletions spring-boot-admin-server-ui/package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions spring-boot-admin-server-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
"@vue/eslint-config-typescript": "^14.0.0",
"@vue/test-utils": "2.4.6",
"autoprefixer": "10.4.27",
"axios-mock-adapter": "^2.1.0",
"babel-loader": "10.0.0",
"eslint": "^10.0.0",
"eslint-config-prettier": "^10.0.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { AxiosError } from 'axios';
import { describe, expect, test, vi } from 'vitest';

import Instance from '@/services/instance';
Expand Down Expand Up @@ -30,6 +31,8 @@ describe('Instance', () => {

const instance = new Instance({
id: 'id',
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
registration: {
metadata: {
['hide-url']: metadataHideUrl,
Expand All @@ -40,4 +43,142 @@ describe('Instance', () => {
expect(instance.showUrl()).toEqual(expectUrlToBeShownOnUI);
},
);

describe('fetchMetric', () => {
const instance = new Instance({
id: 'test-id',
registration: {
name: 'test',
healthUrl: '',
source: '',
},
availableMetrics: ['test.metric', 'cache.size', 'cache.gets'],
});
test('should pass suppressToast option to axios config', async () => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
// Spy on axios.get
const axiosGetSpy = vi.spyOn(instance.axios, 'get');

// Mock the axios request
axiosGetSpy.mockResolvedValue({
data: {
measurements: [{ value: 42 }],
},
});

await instance.fetchMetric(
'test.metric',
{ tag: 'value' },
{
suppressToast: true,
},
);

// Verify suppressToast was passed in config
expect(axiosGetSpy).toHaveBeenCalledWith(
expect.stringContaining('actuator/metrics/test.metric'),
expect.objectContaining({
suppressToast: true,
}),
);
});

test('should work without options parameter for backward compatibility', async () => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
const axiosGetSpy = vi.spyOn(instance.axios, 'get');

axiosGetSpy.mockResolvedValue({
data: {
measurements: [{ value: 42 }],
},
});

await instance.fetchMetric('test.metric', { tag: 'value' });

// Verify it was called without suppressToast
expect(axiosGetSpy).toHaveBeenCalledWith(
expect.stringContaining('actuator/metrics/test.metric'),
expect.objectContaining({
suppressToast: undefined,
}),
);
});

test('should pass suppressToast=false when explicitly set to false', async () => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
const axiosGetSpy = vi.spyOn(instance.axios, 'get');

axiosGetSpy.mockResolvedValue({
data: {
measurements: [{ value: 42 }],
},
});

await instance.fetchMetric(
'test.metric',
{ tag: 'value' },
{
suppressToast: false,
},
);

expect(axiosGetSpy).toHaveBeenCalledWith(
expect.stringContaining('actuator/metrics/test.metric'),
expect.objectContaining({
suppressToast: false,
}),
);
});

test('should include tags in request parameters', async () => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
const axiosGetSpy = vi.spyOn(instance.axios, 'get');

axiosGetSpy.mockResolvedValue({
data: {
measurements: [{ value: 42 }],
},
});

await instance.fetchMetric('cache.gets', {
name: 'my-cache',
result: 'hit',
});

const callArgs = axiosGetSpy.mock.calls[0];
const params = callArgs[1]?.params as URLSearchParams;

expect(params).toBeInstanceOf(URLSearchParams);
expect(params.getAll('tag')).toContain('name:my-cache');
expect(params.getAll('tag')).toContain('result:hit');
});

test('should pass suppressToast function to axios config', async () => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
const axiosGetSpy = vi.spyOn(instance.axios, 'get');

axiosGetSpy.mockResolvedValue({
data: {
measurements: [{ value: 42 }],
},
});

const suppressFn = (err: AxiosError) => err.response?.status === 404;
await instance.fetchMetric(
'cache.size',
{},
{ suppressToast: suppressFn },
);

expect(axiosGetSpy).toHaveBeenCalledWith(
expect.any(String),
expect.objectContaining({ suppressToast: suppressFn }),
);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { AxiosInstance } from 'axios';
import { AxiosError, AxiosInstance } from 'axios';
import saveAs from 'file-saver';
import { Observable, concat, from, ignoreElements } from 'rxjs';

Expand All @@ -29,6 +29,17 @@ import { useSbaConfig } from '@/sba-config';
import { actuatorMimeTypes } from '@/services/spring-mime-types';
import { transformToJSON } from '@/utils/transformToJSON';

// Extend AxiosRequestConfig to allow suppressToast
declare module 'axios' {
interface AxiosRequestConfig {
suppressToast?: boolean | ((error: AxiosError) => boolean);
}
}

export type FetchMetricOptions = {
suppressToast?: boolean | ((error: AxiosError) => boolean);
};

const isInstanceActuatorRequest = (url: string) =>
url.match(/^instances[/][^/]+[/]actuator([/].*)?$/);

Expand Down Expand Up @@ -167,7 +178,11 @@ class Instance {
return response;
}

async fetchMetric(metric: string, tags: Record<string, any>) {
async fetchMetric(
metric: string,
tags?: Record<string, string>,
options?: FetchMetricOptions,
) {
if (this.availableMetrics.length === 0) {
try {
await this.fetchMetrics();
Expand Down Expand Up @@ -203,6 +218,7 @@ class Instance {
}
return this.axios.get(uri`actuator/metrics/${metric}`, {
params,
suppressToast: options?.suppressToast,
});
}

Expand Down
40 changes: 36 additions & 4 deletions spring-boot-admin-server-ui/src/main/frontend/tests/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,36 @@ import { afterAll, afterEach, beforeAll, vi } from 'vitest';
import { server } from '@/mocks/server';
import sbaConfig from '@/sba-config';

// Setup localStorage mock
const localStorageMock = (() => {
let store: Record<string, string> = {};

return {
get length(): number {
return Object.keys(store).length;
},
getItem: (key: string) => store[key] || null,
setItem: (key: string, value: string) => {
store[key] = value.toString();
},
removeItem: (key: string) => {
delete store[key];
},
clear: () => {
store = {};
},
};
})();

Object.defineProperty(window, 'localStorage', {
value: localStorageMock,
});

// Setup globalThis.errorSpy for toast notifications
if (!globalThis.errorSpy) {
globalThis.errorSpy = vi.fn();
}

global.IntersectionObserver = vi.fn().mockImplementation(function () {
return {
observe: vi.fn(),
Expand All @@ -24,10 +54,11 @@ global.matchMedia = vi.fn().mockReturnValue({
addEventListener: vi.fn(),
removeEventListener: vi.fn(),
});
global.EventSource = class {
constructor() {}
close() {}
};
global.EventSource = vi.fn().mockImplementation(function () {
return {
close: vi.fn(),
};
}) as unknown as typeof EventSource;

global.SBA = sbaConfig;

Expand All @@ -38,5 +69,6 @@ afterEach(() => server.resetHandlers());
// runs a cleanup after each test case (e.g. clearing jsdom)
afterEach(() => {
vi.clearAllMocks();
localStorage.clear();
cleanup();
});
Loading