-
Notifications
You must be signed in to change notification settings - Fork 50
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
Implement and show upptime status in footer #5235
Open
ivarnakken
wants to merge
2
commits into
master
Choose a base branch
from
ivarnakken/aba-1200-add-status-badge-in-footer
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+186
−4
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,50 @@ | ||
import { createAsyncThunk } from '@reduxjs/toolkit'; | ||
|
||
export type SystemStatus = { | ||
status: 'operational' | 'degraded' | 'major'; | ||
message: string; | ||
}; | ||
|
||
type UptimeService = { | ||
name: string; | ||
status: 'up' | 'down' | 'degraded'; | ||
uptime: string; | ||
}; | ||
|
||
export const fetchSystemStatus = createAsyncThunk( | ||
'status/fetch', | ||
async (): Promise<SystemStatus> => { | ||
const response = await fetch( | ||
'https://raw.githubusercontent.com/webkom/uptime/master/history/summary.json', | ||
); | ||
|
||
if (!response.ok) { | ||
throw new Error('Failed to fetch system status'); | ||
} | ||
|
||
const data = (await response.json()) as UptimeService[]; | ||
|
||
const servicesDown = data.filter( | ||
(service) => service.status === 'down', | ||
).length; | ||
const servicesDegraded = data.filter( | ||
(service) => service.status === 'degraded', | ||
).length; | ||
|
||
let status: SystemStatus['status']; | ||
let message: string; | ||
|
||
if (servicesDown > 0) { | ||
status = 'major'; | ||
message = `${servicesDown} ${servicesDown === 1 ? 'tjeneste er' : 'tjenester er'} nede`; | ||
} else if (servicesDegraded > 0) { | ||
status = 'degraded'; | ||
message = `${servicesDegraded} ${servicesDegraded === 1 ? 'tjeneste har' : 'tjenester har'} redusert ytelse`; | ||
} else { | ||
status = 'operational'; | ||
message = `Alle tjenester opererer normalt`; | ||
} | ||
|
||
return { status, message }; | ||
}, | ||
); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { createSlice } from '@reduxjs/toolkit'; | ||
import { fetchSystemStatus } from 'app/actions/StatusActions'; | ||
import { EntityType } from 'app/store/models/entities'; | ||
import createLegoAdapter from 'app/utils/legoAdapter/createLegoAdapter'; | ||
import type { SystemStatus } from 'app/actions/StatusActions'; | ||
import type { RootState } from 'app/store/createRootReducer'; | ||
|
||
type ExtraStatusState = { | ||
systemStatus: SystemStatus | null; | ||
}; | ||
|
||
const legoAdapter = createLegoAdapter(EntityType.SystemStatus); | ||
|
||
const statusSlice = createSlice({ | ||
name: EntityType.SystemStatus, | ||
initialState: legoAdapter.getInitialState({ | ||
systemStatus: null, | ||
} as ExtraStatusState), | ||
reducers: {}, | ||
extraReducers: legoAdapter.buildReducers({ | ||
extraCases: (addCase) => { | ||
addCase(fetchSystemStatus.fulfilled, (state, action) => { | ||
state.systemStatus = action.payload; | ||
}); | ||
}, | ||
}), | ||
}); | ||
|
||
export default statusSlice.reducer; | ||
|
||
export const selectSystemStatus = (state: RootState) => | ||
state.status.systemStatus; |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a very clean way of creating a fetching thunk, but it doesn't follow
lego-webapp
convention. Also, I'm pretty sure theSystemStatus.FETCH
won't work now, meaning loading state doesn't get set.I suppose it's fine if we don't need loading state, but in that case just remove the unused
SystemStatus.FETCH
action types.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's sort of a mixture between "the convetion" and the readme fetching way. You're probably right about the loading states. Not sure what's the best way to do this is - do you have any input? I feel like you know our redux and call api implementation much better than I do
Removed 👍🏼