Skip to content

Commit 6e021b6

Browse files
authored
chore: record and raise problematic http protocols for each proxy (coder#15917)
Adds warnings to the proxy and proxy health pages on HTTP 1.1, 1.0, 0.9 protocols. Only the performance API can return the HTTP protocol type. We already use the performance API for latency timings, and each proxy could have this issue.
1 parent f0e81ab commit 6e021b6

File tree

3 files changed

+41
-4
lines changed

3 files changed

+41
-4
lines changed

site/src/contexts/useProxyLatency.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ export interface ProxyLatencyReport {
1515
latencyMS: number;
1616
// at is when the latency was recorded.
1717
at: Date;
18+
/**
19+
* nextHopProtocol can determine if HTTP/2 is being used.
20+
* https://developer.mozilla.org/docs/Web/API/PerformanceResourceTiming/nextHopProtocol
21+
*/
22+
nextHopProtocol?: string;
1823
}
1924

2025
interface ProxyLatencyAction {
@@ -151,6 +156,7 @@ export const useProxyLatency = (
151156
// https://developer.mozilla.org/en-US/docs/Web/API/Performance_API/Resource_timing
152157
let latencyMS = 0;
153158
let accurate = false;
159+
let nextHopProtocol: string | undefined = undefined;
154160
if (
155161
"requestStart" in entry &&
156162
(entry as PerformanceResourceTiming).requestStart !== 0
@@ -159,6 +165,7 @@ export const useProxyLatency = (
159165
const timingEntry = entry as PerformanceResourceTiming;
160166
latencyMS = timingEntry.responseStart - timingEntry.requestStart;
161167
accurate = true;
168+
nextHopProtocol = timingEntry.nextHopProtocol;
162169
} else {
163170
// This is the total duration of the request and will be off by a good margin.
164171
// This is a fallback if the better timing is not available.
@@ -175,7 +182,8 @@ export const useProxyLatency = (
175182
latencyMS,
176183
accurate,
177184
at: new Date(),
178-
},
185+
nextHopProtocol: nextHopProtocol,
186+
} as ProxyLatencyReport,
179187
};
180188
dispatchProxyLatencies(update);
181189
// Also save to local storage to persist the latency across page refreshes.

site/src/pages/UserSettingsPage/WorkspaceProxyPage/WorkspaceProxyRow.tsx

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,30 @@ export const ProxyRow: FC<ProxyRowProps> = ({ proxy, latency }) => {
2626
// All users can see healthy/unhealthy, some can see more.
2727
let statusBadge = <ProxyStatus proxy={proxy} />;
2828
let shouldShowMessages = false;
29+
const extraWarnings: string[] = [];
30+
if (latency?.nextHopProtocol) {
31+
switch (latency.nextHopProtocol) {
32+
case "http/0.9":
33+
case "http/1.0":
34+
case "http/1.1":
35+
extraWarnings.push(
36+
// biome-ignore lint/style/useTemplate: easier to read short lines
37+
`Requests to the proxy from current browser are using "${latency.nextHopProtocol}". ` +
38+
"The proxy server might not support HTTP/2. " +
39+
"For usability reasons, HTTP/2 or above is recommended. " +
40+
"Pages may fail to load if the web browser's concurrent " +
41+
"connection limit per host is reached.",
42+
);
43+
}
44+
}
45+
2946
if ("status" in proxy) {
3047
const wsproxy = proxy as WorkspaceProxy;
3148
statusBadge = <DetailedProxyStatus proxy={wsproxy} />;
3249
shouldShowMessages = Boolean(
3350
(wsproxy.status?.report?.warnings &&
3451
wsproxy.status?.report?.warnings.length > 0) ||
52+
extraWarnings.length > 0 ||
3553
(wsproxy.status?.report?.errors &&
3654
wsproxy.status?.report?.errors.length > 0),
3755
);
@@ -76,7 +94,10 @@ export const ProxyRow: FC<ProxyRowProps> = ({ proxy, latency }) => {
7694
colSpan={4}
7795
css={{ padding: "0 !important", borderBottom: 0 }}
7896
>
79-
<ProxyMessagesRow proxy={proxy as WorkspaceProxy} />
97+
<ProxyMessagesRow
98+
proxy={proxy as WorkspaceProxy}
99+
extraWarnings={extraWarnings}
100+
/>
80101
</TableCell>
81102
</TableRow>
82103
)}
@@ -86,9 +107,13 @@ export const ProxyRow: FC<ProxyRowProps> = ({ proxy, latency }) => {
86107

87108
interface ProxyMessagesRowProps {
88109
proxy: WorkspaceProxy;
110+
extraWarnings: string[];
89111
}
90112

91-
const ProxyMessagesRow: FC<ProxyMessagesRowProps> = ({ proxy }) => {
113+
const ProxyMessagesRow: FC<ProxyMessagesRowProps> = ({
114+
proxy,
115+
extraWarnings,
116+
}) => {
92117
const theme = useTheme();
93118

94119
return (
@@ -101,7 +126,7 @@ const ProxyMessagesRow: FC<ProxyMessagesRowProps> = ({ proxy }) => {
101126
title={
102127
<span css={{ color: theme.palette.warning.light }}>Warnings</span>
103128
}
104-
messages={proxy.status?.report?.warnings}
129+
messages={[...(proxy.status?.report?.warnings ?? []), ...extraWarnings]}
105130
/>
106131
</>
107132
);

site/src/testHelpers/entities.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,10 @@ export const MockProxyLatencies: Record<string, ProxyLatencyReport> = {
206206
100) %
207207
250,
208208
at: new Date(),
209+
nextHopProtocol:
210+
proxy.id === "8444931c-0247-4171-842a-569d9f9cbadb"
211+
? "http/1.1"
212+
: "h2",
209213
};
210214
return acc;
211215
},

0 commit comments

Comments
 (0)