Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

chore: index-advisor guard (#5896)

Danny Xu31c400605971
diff --git a/backend/api/v1/database_service.go b/backend/api/v1/database_service.go
index f89b681f31..3a0df03c70 100644
--- a/backend/api/v1/database_service.go
+++ b/backend/api/v1/database_service.go
@@ -1690,6 +1690,7 @@ func (s *DatabaseService) pgAdviseIndex(ctx context.Context, request *v1pb.Advis
func getOpenAIResponse(ctx context.Context, messages []openai.ChatCompletionMessage, key string, generateResponse func(*v1pb.AdviseIndexResponse) error) (*v1pb.AdviseIndexResponse, error) {
var result v1pb.AdviseIndexResponse
successful := false
+ var retErr error
// Retry 5 times if failed.
for i := 0; i < 5; i++ {
client := openai.NewClient(key)
@@ -1706,12 +1707,15 @@ func getOpenAIResponse(ctx context.Context, messages []openai.ChatCompletionMess
},
)
if err != nil {
+ retErr = err
continue
}
if err := protojson.Unmarshal([]byte(resp.Choices[0].Message.Content), &result); err != nil {
+ retErr = err
continue
}
if err = generateResponse(&result); err != nil {
+ retErr = err
continue
}
successful = true
@@ -1719,7 +1723,7 @@ func getOpenAIResponse(ctx context.Context, messages []openai.ChatCompletionMess
}
if !successful {
- return nil, status.Errorf(codes.Internal, "Failed to get index advice")
+ return nil, status.Errorf(codes.Internal, "Failed to get index advice, error %v", retErr)
}
return &result, nil
}
diff --git a/backend/legacyapi/plan.go b/backend/legacyapi/plan.go
index 02ede311fb..07fb6d364e 100644
--- a/backend/legacyapi/plan.go
+++ b/backend/legacyapi/plan.go
@@ -139,6 +139,8 @@ const (
FeatureReadReplicaConnection FeatureType = "bb.feature.read-replica-connection"
// FeatureSyncSchemaAllVersions allows user to sync the base database schema all versions into target database.
FeatureSyncSchemaAllVersions FeatureType = "bb.feature.sync-schema-all-versions"
+ // FeatureIndexAdvisor provides the index advisor for databases.
+ FeatureIndexAdvisor FeatureType = "bb.feature.index-advisor"
// Policy Control.
@@ -229,6 +231,8 @@ func (e FeatureType) Name() string {
return "Read replica connection"
case FeatureSyncSchemaAllVersions:
return "Synchronize schema all versions"
+ case FeatureIndexAdvisor:
+ return "Index advisor"
// Policy Control
case FeatureApprovalPolicy:
return "Approval policy"
@@ -300,6 +304,7 @@ var FeatureMatrix = map[FeatureType][3]bool{
FeaturePITR: {false, true, true},
FeatureReadReplicaConnection: {false, false, true},
FeatureSyncSchemaAllVersions: {false, true, true},
+ FeatureIndexAdvisor: {false, false, true},
// Policy Control
FeatureApprovalPolicy: {false, true, true},
FeatureBackupPolicy: {false, true, true},
diff --git a/frontend/src/types/plan.ts b/frontend/src/types/plan.ts
index b4842bd2a3..ab44923bfb 100644
--- a/frontend/src/types/plan.ts
+++ b/frontend/src/types/plan.ts
@@ -37,6 +37,7 @@ export type FeatureType =
| "bb.feature.pitr"
| "bb.feature.read-replica-connection"
| "bb.feature.sync-schema-all-versions"
+ | "bb.feature.index-advisor"
// Policy Control
| "bb.feature.approval-policy"
| "bb.feature.backup-policy"