diff --git a/api/server/v1/header.go b/api/server/v1/header.go index 80a4834df..f01b6684e 100644 --- a/api/server/v1/header.go +++ b/api/server/v1/header.go @@ -43,6 +43,8 @@ const ( HeaderTxOrigin = "Tigris-Tx-Origin" grpcGatewayPrefix = "Grpc-Gateway-" HeaderSchemaSignOff = "Tigris-Schema-Sign-Off" + HeaderDisableSearch = "Tigris-Disable-Search" + HeaderSchemaVersion = "Tigris-Schema-Version" HeaderBypassAuthCache = "Tigris-Bypass-Auth-Cache" // #nosec G101 HeaderReadSearchDataFromStorage = "Tigris-Search-Read-From-Storage" HeaderServerTiming = "Server-Timing" diff --git a/server/request/request.go b/server/request/request.go index 6dfae9185..0ac480755 100644 --- a/server/request/request.go +++ b/server/request/request.go @@ -444,6 +444,10 @@ func NeedSchemaValidation(ctx context.Context) bool { return api.GetHeader(ctx, api.HeaderSchemaSignOff) != "true" } +func DisableSearch(ctx context.Context) bool { + return api.GetHeader(ctx, api.HeaderDisableSearch) == "true" +} + func ReadSearchDataFromStorage(ctx context.Context) bool { return api.GetHeader(ctx, api.HeaderReadSearchDataFromStorage) == "true" } diff --git a/server/services/v1/billing.go b/server/services/v1/billing.go index 5eadc0a7d..015f7f91a 100644 --- a/server/services/v1/billing.go +++ b/server/services/v1/billing.go @@ -106,6 +106,9 @@ func (b *billingService) getMetronomeId(ctx context.Context, namespaceId string) log.Warn().Msgf("Could not find namespace, this must not happen with right authn/authz configured") return uuid.Nil, errors.NotFound("Namespace %s not found", namespaceId) } + if nsMeta.Accounts == nil { + nsMeta.Accounts = &metadata.AccountIntegrations{} + } mIdStr, enabled := nsMeta.Accounts.GetMetronomeId() if !enabled || len(mIdStr) == 0 { diff --git a/server/services/v1/billing/reporter.go b/server/services/v1/billing/reporter.go index c6453cd6f..3f890bf71 100644 --- a/server/services/v1/billing/reporter.go +++ b/server/services/v1/billing/reporter.go @@ -188,6 +188,10 @@ func (r *UsageReporter) pushStorage() error { events := make([]*StorageEvent, 0, len(tenants)) for _, t := range tenants { nsMeta := t.GetNamespace().Metadata() + if nsMeta.Accounts == nil { + nsMeta.Accounts = &metadata.AccountIntegrations{} + } + if id, enabled := nsMeta.Accounts.GetMetronomeId(); len(id) == 0 || !enabled { // user doesn't have metronome integration; skip continue diff --git a/server/services/v1/database/search_indexer.go b/server/services/v1/database/search_indexer.go index 8a5109b64..a7cf2285b 100644 --- a/server/services/v1/database/search_indexer.go +++ b/server/services/v1/database/search_indexer.go @@ -32,6 +32,7 @@ import ( "github.com/tigrisdata/tigris/schema" "github.com/tigrisdata/tigris/server/config" "github.com/tigrisdata/tigris/server/metadata" + "github.com/tigrisdata/tigris/server/request" "github.com/tigrisdata/tigris/server/transaction" "github.com/tigrisdata/tigris/store/kv" "github.com/tigrisdata/tigris/store/search" @@ -54,6 +55,10 @@ func NewSearchIndexer(searchStore search.Store, tenantMgr *metadata.TenantManage } func (i *SearchIndexer) OnPostCommit(ctx context.Context, _ *metadata.Tenant, eventListener kv.EventListener) error { + if request.DisableSearch(ctx) { + return nil + } + for _, event := range eventListener.GetEvents() { var err error @@ -77,11 +82,13 @@ func (i *SearchIndexer) OnPostCommit(ctx context.Context, _ *metadata.Tenant, ev if searchIndex == nil { return fmt.Errorf("implicit search index not found") } + if event.Op == kv.DeleteEvent { if err = i.searchStore.DeleteDocument(ctx, searchIndex.StoreIndexName(), searchKey); err != nil { if !search.IsErrNotFound(err) { return err } + return nil } } else { @@ -101,13 +108,16 @@ func (i *SearchIndexer) OnPostCommit(ctx context.Context, _ *metadata.Tenant, ev } reader := bytes.NewReader(searchData) + var resp []search.IndexResp + if resp, err = i.searchStore.IndexDocuments(ctx, searchIndex.StoreIndexName(), reader, search.IndexDocumentsOptions{ Action: action, BatchSize: 1, }); err != nil { return err } + if len(resp) == 1 && !resp[0].Success { return search.NewSearchError(resp[0].Code, search.ErrCodeUnhandled, resp[0].Error) }