Skip to content

Commit

Permalink
Improve log message formatting; handle error fetching dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
sd2k committed Sep 13, 2023
1 parent 43741d1 commit c3f6f4d
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions pkg/plugin/vector/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ func (v *vectorService) syncDashboardsToVectorStore(ctx context.Context) error {
if err != nil {
return fmt.Errorf("create Grafana client: %w", err)
}
log.DefaultLogger.Info("Fetching dashboards")
dashboards, err := client.Dashboards()
if err != nil {
log.DefaultLogger.Error("Error fetching dashboards", "err", err)
Expand All @@ -104,6 +103,9 @@ func (v *vectorService) syncDashboardsToVectorStore(ctx context.Context) error {
for j, folderDashboard := range chunk {
log.DefaultLogger.Debug("Fetching dashboard", "uid", folderDashboard.UID)
dashboard, err := client.DashboardByUID(folderDashboard.UID)
if err != nil {
log.DefaultLogger.Warn("Unable to fetch dashboard", "uid", folderDashboard.UID, "err", err)
}
model := store.Payload{
"title": folderDashboard.Title,
"description": dashboard.Model["description"],
Expand All @@ -129,7 +131,7 @@ func (v *vectorService) syncDashboardsToVectorStore(ctx context.Context) error {

jdoc, err := json.Marshal(model)
if err != nil {
log.DefaultLogger.Warn("marshal dashboard", "uid", folderDashboard.UID, "err", err)
log.DefaultLogger.Warn("Unable to marshal dashboard", "uid", folderDashboard.UID, "err", err)
continue
}

Expand All @@ -138,30 +140,30 @@ func (v *vectorService) syncDashboardsToVectorStore(ctx context.Context) error {
hash.Write([]byte(jdoc))
id := hash.Sum64()
if exists, err := v.store.PointExists(ctx, GrafanaDashboardsCollection, id); err != nil {
log.DefaultLogger.Warn("check vector exists", "collection", GrafanaDashboardsCollection, "id", id, "err", err)
log.DefaultLogger.Warn("Error checking whether vector exists", "collection", GrafanaDashboardsCollection, "id", id, "err", err)
continue
} else if exists {
log.DefaultLogger.Debug("vector already exists, skipping", "collection", GrafanaDashboardsCollection, "id", id, "err", err)
log.DefaultLogger.Debug("Vector already exists, skipping", "collection", GrafanaDashboardsCollection, "id", id, "err", err)
continue
}

// If we're here, we have a new dashboard to embed and add.
log.DefaultLogger.Debug("getting embeddings for dashboard", "collection", GrafanaDashboardsCollection, "index", i+j, "count", len(dashboards))
log.DefaultLogger.Debug("Getting embeddings for dashboard", "collection", GrafanaDashboardsCollection, "index", i+j, "count", len(dashboards))
// TODO: process the dashboard JSON.
e, err := v.embedder.Embed(ctx, c.Model, string(jdoc))
if err != nil {
log.DefaultLogger.Warn("get embeddings", "collection", GrafanaDashboardsCollection, "err", err)
log.DefaultLogger.Warn("Error getting embeddings", "collection", GrafanaDashboardsCollection, "err", err)
continue
}
ids = append(ids, id)
embeddings = append(embeddings, e)
payloads = append(payloads, model)
}
if len(ids) == 0 {
log.DefaultLogger.Debug("no new embeddings to add")
log.DefaultLogger.Debug("No new embeddings to add")
return nil
}
log.DefaultLogger.Debug("adding embeddings to vector DB", "collection", GrafanaDashboardsCollection, "count", len(embeddings))
log.DefaultLogger.Debug("Adding embeddings to vector DB", "collection", GrafanaDashboardsCollection, "count", len(embeddings))
err := v.store.UpsertColumnar(ctx, GrafanaDashboardsCollection, ids, embeddings, payloads)
if err != nil {
return fmt.Errorf("upsert columnar: %w", err)
Expand Down

0 comments on commit c3f6f4d

Please sign in to comment.