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

PSP-9900 : PIMS service availability notifications #4674

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
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
17 changes: 11 additions & 6 deletions source/backend/api/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ public void ConfigureServices(IServiceCollection services)
"PmbcExternalApi",
sp => new PimsExternalApiHealthcheck(this.Configuration.GetSection("HealthChecks:PmbcExternalApi")),
null,
new string[] { "services", "external" })
new string[] { "services", "external", "system-check" })
{ Period = TimeSpan.FromMinutes(allHealthCheckOptions.PmbcExternalApi.Period) });
}

Expand All @@ -314,7 +314,7 @@ public void ConfigureServices(IServiceCollection services)
"Geoserver",
sp => new PimsGeoserverHealthCheck(this.Configuration),
null,
new string[] { "services" })
new string[] { "services", "system", "system-check" })
{ Period = TimeSpan.FromMinutes(allHealthCheckOptions.Geoserver.Period) });
}

Expand All @@ -324,7 +324,7 @@ public void ConfigureServices(IServiceCollection services)
"Mayan",
sp => new PimsMayanHealthcheck(sp.GetService<IEdmsDocumentRepository>()),
null,
new string[] { "services" })
new string[] { "services", "system-check" })
{ Period = TimeSpan.FromMinutes(allHealthCheckOptions.Mayan.Period) });
}

Expand All @@ -334,7 +334,7 @@ public void ConfigureServices(IServiceCollection services)
"Ltsa",
sp => new PimsLtsaHealthcheck(allHealthCheckOptions.Ltsa, sp.GetService<ILtsaService>()),
null,
new string[] { "services", "external" })
new string[] { "services", "external", "system-check" })
{ Period = TimeSpan.FromMinutes(allHealthCheckOptions.Ltsa.Period) });
}

Expand All @@ -344,7 +344,7 @@ public void ConfigureServices(IServiceCollection services)
"Geocoder",
sp => new PimsGeocoderHealthcheck(this.Configuration, sp.GetService<IGeocoderService>()),
null,
new string[] { "services", "external" })
new string[] { "services", "external", "system-check" })
{ Period = TimeSpan.FromMinutes(allHealthCheckOptions.Geocoder.Period) });
}

Expand All @@ -354,7 +354,7 @@ public void ConfigureServices(IServiceCollection services)
"Cdogs",
sp => new PimsCdogsHealthcheck(sp.GetService<IDocumentGenerationRepository>()),
null,
new string[] { "services", "external" })
new string[] { "services", "external", "system-check" })
{ Period = TimeSpan.FromMinutes(allHealthCheckOptions.Cdogs.Period) });
}

