-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: experimental health frontend (#10349)
* feat: display health in frontend Signed-off-by: Philippe Martin <phmartin@redhat.com> * refactor: get experimentalStates config value Signed-off-by: Philippe Martin <phmartin@redhat.com> * test: unit tests Signed-off-by: Philippe Martin <phmartin@redhat.com> * fix: use vi.mocked Signed-off-by: Philippe Martin <phmartin@redhat.com> * fix: do not wast window to any Signed-off-by: Philippe Martin <phmartin@redhat.com> * refactor: use EventStore Signed-off-by: Philippe Martin <phmartin@redhat.com> * fix: compute outside of template Signed-off-by: Philippe Martin <phmartin@redhat.com>
- v1.16.0-202412261749-c1a60eefdd9
- v1.16.0-202412252047-7f43a1e599c
- v1.16.0-202412252047-4e0dd48b110
- v1.16.0-202412251643-610e46af820
- v1.16.0-202412250416-385db92ce92
- v1.16.0-202412241509-151bababa57
- v1.16.0-202412240730-109d227f77a
- v1.16.0-202412232230-69b4f8a14df
- v1.16.0-202412231723-74a4ed4996b
- v1.16.0-202412231207-06dbe6347c5
- v1.16.0-202412201712-8fe30a7fc3d
- v1.16.0-202412200647-47845277445
- v1.16.0-202412200641-918b8102b36
- v1.16.0-202412200633-a9958d59936
- v1.16.0-202412200556-1353b433d33
- v1.16.0-202412200555-5808375af5e
- v1.16.0-202412200450-d73c6d64ab5
- v1.16.0-202412191526-af98dd0c20c
- v1.16.0-202412191415-e310ee948c5
- v1.16.0-202412191403-0c48de37508
- v1.16.0-202412191349-38be9543b74
- v1.16.0-202412191344-b0cfeb292ec
- v1.16.0-202412191256-7448e9d1cef
- v1.16.0-202412191055-6a8f4372262
- v1.16.0-202412190743-e86c68b32b4
- v1.16.0-202412190724-49305c84b51
- v1.16.0-202412190715-d3d4cdfb923
- v1.16.0-202412190653-0ba3943d166
- v1.16.0-202412190522-38e6d956a12
- v1.16.0-202412190417-b4fce7796fa
- v1.16.0-202412181837-969d7ccac25
- v1.16.0-202412181823-eca90822e6d
- v1.16.0-202412181721-40dab1ab109
- v1.16.0-202412181716-8997342915f
- v1.16.0-202412181707-a55912a9406
- v1.16.0-202412181625-cde52790a32
- v1.16.0-202412181244-d83c4c010da
- v1.16.0-202412181138-d3395145ecb
- v1.16.0-202412181122-0f256314e5c
- v1.16.0-202412181050-0256cccc081
- v1.16.0-202412181031-13110e2f0c7
- v1.16.0-202412181016-c8cb6065159
- v1.16.0-202412180735-f15a300f816
- v1.16.0-202412172011-dba905215f8
- v1.16.0-202412171730-0fd1a1456b5
- v1.16.0-202412171719-499bebcf215
- v1.16.0-202412171546-9bcbf15e50b
- v1.16.0-202412171342-8c79939aa99
- v1.16.0-202412171341-333f183edbe
- v1.16.0-202412171239-d0d3cbcd941
- v1.16.0-202412171217-e026f4902dd
- v1.16.0-202412170952-20bb35f39a1
- v1.16.0-202412170936-35d6f948440
- v1.16.0-202412170831-d35ae6ec552
- v1.16.0-202412170800-5a43945d1d9
- v1.16.0-202412170603-262581d32ce
- v1.16.0-202412170603-997d805864c
- v1.16.0-202412170441-a067b857bd3
- v1.16.0-202412170420-ed804fb9d2f
- v1.16.0-202412170413-80adb43d1be
- v1.16.0-202412170344-d9ef799af36
- v1.16.0-202412162050-c84573291f0
- v1.16.0-202412161927-501b4368e5f
- v1.16.0-202412161909-5c963904afc
- v1.16.0-202412161758-35d22aae042
- v1.16.0-202412161700-a6883bc14cf
- v1.16.0-202412161635-41405035451
- v1.16.0-202412161436-7da6e4a4897
Showing
10 changed files
with
418 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/********************************************************************** | ||
* Copyright (C) 2024 Red Hat, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
***********************************************************************/ | ||
|
||
export interface ContextHealth { | ||
contextName: string; | ||
checking: boolean; | ||
reachable: boolean; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
packages/renderer/src/stores/kubernetes-context-health.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/********************************************************************** | ||
* Copyright (C) 2024 Red Hat, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
***********************************************************************/ | ||
|
||
import { get } from 'svelte/store'; | ||
import { expect, test, vi } from 'vitest'; | ||
|
||
import { kubernetesContextsHealths, kubernetesContextsHealthsStore } from './kubernetes-context-health'; | ||
|
||
const callbacks = new Map<string, any>(); | ||
const eventEmitter = { | ||
receive: (message: string, callback: any) => { | ||
callbacks.set(message, callback); | ||
}, | ||
}; | ||
|
||
Object.defineProperty(global, 'window', { | ||
value: { | ||
kubernetesGetContextsHealths: vi.fn(), | ||
addEventListener: eventEmitter.receive, | ||
events: { | ||
receive: eventEmitter.receive, | ||
}, | ||
}, | ||
writable: true, | ||
}); | ||
|
||
test('kubernetesContextsHealths', async () => { | ||
const initialValues = [ | ||
{ | ||
contextName: 'context1', | ||
checking: true, | ||
reachable: false, | ||
}, | ||
{ | ||
contextName: 'context2', | ||
checking: false, | ||
reachable: true, | ||
}, | ||
]; | ||
|
||
const nextValues = [ | ||
{ | ||
contextName: 'context1', | ||
checking: false, | ||
reachable: true, | ||
}, | ||
{ | ||
contextName: 'context2', | ||
checking: false, | ||
reachable: true, | ||
}, | ||
]; | ||
|
||
vi.mocked(window.kubernetesGetContextsHealths).mockResolvedValue(initialValues); | ||
|
||
const kubernetesContextsHealthsInfo = kubernetesContextsHealthsStore.setup(); | ||
await kubernetesContextsHealthsInfo.fetch(); | ||
let currentValue = get(kubernetesContextsHealths); | ||
expect(currentValue).toEqual(initialValues); | ||
|
||
// send 'extensions-already-started' event | ||
const callbackExtensionsStarted = callbacks.get('extensions-already-started'); | ||
expect(callbackExtensionsStarted).toBeDefined(); | ||
await callbackExtensionsStarted(); | ||
|
||
// send an event indicating the data is updated | ||
const event = 'kubernetes-contexts-healths'; | ||
const callback = callbacks.get(event); | ||
expect(callback).toBeDefined(); | ||
await callback(); | ||
|
||
// data has been updated in the backend | ||
vi.mocked(window.kubernetesGetContextsHealths).mockResolvedValue(nextValues); | ||
|
||
// check received data is updated | ||
await kubernetesContextsHealthsInfo.fetch(); | ||
currentValue = get(kubernetesContextsHealths); | ||
expect(currentValue).toEqual(nextValues); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/********************************************************************** | ||
* Copyright (C) 2024 Red Hat, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
***********************************************************************/ | ||
|
||
import { type Writable, writable } from 'svelte/store'; | ||
|
||
import type { ContextHealth } from '/@api/kubernetes-contexts-healths'; | ||
|
||
import { EventStore } from './event-store'; | ||
|
||
const windowEvents = ['kubernetes-contexts-healths', 'extension-stopped', 'extensions-started']; | ||
const windowListeners = ['extensions-already-started']; | ||
|
||
let readyToUpdate = false; | ||
export async function checkForUpdate(eventName: string): Promise<boolean> { | ||
if ('extensions-already-started' === eventName) { | ||
readyToUpdate = true; | ||
} | ||
// do not fetch until extensions are all started | ||
return readyToUpdate; | ||
} | ||
|
||
export const kubernetesContextsHealths: Writable<ContextHealth[]> = writable([]); | ||
|
||
// use helper here as window methods are initialized after the store in tests | ||
const listContextsHealths = (): Promise<ContextHealth[]> => { | ||
return window.kubernetesGetContextsHealths(); | ||
}; | ||
|
||
export const kubernetesContextsHealthsStore = new EventStore<ContextHealth[]>( | ||
'contexts healths', | ||
kubernetesContextsHealths, | ||
checkForUpdate, | ||
windowEvents, | ||
windowListeners, | ||
listContextsHealths, | ||
); | ||
kubernetesContextsHealthsStore.setup(); |