Unified Storage Indexer: Add back metrics (#97310)

* Adds back indexer metrics. Uses config values instead of hardcoded ones.

* cast to int64

* remove unused func

* Index metrics impl doesn't depend on Bleve. Adds a TotalDocs func to SearchBackend interface.

* adds config setting for index_min_count

* rename arg

* rename metric label to namespace instead of slug

* adds default "do nothing" case to satisfy linter

* moves bleve index metrics to search package

* make bleve backend private, dont need to pass in prom reg

* imports

* adds bleve metrics to resource package to avoid circular deps
This commit is contained in:
owensmallwood
2024-12-04 15:02:40 -06:00
committed by GitHub
parent 39b6e712bb
commit 70c9c3889f
7 changed files with 231 additions and 32 deletions
+13 -8
View File
@@ -2,10 +2,11 @@ package sql
import (
"context"
"log/slog"
"os"
"path/filepath"
"strings"
"github.com/grafana/grafana/pkg/storage/unified/search"
"github.com/prometheus/client_golang/prometheus"
infraDB "github.com/grafana/grafana/pkg/infra/db"
@@ -14,7 +15,6 @@ import (
"github.com/grafana/grafana/pkg/services/featuremgmt"
"github.com/grafana/grafana/pkg/setting"
"github.com/grafana/grafana/pkg/storage/unified/resource"
"github.com/grafana/grafana/pkg/storage/unified/search"
"github.com/grafana/grafana/pkg/storage/unified/sql/db/dbimpl"
)
@@ -59,13 +59,18 @@ func NewResourceServer(ctx context.Context, db infraDB.DB, cfg *setting.Cfg,
if features.IsEnabledGlobally(featuremgmt.FlagUnifiedStorageSearch) {
opts.Search = resource.SearchOptions{
Backend: search.NewBleveBackend(search.BleveOptions{
Root: filepath.Join(cfg.DataPath, "unified-search", "bleve"),
FileThreshold: 10, // fewer than X items will use a memory index
BatchSize: 500, // This is the batch size for how many objects to add to the index at once
}, tracer, reg),
Root: cfg.IndexPath,
FileThreshold: int64(cfg.IndexFileThreshold), // fewer than X items will use a memory index
BatchSize: cfg.IndexMaxBatchSize, // This is the batch size for how many objects to add to the index at once
}, tracer),
Resources: docs,
WorkerThreads: 5, // from cfg?
InitMinCount: 1,
WorkerThreads: cfg.IndexWorkers,
InitMinCount: cfg.IndexMinCount,
}
err = reg.Register(resource.NewIndexMetrics(cfg.IndexPath, opts.Search.Backend))
if err != nil {
slog.Warn("Failed to register indexer metrics", "error", err)
}
}