Skip to content

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

chore: apply sampling size (#15932)

Danny Xuae37a4ef1aee
diff --git a/backend/api/v1/plan_service_plan_check.go b/backend/api/v1/plan_service_plan_check.go
index a345163ef4..0c013202ee 100644
--- a/backend/api/v1/plan_service_plan_check.go
+++ b/backend/api/v1/plan_service_plan_check.go
@@ -2,6 +2,7 @@ package v1
import (
"context"
+ "fmt"
"github.com/pkg/errors"
@@ -51,6 +52,19 @@ func getPlanCheckRunsFromPlanSpecs(ctx context.Context, s *store.Store, plan *st
planCheckRuns = append(planCheckRuns, runs...)
}
}
+ if project.Setting.GetCiSamplingSize() > 0 {
+ var updatedRuns []*store.PlanCheckRunMessage
+ countMap := make(map[string]int32)
+ for _, run := range planCheckRuns {
+ key := fmt.Sprintf("%s/%s/%s/%d", run.Type, run.Config.GetInstanceId(), run.Config.GetDatabaseName(), run.Config.GetSheetUid())
+ if countMap[key] >= project.Setting.GetCiSamplingSize() {
+ continue
+ }
+ updatedRuns = append(updatedRuns, run)
+ countMap[key]++
+ }
+ planCheckRuns = updatedRuns
+ }
return planCheckRuns, nil
}