-
Notifications
You must be signed in to change notification settings - Fork 72
Option to configure vector and log storages using UI #486
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
Open
rohhann12
wants to merge
3
commits into
maximhq:main
Choose a base branch
from
rohhann12:feat/update-vector-and-log-storage-using-ui
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
"use client"; | ||
|
||
import { Alert, AlertDescription } from "@/components/ui/alert"; | ||
import { Button } from "@/components/ui/button"; | ||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"; | ||
import { Input } from "@/components/ui/input"; | ||
import { Label } from "@/components/ui/label"; | ||
import { Switch } from "@/components/ui/switch"; | ||
import { useGetLogStoreConfigQuery, useUpdateLogStoreConfigMutation } from "@/lib/store"; | ||
import { LogStoreConfig, SQLiteConfig } from "@/lib/types/config"; | ||
import { getErrorMessage } from "@/lib/store"; | ||
import { AlertTriangle, Database, Save } from "lucide-react"; | ||
import { useCallback, useEffect, useState } from "react"; | ||
import { toast } from "sonner"; | ||
|
||
const defaultSQLiteConfig: SQLiteConfig = { | ||
path: "./bifrost.db", | ||
}; | ||
|
||
export default function LogStoreForm() { | ||
const { data: logStoreConfig, isLoading } = useGetLogStoreConfigQuery(); | ||
const [updateLogStoreConfig] = useUpdateLogStoreConfigMutation(); | ||
|
||
const [localConfig, setLocalConfig] = useState<LogStoreConfig>({ | ||
enabled: false, | ||
type: "sqlite", | ||
config: defaultSQLiteConfig, | ||
}); | ||
|
||
const [needsRestart, setNeedsRestart] = useState(false); | ||
const [hasChanges, setHasChanges] = useState(false); | ||
|
||
// Update local config when data is loaded | ||
useEffect(() => { | ||
if (logStoreConfig) { | ||
setLocalConfig(logStoreConfig); | ||
setHasChanges(false); | ||
} | ||
}, [logStoreConfig]); | ||
|
||
// Track changes | ||
useEffect(() => { | ||
if (logStoreConfig) { | ||
const hasConfigChanges = JSON.stringify(localConfig) !== JSON.stringify(logStoreConfig); | ||
setHasChanges(hasConfigChanges); | ||
setNeedsRestart(hasConfigChanges); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. won't this logic not show the alert when we make some change and the just reload the page without restart bifrost? as we are directly making update in the DB via the handlers |
||
} | ||
}, [localConfig, logStoreConfig]); | ||
|
||
const handleEnabledChange = useCallback((enabled: boolean) => { | ||
setLocalConfig(prev => ({ ...prev, enabled })); | ||
}, []); | ||
|
||
const handleSQLiteConfigChange = useCallback((field: keyof SQLiteConfig, value: string) => { | ||
setLocalConfig(prev => ({ | ||
...prev, | ||
config: { | ||
...(prev.config as SQLiteConfig), | ||
[field]: value, | ||
}, | ||
})); | ||
}, []); | ||
|
||
const handleSave = useCallback(async () => { | ||
try { | ||
await updateLogStoreConfig(localConfig).unwrap(); | ||
toast.success("Log store configuration updated successfully."); | ||
setHasChanges(false); | ||
setNeedsRestart(false); | ||
} catch (error) { | ||
toast.error(getErrorMessage(error)); | ||
} | ||
}, [localConfig, updateLogStoreConfig]); | ||
|
||
if (isLoading) { | ||
return <div>Loading log store configuration...</div>; | ||
} | ||
|
||
return ( | ||
<Card> | ||
<CardHeader> | ||
<CardTitle className="flex items-center gap-2"> | ||
<Database className="h-5 w-5" /> | ||
Log Store Configuration | ||
</CardTitle> | ||
<CardDescription> | ||
Configure log store for request and response logging to a SQLite database. | ||
</CardDescription> | ||
</CardHeader> | ||
<CardContent className="space-y-6"> | ||
<div className="flex items-center justify-between space-x-2 rounded-lg border p-4"> | ||
<div className="space-y-0.5"> | ||
<Label htmlFor="log-store-enabled" className="text-sm font-medium"> | ||
Enable Log Store | ||
</Label> | ||
<p className="text-muted-foreground text-sm"> | ||
Enable logging of requests and responses to a SQLite database. This can add 40-60mb of overhead to the system memory. | ||
</p> | ||
</div> | ||
<Switch | ||
id="log-store-enabled" | ||
size="md" | ||
checked={localConfig.enabled} | ||
onCheckedChange={handleEnabledChange} | ||
/> | ||
</div> | ||
|
||
{localConfig.enabled && ( | ||
<> | ||
<div className="space-y-4"> | ||
<h4 className="font-medium">SQLite Configuration</h4> | ||
<div className="space-y-2"> | ||
<Label htmlFor="sqlite-path">Database Path</Label> | ||
<Input | ||
id="sqlite-path" | ||
value={(localConfig.config as SQLiteConfig).path} | ||
onChange={(e) => handleSQLiteConfigChange("path", e.target.value)} | ||
placeholder="./bifrost.db" | ||
/> | ||
<p className="text-muted-foreground text-xs"> | ||
Path to the SQLite database file. Use relative path for current directory or absolute path. | ||
</p> | ||
</div> | ||
</div> | ||
|
||
{needsRestart && ( | ||
<Alert> | ||
<AlertTriangle className="h-4 w-4" /> | ||
<AlertDescription> | ||
Log store configuration changes require a Bifrost service restart to take effect. | ||
</AlertDescription> | ||
</Alert> | ||
)} | ||
|
||
{hasChanges && ( | ||
<div className="flex justify-end"> | ||
<Button onClick={handleSave} className="flex items-center gap-2"> | ||
<Save className="h-4 w-4" /> | ||
Save Configuration | ||
</Button> | ||
</div> | ||
)} | ||
</> | ||
)} | ||
</CardContent> | ||
</Card> | ||
); | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.