Expand Down Expand Up @@ -489,6 +489,11 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IApiVers
app.UseEndpoints(config =>
{
config.MapControllers();
config.MapHealthChecks("health/system", new HealthCheckOptions()
{
Predicate = r => r.Tags.Contains("system-check"),
ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse,
});

// Enable the /metrics page to export Prometheus metrics
config.MapMetrics();
Expand Down
1 change: 1 addition & 0 deletions source/frontend/src/assets/scss/_variables.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
@import './variables';

:export {
healthcheckHeight: $healthcheck-height;
mapfilterHeight: $mapfilter-height;
footerHeight: $footer-height;
headerHeight: $header-height;
Expand Down
1 change: 1 addition & 0 deletions source/frontend/src/assets/scss/_variables.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@import './colors.scss';

$healthcheck-height: 4.5rem;
$header-height: 7.2rem;
$mapfilter-height: 6rem;
$footer-height: 4.4rem;
4 changes: 4 additions & 0 deletions source/frontend/src/components/common/ApiVersionInfo.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { useApiHealth } from '@/hooks/pims-api/useApiHealth';
import { render, RenderOptions, waitForEffects } from '@/utils/test-utils';

import { ApiVersionInfo } from './ApiVersionInfo';
import ISystemCheck from '@/hooks/pims-api/interfaces/ISystemCheck';
import { AxiosResponse } from 'axios';

const defaultVersion: IApiVersion = {
environment: 'test',
Expand All @@ -15,12 +17,14 @@ const defaultVersion: IApiVersion = {
const mockGetVersionApi = vi.fn();
const mockGetLiveApi = vi.fn();
const mockGetReady = vi.fn();
const mockGetSystemCheckApi = vi.fn();

vi.mock('@/hooks/pims-api/useApiHealth');
vi.mocked(useApiHealth).mockReturnValue({
getVersion: mockGetVersionApi,
getLive: mockGetLiveApi,
getReady: mockGetReady,
getSystemCheck: mockGetSystemCheckApi,
});

describe('ApiVersionInfo suite', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import HealthcheckView, { IHealthCheckIssue, IHealthCheckViewProps } from './HealthcheckView';
import { act, render, RenderOptions, userEvent, screen } from '@/utils/test-utils';

const mockHealthcheckIssues: IHealthCheckIssue[] = [
{
key: 'PimsApi',
msg: 'The PIMS server is currently unavailable, PIMS will not be useable until this is resolved.',
},
];

describe('Healthcheck View component', () => {
const setup = async (
renderOptions: RenderOptions & { props?: Partial<IHealthCheckViewProps> } = {},
) => {
const utils = render(
<HealthcheckView
{...renderOptions.props}
systemChecks={renderOptions.props?.systemChecks ?? mockHealthcheckIssues}
/>,
{
...renderOptions,
},
);

return {
...utils,
};
};

afterEach(() => {
vi.clearAllMocks();
});

it('renders as expected', async () => {
const { asFragment } = await setup({});
expect(asFragment()).toMatchSnapshot();
});

it(`renders 'See the full list here' link`, async () => {
const { getByTestId } = await setup({
props: {
systemChecks: [
{
key: 'Mayan',
msg: 'The PIMS Document server is experiencing service degradation, you will be unable to view, download or upload documents until resolved.',
},
...mockHealthcheckIssues,
],
},
});
expect(getByTestId('healthcheck-full-list-lnk')).toBeVisible();
});
});
130 changes: 130 additions & 0 deletions source/frontend/src/components/layout/Healthcheck/HealthcheckView.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
import { FaBan } from 'react-icons/fa';
import styled from 'styled-components';

import { LinkButton } from '@/components/common/buttons/LinkButton';
import { ModalSize } from '@/components/common/GenericModal';
import { useModalContext } from '@/hooks/useModalContext';

export interface IHealthCheckIssue {
key: string;
msg: string;
}

export interface IHealthCheckViewProps {
systemChecks: IHealthCheckIssue[];
}

const HealthcheckView: React.FunctionComponent<IHealthCheckViewProps> = ({ systemChecks }) => {
const { setModalContent, setDisplayModal } = useModalContext();

return (
systemChecks.length && (
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this appears to throw an NPE, as this is initialized with null until the promise returns.

<StyledWrapperDiv>
<StyledIconDiv>
<FaBan size={24} />
</StyledIconDiv>
<StyledContainer>
<label>
<span>{systemChecks[0].key}: </span>
{systemChecks[0].msg}
</label>
{systemChecks.length > 1 && (
<LinkButton
data-testid="healthcheck-full-list-lnk"
onClick={() => {
setModalContent({
variant: 'error',
title: 'Error',
modalSize: ModalSize.LARGE,
message: (
<StyledList>
{systemChecks.map(x => {
return (
<label key={x.key}>
<span>{x.key}: </span>
{x.msg}
</label>
);
})}
</StyledList>
),
okButtonText: 'Close',
handleOk: async () => {
setDisplayModal(false);
},
});
setDisplayModal(true);
}}
>
See the full list here...
</LinkButton>
)}
</StyledContainer>
</StyledWrapperDiv>
)
);
};

const StyledWrapperDiv = styled.div`
display: flex;
height: 100%;
background-color: ${props => props.theme.css.dangerBackgroundColor};
`;

const StyledIconDiv = styled.div`
display: flex;
justify-content: center;
align-items: center;
width: auto;
min-width: 6rem;
height: 100%;
background-color: ${props => props.theme.bcTokens.typographyColorDanger};

svg {
color: ${props => props.theme.css.pimsWhite};
}
`;

const StyledContainer = styled.div`
display: flex;
align-items: center;
flex-direction: row;
flex-grow: 1;
justify-content: flex-start;
padding-left: 6rem;
background-color: ${props => props.theme.css.dangerBackgroundColor};

label {
display: list-item;
margin-bottom: 0;

span {
text-transform: uppercase;
font-weight: bolder;
}
}

button {
margin-left: 6rem;
}
`;

const StyledList = styled.div`
padding: 1rem 2rem;

label {
display: list-item;
margin-bottom: 0;

span {
text-transform: uppercase;
font-weight: bolder;
}
}

button {
margin-left: 6rem;
}
`;

export default HealthcheckView;
Loading
Loading