From a45c830c38bc619875d75d24fa86a14f8929afda Mon Sep 17 00:00:00 2001 From: Valentin Knabel Date: Tue, 14 Nov 2023 10:45:41 +0100 Subject: [PATCH 1/3] fix(auditing): increase timeout for meili index creation The first audited request of the day fails due to an exceeded deadline --- auditing/meilisearch.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/auditing/meilisearch.go b/auditing/meilisearch.go index 2a7ef71..c54c17e 100644 --- a/auditing/meilisearch.go +++ b/auditing/meilisearch.go @@ -1,6 +1,7 @@ package auditing import ( + "context" "errors" "fmt" "os" @@ -28,7 +29,11 @@ type meiliAuditing struct { index *meilisearch.Index } -const meiliIndexNameTimeSuffixSchema = "\\d\\d\\d\\d-\\d\\d(-\\d\\d(_\\d\\d)?)?" +const ( + meiliIndexNameTimeSuffixSchema = "\\d\\d\\d\\d-\\d\\d(-\\d\\d(_\\d\\d)?)?" + meiliIndexCreationWaitTimeout = 15 * time.Second + meiliIndexCreationWaitInterval = 50 * time.Millisecond +) func New(c Config) (Auditing, error) { if c.Component == "" { @@ -351,7 +356,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.WithTimeout(context.Background(), meiliIndexCreationWaitTimeout) + 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) } From 7b700a0e3181a7d4f8a8f697a656095906349ce1 Mon Sep 17 00:00:00 2001 From: Valentin Knabel Date: Tue, 14 Nov 2023 11:24:55 +0100 Subject: [PATCH 2/3] refactor(auditing): use explicit timeout cause Gives a hint how to handle the error --- auditing/meilisearch.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/auditing/meilisearch.go b/auditing/meilisearch.go index c54c17e..802eafb 100644 --- a/auditing/meilisearch.go +++ b/auditing/meilisearch.go @@ -29,6 +29,10 @@ type meiliAuditing struct { index *meilisearch.Index } +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 = 15 * time.Second @@ -357,7 +361,7 @@ func (a *meiliAuditing) getLatestIndex() (*meilisearch.Index, error) { return nil, fmt.Errorf("failed to request create index (%s): %w", indexUid, err) } - waitCtx, cancelFunc := context.WithTimeout(context.Background(), meiliIndexCreationWaitTimeout) + waitCtx, cancelFunc := context.WithTimeoutCause(context.Background(), meiliIndexCreationWaitTimeout, errAuditingIndexCreationDeadlineUnsufficient) defer cancelFunc() _, err = a.client.WaitForTask(creationTask.TaskUID, meilisearch.WaitParams{ Context: waitCtx, From a67549575135e43da3fac461df74f55994cddd8d Mon Sep 17 00:00:00 2001 From: Valentin Knabel Date: Tue, 14 Nov 2023 11:31:55 +0100 Subject: [PATCH 3/3] Update meilisearch.go --- auditing/meilisearch.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/auditing/meilisearch.go b/auditing/meilisearch.go index cec5d1d..49c5da6 100644 --- a/auditing/meilisearch.go +++ b/auditing/meilisearch.go @@ -35,7 +35,7 @@ var ( const ( meiliIndexNameTimeSuffixSchema = "\\d\\d\\d\\d-\\d\\d(-\\d\\d(_\\d\\d)?)?" - meiliIndexCreationWaitTimeout = 15 * time.Second + meiliIndexCreationWaitTimeout = 30 * time.Second meiliIndexCreationWaitInterval = 50 * time.Millisecond )