Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
feat: instance pagination in the backend (#15677)
ecmadaob994926a33f4
diff --git a/backend/api/v1/auth_service.go b/backend/api/v1/auth_service.goindex 45ae3cedfb..38aa43b92c 100644--- a/backend/api/v1/auth_service.go+++ b/backend/api/v1/auth_service.go@@ -56,7 +56,7 @@ type AuthService struct {}// NewAuthService creates a new AuthService.-func NewAuthService(store *store.Store, secret string, licenseService enterprise.LicenseService, metricReporter *metricreport.Reporter, profile *config.Profile, stateCfg *state.State, iamManager *iam.Manager, postCreateUser func(ctx context.Context, user *store.UserMessage, firstEndUser bool) error) (*AuthService, error) {+func NewAuthService(store *store.Store, secret string, licenseService enterprise.LicenseService, metricReporter *metricreport.Reporter, profile *config.Profile, stateCfg *state.State, iamManager *iam.Manager, postCreateUser func(ctx context.Context, user *store.UserMessage, firstEndUser bool) error) *AuthService {return &AuthService{store: store,secret: secret,@@ -66,7 +66,7 @@ func NewAuthService(store *store.Store, secret string, licenseService enterprisestateCfg: stateCfg,iamManager: iamManager,postCreateUser: postCreateUser,- }, nil+ }}// Login is the auth login method including SSO.diff --git a/backend/api/v1/database_service.go b/backend/api/v1/database_service.goindex 57ce36c591..9fd910f10b 100644--- a/backend/api/v1/database_service.go+++ b/backend/api/v1/database_service.go@@ -123,6 +123,32 @@ func getSubConditionFromExpr(expr celast.Expr, getFilter func(expr celast.Expr)return strings.Join(args, fmt.Sprintf(" %s ", join)), nil}+func parseToEngineSQL(expr celast.Expr, relation string) (string, error) {+ variable, value := getVariableAndValueFromExpr(expr)+ if variable != "engine" {+ return "", status.Errorf(codes.InvalidArgument, `only "engine" support "engine in [xx]"/"!(engine in [xx])" operator`)+ }++ rawEngineList, ok := value.([]any)+ if !ok {+ return "", status.Errorf(codes.InvalidArgument, "invalid engine value %q", value)+ }+ if len(rawEngineList) == 0 {+ return "", status.Errorf(codes.InvalidArgument, "empty engine filter")+ }+ engineList := []string{}+ for _, rawEngine := range rawEngineList {+ v1Engine, ok := v1pb.Engine_value[rawEngine.(string)]+ if !ok {+ return "", status.Errorf(codes.InvalidArgument, "invalid engine filter %q", rawEngine)+ }+ engine := convertEngine(v1pb.Engine(v1Engine))+ engineList = append(engineList, fmt.Sprintf(`'%s'`, engine.String()))+ }++ return fmt.Sprintf("instance.metadata->>'engine' %s (%s)", relation, strings.Join(engineList, ",")), nil+}+func getListDatabaseFilter(filter string) (*store.ListResourceFilter, error) {if filter == "" {return nil, nil@@ -198,33 +224,6 @@ func getListDatabaseFilter(filter string) (*store.ListResourceFilter, error) {}}- parseToEngineSQL := func(expr celast.Expr, relation string) (string, error) {- variable, value := getVariableAndValueFromExpr(expr)- if variable != "engine" {- return "", status.Errorf(codes.InvalidArgument, `only "engine" support "engine in [xx]"/"!(engine in [xx])" operator`)- }-- rawEngineList, ok := value.([]any)- if !ok {- return "", status.Errorf(codes.InvalidArgument, "invalid engine value %q", value)- }- if len(rawEngineList) == 0 {- return "", status.Errorf(codes.InvalidArgument, "empty engine filter")- }- engineList := []string{}- for _, rawEngine := range rawEngineList {- v1Engine, ok := v1pb.Engine_value[rawEngine.(string)]- if !ok {- return "", status.Errorf(codes.InvalidArgument, "invalid engine filter %q", rawEngine)- }- engine := convertEngine(v1pb.Engine(v1Engine))- positionalArgs = append(positionalArgs, engine)- engineList = append(engineList, fmt.Sprintf("$%d", len(positionalArgs)))- }-- return fmt.Sprintf("instance.metadata->>'engine' %s (%s)", relation, strings.Join(engineList, ",")), nil- }-getFilter = func(expr celast.Expr) (string, error) {switch expr.Kind() {case celast.CallKind:diff --git a/backend/api/v1/database_service_test.go b/backend/api/v1/database_service_test.goindex 263e5502f3..c23811b9a3 100644--- a/backend/api/v1/database_service_test.go+++ b/backend/api/v1/database_service_test.go@@ -1,6 +1,7 @@package v1import (+ "fmt""testing""github.com/stretchr/testify/require"@@ -160,8 +161,8 @@ func TestListDatabaseFilter(t *testing.T) {{input: `engine in ["MYSQL", "POSTGRES"]`,want: &store.ListResourceFilter{- Where: `(instance.metadata->>'engine' IN ($1,$2))`,- Args: []any{v1pb.Engine_MYSQL, v1pb.Engine_POSTGRES},+ Where: fmt.Sprintf(`(instance.metadata->>'engine' IN ('%s','%s'))`, v1pb.Engine_MYSQL.String(), v1pb.Engine_POSTGRES.String()),+ Args: []any{},},},{diff --git a/backend/api/v1/instance_service.go b/backend/api/v1/instance_service.goindex e902bec1ca..e8217b61b1 100644--- a/backend/api/v1/instance_service.go+++ b/backend/api/v1/instance_service.go@@ -2,9 +2,14 @@ package v1import ("context"+ "fmt""log/slog""strings"+ "github.com/google/cel-go/cel"+ celast "github.com/google/cel-go/common/ast"+ celoperators "github.com/google/cel-go/common/operators"+ celoverloads "github.com/google/cel-go/common/overloads""github.com/pkg/errors""google.golang.org/grpc/codes""google.golang.org/grpc/status"@@ -63,16 +68,167 @@ func (s *InstanceService) GetInstance(ctx context.Context, request *v1pb.GetInstreturn convertInstanceMessage(instance)}+func parseListInstanceFilter(filter string) (*store.ListResourceFilter, error) {+ if filter == "" {+ return nil, nil+ }+ e, err := cel.NewEnv()+ if err != nil {+ return nil, status.Errorf(codes.Internal, "failed to create cel env")+ }+ ast, iss := e.Parse(filter)+ if iss != nil {+ return nil, status.Errorf(codes.InvalidArgument, "failed to parse filter %v, error: %v", filter, iss.String())+ }++ var getFilter func(expr celast.Expr) (string, error)+ var positionalArgs []any++ parseToSQL := func(variable, value any) (string, error) {+ switch variable {+ case "name":+ positionalArgs = append(positionalArgs, value.(string))+ return fmt.Sprintf("instance.metadata->>'title' = $%d", len(positionalArgs)), nil+ case "resource_id":+ positionalArgs = append(positionalArgs, value.(string))+ return fmt.Sprintf("instance.resource_id = $%d", len(positionalArgs)), nil+ case "environment":+ environmentID, err := common.GetEnvironmentID(value.(string))+ if err != nil {+ return "", status.Errorf(codes.InvalidArgument, "invalid environment filter %q", value)+ }+ positionalArgs = append(positionalArgs, environmentID)+ return fmt.Sprintf("instance.environment = $%d", len(positionalArgs)), nil+ case "state":+ v1State, ok := v1pb.State_value[value.(string)]+ if !ok {+ return "", status.Errorf(codes.InvalidArgument, "invalid state filter %q", value)+ }+ positionalArgs = append(positionalArgs, v1pb.State(v1State) == v1pb.State_DELETED)+ return fmt.Sprintf("instance.deleted = $%d", len(positionalArgs)), nil+ case "engine":+ v1Engine, ok := v1pb.Engine_value[value.(string)]+ if !ok {+ return "", status.Errorf(codes.InvalidArgument, "invalid engine filter %q", value)+ }+ engine := convertEngine(v1pb.Engine(v1Engine))+ positionalArgs = append(positionalArgs, engine)+ return fmt.Sprintf("instance.metadata->>'engine' = $%d", len(positionalArgs)), nil+ case "host":+ positionalArgs = append(positionalArgs, value.(string))+ return fmt.Sprintf("ds ->> 'host' = $%d", len(positionalArgs)), nil+ case "port":+ positionalArgs = append(positionalArgs, value.(string))+ return fmt.Sprintf("ds ->> 'port' = $%d", len(positionalArgs)), nil+ case "project":+ projectID, err := common.GetProjectID(value.(string))+ if err != nil {+ return "", status.Errorf(codes.InvalidArgument, "invalid project filter %q", value)+ }+ positionalArgs = append(positionalArgs, projectID)+ return fmt.Sprintf("db.project = $%d", len(positionalArgs)), nil+ default:+ return "", status.Errorf(codes.InvalidArgument, "unsupport variable %q", variable)+ }+ }++ getFilter = func(expr celast.Expr) (string, error) {+ switch expr.Kind() {+ case celast.CallKind:+ functionName := expr.AsCall().FunctionName()+ switch functionName {+ case celoperators.LogicalOr:+ return getSubConditionFromExpr(expr, getFilter, "OR")+ case celoperators.LogicalAnd:+ return getSubConditionFromExpr(expr, getFilter, "AND")+ case celoperators.Equals:+ variable, value := getVariableAndValueFromExpr(expr)+ return parseToSQL(variable, value)+ case celoverloads.Matches:+ variable := expr.AsCall().Target().AsIdent()+ args := expr.AsCall().Args()+ if len(args) != 1 {+ return "", status.Errorf(codes.InvalidArgument, `invalid args for %q`, variable)+ }+ value := args[0].AsLiteral().Value()+ strValue, ok := value.(string)+ if !ok {+ return "", status.Errorf(codes.InvalidArgument, "expect string, got %T, hint: filter literals should be string", value)+ }++ switch variable {+ case "name":+ return "LOWER(instance.metadata->>'title') LIKE '%" + strings.ToLower(strValue) + "%'", nil+ case "resource_id":+ return "LOWER(instance.resource_id) LIKE '%" + strings.ToLower(strValue) + "%'", nil+ default:+ return "", status.Errorf(codes.InvalidArgument, "unsupport variable %q", variable)+ }+ case celoperators.In:+ return parseToEngineSQL(expr, "IN")+ case celoperators.LogicalNot:+ args := expr.AsCall().Args()+ if len(args) != 1 {+ return "", status.Errorf(codes.InvalidArgument, `only support !(engine in ["{engine1}", "{engine2}"]) format`)+ }+ return parseToEngineSQL(args[0], "NOT IN")+ default:+ return "", status.Errorf(codes.InvalidArgument, "unexpected function %v", functionName)+ }+ default:+ return "", status.Errorf(codes.InvalidArgument, "unexpected expr kind %v", expr.Kind())+ }+ }++ where, err := getFilter(ast.NativeRep().Expr())+ if err != nil {+ return nil, err+ }++ return &store.ListResourceFilter{+ Args: positionalArgs,+ Where: "(" + where + ")",+ }, nil+}+// ListInstances lists all instances.func (s *InstanceService) ListInstances(ctx context.Context, request *v1pb.ListInstancesRequest) (*v1pb.ListInstancesResponse, error) {+ offset, err := parseLimitAndOffset(&pageSize{+ token: request.PageToken,+ limit: int(request.PageSize),+ maximum: 1000,+ })+ if err != nil {+ return nil, err+ }+ limitPlusOne := offset.limit + 1+find := &store.FindInstanceMessage{ShowDeleted: request.ShowDeleted,+ Limit: &limitPlusOne,+ Offset: &offset.offset,+ }+ filter, err := parseListInstanceFilter(request.Filter)+ if err != nil {+ return nil, err}+ find.Filter = filterinstances, err := s.store.ListInstancesV2(ctx, find)if err != nil {return nil, status.Error(codes.Internal, err.Error())}- response := &v1pb.ListInstancesResponse{}++ nextPageToken := ""+ if len(instances) == limitPlusOne {+ instances = instances[:offset.limit]+ if nextPageToken, err = offset.getNextPageToken(); err != nil {+ return nil, status.Errorf(codes.Internal, "failed to marshal next page token, error: %v", err)+ }+ }++ response := &v1pb.ListInstancesResponse{+ NextPageToken: nextPageToken,+ }for _, instance := range instances {ins, err := convertInstanceMessage(instance)if err != nil {diff --git a/backend/api/v1/project_service.go b/backend/api/v1/project_service.goindex 7dbfefe7a8..50982de7f7 100644--- a/backend/api/v1/project_service.go+++ b/backend/api/v1/project_service.go@@ -46,7 +46,12 @@ type ProjectService struct {}// NewProjectService creates a new ProjectService.-func NewProjectService(store *store.Store, profile *config.Profile, iamManager *iam.Manager, licenseService enterprise.LicenseService) *ProjectService {+func NewProjectService(+ store *store.Store,+ profile *config.Profile,+ iamManager *iam.Manager,+ licenseService enterprise.LicenseService,+) *ProjectService {return &ProjectService{store: store,profile: profile,diff --git a/backend/api/v1/user_service.go b/backend/api/v1/user_service.goindex 736161fac4..693c434197 100644--- a/backend/api/v1/user_service.go+++ b/backend/api/v1/user_service.go@@ -48,7 +48,7 @@ type UserService struct {}// NewUserService creates a new UserService.-func NewUserService(store *store.Store, secret string, licenseService enterprise.LicenseService, metricReporter *metricreport.Reporter, profile *config.Profile, stateCfg *state.State, iamManager *iam.Manager, postCreateUser func(ctx context.Context, user *store.UserMessage, firstEndUser bool) error) (*UserService, error) {+func NewUserService(store *store.Store, secret string, licenseService enterprise.LicenseService, metricReporter *metricreport.Reporter, profile *config.Profile, stateCfg *state.State, iamManager *iam.Manager, postCreateUser func(ctx context.Context, user *store.UserMessage, firstEndUser bool) error) *UserService {return &UserService{store: store,secret: secret,@@ -58,7 +58,7 @@ func NewUserService(store *store.Store, secret string, licenseService enterprisestateCfg: stateCfg,iamManager: iamManager,postCreateUser: postCreateUser,- }, nil+ }}// GetUser gets a user.diff --git a/backend/server/grpc_routes.go b/backend/server/grpc_routes.goindex 9012b04882..0d612262dd 100644--- a/backend/server/grpc_routes.go+++ b/backend/server/grpc_routes.go@@ -40,14 +40,8 @@ func configureGrpcRouters(postCreateUser apiv1.CreateUserFunc,secret string) error {// Register services.- authService, err := apiv1.NewAuthService(stores, secret, licenseService, metricReporter, profile, stateCfg, iamManager, postCreateUser)- if err != nil {- return err- }- userService, err := apiv1.NewUserService(stores, secret, licenseService, metricReporter, profile, stateCfg, iamManager, postCreateUser)- if err != nil {- return err- }+ authService := apiv1.NewAuthService(stores, secret, licenseService, metricReporter, profile, stateCfg, iamManager, postCreateUser)+ userService := apiv1.NewUserService(stores, secret, licenseService, metricReporter, profile, stateCfg, iamManager, postCreateUser)v1pb.RegisterAuditLogServiceServer(grpcServer, apiv1.NewAuditLogService(stores, iamManager, licenseService))v1pb.RegisterAuthServiceServer(grpcServer, authService)v1pb.RegisterUserServiceServer(grpcServer, userService)diff --git a/backend/store/instance.go b/backend/store/instance.goindex dc9cffc54e..934c8aec27 100644--- a/backend/store/instance.go+++ b/backend/store/instance.go@@ -39,6 +39,9 @@ type FindInstanceMessage struct {ResourceID *stringResourceIDs *[]stringShowDeleted bool+ Limit *int+ Offset *int+ Filter *ListResourceFilter}// GetInstanceV2 gets an instance by the resource_id.@@ -190,6 +193,10 @@ func (s *Store) UpdateInstanceV2(ctx context.Context, patch *UpdateInstanceMessafunc (s *Store) listInstanceImplV2(ctx context.Context, txn *sql.Tx, find *FindInstanceMessage) ([]*InstanceMessage, error) {where, args := []string{"TRUE"}, []any{}+ if filter := find.Filter; filter != nil {+ where = append(where, filter.Where)+ args = append(args, filter.Args...)+ }if v := find.ResourceID; v != nil {where, args = append(where, fmt.Sprintf("instance.resource_id = $%d", len(args)+1)), append(args, *v)}@@ -200,18 +207,26 @@ func (s *Store) listInstanceImplV2(ctx context.Context, txn *sql.Tx, find *FindIwhere, args = append(where, fmt.Sprintf("instance.deleted = $%d", len(args)+1)), append(args, false)}- var instanceMessages []*InstanceMessage- rows, err := txn.QueryContext(ctx, fmt.Sprintf(`- SELECT- resource_id,- environment,- deleted,- metadata+ query := fmt.Sprintf(`+ SELECT DISTINCT ON (resource_id)+ instance.resource_id,+ instance.environment,+ instance.deleted,+ instance.metadataFROM instance+ CROSS JOIN jsonb_array_elements(instance.metadata -> 'dataSources') AS ds+ LEFT JOIN db ON db.instance = instance.resource_idWHERE %s- ORDER BY resource_id`, strings.Join(where, " AND ")),- args...,- )+ ORDER BY resource_id`, strings.Join(where, " AND "))+ if v := find.Limit; v != nil {+ query += fmt.Sprintf(" LIMIT %d", *v)+ }+ if v := find.Offset; v != nil {+ query += fmt.Sprintf(" OFFSET %d", *v)+ }++ var instanceMessages []*InstanceMessage+ rows, err := txn.QueryContext(ctx, query, args...)if err != nil {return nil, err}diff --git a/frontend/src/types/proto/v1/instance_service.ts b/frontend/src/types/proto/v1/instance_service.tsindex c4790c1880..0c29642f25 100644--- a/frontend/src/types/proto/v1/instance_service.ts+++ b/frontend/src/types/proto/v1/instance_service.ts@@ -87,7 +87,6 @@ export interface GetInstanceRequest {export interface ListInstancesRequest {/**- * Not used.* The maximum number of instances to return. The service may return fewer than* this value.* If unspecified, at most 10 instances will be returned.@@ -95,7 +94,6 @@ export interface ListInstancesRequest {*/pageSize: number;/**- * Not used.* A page token, received from a previous `ListInstances` call.* Provide this to retrieve the subsequent page.*@@ -105,6 +103,36 @@ export interface ListInstancesRequest {pageToken: string;/** Show deleted instances if specified. */showDeleted: boolean;+ /**+ * Filter the project.+ * Supported filters:+ * - name+ * - resource_id+ * - environment+ * - state+ * - engine+ * - host+ * - port+ * - project+ *+ * For example:+ * name == "sample instance"+ * name.matches("sample")+ * resource_id = "sample-instance"+ * resource_id.matches("sample")+ * state == "DELETED"+ * environment == "environments/test"+ * engine == "MYSQL"+ * engine in ["MYSQL", "POSTGRES"]+ * !(engine in ["MYSQL", "POSTGRES"])+ * host == "127.0.0.1"+ * port == "54321"+ * project == "projects/sample-project"+ * You can combine filter conditions like:+ * name.matches("sample") && environment == "environments/test"+ * host == "127.0.0.1" && port == "54321"+ */+ filter: string;}export interface ListInstancesResponse {@@ -812,7 +840,7 @@ export const GetInstanceRequest: MessageFns<GetInstanceRequest> = {};function createBaseListInstancesRequest(): ListInstancesRequest {- return { pageSize: 0, pageToken: "", showDeleted: false };+ return { pageSize: 0, pageToken: "", showDeleted: false, filter: "" };}export const ListInstancesRequest: MessageFns<ListInstancesRequest> = {@@ -826,6 +854,9 @@ export const ListInstancesRequest: MessageFns<ListInstancesRequest> = {if (message.showDeleted !== false) {writer.uint32(24).bool(message.showDeleted);}+ if (message.filter !== "") {+ writer.uint32(34).string(message.filter);+ }return writer;},@@ -860,6 +891,14 @@ export const ListInstancesRequest: MessageFns<ListInstancesRequest> = {message.showDeleted = reader.bool();continue;}+ case 4: {+ if (tag !== 34) {+ break;+ }++ message.filter = reader.string();+ continue;+ }}if ((tag & 7) === 4 || tag === 0) {break;@@ -874,6 +913,7 @@ export const ListInstancesRequest: MessageFns<ListInstancesRequest> = {pageSize: isSet(object.pageSize) ? globalThis.Number(object.pageSize) : 0,pageToken: isSet(object.pageToken) ? globalThis.String(object.pageToken) : "",showDeleted: isSet(object.showDeleted) ? globalThis.Boolean(object.showDeleted) : false,+ filter: isSet(object.filter) ? globalThis.String(object.filter) : "",};},@@ -888,6 +928,9 @@ export const ListInstancesRequest: MessageFns<ListInstancesRequest> = {if (message.showDeleted !== false) {obj.showDeleted = message.showDeleted;}+ if (message.filter !== "") {+ obj.filter = message.filter;+ }return obj;},@@ -899,6 +942,7 @@ export const ListInstancesRequest: MessageFns<ListInstancesRequest> = {message.pageSize = object.pageSize ?? 0;message.pageToken = object.pageToken ?? "";message.showDeleted = object.showDeleted ?? false;+ message.filter = object.filter ?? "";return message;},};diff --git a/proto/gen/grpc-doc/openapi.yaml b/proto/gen/grpc-doc/openapi.yamlindex 0107b70821..19b9f9cad7 100644--- a/proto/gen/grpc-doc/openapi.yaml+++ b/proto/gen/grpc-doc/openapi.yaml@@ -1087,8 +1087,7 @@ paths:- name: pageSizein: querydescription: |-- Not used.- The maximum number of instances to return. The service may return fewer than+ The maximum number of instances to return. The service may return fewer thanthis value.If unspecified, at most 10 instances will be returned.The maximum value is 1000; values above 1000 will be coerced to 1000.@@ -1098,8 +1097,7 @@ paths:- name: pageTokenin: querydescription: |-- Not used.- A page token, received from a previous `ListInstances` call.+ A page token, received from a previous `ListInstances` call.Provide this to retrieve the subsequent page.When paginating, all other parameters provided to `ListInstances` must match@@ -1111,6 +1109,38 @@ paths:description: Show deleted instances if specified.schema:type: boolean+ - name: filter+ in: query+ description: |-+ Filter the project.+ Supported filters:+ - name+ - resource_id+ - environment+ - state+ - engine+ - host+ - port+ - project++ For example:+ name == "sample instance"+ name.matches("sample")+ resource_id = "sample-instance"+ resource_id.matches("sample")+ state == "DELETED"+ environment == "environments/test"+ engine == "MYSQL"+ engine in ["MYSQL", "POSTGRES"]+ !(engine in ["MYSQL", "POSTGRES"])+ host == "127.0.0.1"+ port == "54321"+ project == "projects/sample-project"+ You can combine filter conditions like:+ name.matches("sample") && environment == "environments/test"+ host == "127.0.0.1" && port == "54321"+ schema:+ type: stringresponses:"200":description: OKdiff --git a/proto/gen/grpc-doc/v1/README.md b/proto/gen/grpc-doc/v1/README.mdindex 4552100e87..34370468db 100644--- a/proto/gen/grpc-doc/v1/README.md+++ b/proto/gen/grpc-doc/v1/README.md@@ -1569,11 +1569,14 @@ This value should be 4-63 characters, and valid characters are /[a-z][0-9]-/. || Field | Type | Label | Description || ----- | ---- | ----- | ----------- |-| page_size | [int32](#int32) | | Not used. The maximum number of instances to return. The service may return fewer than this value. If unspecified, at most 10 instances will be returned. The maximum value is 1000; values above 1000 will be coerced to 1000. |-| page_token | [string](#string) | | Not used. A page token, received from a previous `ListInstances` call. Provide this to retrieve the subsequent page.+| page_size | [int32](#int32) | | The maximum number of instances to return. The service may return fewer than this value. If unspecified, at most 10 instances will be returned. The maximum value is 1000; values above 1000 will be coerced to 1000. |+| page_token | [string](#string) | | A page token, received from a previous `ListInstances` call. Provide this to retrieve the subsequent page.When paginating, all other parameters provided to `ListInstances` must match the call that provided the page token. || show_deleted | [bool](#bool) | | Show deleted instances if specified. |+| filter | [string](#string) | | Filter the project. Supported filters: - name - resource_id - environment - state - engine - host - port - project++For example: name == "sample instance" name.matches("sample") resource_id = "sample-instance" resource_id.matches("sample") state == "DELETED" environment == "environments/test" engine == "MYSQL" engine in ["MYSQL", "POSTGRES"] !(engine in ["MYSQL", "POSTGRES"]) host == "127.0.0.1" port == "54321" project == "projects/sample-project" You can combine filter conditions like: name.matches("sample") && environment == "environments/test" host == "127.0.0.1" && port == "54321" |diff --git a/proto/gen/grpc-doc/v1/index.html b/proto/gen/grpc-doc/v1/index.htmlindex eb7c2ce322..7c8619de4d 100644--- a/proto/gen/grpc-doc/v1/index.html+++ b/proto/gen/grpc-doc/v1/index.html@@ -5102,8 +5102,7 @@ Format: instances/{instance} </p></td><td>page_size</td><td><a href="#int32">int32</a></td><td></td>- <td><p>Not used.-The maximum number of instances to return. The service may return fewer than+ <td><p>The maximum number of instances to return. The service may return fewer thanthis value.If unspecified, at most 10 instances will be returned.The maximum value is 1000; values above 1000 will be coerced to 1000. </p></td>@@ -5113,8 +5112,7 @@ The maximum value is 1000; values above 1000 will be coerced to 1000. </p></td><td>page_token</td><td><a href="#string">string</a></td><td></td>- <td><p>Not used.-A page token, received from a previous `ListInstances` call.+ <td><p>A page token, received from a previous `ListInstances` call.Provide this to retrieve the subsequent page.When paginating, all other parameters provided to `ListInstances` must match@@ -5128,6 +5126,39 @@ the call that provided the page token. </p></td><td><p>Show deleted instances if specified. </p></td></tr>+ <tr>+ <td>filter</td>+ <td><a href="#string">string</a></td>+ <td></td>+ <td><p>Filter the project.+Supported filters:+- name+- resource_id+- environment+- state+- engine+- host+- port+- project++For example:+name == "sample instance"+name.matches("sample")+resource_id = "sample-instance"+resource_id.matches("sample")+state == "DELETED"+environment == "environments/test"+engine == "MYSQL"+engine in ["MYSQL", "POSTGRES"]+!(engine in ["MYSQL", "POSTGRES"])+host == "127.0.0.1"+port == "54321"+project == "projects/sample-project"+You can combine filter conditions like:+name.matches("sample") && environment == "environments/test"+host == "127.0.0.1" && port == "54321" </p></td>+ </tr>+</tbody></table>diff --git a/proto/generated-go/v1/instance_service.pb.go b/proto/generated-go/v1/instance_service.pb.goindex 4b7d34ee08..f31354952f 100644--- a/proto/generated-go/v1/instance_service.pb.go+++ b/proto/generated-go/v1/instance_service.pb.go@@ -384,13 +384,11 @@ func (x *GetInstanceRequest) GetName() string {type ListInstancesRequest struct {state protoimpl.MessageState `protogen:"open.v1"`- // Not used.// The maximum number of instances to return. The service may return fewer than// this value.// If unspecified, at most 10 instances will be returned.// The maximum value is 1000; values above 1000 will be coerced to 1000.PageSize int32 `protobuf:"varint,1,opt,name=page_size,json=pageSize,proto3" json:"page_size,omitempty"`- // Not used.// A page token, received from a previous `ListInstances` call.// Provide this to retrieve the subsequent page.//@@ -398,7 +396,35 @@ type ListInstancesRequest struct {// the call that provided the page token.PageToken string `protobuf:"bytes,2,opt,name=page_token,json=pageToken,proto3" json:"page_token,omitempty"`// Show deleted instances if specified.- ShowDeleted bool `protobuf:"varint,3,opt,name=show_deleted,json=showDeleted,proto3" json:"show_deleted,omitempty"`+ ShowDeleted bool `protobuf:"varint,3,opt,name=show_deleted,json=showDeleted,proto3" json:"show_deleted,omitempty"`+ // Filter the project.+ // Supported filters:+ // - name+ // - resource_id+ // - environment+ // - state+ // - engine+ // - host+ // - port+ // - project+ //+ // For example:+ // name == "sample instance"+ // name.matches("sample")+ // resource_id = "sample-instance"+ // resource_id.matches("sample")+ // state == "DELETED"+ // environment == "environments/test"+ // engine == "MYSQL"+ // engine in ["MYSQL", "POSTGRES"]+ // !(engine in ["MYSQL", "POSTGRES"])+ // host == "127.0.0.1"+ // port == "54321"+ // project == "projects/sample-project"+ // You can combine filter conditions like:+ // name.matches("sample") && environment == "environments/test"+ // host == "127.0.0.1" && port == "54321"+ Filter string `protobuf:"bytes,4,opt,name=filter,proto3" json:"filter,omitempty"`unknownFields protoimpl.UnknownFieldssizeCache protoimpl.SizeCache}@@ -454,6 +480,13 @@ func (x *ListInstancesRequest) GetShowDeleted() bool {return false}+func (x *ListInstancesRequest) GetFilter() string {+ if x != nil {+ return x.Filter+ }+ return ""+}+type ListInstancesResponse struct {state protoimpl.MessageState `protogen:"open.v1"`// The instances from the specified request.@@ -2308,12 +2341,13 @@ const file_v1_instance_service_proto_rawDesc = "" +"\x19v1/instance_service.proto\x12\vbytebase.v1\x1a\x1cgoogle/api/annotations.proto\x1a\x17google/api/client.proto\x1a\x1fgoogle/api/field_behavior.proto\x1a\x19google/api/resource.proto\x1a\x1egoogle/protobuf/duration.proto\x1a\x1bgoogle/protobuf/empty.proto\x1a google/protobuf/field_mask.proto\x1a\x13v1/annotation.proto\x1a\x0fv1/common.proto\x1a\x1ev1/instance_role_service.proto\"H\n" +"\x12GetInstanceRequest\x122\n" +"\x04name\x18\x01 \x01(\tB\x1e\xe2A\x01\x02\xfaA\x17\n" +- "\x15bytebase.com/InstanceR\x04name\"u\n" ++ "\x15bytebase.com/InstanceR\x04name\"\x8d\x01\n" +"\x14ListInstancesRequest\x12\x1b\n" +"\tpage_size\x18\x01 \x01(\x05R\bpageSize\x12\x1d\n" +"\n" +"page_token\x18\x02 \x01(\tR\tpageToken\x12!\n" +- "\fshow_deleted\x18\x03 \x01(\bR\vshowDeleted\"t\n" ++ "\fshow_deleted\x18\x03 \x01(\bR\vshowDeleted\x12\x16\n" ++ "\x06filter\x18\x04 \x01(\tR\x06filter\"t\n" +"\x15ListInstancesResponse\x123\n" +"\tinstances\x18\x01 \x03(\v2\x15.bytebase.v1.InstanceR\tinstances\x12&\n" +"\x0fnext_page_token\x18\x02 \x01(\tR\rnextPageToken\"\x96\x01\n" +diff --git a/proto/v1/instance_service.proto b/proto/v1/instance_service.protoindex 6920ef995e..9ad205bce9 100644--- a/proto/v1/instance_service.proto+++ b/proto/v1/instance_service.proto@@ -138,14 +138,12 @@ message GetInstanceRequest {}message ListInstancesRequest {- // Not used.// The maximum number of instances to return. The service may return fewer than// this value.// If unspecified, at most 10 instances will be returned.// The maximum value is 1000; values above 1000 will be coerced to 1000.int32 page_size = 1;- // Not used.// A page token, received from a previous `ListInstances` call.// Provide this to retrieve the subsequent page.//@@ -155,6 +153,35 @@ message ListInstancesRequest {// Show deleted instances if specified.bool show_deleted = 3;++ // Filter the project.+ // Supported filters:+ // - name+ // - resource_id+ // - environment+ // - state+ // - engine+ // - host+ // - port+ // - project+ //+ // For example:+ // name == "sample instance"+ // name.matches("sample")+ // resource_id = "sample-instance"+ // resource_id.matches("sample")+ // state == "DELETED"+ // environment == "environments/test"+ // engine == "MYSQL"+ // engine in ["MYSQL", "POSTGRES"]+ // !(engine in ["MYSQL", "POSTGRES"])+ // host == "127.0.0.1"+ // port == "54321"+ // project == "projects/sample-project"+ // You can combine filter conditions like:+ // name.matches("sample") && environment == "environments/test"+ // host == "127.0.0.1" && port == "54321"+ string filter = 4;}message ListInstancesResponse {