Skip to content
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

fix(auditing): increase timeout for meili index creation #113

Merged
merged 4 commits into from
Nov 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions auditing/meilisearch.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package auditing

import (
"context"
"errors"
"fmt"
"os"
Expand Down Expand Up @@ -28,7 +29,15 @@ type meiliAuditing struct {
index *meilisearch.Index
}

const meiliIndexNameTimeSuffixSchema = "\\d\\d\\d\\d-\\d\\d(-\\d\\d(_\\d\\d)?)?"
var (
errAuditingIndexCreationDeadlineUnsufficient = errors.New("auditing index creation timed out, because meilisearch took too long. Consider increasing the timeout to prevent failing requests")
)

const (
meiliIndexNameTimeSuffixSchema = "\\d\\d\\d\\d-\\d\\d(-\\d\\d(_\\d\\d)?)?"
meiliIndexCreationWaitTimeout = 30 * time.Second
meiliIndexCreationWaitInterval = 50 * time.Millisecond
)

func New(c Config) (Auditing, error) {
if c.Component == "" {
Expand Down Expand Up @@ -355,7 +364,13 @@ func (a *meiliAuditing) getLatestIndex() (*meilisearch.Index, error) {
if err != nil {
return nil, fmt.Errorf("failed to request create index (%s): %w", indexUid, err)
}
_, err = a.client.WaitForTask(creationTask.TaskUID)

waitCtx, cancelFunc := context.WithTimeoutCause(context.Background(), meiliIndexCreationWaitTimeout, errAuditingIndexCreationDeadlineUnsufficient)
defer cancelFunc()
_, err = a.client.WaitForTask(creationTask.TaskUID, meilisearch.WaitParams{
Context: waitCtx,
Interval: meiliIndexCreationWaitInterval,
})
if err != nil {
return nil, fmt.Errorf("failed to execute create index (%s): %w", indexUid, err)
}
Expand Down