Skip to content

feat: adding infrastructure display support to status page#3343

Open
akashmannil wants to merge 1 commit intodevelopfrom
feat/statuspage-infrastructure-section
Open

feat: adding infrastructure display support to status page#3343
akashmannil wants to merge 1 commit intodevelopfrom
feat/statuspage-infrastructure-section

Conversation

@akashmannil
Copy link

These changes focus on adding Infrastructure section to currently existing status Page.

Fixes #3305

Status.-.Infra.sections.mp4

Latest UI after adding a little bit more padding.
image

image
  • [ x ] (Do not skip this or your PR will be closed) I deployed the application locally.
  • [ x ] (Do not skip this or your PR will be closed) I have performed a self-review and testing of my code.
  • [ x ] I have included the issue # in the PR.
  • [ x ] I have added i18n support to visible strings (instead of <div>Add</div>, use):
const { t } = useTranslation();
<div>{t('add')}</div>
  • [ x ] I have not included any files that are not related to my pull request, including package-lock and package-json if dependencies have not changed
  • [ x ] I didn't use any hardcoded values (otherwise it will not scale, and will make it difficult to maintain consistency across the application).
  • [ x ] I made sure font sizes, color choices etc are all referenced from the theme. I don't have any hardcoded dimensions.
  • [ x ] My PR is granular and targeted to one specific feature.
  • [ x ] I ran npm run format in server and client directories, which automatically formats your code.
  • [ x ] I took a screenshot or a video and attached to this PR if there is a UI change.
Copy link
Collaborator

@ajhollid ajhollid left a comment

Choose a reason for hiding this comment

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

In general, it seems to work well.

My main concern is the abundance of complexity and conditional rendering.

I think we need to spend some time simplifying this, extracting complex rendering logic, and cleaning up as much as possible.

Aside from that, we need to be extremely careful with the localization file. If we have "http" declared for a type of monitor somewhere else ("optionHttp": "HTTP(S)") , we don't want to do it again for the badges.

If we do, we now have to make sure these always stay in sync, which is frustrating. If the same string needs to be used in multiple places it should be extracted to the "common" key in en.json.

"docker": "Docker",
"pagespeed": "PageSpeed",
"hardware": "Infrastructure",
"game": "Game"
Copy link
Collaborator

Choose a reason for hiding this comment

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

I have a feeling these values are all declared somewhere else already, can you please thoroughly check the localization file? Duplicated strings is a maintenance nightmare

</Typography>
<Typography variant="body2">{upperValue}</Typography>
</Stack>
)}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe we can better handle this nested conditional rendering.

The rendering condition for the inner stack is equivalent to

if (A or B){
  if (A) {
    // do A
  }
  if (B) {
    // do B
  }
}

At this level of complexity, it's probably time to define a component that internalizes this logic in a clear easy to understand way

paddingBottom={theme.spacing(10)}
>
{upperLabel && (
<Stack
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is quite deeply nested. We can probably flatten this layout considerably using grids

>
<Typography
variant="body2"
color="text.secondary"
Copy link
Collaborator

Choose a reason for hiding this comment

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

We generally don't use this contention in the project, let's stick with referencing the palette for theme colors for consistency.


const disks = latestCheck?.disk ?? [];
const totalDiskUsage = disks.reduce((acc, disk) => acc + (disk?.usage_percent || 0), 0);
const diskCount = disks.length || 1;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This seems problematic, if disks is empty, ie no disks, this will evaluate to 1 🤔

If there are no discs, there should be no disk metrics and we should return.

Comment on lines +119 to +158
{!isInfrastructureMonitor && (
<>
{statusPage.showCharts !== false && (
<Box
sx={{
overflow: "hidden",
minWidth: 0,
flex: 1,
mb: theme.spacing(2),
}}
>
{chartType === "histogram" ? (
<HistogramResponseTime
height={{ xs: 50, md: 100 }}
gap={{ xs: theme.spacing(0.5), md: theme.spacing(5) }}
checks={monitor?.checks?.slice().reverse() ?? []}
/>
) : (
<HeatmapResponseTime
checks={monitor?.checks?.slice().reverse() ?? []}
/>
)}
</Box>
)}
</Box>
</>
)}

{isInfrastructureMonitor && statusPage.showInfrastructure !== false && (
<BaseBox
key={monitor.id}
padding={theme.spacing(4)}
>
<Stack
direction="row"
alignItems="center"
justifyContent="space-between"
gap={theme.spacing(8)}
></Stack>
<InfrastructureMetrics monitor={monitor} />
</BaseBox>
Copy link
Collaborator

Choose a reason for hiding this comment

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

This rendering logic is also becoming deeply nested, probably time to extract here as well

Comment on lines +92 to +98
monitor?.type === "hardware"
? theme.palette.info.light
: theme.palette.success.light,
color:
monitor?.type === "hardware"
? theme.palette.info.dark
: theme.palette.success.dark,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's create helper functions for these, there may be more monitor types in the future and having this all inline ternaries will become messy fast.

Additionally, they are somewhat difficult to read 🤔 I don't think there's enough contrast between the bg and the text. Probably a black/transparent bg with colored text would be more readable.

Image
monitor?.type === "hardware"
? theme.palette.info.dark
: theme.palette.success.dark,
padding: `${theme.spacing(0.5)} ${theme.spacing(1.5)}`,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why fractional spacings?

Comment on lines +146 to +157
{isInfrastructureMonitor && statusPage.showInfrastructure !== false && (
<BaseBox
key={monitor.id}
padding={theme.spacing(4)}
>
<Stack
direction="row"
alignItems="center"
justifyContent="space-between"
gap={theme.spacing(8)}
></Stack>
<InfrastructureMetrics monitor={monitor} />
Copy link
Collaborator

Choose a reason for hiding this comment

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

What's going on here actually? Why do we have a BaseBox inside another BaseBox, holding an empty stack?

A BaseBox should be a base component 🤔 If showing infra stats is set to false, lets just display the regular histogram then rather than an empty row.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants