mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 02:27:26 +01:00
admin: indexed metadata keys panel on the S3 Vectors bucket page
Each index of a vector bucket gets a card: dimension, metric, vectors and vector index type; its indexed metadata keys with state, coverage of the table's rows, filtered queries per hour and index size, with Remove for a ready key and Cancel for a requested or building one; and the keys its queries filtered on most in the last hour that are not indexed, with their average latency. A key filtered only with numbers is marked "(numeric: phase 2)" and has no Index button. "+ Index a key" and a listed key's Index button open a dialog for the key, which refuses the index's non-filterable keys. Adding or removing goes through the engine; the admin then dispatches the lance_metadata_index job for that key when a worker can run it, and detection finds it otherwise. Filter stats are read from every registered engine and summed per hour over each engine's window. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011UpvafvK8JpagF94MHWqwK
This commit is contained in:
1 parent
5b85272687
commit
82df627a24
7 files changed
+1063
-24
No files matched your search
@@ -12,6 +12,7 @@ import (
|
||||
"github.com/seaweedfs/seaweedfs/weed/s3api/s3_constants"
|
||||
"github.com/seaweedfs/seaweedfs/weed/s3api/s3tables"
|
||||
"github.com/seaweedfs/seaweedfs/weed/s3api/s3vectors"
|
||||
"golang.org/x/sync/errgroup"
|
||||
)
|
||||
|
||||
type S3VectorsBucketsData struct {
|
||||
@@ -36,6 +37,7 @@ type S3VectorsBucketData struct {
|
||||
Bucket S3VectorsBucketSummary `json:"bucket"`
|
||||
Policy string `json:"policy,omitempty"`
|
||||
Indexes []*s3vectors.Index `json:"indexes"`
|
||||
Panels []S3VectorsIndexPanel `json:"panels"`
|
||||
Operations VectorOperationsData `json:"operations"`
|
||||
TotalIndexes int `json:"total_indexes"`
|
||||
Truncated bool `json:"truncated,omitempty"`
|
||||
@@ -159,6 +161,16 @@ func (s *AdminServer) GetS3VectorsBucketData(ctx context.Context, bucket string)
|
||||
}
|
||||
data.Operations = s.GetVectorOperationsData(ctx)
|
||||
data.TotalIndexes = len(data.Indexes)
|
||||
data.Panels = make([]S3VectorsIndexPanel, len(data.Indexes))
|
||||
var panels errgroup.Group
|
||||
panels.SetLimit(8)
|
||||
for i, index := range data.Indexes {
|
||||
panels.Go(func() error {
|
||||
data.Panels[i] = s.s3VectorsIndexPanel(ctx, bucket, index, data.Operations.Engines)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
_ = panels.Wait()
|
||||
return data, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,260 @@
|
||||
package dash
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"sort"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/seaweedfs/seaweedfs/weed/glog"
|
||||
"github.com/seaweedfs/seaweedfs/weed/pb"
|
||||
"github.com/seaweedfs/seaweedfs/weed/pb/plugin_pb"
|
||||
"github.com/seaweedfs/seaweedfs/weed/pb/vector_pb"
|
||||
"github.com/seaweedfs/seaweedfs/weed/s3api/s3vectors"
|
||||
"golang.org/x/sync/errgroup"
|
||||
)
|
||||
|
||||
// metadataIndexJobType is the worker job that adds, maintains and removes
|
||||
// indexed metadata keys.
|
||||
const metadataIndexJobType = "lance_metadata_index"
|
||||
|
||||
// frequentFilterKeys caps the "frequently filtered, not indexed" list.
|
||||
const frequentFilterKeys = 10
|
||||
|
||||
// S3VectorsIndexPanel is one index's card on the bucket page: its vector
|
||||
// count and vector index, its indexed metadata keys, and the keys its
|
||||
// queries filter on most that are not indexed.
|
||||
type S3VectorsIndexPanel struct {
|
||||
Index *s3vectors.Index `json:"index"`
|
||||
Vectors uint64 `json:"vectors"`
|
||||
VectorIndex string `json:"vector_index"`
|
||||
Keys []S3VectorsMetadataKeyRow `json:"keys"`
|
||||
Frequent []S3VectorsFilterKeyRow `json:"frequent"`
|
||||
Error string `json:"error,omitempty"`
|
||||
StatsError string `json:"stats_error,omitempty"`
|
||||
stats map[string]*filterKeyTotal `json:"-"`
|
||||
}
|
||||
|
||||
type S3VectorsMetadataKeyRow struct {
|
||||
Key string `json:"key"`
|
||||
State string `json:"state"`
|
||||
Coverage float64 `json:"coverage"`
|
||||
QueriesPerHour float64 `json:"queries_per_hour"`
|
||||
IndexBytes uint64 `json:"index_bytes"`
|
||||
}
|
||||
|
||||
type S3VectorsFilterKeyRow struct {
|
||||
Key string `json:"key"`
|
||||
QueriesPerHour float64 `json:"queries_per_hour"`
|
||||
AvgMs float64 `json:"avg_ms"`
|
||||
// Numeric marks a key filtered only with numbers, which phase 1 does
|
||||
// not index.
|
||||
Numeric bool `json:"numeric"`
|
||||
}
|
||||
|
||||
type filterKeyTotal struct {
|
||||
perHour float64
|
||||
seconds float64
|
||||
queries uint64
|
||||
strings bool
|
||||
numbers bool
|
||||
}
|
||||
|
||||
// s3VectorsIndexPanel reads one index's keys from its table through an
|
||||
// engine, and its filter stats from every registered engine.
|
||||
func (s *AdminServer) s3VectorsIndexPanel(ctx context.Context, bucket string, index *s3vectors.Index, engines []VectorNode) S3VectorsIndexPanel {
|
||||
panel := S3VectorsIndexPanel{Index: index, Keys: []S3VectorsMetadataKeyRow{}, Frequent: []S3VectorsFilterKeyRow{}}
|
||||
keys, err := s.s3VectorsServer.MetadataKeys(ctx, bucket, index.IndexName)
|
||||
if err != nil {
|
||||
panel.Error = err.Error()
|
||||
}
|
||||
stats, err := s.s3VectorsFilterStats(ctx, bucket, index.IndexName, engines)
|
||||
if err != nil {
|
||||
panel.StatsError = err.Error()
|
||||
}
|
||||
panel.stats = stats
|
||||
indexed := map[string]bool{}
|
||||
if keys != nil {
|
||||
panel.Vectors = keys.Rows
|
||||
panel.VectorIndex = keys.VectorIndex
|
||||
for _, k := range keys.Keys {
|
||||
indexed[k.Key] = true
|
||||
row := S3VectorsMetadataKeyRow{Key: k.Key, State: k.State, IndexBytes: k.IndexBytes}
|
||||
if k.Rows > 0 {
|
||||
row.Coverage = float64(k.IndexedRows) * 100 / float64(k.Rows)
|
||||
}
|
||||
if total := stats[k.Key]; total != nil {
|
||||
row.QueriesPerHour = total.perHour
|
||||
}
|
||||
panel.Keys = append(panel.Keys, row)
|
||||
}
|
||||
}
|
||||
nonFilterable := map[string]bool{}
|
||||
if index.MetadataConfiguration != nil {
|
||||
for _, k := range index.MetadataConfiguration.NonFilterableMetadataKeys {
|
||||
nonFilterable[k] = true
|
||||
}
|
||||
}
|
||||
for key, total := range stats {
|
||||
if indexed[key] || nonFilterable[key] || (!total.strings && !total.numbers) {
|
||||
continue
|
||||
}
|
||||
row := S3VectorsFilterKeyRow{Key: key, QueriesPerHour: total.perHour, Numeric: !total.strings}
|
||||
if total.queries > 0 {
|
||||
row.AvgMs = total.seconds * 1000 / float64(total.queries)
|
||||
}
|
||||
panel.Frequent = append(panel.Frequent, row)
|
||||
}
|
||||
sort.Slice(panel.Frequent, func(i, j int) bool {
|
||||
if panel.Frequent[i].QueriesPerHour != panel.Frequent[j].QueriesPerHour {
|
||||
return panel.Frequent[i].QueriesPerHour > panel.Frequent[j].QueriesPerHour
|
||||
}
|
||||
return panel.Frequent[i].Key < panel.Frequent[j].Key
|
||||
})
|
||||
if len(panel.Frequent) > frequentFilterKeys {
|
||||
panel.Frequent = panel.Frequent[:frequentFilterKeys]
|
||||
}
|
||||
return panel
|
||||
}
|
||||
|
||||
// s3VectorsFilterStats sums an index's filter stats over the engines, each
|
||||
// counted per hour over its own window.
|
||||
func (s *AdminServer) s3VectorsFilterStats(ctx context.Context, bucket, index string, engines []VectorNode) (map[string]*filterKeyTotal, error) {
|
||||
responses := make([]*vector_pb.FilterStatsResponse, len(engines))
|
||||
errs := make([]error, len(engines))
|
||||
var calls errgroup.Group
|
||||
calls.SetLimit(8)
|
||||
for i, engine := range engines {
|
||||
calls.Go(func() error {
|
||||
ctx, cancel := context.WithTimeout(ctx, 3*time.Second)
|
||||
defer cancel()
|
||||
conn, err := pb.GrpcDial(ctx, engine.Address, false, s.grpcDialOption)
|
||||
if err != nil {
|
||||
errs[i] = err
|
||||
return nil
|
||||
}
|
||||
defer conn.Close()
|
||||
responses[i], errs[i] = vector_pb.NewVectorServiceClient(conn).FilterStats(ctx, &vector_pb.FilterStatsRequest{
|
||||
Table: &vector_pb.Table{Id: []string{bucket, "vector", index}},
|
||||
})
|
||||
return nil
|
||||
})
|
||||
}
|
||||
_ = calls.Wait()
|
||||
return sumFilterStats(responses), firstError(engines, errs)
|
||||
}
|
||||
|
||||
func sumFilterStats(responses []*vector_pb.FilterStatsResponse) map[string]*filterKeyTotal {
|
||||
out := map[string]*filterKeyTotal{}
|
||||
for _, resp := range responses {
|
||||
if resp == nil || resp.WindowSeconds == 0 {
|
||||
continue
|
||||
}
|
||||
for _, k := range resp.Keys {
|
||||
total := out[k.Key]
|
||||
if total == nil {
|
||||
total = &filterKeyTotal{}
|
||||
out[k.Key] = total
|
||||
}
|
||||
total.perHour += float64(k.Queries) * 3600 / float64(resp.WindowSeconds)
|
||||
total.queries += k.Queries
|
||||
total.seconds += k.Seconds
|
||||
total.strings = total.strings || k.StringOperand
|
||||
total.numbers = total.numbers || k.NumberOperand
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func firstError(engines []VectorNode, errs []error) error {
|
||||
for i, err := range errs {
|
||||
if err != nil {
|
||||
return fmt.Errorf("filter stats from %s: %w", engines[i].Address, err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// UpdateS3VectorsMetadataKeyAPI asks to index a metadata key (POST) or to
|
||||
// stop (DELETE), then dispatches the worker job that carries it out.
|
||||
func (s *AdminServer) UpdateS3VectorsMetadataKeyAPI(w http.ResponseWriter, r *http.Request) {
|
||||
if !requireSessionCSRFToken(w, r) {
|
||||
return
|
||||
}
|
||||
var req struct {
|
||||
Bucket string `json:"bucket"`
|
||||
Index string `json:"index"`
|
||||
Key string `json:"key"`
|
||||
}
|
||||
if r.Method == http.MethodDelete {
|
||||
q := r.URL.Query()
|
||||
req.Bucket, req.Index, req.Key = q.Get("bucket"), q.Get("index"), q.Get("key")
|
||||
} else if err := json.NewDecoder(http.MaxBytesReader(w, r.Body, 1<<16)).Decode(&req); err != nil {
|
||||
writeJSONError(w, http.StatusBadRequest, "invalid request body: "+err.Error())
|
||||
return
|
||||
}
|
||||
if req.Bucket == "" || req.Index == "" || req.Key == "" {
|
||||
writeJSONError(w, http.StatusBadRequest, "bucket, index and key are required")
|
||||
return
|
||||
}
|
||||
remove := r.Method == http.MethodDelete
|
||||
keys, err := s.s3VectorsServer.UpdateMetadataKey(r.Context(), req.Bucket, req.Index, req.Key, remove)
|
||||
if err != nil {
|
||||
writeJSONError(w, http.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
// A withdrawn request leaves nothing for a worker to do.
|
||||
action := "add"
|
||||
if remove {
|
||||
action = ""
|
||||
for _, k := range keys.GetKeys() {
|
||||
if k.Key == req.Key && k.State == "off" {
|
||||
action = "remove"
|
||||
}
|
||||
}
|
||||
}
|
||||
dispatched := false
|
||||
if action != "" {
|
||||
dispatched = s.dispatchMetadataIndexJob(req.Bucket, req.Index, req.Key, action)
|
||||
}
|
||||
writeJSON(w, http.StatusOK, map[string]interface{}{"keys": keys.GetKeys(), "job_dispatched": dispatched})
|
||||
}
|
||||
|
||||
// dispatchMetadataIndexJob runs the job for one key in the background when
|
||||
// a worker can; otherwise the job's detection finds the work.
|
||||
func (s *AdminServer) dispatchMetadataIndexJob(bucket, index, key, action string) bool {
|
||||
if s.plugin == nil || !s.hasCapableWorker(metadataIndexJobType) {
|
||||
return false
|
||||
}
|
||||
job := &plugin_pb.JobSpec{
|
||||
JobId: uuid.NewString(),
|
||||
JobType: metadataIndexJobType,
|
||||
DedupeKey: fmt.Sprintf("%s:%s$vector$%s:%s:%s", metadataIndexJobType, bucket, index, key, action),
|
||||
Summary: fmt.Sprintf("%s metadata key %s of %s/%s", action, key, bucket, index),
|
||||
Parameters: map[string]*plugin_pb.ConfigValue{
|
||||
"table_id": {Kind: &plugin_pb.ConfigValue_StringList{StringList: &plugin_pb.StringList{Values: []string{bucket, "vector", index}}}},
|
||||
"key": {Kind: &plugin_pb.ConfigValue_StringValue{StringValue: key}},
|
||||
"action": {Kind: &plugin_pb.ConfigValue_StringValue{StringValue: action}},
|
||||
},
|
||||
}
|
||||
go func() {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Hour)
|
||||
defer cancel()
|
||||
if _, err := s.ExecutePluginJob(ctx, job, s.buildDefaultPluginClusterContext(), 1); err != nil {
|
||||
glog.Warningf("%s for %s/%s key %s: %v", metadataIndexJobType, bucket, index, key, err)
|
||||
}
|
||||
}()
|
||||
return true
|
||||
}
|
||||
|
||||
func (s *AdminServer) hasCapableWorker(jobType string) bool {
|
||||
for _, worker := range s.GetPluginWorkers() {
|
||||
if capability := worker.Capabilities[jobType]; capability != nil && capability.CanExecute {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package dash
|
||||
|
||||
import (
|
||||
"math"
|
||||
"testing"
|
||||
|
||||
"github.com/seaweedfs/seaweedfs/weed/pb/vector_pb"
|
||||
)
|
||||
|
||||
func TestSumFilterStatsPerHourAcrossEngines(t *testing.T) {
|
||||
got := sumFilterStats([]*vector_pb.FilterStatsResponse{
|
||||
{WindowSeconds: 3600, Keys: []*vector_pb.FilterKeyStats{
|
||||
{Key: "author", Queries: 100, Seconds: 2, StringOperand: true},
|
||||
{Key: "year", Queries: 10, Seconds: 0.5, NumberOperand: true},
|
||||
}},
|
||||
// An engine up for half an hour counts double per hour.
|
||||
{WindowSeconds: 1800, Keys: []*vector_pb.FilterKeyStats{
|
||||
{Key: "author", Queries: 50, Seconds: 1, StringOperand: true},
|
||||
}},
|
||||
nil,
|
||||
{WindowSeconds: 0, Keys: []*vector_pb.FilterKeyStats{{Key: "ignored", Queries: 5}}},
|
||||
})
|
||||
author := got["author"]
|
||||
if author == nil || math.Abs(author.perHour-200) > 1e-9 || author.queries != 150 || math.Abs(author.seconds-3) > 1e-9 || !author.strings {
|
||||
t.Fatalf("author: %+v", author)
|
||||
}
|
||||
if year := got["year"]; year == nil || year.strings || !year.numbers || year.perHour != 10 {
|
||||
t.Fatalf("year: %+v", year)
|
||||
}
|
||||
if _, ok := got["ignored"]; ok {
|
||||
t.Fatal("an engine with no window must not count")
|
||||
}
|
||||
}
|
||||
@@ -264,6 +264,7 @@ func (h *AdminHandlers) registerAPIRoutes(api *mux.Router, enforceWrite bool) {
|
||||
s3VectorsApi.Handle("/buckets", wrapWrite(h.adminServer.DeleteS3VectorsBucket)).Methods(http.MethodDelete)
|
||||
s3VectorsApi.HandleFunc("/indexes", h.adminServer.GetS3VectorsBucketAPI).Methods(http.MethodGet)
|
||||
s3VectorsApi.Handle("/indexes", wrapWrite(h.adminServer.DeleteS3VectorsIndex)).Methods(http.MethodDelete)
|
||||
s3VectorsApi.Handle("/metadata-keys", wrapWrite(h.adminServer.UpdateS3VectorsMetadataKeyAPI)).Methods(http.MethodPost, http.MethodDelete)
|
||||
|
||||
filesApi := api.PathPrefix("/files").Subrouter()
|
||||
filesApi.Handle("/delete", wrapWrite(h.fileBrowserHandlers.DeleteFile)).Methods(http.MethodDelete)
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/seaweedfs/seaweedfs/weed/admin/dash"
|
||||
"github.com/seaweedfs/seaweedfs/weed/s3api/s3vectors"
|
||||
)
|
||||
|
||||
templ S3VectorsBucketDetails(data dash.S3VectorsBucketData) {
|
||||
@@ -103,6 +104,9 @@ templ S3VectorsBucketDetails(data dash.S3VectorsBucketData) {
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
for _, panel := range data.Panels {
|
||||
@S3VectorsIndexPanel(panel)
|
||||
}
|
||||
<div class="card shadow mb-4">
|
||||
<div class="card-header py-3">
|
||||
<h6 class="m-0 font-weight-bold text-primary">
|
||||
@@ -138,6 +142,30 @@ templ S3VectorsBucketDetails(data dash.S3VectorsBucketData) {
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal fade" id="indexS3VectorsMetadataKeyModal" tabindex="-1" aria-labelledby="indexS3VectorsMetadataKeyModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="indexS3VectorsMetadataKeyModalLabel">
|
||||
<i class="bi bi-tags me-2"></i>Index a metadata key of <span id="indexS3VectorsMetadataKeyIndex"></span>
|
||||
</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<label for="indexS3VectorsMetadataKeyName" class="form-label">Metadata key</label>
|
||||
<input type="text" class="form-control" id="indexS3VectorsMetadataKeyName" autocomplete="off"/>
|
||||
<div class="form-text">Filters comparing this key with strings ($eq, $in) read its index instead of every row's metadata. Results do not change.</div>
|
||||
<div class="text-danger small mt-2" id="indexS3VectorsMetadataKeyError"></div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
|
||||
<button type="button" class="btn btn-primary" id="indexS3VectorsMetadataKeyBtn">
|
||||
<i class="bi bi-plus-lg me-1"></i>Index
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="s3vectorsBucketDetails" data-bucket-name={ data.Bucket.Name }></div>
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
@@ -151,6 +179,65 @@ templ S3VectorsBucketDetails(data dash.S3VectorsBucketData) {
|
||||
modal.show();
|
||||
});
|
||||
});
|
||||
async function updateMetadataKey(index, key, remove) {
|
||||
const url = remove
|
||||
? '/api/s3vectors/metadata-keys?bucket=' + encodeURIComponent(bucket) + '&index=' + encodeURIComponent(index) + '&key=' + encodeURIComponent(key)
|
||||
: '/api/s3vectors/metadata-keys';
|
||||
const options = { method: remove ? 'DELETE' : 'POST', headers: s3tWriteHeaders() };
|
||||
if (!remove) {
|
||||
options.headers = Object.assign({ 'Content-Type': 'application/json' }, options.headers);
|
||||
options.body = JSON.stringify({ bucket: bucket, index: index, key: key });
|
||||
}
|
||||
const response = await fetch(s3tBasePath(url), options);
|
||||
const data = await response.json();
|
||||
if (!response.ok) {
|
||||
throw new Error(data.error || 'request failed');
|
||||
}
|
||||
return data;
|
||||
}
|
||||
const keyModalEl = document.getElementById('indexS3VectorsMetadataKeyModal');
|
||||
const keyModal = new bootstrap.Modal(keyModalEl);
|
||||
const keyInput = document.getElementById('indexS3VectorsMetadataKeyName');
|
||||
const keyError = document.getElementById('indexS3VectorsMetadataKeyError');
|
||||
document.querySelectorAll('.s3vectors-index-key-btn').forEach(button => {
|
||||
button.addEventListener('click', function () {
|
||||
keyModalEl.dataset.indexName = this.dataset.indexName || '';
|
||||
keyModalEl.dataset.nonFilterable = this.dataset.nonFilterable || '[]';
|
||||
document.getElementById('indexS3VectorsMetadataKeyIndex').textContent = this.dataset.indexName || '';
|
||||
keyInput.value = this.dataset.key || '';
|
||||
keyError.textContent = '';
|
||||
keyModal.show();
|
||||
});
|
||||
});
|
||||
document.getElementById('indexS3VectorsMetadataKeyBtn').addEventListener('click', async function () {
|
||||
const index = keyModalEl.dataset.indexName;
|
||||
const key = keyInput.value.trim();
|
||||
if (!key) {
|
||||
keyError.textContent = 'Enter a metadata key.';
|
||||
return;
|
||||
}
|
||||
if (JSON.parse(keyModalEl.dataset.nonFilterable || '[]').includes(key)) {
|
||||
keyError.textContent = key + ' is a non-filterable key of this index and cannot be indexed.';
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await updateMetadataKey(index, key, false);
|
||||
location.reload();
|
||||
} catch (error) {
|
||||
keyError.textContent = error.message;
|
||||
}
|
||||
});
|
||||
document.querySelectorAll('.s3vectors-remove-key-btn').forEach(button => {
|
||||
button.addEventListener('click', async function () {
|
||||
if (!confirm((this.dataset.action || 'Remove') + ' the index of metadata key ' + this.dataset.key + '?')) return;
|
||||
try {
|
||||
await updateMetadataKey(this.dataset.indexName, this.dataset.key, true);
|
||||
location.reload();
|
||||
} catch (error) {
|
||||
alert(error.message);
|
||||
}
|
||||
});
|
||||
});
|
||||
document.getElementById('deleteS3VectorsIndexBtn').addEventListener('click', async function () {
|
||||
const index = modalEl.dataset.indexName;
|
||||
if (!bucket || !index) return;
|
||||
@@ -170,6 +257,141 @@ templ S3VectorsBucketDetails(data dash.S3VectorsBucketData) {
|
||||
</script>
|
||||
}
|
||||
|
||||
templ S3VectorsIndexPanel(panel dash.S3VectorsIndexPanel) {
|
||||
<div class="card shadow mb-4 s3vectors-index-panel" data-index-name={ panel.Index.IndexName }>
|
||||
<div class="card-header py-3">
|
||||
<h6 class="m-0 font-weight-bold text-primary">
|
||||
<i class="bi bi-diagram-3 me-2"></i>Index: { panel.Index.IndexName }
|
||||
</h6>
|
||||
<div class="small text-muted mt-1">
|
||||
{ fmt.Sprintf("Dimension %d", panel.Index.Dimension) } · { panel.Index.DistanceMetric } · { groupDigits(float64(panel.Vectors)) } vectors · Vector index:
|
||||
if panel.VectorIndex != "" {
|
||||
{ panel.VectorIndex }
|
||||
} else {
|
||||
none (exact scan)
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
if panel.Error != "" {
|
||||
<div class="alert alert-warning py-2 small">{ panel.Error }</div>
|
||||
}
|
||||
<div class="d-flex justify-content-between align-items-center mb-2">
|
||||
<strong>Metadata indexes</strong>
|
||||
<button type="button" class="btn btn-outline-primary btn-sm s3vectors-index-key-btn" data-index-name={ panel.Index.IndexName } data-non-filterable={ nonFilterableJSON(panel.Index) }>
|
||||
<i class="bi bi-plus-lg me-1"></i>Index a key
|
||||
</button>
|
||||
</div>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-sm table-hover mb-3">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Key</th>
|
||||
<th>State</th>
|
||||
<th>Coverage</th>
|
||||
<th>Filtered queries/h</th>
|
||||
<th>Size</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
for _, key := range panel.Keys {
|
||||
<tr>
|
||||
<td><code>{ key.Key }</code></td>
|
||||
<td>{ keyState(key.State) }</td>
|
||||
<td>
|
||||
if key.State == "requested" {
|
||||
—
|
||||
} else {
|
||||
{ fmt.Sprintf("%.0f%%", key.Coverage) }
|
||||
}
|
||||
</td>
|
||||
<td>{ groupDigits(key.QueriesPerHour) }</td>
|
||||
<td>
|
||||
if key.IndexBytes > 0 {
|
||||
{ fmt.Sprintf("%.1f MiB", float64(key.IndexBytes)/(1<<20)) }
|
||||
} else {
|
||||
—
|
||||
}
|
||||
</td>
|
||||
<td>
|
||||
if key.State == "ready" {
|
||||
<button type="button" class="btn btn-link btn-sm p-0 text-danger s3vectors-remove-key-btn" data-index-name={ panel.Index.IndexName } data-key={ key.Key } data-action="Remove">Remove</button>
|
||||
} else if key.State == "requested" || key.State == "building" {
|
||||
<button type="button" class="btn btn-link btn-sm p-0 s3vectors-remove-key-btn" data-index-name={ panel.Index.IndexName } data-key={ key.Key } data-action="Cancel">Cancel</button>
|
||||
}
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
if len(panel.Keys) == 0 {
|
||||
<tr>
|
||||
<td colspan="6" class="text-center text-muted">No indexed metadata keys.</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<strong>Frequently filtered, not indexed</strong>
|
||||
if panel.StatsError != "" {
|
||||
<div class="text-muted small">{ panel.StatsError }</div>
|
||||
}
|
||||
if len(panel.Frequent) == 0 {
|
||||
<div class="text-muted small mt-1">No filtered queries in the last hour on keys without an index.</div>
|
||||
}
|
||||
<ul class="list-unstyled mt-1 mb-0">
|
||||
for _, key := range panel.Frequent {
|
||||
<li class="d-flex align-items-center py-1">
|
||||
<code class="me-3">{ key.Key }</code>
|
||||
<span class="me-3">{ groupDigits(key.QueriesPerHour) } queries/h</span>
|
||||
<span class="me-3 text-muted">{ fmt.Sprintf("avg %.0f ms", key.AvgMs) }</span>
|
||||
if key.Numeric {
|
||||
<span class="text-muted small">(numeric: phase 2)</span>
|
||||
} else {
|
||||
<button type="button" class="btn btn-outline-primary btn-sm ms-auto s3vectors-index-key-btn" data-index-name={ panel.Index.IndexName } data-key={ key.Key } data-non-filterable={ nonFilterableJSON(panel.Index) }>Index</button>
|
||||
}
|
||||
</li>
|
||||
}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
func keyState(state string) string {
|
||||
switch state {
|
||||
case "requested":
|
||||
return "Requested"
|
||||
case "building":
|
||||
return "Building"
|
||||
case "ready":
|
||||
return "Ready"
|
||||
case "off":
|
||||
return "Removing"
|
||||
}
|
||||
return state
|
||||
}
|
||||
|
||||
// groupDigits renders n rounded, with thousands separators.
|
||||
func groupDigits(n float64) string {
|
||||
digits := fmt.Sprintf("%.0f", n)
|
||||
var out []byte
|
||||
for i := range digits {
|
||||
if i > 0 && (len(digits)-i)%3 == 0 {
|
||||
out = append(out, ',')
|
||||
}
|
||||
out = append(out, digits[i])
|
||||
}
|
||||
return string(out)
|
||||
}
|
||||
|
||||
func nonFilterableJSON(index *s3vectors.Index) string {
|
||||
keys := []string{}
|
||||
if index.MetadataConfiguration != nil {
|
||||
keys = index.MetadataConfiguration.NonFilterableMetadataKeys
|
||||
}
|
||||
b, _ := json.Marshal(keys)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
const maxIndentedJSONDepth = 32
|
||||
|
||||
func indentJSON(s string) string {
|
||||
|
||||
@@ -16,6 +16,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/seaweedfs/seaweedfs/weed/admin/dash"
|
||||
"github.com/seaweedfs/seaweedfs/weed/s3api/s3vectors"
|
||||
)
|
||||
|
||||
func S3VectorsBucketDetails(data dash.S3VectorsBucketData) templ.Component {
|
||||
@@ -42,7 +43,7 @@ func S3VectorsBucketDetails(data dash.S3VectorsBucketData) templ.Component {
|
||||
var templ_7745c5c3_Var2 string
|
||||
templ_7745c5c3_Var2, templ_7745c5c3_Err = templ.JoinStringErrs(data.Bucket.Name)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/s3vectors_bucket_details.templ`, Line: 16, Col: 63}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/s3vectors_bucket_details.templ`, Line: 17, Col: 63}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var2))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -55,7 +56,7 @@ func S3VectorsBucketDetails(data dash.S3VectorsBucketData) templ.Component {
|
||||
var templ_7745c5c3_Var3 string
|
||||
templ_7745c5c3_Var3, templ_7745c5c3_Err = templruntime.NewAttributeExpression(dash.PUrl(ctx, "/object-store/vector-buckets")).ResolveURL(ctx)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/s3vectors_bucket_details.templ`, Line: 20, Col: 89}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/s3vectors_bucket_details.templ`, Line: 21, Col: 89}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var3)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -68,7 +69,7 @@ func S3VectorsBucketDetails(data dash.S3VectorsBucketData) templ.Component {
|
||||
var templ_7745c5c3_Var4 string
|
||||
templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(data.Bucket.Name)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/s3vectors_bucket_details.templ`, Line: 21, Col: 78}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/s3vectors_bucket_details.templ`, Line: 22, Col: 78}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -93,7 +94,7 @@ func S3VectorsBucketDetails(data dash.S3VectorsBucketData) templ.Component {
|
||||
var templ_7745c5c3_Var5 string
|
||||
templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(data.Bucket.ARN)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/s3vectors_bucket_details.templ`, Line: 32, Col: 49}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/s3vectors_bucket_details.templ`, Line: 33, Col: 49}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -106,7 +107,7 @@ func S3VectorsBucketDetails(data dash.S3VectorsBucketData) templ.Component {
|
||||
var templ_7745c5c3_Var6 string
|
||||
templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(data.Bucket.CreatedAt.Format("2006-01-02 15:04:05"))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/s3vectors_bucket_details.templ`, Line: 34, Col: 79}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/s3vectors_bucket_details.templ`, Line: 35, Col: 79}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -124,7 +125,7 @@ func S3VectorsBucketDetails(data dash.S3VectorsBucketData) templ.Component {
|
||||
var templ_7745c5c3_Var7 string
|
||||
templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinStringErrs(data.Bucket.Encryption)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/s3vectors_bucket_details.templ`, Line: 38, Col: 61}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/s3vectors_bucket_details.templ`, Line: 39, Col: 61}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -147,7 +148,7 @@ func S3VectorsBucketDetails(data dash.S3VectorsBucketData) templ.Component {
|
||||
var templ_7745c5c3_Var8 string
|
||||
templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d indexes", data.TotalIndexes))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/s3vectors_bucket_details.templ`, Line: 49, Col: 84}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/s3vectors_bucket_details.templ`, Line: 50, Col: 84}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -165,7 +166,7 @@ func S3VectorsBucketDetails(data dash.S3VectorsBucketData) templ.Component {
|
||||
var templ_7745c5c3_Var9 string
|
||||
templ_7745c5c3_Var9, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("showing the first %d; list the rest with an S3 Vectors client", data.TotalIndexes))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/s3vectors_bucket_details.templ`, Line: 51, Col: 138}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/s3vectors_bucket_details.templ`, Line: 52, Col: 138}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var9))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -188,7 +189,7 @@ func S3VectorsBucketDetails(data dash.S3VectorsBucketData) templ.Component {
|
||||
var templ_7745c5c3_Var10 string
|
||||
templ_7745c5c3_Var10, templ_7745c5c3_Err = templ.JoinStringErrs(index.IndexName)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/s3vectors_bucket_details.templ`, Line: 73, Col: 26}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/s3vectors_bucket_details.templ`, Line: 74, Col: 26}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var10))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -201,7 +202,7 @@ func S3VectorsBucketDetails(data dash.S3VectorsBucketData) templ.Component {
|
||||
var templ_7745c5c3_Var11 string
|
||||
templ_7745c5c3_Var11, templ_7745c5c3_Err = templ.JoinStringErrs(index.IndexArn)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/s3vectors_bucket_details.templ`, Line: 74, Col: 55}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/s3vectors_bucket_details.templ`, Line: 75, Col: 55}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var11))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -214,7 +215,7 @@ func S3VectorsBucketDetails(data dash.S3VectorsBucketData) templ.Component {
|
||||
var templ_7745c5c3_Var12 string
|
||||
templ_7745c5c3_Var12, templ_7745c5c3_Err = templ.JoinStringErrs(index.DataType)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/s3vectors_bucket_details.templ`, Line: 76, Col: 28}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/s3vectors_bucket_details.templ`, Line: 77, Col: 28}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var12))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -227,7 +228,7 @@ func S3VectorsBucketDetails(data dash.S3VectorsBucketData) templ.Component {
|
||||
var templ_7745c5c3_Var13 string
|
||||
templ_7745c5c3_Var13, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", index.Dimension))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/s3vectors_bucket_details.templ`, Line: 77, Col: 48}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/s3vectors_bucket_details.templ`, Line: 78, Col: 48}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var13))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -240,7 +241,7 @@ func S3VectorsBucketDetails(data dash.S3VectorsBucketData) templ.Component {
|
||||
var templ_7745c5c3_Var14 string
|
||||
templ_7745c5c3_Var14, templ_7745c5c3_Err = templ.JoinStringErrs(index.DistanceMetric)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/s3vectors_bucket_details.templ`, Line: 78, Col: 34}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/s3vectors_bucket_details.templ`, Line: 79, Col: 34}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var14))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -258,7 +259,7 @@ func S3VectorsBucketDetails(data dash.S3VectorsBucketData) templ.Component {
|
||||
var templ_7745c5c3_Var15 string
|
||||
templ_7745c5c3_Var15, templ_7745c5c3_Err = templ.JoinStringErrs(strings.Join(index.MetadataConfiguration.NonFilterableMetadataKeys, ", "))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/s3vectors_bucket_details.templ`, Line: 81, Col: 91}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/s3vectors_bucket_details.templ`, Line: 82, Col: 91}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var15))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -281,7 +282,7 @@ func S3VectorsBucketDetails(data dash.S3VectorsBucketData) templ.Component {
|
||||
var templ_7745c5c3_Var16 string
|
||||
templ_7745c5c3_Var16, templ_7745c5c3_Err = templ.JoinStringErrs(index.CreationTime.Format("2006-01-02 15:04"))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/s3vectors_bucket_details.templ`, Line: 86, Col: 59}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/s3vectors_bucket_details.templ`, Line: 87, Col: 59}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var16))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -294,7 +295,7 @@ func S3VectorsBucketDetails(data dash.S3VectorsBucketData) templ.Component {
|
||||
var templ_7745c5c3_Var17 string
|
||||
templ_7745c5c3_Var17, templ_7745c5c3_Err = templruntime.NewAttributeExpression(index.IndexName).Resolve(ctx)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/s3vectors_bucket_details.templ`, Line: 88, Col: 129}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/s3vectors_bucket_details.templ`, Line: 89, Col: 129}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var17)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -311,48 +312,58 @@ func S3VectorsBucketDetails(data dash.S3VectorsBucketData) templ.Component {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
}
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 29, "</tbody></table></div></div></div><div class=\"card shadow mb-4\"><div class=\"card-header py-3\"><h6 class=\"m-0 font-weight-bold text-primary\"><i class=\"bi bi-shield me-2\"></i>Bucket Policy</h6></div><div class=\"card-body\">")
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 29, "</tbody></table></div></div></div>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
for _, panel := range data.Panels {
|
||||
templ_7745c5c3_Err = S3VectorsIndexPanel(panel).Render(ctx, templ_7745c5c3_Buffer)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
}
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 30, "<div class=\"card shadow mb-4\"><div class=\"card-header py-3\"><h6 class=\"m-0 font-weight-bold text-primary\"><i class=\"bi bi-shield me-2\"></i>Bucket Policy</h6></div><div class=\"card-body\">")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
if data.Policy != "" {
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 30, "<pre class=\"bg-light p-3 border rounded mb-0\" id=\"s3vectorsBucketPolicy\">")
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 31, "<pre class=\"bg-light p-3 border rounded mb-0\" id=\"s3vectorsBucketPolicy\">")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var18 string
|
||||
templ_7745c5c3_Var18, templ_7745c5c3_Err = templ.JoinStringErrs(indentJSON(data.Policy))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/s3vectors_bucket_details.templ`, Line: 114, Col: 102}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/s3vectors_bucket_details.templ`, Line: 118, Col: 102}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var18))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 31, "</pre>")
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 32, "</pre>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
} else {
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 32, "<span class=\"text-muted\">No policy. Set one with <code>PutVectorBucketPolicy</code>.</span>")
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 33, "<span class=\"text-muted\">No policy. Set one with <code>PutVectorBucketPolicy</code>.</span>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
}
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 33, "</div></div><div class=\"modal fade\" id=\"deleteS3VectorsIndexModal\" tabindex=\"-1\" aria-labelledby=\"deleteS3VectorsIndexModalLabel\" aria-hidden=\"true\"><div class=\"modal-dialog\"><div class=\"modal-content\"><div class=\"modal-header\"><h5 class=\"modal-title\" id=\"deleteS3VectorsIndexModalLabel\"><i class=\"bi bi-exclamation-triangle me-2 text-warning\"></i>Delete Index</h5><button type=\"button\" class=\"btn-close\" data-bs-dismiss=\"modal\" aria-label=\"Close\"></button></div><div class=\"modal-body\"><p>Delete the index <strong id=\"deleteS3VectorsIndexName\"></strong> and all its vectors?</p></div><div class=\"modal-footer\"><button type=\"button\" class=\"btn btn-secondary\" data-bs-dismiss=\"modal\">Cancel</button> <button type=\"button\" class=\"btn btn-danger\" id=\"deleteS3VectorsIndexBtn\"><i class=\"bi bi-trash me-1\"></i>Delete</button></div></div></div></div><div id=\"s3vectorsBucketDetails\" data-bucket-name=\"")
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 34, "</div></div><div class=\"modal fade\" id=\"deleteS3VectorsIndexModal\" tabindex=\"-1\" aria-labelledby=\"deleteS3VectorsIndexModalLabel\" aria-hidden=\"true\"><div class=\"modal-dialog\"><div class=\"modal-content\"><div class=\"modal-header\"><h5 class=\"modal-title\" id=\"deleteS3VectorsIndexModalLabel\"><i class=\"bi bi-exclamation-triangle me-2 text-warning\"></i>Delete Index</h5><button type=\"button\" class=\"btn-close\" data-bs-dismiss=\"modal\" aria-label=\"Close\"></button></div><div class=\"modal-body\"><p>Delete the index <strong id=\"deleteS3VectorsIndexName\"></strong> and all its vectors?</p></div><div class=\"modal-footer\"><button type=\"button\" class=\"btn btn-secondary\" data-bs-dismiss=\"modal\">Cancel</button> <button type=\"button\" class=\"btn btn-danger\" id=\"deleteS3VectorsIndexBtn\"><i class=\"bi bi-trash me-1\"></i>Delete</button></div></div></div></div><div class=\"modal fade\" id=\"indexS3VectorsMetadataKeyModal\" tabindex=\"-1\" aria-labelledby=\"indexS3VectorsMetadataKeyModalLabel\" aria-hidden=\"true\"><div class=\"modal-dialog\"><div class=\"modal-content\"><div class=\"modal-header\"><h5 class=\"modal-title\" id=\"indexS3VectorsMetadataKeyModalLabel\"><i class=\"bi bi-tags me-2\"></i>Index a metadata key of <span id=\"indexS3VectorsMetadataKeyIndex\"></span></h5><button type=\"button\" class=\"btn-close\" data-bs-dismiss=\"modal\" aria-label=\"Close\"></button></div><div class=\"modal-body\"><label for=\"indexS3VectorsMetadataKeyName\" class=\"form-label\">Metadata key</label> <input type=\"text\" class=\"form-control\" id=\"indexS3VectorsMetadataKeyName\" autocomplete=\"off\"><div class=\"form-text\">Filters comparing this key with strings ($eq, $in) read its index instead of every row's metadata. Results do not change.</div><div class=\"text-danger small mt-2\" id=\"indexS3VectorsMetadataKeyError\"></div></div><div class=\"modal-footer\"><button type=\"button\" class=\"btn btn-secondary\" data-bs-dismiss=\"modal\">Cancel</button> <button type=\"button\" class=\"btn btn-primary\" id=\"indexS3VectorsMetadataKeyBtn\"><i class=\"bi bi-plus-lg me-1\"></i>Index</button></div></div></div></div><div id=\"s3vectorsBucketDetails\" data-bucket-name=\"")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var19 string
|
||||
templ_7745c5c3_Var19, templ_7745c5c3_Err = templruntime.NewAttributeExpression(data.Bucket.Name).Resolve(ctx)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/s3vectors_bucket_details.templ`, Line: 141, Col: 69}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/s3vectors_bucket_details.templ`, Line: 169, Col: 69}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var19)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 34, "\"></div><script>\n\t\tdocument.addEventListener('DOMContentLoaded', function () {\n\t\t\tconst bucket = document.getElementById('s3vectorsBucketDetails').dataset.bucketName;\n\t\t\tconst modalEl = document.getElementById('deleteS3VectorsIndexModal');\n\t\t\tconst modal = new bootstrap.Modal(modalEl);\n\t\t\tdocument.querySelectorAll('.s3vectors-delete-index-btn').forEach(button => {\n\t\t\t\tbutton.addEventListener('click', function () {\n\t\t\t\t\tmodalEl.dataset.indexName = this.dataset.indexName || '';\n\t\t\t\t\tdocument.getElementById('deleteS3VectorsIndexName').textContent = this.dataset.indexName || '';\n\t\t\t\t\tmodal.show();\n\t\t\t\t});\n\t\t\t});\n\t\t\tdocument.getElementById('deleteS3VectorsIndexBtn').addEventListener('click', async function () {\n\t\t\t\tconst index = modalEl.dataset.indexName;\n\t\t\t\tif (!bucket || !index) return;\n\t\t\t\ttry {\n\t\t\t\t\tconst response = await fetch(s3tBasePath('/api/s3vectors/indexes?bucket=' + encodeURIComponent(bucket) + '&index=' + encodeURIComponent(index)), { method: 'DELETE', headers: s3tWriteHeaders() });\n\t\t\t\t\tconst data = await response.json();\n\t\t\t\t\tif (!response.ok) {\n\t\t\t\t\t\talert(data.error || 'Failed to delete index');\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tlocation.reload();\n\t\t\t\t} catch (error) {\n\t\t\t\t\talert('Failed to delete index: ' + error.message);\n\t\t\t\t}\n\t\t\t});\n\t\t});\n\t</script>")
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 35, "\"></div><script>\n\t\tdocument.addEventListener('DOMContentLoaded', function () {\n\t\t\tconst bucket = document.getElementById('s3vectorsBucketDetails').dataset.bucketName;\n\t\t\tconst modalEl = document.getElementById('deleteS3VectorsIndexModal');\n\t\t\tconst modal = new bootstrap.Modal(modalEl);\n\t\t\tdocument.querySelectorAll('.s3vectors-delete-index-btn').forEach(button => {\n\t\t\t\tbutton.addEventListener('click', function () {\n\t\t\t\t\tmodalEl.dataset.indexName = this.dataset.indexName || '';\n\t\t\t\t\tdocument.getElementById('deleteS3VectorsIndexName').textContent = this.dataset.indexName || '';\n\t\t\t\t\tmodal.show();\n\t\t\t\t});\n\t\t\t});\n\t\t\tasync function updateMetadataKey(index, key, remove) {\n\t\t\t\tconst url = remove\n\t\t\t\t\t? '/api/s3vectors/metadata-keys?bucket=' + encodeURIComponent(bucket) + '&index=' + encodeURIComponent(index) + '&key=' + encodeURIComponent(key)\n\t\t\t\t\t: '/api/s3vectors/metadata-keys';\n\t\t\t\tconst options = { method: remove ? 'DELETE' : 'POST', headers: s3tWriteHeaders() };\n\t\t\t\tif (!remove) {\n\t\t\t\t\toptions.headers = Object.assign({ 'Content-Type': 'application/json' }, options.headers);\n\t\t\t\t\toptions.body = JSON.stringify({ bucket: bucket, index: index, key: key });\n\t\t\t\t}\n\t\t\t\tconst response = await fetch(s3tBasePath(url), options);\n\t\t\t\tconst data = await response.json();\n\t\t\t\tif (!response.ok) {\n\t\t\t\t\tthrow new Error(data.error || 'request failed');\n\t\t\t\t}\n\t\t\t\treturn data;\n\t\t\t}\n\t\t\tconst keyModalEl = document.getElementById('indexS3VectorsMetadataKeyModal');\n\t\t\tconst keyModal = new bootstrap.Modal(keyModalEl);\n\t\t\tconst keyInput = document.getElementById('indexS3VectorsMetadataKeyName');\n\t\t\tconst keyError = document.getElementById('indexS3VectorsMetadataKeyError');\n\t\t\tdocument.querySelectorAll('.s3vectors-index-key-btn').forEach(button => {\n\t\t\t\tbutton.addEventListener('click', function () {\n\t\t\t\t\tkeyModalEl.dataset.indexName = this.dataset.indexName || '';\n\t\t\t\t\tkeyModalEl.dataset.nonFilterable = this.dataset.nonFilterable || '[]';\n\t\t\t\t\tdocument.getElementById('indexS3VectorsMetadataKeyIndex').textContent = this.dataset.indexName || '';\n\t\t\t\t\tkeyInput.value = this.dataset.key || '';\n\t\t\t\t\tkeyError.textContent = '';\n\t\t\t\t\tkeyModal.show();\n\t\t\t\t});\n\t\t\t});\n\t\t\tdocument.getElementById('indexS3VectorsMetadataKeyBtn').addEventListener('click', async function () {\n\t\t\t\tconst index = keyModalEl.dataset.indexName;\n\t\t\t\tconst key = keyInput.value.trim();\n\t\t\t\tif (!key) {\n\t\t\t\t\tkeyError.textContent = 'Enter a metadata key.';\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (JSON.parse(keyModalEl.dataset.nonFilterable || '[]').includes(key)) {\n\t\t\t\t\tkeyError.textContent = key + ' is a non-filterable key of this index and cannot be indexed.';\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\ttry {\n\t\t\t\t\tawait updateMetadataKey(index, key, false);\n\t\t\t\t\tlocation.reload();\n\t\t\t\t} catch (error) {\n\t\t\t\t\tkeyError.textContent = error.message;\n\t\t\t\t}\n\t\t\t});\n\t\t\tdocument.querySelectorAll('.s3vectors-remove-key-btn').forEach(button => {\n\t\t\t\tbutton.addEventListener('click', async function () {\n\t\t\t\t\tif (!confirm((this.dataset.action || 'Remove') + ' the index of metadata key ' + this.dataset.key + '?')) return;\n\t\t\t\t\ttry {\n\t\t\t\t\t\tawait updateMetadataKey(this.dataset.indexName, this.dataset.key, true);\n\t\t\t\t\t\tlocation.reload();\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\talert(error.message);\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t});\n\t\t\tdocument.getElementById('deleteS3VectorsIndexBtn').addEventListener('click', async function () {\n\t\t\t\tconst index = modalEl.dataset.indexName;\n\t\t\t\tif (!bucket || !index) return;\n\t\t\t\ttry {\n\t\t\t\t\tconst response = await fetch(s3tBasePath('/api/s3vectors/indexes?bucket=' + encodeURIComponent(bucket) + '&index=' + encodeURIComponent(index)), { method: 'DELETE', headers: s3tWriteHeaders() });\n\t\t\t\t\tconst data = await response.json();\n\t\t\t\t\tif (!response.ok) {\n\t\t\t\t\t\talert(data.error || 'Failed to delete index');\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tlocation.reload();\n\t\t\t\t} catch (error) {\n\t\t\t\t\talert('Failed to delete index: ' + error.message);\n\t\t\t\t}\n\t\t\t});\n\t\t});\n\t</script>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
@@ -360,6 +371,495 @@ func S3VectorsBucketDetails(data dash.S3VectorsBucketData) templ.Component {
|
||||
})
|
||||
}
|
||||
|
||||
func S3VectorsIndexPanel(panel dash.S3VectorsIndexPanel) templ.Component {
|
||||
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
|
||||
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
|
||||
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
|
||||
return templ_7745c5c3_CtxErr
|
||||
}
|
||||
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
|
||||
if !templ_7745c5c3_IsBuffer {
|
||||
defer func() {
|
||||
templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
|
||||
if templ_7745c5c3_Err == nil {
|
||||
templ_7745c5c3_Err = templ_7745c5c3_BufErr
|
||||
}
|
||||
}()
|
||||
}
|
||||
ctx = templ.InitializeContext(ctx)
|
||||
ctx = templ.ClearChildren(ctx)
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 36, "<div class=\"card shadow mb-4 s3vectors-index-panel\" data-index-name=\"")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var21 string
|
||||
templ_7745c5c3_Var21, templ_7745c5c3_Err = templruntime.NewAttributeExpression(panel.Index.IndexName).Resolve(ctx)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/s3vectors_bucket_details.templ`, Line: 261, Col: 92}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var21)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 37, "\"><div class=\"card-header py-3\"><h6 class=\"m-0 font-weight-bold text-primary\"><i class=\"bi bi-diagram-3 me-2\"></i>Index: ")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var22 string
|
||||
templ_7745c5c3_Var22, templ_7745c5c3_Err = templ.JoinStringErrs(panel.Index.IndexName)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/s3vectors_bucket_details.templ`, Line: 264, Col: 70}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var22))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 38, "</h6><div class=\"small text-muted mt-1\">")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var23 string
|
||||
templ_7745c5c3_Var23, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("Dimension %d", panel.Index.Dimension))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/s3vectors_bucket_details.templ`, Line: 267, Col: 56}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var23))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 39, " · ")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var24 string
|
||||
templ_7745c5c3_Var24, templ_7745c5c3_Err = templ.JoinStringErrs(panel.Index.DistanceMetric)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/s3vectors_bucket_details.templ`, Line: 267, Col: 90}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var24))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 40, " · ")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var25 string
|
||||
templ_7745c5c3_Var25, templ_7745c5c3_Err = templ.JoinStringErrs(groupDigits(float64(panel.Vectors)))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/s3vectors_bucket_details.templ`, Line: 267, Col: 133}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var25))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 41, " vectors · Vector index: ")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
if panel.VectorIndex != "" {
|
||||
var templ_7745c5c3_Var26 string
|
||||
templ_7745c5c3_Var26, templ_7745c5c3_Err = templ.JoinStringErrs(panel.VectorIndex)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/s3vectors_bucket_details.templ`, Line: 269, Col: 24}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var26))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
} else {
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 42, "none (exact scan)")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
}
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 43, "</div></div><div class=\"card-body\">")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
if panel.Error != "" {
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 44, "<div class=\"alert alert-warning py-2 small\">")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var27 string
|
||||
templ_7745c5c3_Var27, templ_7745c5c3_Err = templ.JoinStringErrs(panel.Error)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/s3vectors_bucket_details.templ`, Line: 277, Col: 61}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var27))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 45, "</div>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
}
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 46, "<div class=\"d-flex justify-content-between align-items-center mb-2\"><strong>Metadata indexes</strong> <button type=\"button\" class=\"btn btn-outline-primary btn-sm s3vectors-index-key-btn\" data-index-name=\"")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var28 string
|
||||
templ_7745c5c3_Var28, templ_7745c5c3_Err = templruntime.NewAttributeExpression(panel.Index.IndexName).Resolve(ctx)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/s3vectors_bucket_details.templ`, Line: 281, Col: 128}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var28)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 47, "\" data-non-filterable=\"")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var29 string
|
||||
templ_7745c5c3_Var29, templ_7745c5c3_Err = templruntime.NewAttributeExpression(nonFilterableJSON(panel.Index)).Resolve(ctx)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/s3vectors_bucket_details.templ`, Line: 281, Col: 183}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var29)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 48, "\"><i class=\"bi bi-plus-lg me-1\"></i>Index a key</button></div><div class=\"table-responsive\"><table class=\"table table-sm table-hover mb-3\"><thead><tr><th>Key</th><th>State</th><th>Coverage</th><th>Filtered queries/h</th><th>Size</th><th></th></tr></thead> <tbody>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
for _, key := range panel.Keys {
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 49, "<tr><td><code>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var30 string
|
||||
templ_7745c5c3_Var30, templ_7745c5c3_Err = templ.JoinStringErrs(key.Key)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/s3vectors_bucket_details.templ`, Line: 300, Col: 27}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var30))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 50, "</code></td><td>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var31 string
|
||||
templ_7745c5c3_Var31, templ_7745c5c3_Err = templ.JoinStringErrs(keyState(key.State))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/s3vectors_bucket_details.templ`, Line: 301, Col: 33}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var31))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 51, "</td><td>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
if key.State == "requested" {
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 52, "—")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
} else {
|
||||
var templ_7745c5c3_Var32 string
|
||||
templ_7745c5c3_Var32, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%.0f%%", key.Coverage))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/s3vectors_bucket_details.templ`, Line: 306, Col: 47}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var32))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
}
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 53, "</td><td>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var33 string
|
||||
templ_7745c5c3_Var33, templ_7745c5c3_Err = templ.JoinStringErrs(groupDigits(key.QueriesPerHour))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/s3vectors_bucket_details.templ`, Line: 309, Col: 45}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var33))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 54, "</td><td>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
if key.IndexBytes > 0 {
|
||||
var templ_7745c5c3_Var34 string
|
||||
templ_7745c5c3_Var34, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%.1f MiB", float64(key.IndexBytes)/(1<<20)))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/s3vectors_bucket_details.templ`, Line: 312, Col: 68}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var34))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
} else {
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 55, "—")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
}
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 56, "</td><td>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
if key.State == "ready" {
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 57, "<button type=\"button\" class=\"btn btn-link btn-sm p-0 text-danger s3vectors-remove-key-btn\" data-index-name=\"")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var35 string
|
||||
templ_7745c5c3_Var35, templ_7745c5c3_Err = templruntime.NewAttributeExpression(panel.Index.IndexName).Resolve(ctx)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/s3vectors_bucket_details.templ`, Line: 319, Col: 140}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var35)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 58, "\" data-key=\"")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var36 string
|
||||
templ_7745c5c3_Var36, templ_7745c5c3_Err = templruntime.NewAttributeExpression(key.Key).Resolve(ctx)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/s3vectors_bucket_details.templ`, Line: 319, Col: 161}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var36)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 59, "\" data-action=\"Remove\">Remove</button>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
} else if key.State == "requested" || key.State == "building" {
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 60, "<button type=\"button\" class=\"btn btn-link btn-sm p-0 s3vectors-remove-key-btn\" data-index-name=\"")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var37 string
|
||||
templ_7745c5c3_Var37, templ_7745c5c3_Err = templruntime.NewAttributeExpression(panel.Index.IndexName).Resolve(ctx)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/s3vectors_bucket_details.templ`, Line: 321, Col: 128}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var37)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 61, "\" data-key=\"")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var38 string
|
||||
templ_7745c5c3_Var38, templ_7745c5c3_Err = templruntime.NewAttributeExpression(key.Key).Resolve(ctx)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/s3vectors_bucket_details.templ`, Line: 321, Col: 149}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var38)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 62, "\" data-action=\"Cancel\">Cancel</button>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
}
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 63, "</td></tr>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
}
|
||||
if len(panel.Keys) == 0 {
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 64, "<tr><td colspan=\"6\" class=\"text-center text-muted\">No indexed metadata keys.</td></tr>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
}
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 65, "</tbody></table></div><strong>Frequently filtered, not indexed</strong> ")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
if panel.StatsError != "" {
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 66, "<div class=\"text-muted small\">")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var39 string
|
||||
templ_7745c5c3_Var39, templ_7745c5c3_Err = templ.JoinStringErrs(panel.StatsError)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/s3vectors_bucket_details.templ`, Line: 336, Col: 52}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var39))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 67, "</div>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
}
|
||||
if len(panel.Frequent) == 0 {
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 68, "<div class=\"text-muted small mt-1\">No filtered queries in the last hour on keys without an index.</div>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
}
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 69, "<ul class=\"list-unstyled mt-1 mb-0\">")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
for _, key := range panel.Frequent {
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 70, "<li class=\"d-flex align-items-center py-1\"><code class=\"me-3\">")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var40 string
|
||||
templ_7745c5c3_Var40, templ_7745c5c3_Err = templ.JoinStringErrs(key.Key)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/s3vectors_bucket_details.templ`, Line: 344, Col: 34}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var40))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 71, "</code> <span class=\"me-3\">")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var41 string
|
||||
templ_7745c5c3_Var41, templ_7745c5c3_Err = templ.JoinStringErrs(groupDigits(key.QueriesPerHour))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/s3vectors_bucket_details.templ`, Line: 345, Col: 58}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var41))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 72, " queries/h</span> <span class=\"me-3 text-muted\">")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var42 string
|
||||
templ_7745c5c3_Var42, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("avg %.0f ms", key.AvgMs))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/s3vectors_bucket_details.templ`, Line: 346, Col: 75}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var42))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 73, "</span> ")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
if key.Numeric {
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 74, "<span class=\"text-muted small\">(numeric: phase 2)</span>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
} else {
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 75, "<button type=\"button\" class=\"btn btn-outline-primary btn-sm ms-auto s3vectors-index-key-btn\" data-index-name=\"")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var43 string
|
||||
templ_7745c5c3_Var43, templ_7745c5c3_Err = templruntime.NewAttributeExpression(panel.Index.IndexName).Resolve(ctx)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/s3vectors_bucket_details.templ`, Line: 350, Col: 139}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var43)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 76, "\" data-key=\"")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var44 string
|
||||
templ_7745c5c3_Var44, templ_7745c5c3_Err = templruntime.NewAttributeExpression(key.Key).Resolve(ctx)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/s3vectors_bucket_details.templ`, Line: 350, Col: 160}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var44)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 77, "\" data-non-filterable=\"")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var45 string
|
||||
templ_7745c5c3_Var45, templ_7745c5c3_Err = templruntime.NewAttributeExpression(nonFilterableJSON(panel.Index)).Resolve(ctx)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/app/s3vectors_bucket_details.templ`, Line: 350, Col: 215}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var45)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 78, "\">Index</button>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
}
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 79, "</li>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
}
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 80, "</ul></div></div>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func keyState(state string) string {
|
||||
switch state {
|
||||
case "requested":
|
||||
return "Requested"
|
||||
case "building":
|
||||
return "Building"
|
||||
case "ready":
|
||||
return "Ready"
|
||||
case "off":
|
||||
return "Removing"
|
||||
}
|
||||
return state
|
||||
}
|
||||
|
||||
// groupDigits renders n rounded, with thousands separators.
|
||||
func groupDigits(n float64) string {
|
||||
digits := fmt.Sprintf("%.0f", n)
|
||||
var out []byte
|
||||
for i := range digits {
|
||||
if i > 0 && (len(digits)-i)%3 == 0 {
|
||||
out = append(out, ',')
|
||||
}
|
||||
out = append(out, digits[i])
|
||||
}
|
||||
return string(out)
|
||||
}
|
||||
|
||||
func nonFilterableJSON(index *s3vectors.Index) string {
|
||||
keys := []string{}
|
||||
if index.MetadataConfiguration != nil {
|
||||
keys = index.MetadataConfiguration.NonFilterableMetadataKeys
|
||||
}
|
||||
b, _ := json.Marshal(keys)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
const maxIndentedJSONDepth = 32
|
||||
|
||||
func indentJSON(s string) string {
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package app
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestGroupDigits(t *testing.T) {
|
||||
for n, want := range map[float64]string{0: "0", 999: "999", 1000: "1,000", 12400: "12,400", 2140312: "2,140,312", 8899.6: "8,900"} {
|
||||
if got := groupDigits(n); got != want {
|
||||
t.Errorf("groupDigits(%v) = %q, want %q", n, got, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user