Skip to content

Commit 4fdd139

Browse files
committed
fix: type issues
1 parent 5636af1 commit 4fdd139

File tree

9 files changed

+52
-39
lines changed

9 files changed

+52
-39
lines changed

backend/analytics_server/app.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
from mhq.store import configure_db_with_app
1010
from mhq.api.hello import app as core_api
11+
from mhq.api.health import app as core_api
1112
from mhq.api.settings import app as settings_api
1213
from mhq.api.pull_requests import app as pull_requests_api
1314
from mhq.api.incidents import app as incidents_api
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from flask import Blueprint
2+
3+
app = Blueprint("health", __name__)
4+
5+
@app.route("/health", methods=["GET"])
6+
def health_check():
7+
return {
8+
"message": "server is up and running",
9+
"status": "healthy"
10+
}

backend/analytics_server/sync_app.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
from mhq.store import configure_db_with_app
1010
from mhq.api.hello import app as core_api
11+
from mhq.api.health import app as core_api
1112
from mhq.api.sync import app as sync_api
1213

1314
SYNC_SERVER_PORT = getenv("SYNC_SERVER_PORT")

web-server/app/api/stream/route.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ const checkServiceStatus = async (
2929
try {
3030
switch (serviceName) {
3131
case ServiceNames.API_SERVER:
32-
const apiResponse = await handleRequest('');
33-
return apiResponse.message.includes('hello world');
32+
const apiResponse = await handleRequest('/health');
33+
return apiResponse.status.includes('healthy');
3434

3535
case ServiceNames.REDIS:
3636
const redisPingResponse = await execPromise(
@@ -45,8 +45,8 @@ const checkServiceStatus = async (
4545
return postgresResponse.includes('accepting connections');
4646

4747
case ServiceNames.SYNC_SERVER:
48-
const syncServerResponse = await handleSyncServerRequest('');
49-
return syncServerResponse.message.includes('hello world');
48+
const syncServerResponse = await handleSyncServerRequest('/health');
49+
return syncServerResponse.status.includes('healthy');
5050

5151
default:
5252
console.warn(`Service ${serviceName} not recognized.`);

web-server/pages/system.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Authenticated } from 'src/components/Authenticated';
2+
23
import { FlexBox } from '@/components/FlexBox';
34
import Loader from '@/components/Loader';
45
import { SystemStatus } from '@/components/Service/SystemStatus';
@@ -28,11 +29,11 @@ function Service() {
2829
<PageWrapper
2930
title={
3031
<FlexBox gap={1} alignCenter>
31-
System
32+
System logs
3233
</FlexBox>
3334
}
3435
hideAllSelectors
35-
pageTitle="System"
36+
pageTitle="System logs"
3637
showEvenIfNoTeamSelected={true}
3738
isLoading={isLoading}
3839
>

web-server/src/components/Service/SystemStatus.tsx

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import { Box, CircularProgress, Divider } from '@mui/material';
1+
import { Box, CircularProgress, Divider, useTheme } from '@mui/material';
22
import { FC, useEffect } from 'react';
3+
import { alpha } from '@mui/material/styles';
34

45
import { ServiceNames } from '@/constants/service';
56
import { StreamEventType } from '@/constants/stream';
67
import { CardRoot } from '@/content/DoraMetrics/DoraCards/sharedComponents';
7-
import { serviceSlice, ServiceStatusState } from '@/slices/service';
8+
import { serviceSlice } from '@/slices/service';
89
import { useDispatch, useSelector } from '@/store';
910

1011
import { FlexBox } from '../FlexBox';
@@ -14,13 +15,13 @@ import { Line } from '../Text';
1415
export const SystemStatus: FC = () => {
1516
const dispatch = useDispatch();
1617
const loading = useSelector((state) => state.service.loading);
17-
const services = useSelector(
18-
(state: { service: { services: ServiceStatusState } }) =>
19-
state.service.services
20-
);
18+
const services = useSelector((state) => state.service.services);
19+
2120
console.log('Status Page render');
21+
const theme = useTheme();
2222
useEffect(() => {
2323
const eventSource = new EventSource(`/api/stream`);
24+
2425
eventSource.onmessage = (event) => {
2526
const data = JSON.parse(event.data);
2627

@@ -56,12 +57,13 @@ export const SystemStatus: FC = () => {
5657

5758
const { addPage } = useOverlayPage();
5859

59-
const ServiceTitle: { [key: string]: string } = {
60+
const ServiceTitle: Record<ServiceNames, string> = {
6061
[ServiceNames.API_SERVER]: 'Backend Server',
6162
[ServiceNames.REDIS]: 'Redis Database',
6263
[ServiceNames.POSTGRES]: 'Postgres Database',
6364
[ServiceNames.SYNC_SERVER]: 'Sync Server'
6465
};
66+
6567
return (
6668
<FlexBox col gap={2} sx={{ padding: '16px' }}>
6769
<Line bold white fontSize="24px" sx={{ mb: 2 }}>
@@ -84,17 +86,16 @@ export const SystemStatus: FC = () => {
8486
{Object.keys(services).map((serviceName) => {
8587
const serviceKey = serviceName as ServiceNames;
8688
const { isUp } = services[serviceKey];
89+
8790
return (
8891
<CardRoot
8992
key={serviceName}
9093
onClick={() => {
9194
addPage({
9295
page: {
9396
ui: 'system_logs',
94-
title: `${ServiceTitle[serviceName]} Logs`,
95-
props: {
96-
serviceName: serviceName
97-
}
97+
title: `${ServiceTitle[serviceKey]} Logs`,
98+
props: { serviceName }
9899
}
99100
});
100101
}}
@@ -106,7 +107,9 @@ export const SystemStatus: FC = () => {
106107
backgroundColor: 'rgba(255, 255, 255, 0.05)',
107108
borderRadius: '12px',
108109
border: `1px solid ${
109-
isUp ? 'rgba(0, 255, 0, 0.3)' : 'rgba(255, 0, 0, 0.3)'
110+
isUp
111+
? alpha(theme.colors.success.main, 0.3)
112+
: alpha(theme.colors.error.main, 0.3)
110113
}`,
111114
padding: '16px',
112115
cursor: 'pointer',
@@ -125,7 +128,7 @@ export const SystemStatus: FC = () => {
125128
alignItems: 'center'
126129
}}
127130
>
128-
{ServiceTitle[serviceName]}
131+
{ServiceTitle[serviceKey]}
129132
<Box
130133
component="span"
131134
sx={{
@@ -134,9 +137,11 @@ export const SystemStatus: FC = () => {
134137
width: '10px',
135138
height: '10px',
136139
borderRadius: '50%',
137-
backgroundColor: isUp ? '#28a745' : '#dc3545'
140+
backgroundColor: isUp
141+
? theme.colors.success.main
142+
: theme.colors.error.main
138143
}}
139-
></Box>
144+
/>
140145
</Line>
141146
</FlexBox>
142147

web-server/src/constants/stream.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ type LogFile = {
55
serviceName: ServiceNames;
66
};
77

8-
type ServiceStatus = {
9-
[key in ServiceNames]: { isUp: boolean };
10-
};
8+
type ServiceStatus = Record<ServiceNames, { isUp: boolean }>;
119

1210
const UPDATE_INTERVAL = 10000;
1311

web-server/src/content/Service/SystemLogs.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,13 @@ import { useRouter } from 'next/router';
33
import { useEffect, useRef, useMemo } from 'react';
44

55
import { ServiceNames } from '@/constants/service';
6-
import { ServiceStatusState } from '@/slices/service';
76
import { useSelector } from '@/store';
87

98
export const SystemLogs = ({ serviceName }: { serviceName: ServiceNames }) => {
109
const router = useRouter();
1110
const containerRef = useRef<HTMLDivElement>(null);
1211

13-
const services = useSelector(
14-
(state: { service: { services: ServiceStatusState } }) =>
15-
state.service.services
16-
);
12+
const services = useSelector((state) => state.service.services);
1713

1814
const logs = useMemo(() => {
1915
return serviceName ? services[serviceName]?.logs || [] : [];

web-server/src/slices/service.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,12 @@ type Service = {
1111
logs: string[];
1212
};
1313

14-
export type ServiceStatusState = {
15-
[key in ServiceNames]: Service;
16-
};
14+
export type ServiceStatusState = Record<ServiceNames, Service>;
1715

1816
type State = {
1917
services: ServiceStatusState;
2018
loading: boolean;
21-
error?: string;
19+
error: string | null;
2220
};
2321

2422
const initialState: State = {
@@ -29,11 +27,11 @@ const initialState: State = {
2927
[ServiceNames.SYNC_SERVER]: { isUp: false, logs: [] }
3028
},
3129
loading: true,
32-
error: undefined
30+
error: null
3331
};
3432

3533
type SetStatusPayload = {
36-
statuses: { [key in ServiceNames]: Status };
34+
statuses: Record<ServiceNames, Status>;
3735
};
3836

3937
export const serviceSlice = createSlice({
@@ -47,11 +45,14 @@ export const serviceSlice = createSlice({
4745
state.loading = false;
4846
const { statuses } = action.payload;
4947

50-
for (const [serviceName, { isUp }] of Object.entries(statuses)) {
51-
if (state.services[serviceName as ServiceNames]) {
52-
state.services[serviceName as ServiceNames].isUp = isUp;
48+
Object.entries(statuses).forEach(([serviceNameKey, { isUp }]) => {
49+
const serviceName = serviceNameKey as ServiceNames;
50+
const service = state.services[serviceName];
51+
52+
if (service) {
53+
service.isUp = isUp;
5354
}
54-
}
55+
});
5556
},
5657
setServiceLogs: (
5758
state,

0 commit comments

Comments
 (0)