chore: lower log messages

This commit is contained in:
Miroslav Cvetic 2025-03-12 12:05:22 +01:00
parent 8203d4ed67
commit 05e2881851
3 changed files with 33 additions and 33 deletions

View File

@ -85,18 +85,18 @@ func (b *BaseAPI[indexDocument, returnType]) Indices() ([]pkgx.IndexID, error) {
// are correctly linked to their respective aliases.
// The function sets the revisionID that is currently linked to the aliases internally.
func (b *BaseAPI[indexDocument, returnType]) Initialize(ctx context.Context) (pkgx.RevisionID, error) {
b.l.Info("Initializing Typesense collections and aliases...")
b.l.Info("initializing typesense collections and aliases...")
// Step 1: Check Typesense connection
if _, err := b.client.Health(ctx, 5*time.Second); err != nil {
b.l.Error("Typesense health check failed", zap.Error(err))
b.l.Error("typesense health check failed", zap.Error(err))
return "", err
}
// Step 2: Retrieve existing aliases and collections
aliases, err := b.client.Aliases().Retrieve(ctx)
if err != nil {
b.l.Error("Failed to retrieve aliases", zap.Error(err))
b.l.Error("failed to retrieve aliases", zap.Error(err))
return "", err
}
@ -125,7 +125,7 @@ func (b *BaseAPI[indexDocument, returnType]) Initialize(ctx context.Context) (pk
// Step 4: Ensure all aliases are correctly mapped to collections and create a new revision
newRevisionID := b.generateRevisionID()
b.l.Info("Generated new revision", zap.String("revisionID", string(newRevisionID)))
b.l.Info("generated new revision", zap.String("revisionID", string(newRevisionID)))
for indexID, schema := range b.collections {
collectionName := formatCollectionName(indexID, newRevisionID)
@ -153,12 +153,12 @@ func (b *BaseAPI[indexDocument, returnType]) Initialize(ctx context.Context) (pk
if b.preset != nil {
_, err := b.client.Presets().Upsert(ctx, defaultSearchPresetName, b.preset)
if err != nil {
b.l.Error("Failed to upsert search preset", zap.Error(err))
b.l.Error("failed to upsert search preset", zap.Error(err))
return "", err
}
}
b.l.Info("Initialization completed", zap.String("revisionID", string(b.revisionID)))
b.l.Info("initialization completed", zap.String("revisionID", string(b.revisionID)))
return b.revisionID, nil
}
@ -190,7 +190,7 @@ func (b *BaseAPI[indexDocument, returnType]) UpsertDocuments(
importResults, err := b.client.Collection(collectionName).Documents().Import(ctx, docInterfaces, params)
if err != nil {
b.l.Error("Failed to bulk upsert documents", zap.String("collection", collectionName), zap.Error(err))
b.l.Error("failed to bulk upsert documents", zap.String("collection", collectionName), zap.Error(err))
return err
}
@ -208,7 +208,7 @@ func (b *BaseAPI[indexDocument, returnType]) UpsertDocuments(
}
}
b.l.Info("Bulk upsert completed",
b.l.Info("bulk upsert completed",
zap.String("collection", collectionName),
zap.Int("successful_documents", successCount),
zap.Int("failed_documents", failureCount),
@ -231,15 +231,15 @@ func (b *BaseAPI[indexDocument, returnType]) CommitRevision(ctx context.Context,
CollectionName: newCollectionName,
})
if err != nil {
b.l.Error("Failed to update alias", zap.String("alias", alias), zap.Error(err))
b.l.Error("failed to update alias", zap.String("alias", alias), zap.Error(err))
return err
}
b.l.Info("Updated alias", zap.String("alias", alias), zap.String("collection", newCollectionName))
b.l.Info("updated alias", zap.String("alias", alias), zap.String("collection", newCollectionName))
// Step 2: Clean up old collections (keep only the last two)
err = b.pruneOldCollections(ctx, alias, newCollectionName)
if err != nil {
b.l.Error("Failed to clean up old collections", zap.String("alias", alias), zap.Error(err))
b.l.Error("failed to clean up old collections", zap.String("alias", alias), zap.Error(err))
}
}
@ -289,14 +289,14 @@ func (b *BaseAPI[indexDocument, returnType]) ExpertSearch(
parameters *api.SearchCollectionParams,
) ([]returnType, pkgx.Scores, int, error) {
if parameters == nil {
b.l.Error("Search parameters are nil")
b.l.Error("search parameters are nil")
return nil, nil, 0, errors.New("search parameters cannot be nil")
}
collectionName := string(indexID) // digital-bks-at-de
searchResponse, err := b.client.Collection(collectionName).Documents().Search(ctx, parameters)
if err != nil {
b.l.Error("Failed to perform search", zap.String("index", collectionName), zap.Error(err))
b.l.Error("failed to perform search", zap.String("index", collectionName), zap.Error(err))
return nil, nil, 0, err
}
// Extract totalResults from the search response
@ -304,7 +304,7 @@ func (b *BaseAPI[indexDocument, returnType]) ExpertSearch(
// Ensure Hits is not empty before proceeding
if searchResponse.Hits == nil || len(*searchResponse.Hits) == 0 {
b.l.Warn("Search response contains no hits", zap.String("index", collectionName))
b.l.Warn("search response contains no hits", zap.String("index", collectionName))
return nil, nil, totalResults, nil
}
@ -313,7 +313,7 @@ func (b *BaseAPI[indexDocument, returnType]) ExpertSearch(
for i, hit := range *searchResponse.Hits {
if hit.Document == nil {
b.l.Warn("Hit document is nil", zap.String("index", collectionName))
b.l.Warn("hit document is nil", zap.String("index", collectionName))
continue
}

View File

@ -88,7 +88,7 @@ func (b *BaseAPI[indexDocument, returnType]) ensureAliasMapping(ctx context.Cont
CollectionName: collectionName,
})
if err != nil {
b.l.Error("Failed to upsert alias",
b.l.Error("failed to upsert alias",
zap.String("alias", string(indexID)),
zap.String("collection", collectionName),
zap.Error(err),
@ -101,7 +101,7 @@ func (b *BaseAPI[indexDocument, returnType]) pruneOldCollections(ctx context.Con
// Step 1: Retrieve all collections
collections, err := b.client.Collections().Retrieve(ctx)
if err != nil {
b.l.Error("Failed to retrieve collections", zap.Error(err))
b.l.Error("failed to retrieve collections", zap.Error(err))
return err
}
@ -123,9 +123,9 @@ func (b *BaseAPI[indexDocument, returnType]) pruneOldCollections(ctx context.Con
for _, col := range toDelete {
_, err := b.client.Collection(col).Delete(ctx)
if err != nil {
b.l.Error("Failed to delete collection", zap.String("collection", col), zap.Error(err))
b.l.Error("failed to delete collection", zap.String("collection", col), zap.Error(err))
} else {
b.l.Info("Deleted old collection", zap.String("collection", col))
b.l.Info("deleted old collection", zap.String("collection", col))
}
}
}
@ -137,7 +137,7 @@ func (b *BaseAPI[indexDocument, returnType]) pruneOldCollections(ctx context.Con
func (b *BaseAPI[indexDocument, returnType]) fetchExistingCollections(ctx context.Context) (map[string]bool, error) {
collections, err := b.client.Collections().Retrieve(ctx)
if err != nil {
b.l.Error("Failed to retrieve collections", zap.Error(err))
b.l.Error("failed to retrieve collections", zap.Error(err))
return nil, err
}
@ -158,7 +158,7 @@ func (b *BaseAPI[indexDocument, returnType]) createCollectionIfNotExists(ctx con
}
if existingCollections[collectionName] {
b.l.Info("Collection already exists, skipping creation", zap.String("collection", collectionName))
b.l.Info("collection already exists, skipping creation", zap.String("collection", collectionName))
return nil
}
@ -166,10 +166,10 @@ func (b *BaseAPI[indexDocument, returnType]) createCollectionIfNotExists(ctx con
schema.Name = collectionName
_, err = b.client.Collections().Create(ctx, schema)
if err != nil {
b.l.Error("Failed to create collection", zap.String("collection", collectionName), zap.Error(err))
b.l.Error("failed to create collection", zap.String("collection", collectionName), zap.Error(err))
return err
}
b.l.Info("Created new collection", zap.String("collection", collectionName))
b.l.Info("created new collection", zap.String("collection", collectionName))
return nil
}

View File

@ -33,14 +33,14 @@ func (b *BaseIndexer[indexDocument, returnType]) Run(ctx context.Context) error
// Step 1: Ensure Typesense is initialized
revisionID, err := b.typesenseAPI.Initialize(ctx)
if err != nil || revisionID == "" {
b.l.Error("Failed to initialize Typesense", zap.Error(err))
b.l.Error("failed to initialize typesense", zap.Error(err))
return err
}
// Step 2: Retrieve all configured indices
indices, err := b.typesenseAPI.Indices()
if err != nil {
b.l.Error("Failed to retrieve indices from Typesense", zap.Error(err))
b.l.Error("failed to retrieve indices from typesense", zap.Error(err))
return err
}
@ -52,7 +52,7 @@ func (b *BaseIndexer[indexDocument, returnType]) Run(ctx context.Context) error
// Fetch documents from the provider
documents, err := b.documentProvider.Provide(ctx, indexID)
if err != nil {
b.l.Error("Failed to fetch documents", zap.String("index", string(indexID)), zap.Error(err))
b.l.Error("failed to fetch documents", zap.String("index", string(indexID)), zap.Error(err))
tainted = true
continue
}
@ -60,7 +60,7 @@ func (b *BaseIndexer[indexDocument, returnType]) Run(ctx context.Context) error
err = b.typesenseAPI.UpsertDocuments(ctx, revisionID, indexID, documents)
if err != nil {
b.l.Error(
"Failed to upsert documents",
"failed to upsert documents",
zap.String("index", string(indexID)),
zap.String("revision", string(revisionID)),
zap.Int("documents", len(documents)),
@ -71,7 +71,7 @@ func (b *BaseIndexer[indexDocument, returnType]) Run(ctx context.Context) error
}
indexedDocuments += len(documents)
b.l.Info("Successfully upserted documents",
b.l.Info("successfully upserted documents",
zap.String("index", string(indexID)),
zap.Int("count", len(documents)),
)
@ -82,20 +82,20 @@ func (b *BaseIndexer[indexDocument, returnType]) Run(ctx context.Context) error
// No errors encountered, commit the revision
err = b.typesenseAPI.CommitRevision(ctx, revisionID)
if err != nil {
b.l.Error("Failed to commit revision", zap.String("revision", string(revisionID)), zap.Error(err))
b.l.Error("failed to commit revision", zap.String("revision", string(revisionID)), zap.Error(err))
return err
}
b.l.Info("Successfully committed revision", zap.String("revision", string(revisionID)))
b.l.Info("successfully committed revision", zap.String("revision", string(revisionID)))
} else {
// If errors occurred, revert the revision
b.l.Warn("Errors detected during upsert, reverting revision", zap.String("revision", string(revisionID)))
b.l.Warn("errors detected during upsert, reverting revision", zap.String("revision", string(revisionID)))
err = b.typesenseAPI.RevertRevision(ctx, revisionID)
if err != nil {
b.l.Error("Failed to revert revision", zap.String("revision", string(revisionID)), zap.Error(err))
b.l.Error("failed to revert revision", zap.String("revision", string(revisionID)), zap.Error(err))
return err
}
b.l.Info("Successfully reverted revision", zap.String("revision", string(revisionID)))
b.l.Info("successfully reverted revision", zap.String("revision", string(revisionID)))
}
return nil