feat: hide performance menu item if disabled (#832)
Hide the Performance UI item of the navigation bar if its disabled.
This commit is contained in:
@@ -105,7 +105,9 @@ func (s *Server) handleAPIMetrics(w http.ResponseWriter, r *http.Request) {
|
|||||||
// filtered to samples after the ?after=<RFC3339> timestamp.
|
// filtered to samples after the ?after=<RFC3339> timestamp.
|
||||||
func (s *Server) handleAPIPerformance(w http.ResponseWriter, r *http.Request) {
|
func (s *Server) handleAPIPerformance(w http.ResponseWriter, r *http.Request) {
|
||||||
if s.perf == nil {
|
if s.perf == nil {
|
||||||
shared.SendResponse(w, r, http.StatusServiceUnavailable, "performance monitor not available")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
w.WriteHeader(http.StatusServiceUnavailable)
|
||||||
|
json.NewEncoder(w).Encode(map[string]bool{"enabled": false})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -136,6 +138,7 @@ func (s *Server) handleAPIPerformance(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
json.NewEncoder(w).Encode(map[string]any{
|
json.NewEncoder(w).Encode(map[string]any{
|
||||||
|
"enabled": true,
|
||||||
"sys_stats": sysStats,
|
"sys_stats": sysStats,
|
||||||
"gpu_stats": gpuStats,
|
"gpu_stats": gpuStats,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
import Performance from "./routes/Performance.svelte";
|
import Performance from "./routes/Performance.svelte";
|
||||||
import Playground from "./routes/Playground.svelte";
|
import Playground from "./routes/Playground.svelte";
|
||||||
import PlaygroundStub from "./routes/PlaygroundStub.svelte";
|
import PlaygroundStub from "./routes/PlaygroundStub.svelte";
|
||||||
import { enableAPIEvents } from "./stores/api";
|
import { enableAPIEvents, checkPerformanceEnabled } from "./stores/api";
|
||||||
import { initScreenWidth, initSystemThemeListener, isDarkMode, appTitle, connectionState } from "./stores/theme";
|
import { initScreenWidth, initSystemThemeListener, isDarkMode, appTitle, connectionState } from "./stores/theme";
|
||||||
import { currentRoute } from "./stores/route";
|
import { currentRoute } from "./stores/route";
|
||||||
|
|
||||||
@@ -39,6 +39,7 @@
|
|||||||
const cleanupScreenWidth = initScreenWidth();
|
const cleanupScreenWidth = initScreenWidth();
|
||||||
const cleanupSystemTheme = initSystemThemeListener();
|
const cleanupSystemTheme = initSystemThemeListener();
|
||||||
enableAPIEvents(true);
|
enableAPIEvents(true);
|
||||||
|
checkPerformanceEnabled();
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
cleanupScreenWidth();
|
cleanupScreenWidth();
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
import { screenWidth, toggleTheme, themeMode, appTitle, isNarrow } from "../stores/theme";
|
import { screenWidth, toggleTheme, themeMode, appTitle, isNarrow } from "../stores/theme";
|
||||||
import { currentRoute } from "../stores/route";
|
import { currentRoute } from "../stores/route";
|
||||||
import { playgroundActivity } from "../stores/playgroundActivity";
|
import { playgroundActivity } from "../stores/playgroundActivity";
|
||||||
|
import { performanceEnabled } from "../stores/api";
|
||||||
import ConnectionStatus from "./ConnectionStatus.svelte";
|
import ConnectionStatus from "./ConnectionStatus.svelte";
|
||||||
|
|
||||||
function handleTitleChange(newTitle: string): void {
|
function handleTitleChange(newTitle: string): void {
|
||||||
@@ -84,6 +85,7 @@
|
|||||||
>
|
>
|
||||||
Logs
|
Logs
|
||||||
</a>
|
</a>
|
||||||
|
{#if $performanceEnabled}
|
||||||
<a
|
<a
|
||||||
href="/performance"
|
href="/performance"
|
||||||
use:link
|
use:link
|
||||||
@@ -94,6 +96,7 @@
|
|||||||
>
|
>
|
||||||
Performance
|
Performance
|
||||||
</a>
|
</a>
|
||||||
|
{/if}
|
||||||
<button onclick={toggleTheme} title="Toggle theme (current: {$themeMode})">
|
<button onclick={toggleTheme} title="Toggle theme (current: {$themeMode})">
|
||||||
{#if $themeMode === "system"}
|
{#if $themeMode === "system"}
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" class="w-5 h-5">
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" class="w-5 h-5">
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ export const proxyLogs = writable<string>("");
|
|||||||
export const upstreamLogs = writable<string>("");
|
export const upstreamLogs = writable<string>("");
|
||||||
export const metrics = writable<ActivityLogEntry[]>([]);
|
export const metrics = writable<ActivityLogEntry[]>([]);
|
||||||
export const inFlightRequests = writable<number>(0);
|
export const inFlightRequests = writable<number>(0);
|
||||||
|
export const performanceEnabled = writable<boolean>(false);
|
||||||
export const versionInfo = writable<VersionInfo>({
|
export const versionInfo = writable<VersionInfo>({
|
||||||
build_date: "unknown",
|
build_date: "unknown",
|
||||||
commit: "unknown",
|
commit: "unknown",
|
||||||
@@ -210,6 +211,20 @@ export async function getCapture(id: number): Promise<ReqRespCapture | null> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function checkPerformanceEnabled(): Promise<void> {
|
||||||
|
try {
|
||||||
|
const response = await fetch("/api/performance");
|
||||||
|
if (!response.ok) {
|
||||||
|
performanceEnabled.set(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const data = await response.json();
|
||||||
|
performanceEnabled.set(data.enabled);
|
||||||
|
} catch {
|
||||||
|
performanceEnabled.set(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export async function fetchPerformance(after?: string): Promise<PerformanceResponse | null> {
|
export async function fetchPerformance(after?: string): Promise<PerformanceResponse | null> {
|
||||||
try {
|
try {
|
||||||
const url = after ? `/api/performance?after=${encodeURIComponent(after)}` : "/api/performance";
|
const url = after ? `/api/performance?after=${encodeURIComponent(after)}` : "/api/performance";
|
||||||
|
|||||||
Reference in New Issue
Block a user