// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

syntax = "proto3";

package google.cloud.databasecenter.v1beta;

import "google/api/annotations.proto";
import "google/api/client.proto";
import "google/api/field_behavior.proto";
import "google/api/resource.proto";
import "google/cloud/databasecenter/v1beta/affiliation.proto";
import "google/cloud/databasecenter/v1beta/machine_config.proto";
import "google/cloud/databasecenter/v1beta/maintenance.proto";
import "google/cloud/databasecenter/v1beta/metric_data.proto";
import "google/cloud/databasecenter/v1beta/product.proto";
import "google/cloud/databasecenter/v1beta/signals.proto";
import "google/protobuf/duration.proto";
import "google/type/date.proto";

option csharp_namespace = "Google.Cloud.DatabaseCenter.V1Beta";
option go_package = "cloud.google.com/go/databasecenter/apiv1beta/databasecenterpb;databasecenterpb";
option java_multiple_files = true;
option java_outer_classname = "ServiceProto";
option java_package = "com.google.cloud.databasecenter.v1beta";
option php_namespace = "Google\\Cloud\\DatabaseCenter\\V1beta";
option ruby_package = "Google::Cloud::DatabaseCenter::V1beta";

// DatabaseCenter contains methods to query fleet view for database resources.
service DatabaseCenter {
  option (google.api.default_host) = "databasecenter.googleapis.com";
  option (google.api.oauth_scopes) =
      "https://www.googleapis.com/auth/cloud-platform";

  // QueryProducts provides a list of all possible products which can be used to
  // filter database resources.
  rpc QueryProducts(QueryProductsRequest) returns (QueryProductsResponse) {
    option (google.api.http) = {
      get: "/v1beta:queryProducts"
    };
  }

  // AggregateFleet provides statistics about the fleet grouped by various
  // fields.
  rpc AggregateFleet(AggregateFleetRequest) returns (AggregateFleetResponse) {
    option (google.api.http) = {
      get: "/v1beta:aggregateFleet"
    };
  }

  // QueryDatabaseResourceGroups returns paginated results of database groups.
  rpc QueryDatabaseResourceGroups(QueryDatabaseResourceGroupsRequest)
      returns (QueryDatabaseResourceGroupsResponse) {
    option (google.api.http) = {
      post: "/v1beta:queryDatabaseResourceGroups"
      body: "*"
    };
  }

  // AggregateIssueStats provides database resource issues statistics.
  rpc AggregateIssueStats(AggregateIssueStatsRequest)
      returns (AggregateIssueStatsResponse) {
    option (google.api.http) = {
      post: "/v1beta:aggregateIssueStats"
      body: "*"
    };
  }

  // AggregateQueryStats provides database resource query execution statistics.
  rpc AggregateQueryStats(AggregateQueryStatsRequest)
      returns (AggregateQueryStatsResponse) {
    option (google.api.http) = {
      post: "/v1beta/{parent=organizations/*}:aggregateQueryStats"
      body: "*"
      additional_bindings {
        post: "/v1beta/{parent=folders/*}:aggregateQueryStats"
        body: "*"
      }
      additional_bindings {
        post: "/v1beta/{parent=projects/*}:aggregateQueryStats"
        body: "*"
      }
    };
  }

  // QueryIssues provides a list of issues and recommendations
  // that a user has access to and that are within the requested scope.
  rpc QueryIssues(QueryIssuesRequest) returns (QueryIssuesResponse) {
    option (google.api.http) = {
      post: "/v1beta:queryIssues"
      body: "*"
    };
    option (google.api.method_signature) = "parent";
  }
}

// Represents the edition of a database resource.
enum Edition {
  // Default, to make it consistent with instance edition enum.
  EDITION_UNSPECIFIED = 0;

  // Represents the enterprise edition.
  EDITION_ENTERPRISE = 1;

  // Represents the enterprise plus edition.
  EDITION_ENTERPRISE_PLUS = 2;

  // Represents the standard edition.
  EDITION_STANDARD = 3;
}

// SubResourceType refers to the sub-type of database resource.
enum SubResourceType {
  // Unspecified.
  SUB_RESOURCE_TYPE_UNSPECIFIED = 0;

  // A resource acting as a primary.
  SUB_RESOURCE_TYPE_PRIMARY = 1;

  // A resource acting as a secondary.
  SUB_RESOURCE_TYPE_SECONDARY = 2;

  // A resource acting as a read-replica.
  SUB_RESOURCE_TYPE_READ_REPLICA = 3;

  // A resource acting as an external primary.
  SUB_RESOURCE_TYPE_EXTERNAL_PRIMARY = 5;

  // A resource acting as a read pool.
  SUB_RESOURCE_TYPE_READ_POOL = 6;

  // Represents a reservation resource.
  SUB_RESOURCE_TYPE_RESERVATION = 7;

  // Represents a dataset resource.
  SUB_RESOURCE_TYPE_DATASET = 8;

  // For the rest of the categories.
  SUB_RESOURCE_TYPE_OTHER = 4;
}

// The management type of the resource.
enum ManagementType {
  // Unspecified.
  MANAGEMENT_TYPE_UNSPECIFIED = 0;

  // Google-managed resource.
  MANAGEMENT_TYPE_GCP_MANAGED = 1;

  // Self-managed resource.
  MANAGEMENT_TYPE_SELF_MANAGED = 2;
}

// The enum value corresponds to 'type' suffix in the resource_type field.
enum ResourceCategory {
  // Unspecified.
  RESOURCE_CATEGORY_UNSPECIFIED = 0;

  // A resource that is an Instance.
  INSTANCE = 1;

  // A resource that is a Cluster.
  CLUSTER = 2;

  // A resource that is a Database.
  DATABASE = 3;

  // A resource that is a Dataset.
  DATASET = 4;

  // A resource that is a Reservation.
  RESERVATION = 5;
}

// QueryProductsRequest is the request to get a list of products.
message QueryProductsRequest {
  // Required. Parent can be a project, a folder, or an organization.
  //
  // The allowed values are:
  //
  // * projects/{PROJECT_ID}/locations/{LOCATION}
  // (e.g.,"projects/foo-bar/locations/us-central1")
  // * projects/{PROJECT_NUMBER}/locations/{LOCATION}
  // (e.g.,"projects/12345678/locations/us-central1")
  // * folders/{FOLDER_NUMBER}/locations/{LOCATION}
  // (e.g.,"folders/1234567/locations/us-central1")
  // * organizations/{ORGANIZATION_NUMBER}/locations/{LOCATION}
  // (e.g.,"organizations/123456/locations/us-central1")
  // * projects/{PROJECT_ID} (e.g., "projects/foo-bar")
  // * projects/{PROJECT_NUMBER} (e.g., "projects/12345678")
  // * folders/{FOLDER_NUMBER} (e.g., "folders/1234567")
  // * organizations/{ORGANIZATION_NUMBER} (e.g., "organizations/123456")
  string parent = 3 [(google.api.field_behavior) = REQUIRED];

  // Optional. If unspecified, at most 50 products will be returned.
  // The maximum value is 1000; values above 1000 will be coerced to 1000.
  int32 page_size = 1 [(google.api.field_behavior) = OPTIONAL];

  // Optional. A page token, received from a previous `ListLocations` call.
  // Provide this to retrieve the subsequent page.
  // All other parameters except page size should match the call that provided
  // the page page token.
  string page_token = 2 [(google.api.field_behavior) = OPTIONAL];
}

// QueryProductsResponse represents the response containing a list of products.
message QueryProductsResponse {
  // List of database products returned.
  repeated Product products = 1;

  // A token that can be sent as `page_token` to retrieve the next page.
  // If this field is omitted, there are no subsequent pages
  string next_page_token = 2;

  // Unordered list. List of unreachable regions from where data could not be
  // retrieved.
  repeated string unreachable = 3
      [(google.api.field_behavior) = UNORDERED_LIST];
}

// QueryDatabaseResourceGroupsRequest is the request to get a list of database
// groups.
message QueryDatabaseResourceGroupsRequest {
  // Required. Parent can be a project, a folder, or an organization. The search
  // is limited to the resources within the `scope`.
  //
  // The allowed values are:
  //
  // * projects/{PROJECT_ID} (e.g., "projects/foo-bar")
  // * projects/{PROJECT_NUMBER} (e.g., "projects/12345678")
  // * folders/{FOLDER_NUMBER} (e.g., "folders/1234567")
  // * organizations/{ORGANIZATION_NUMBER} (e.g., "organizations/123456")
  string parent = 1 [(google.api.field_behavior) = REQUIRED];

  // Optional. The expression to filter resources.
  //
  // The following fields are filterable:
  //   * full_resource_name
  //   * resource_type
  //   * container
  //   * product.type
  //   * product.engine
  //   * product.version
  //   * location
  //   * labels
  //   * resource_category
  //   * machine_config.cpu_count
  //   * machine_config.memory_size_bytes
  //   * machine_config.shard_count
  //   * resource_name
  //   * tags
  //   * backupdr_config.backupdr_managed
  //   * edition
  //
  // The expression is a list of zero or more restrictions combined via logical
  // operators `AND` and `OR`. When `AND` and `OR` are both used in the
  // expression, parentheses must be appropriately used to group the
  // combinations.
  //
  // Example: `location="us-east1"`
  // Example: `container="projects/123" OR container="projects/456"`
  // Example: `(container="projects/123" OR
  //           container="projects/456") AND location="us-east1"`
  // Example: `full_resource_name=~"test"`
  // Example: `full_resource_name=~"test.*master"`
  string filter = 2 [(google.api.field_behavior) = OPTIONAL];

  // Optional. Groups of signal types that are requested.
  repeated SignalTypeGroup signal_type_groups = 3
      [(google.api.field_behavior) = OPTIONAL];

  // Optional. Filters based on signals. The list will be ORed together and then
  // ANDed with the `filters` field above.
  repeated SignalFilter signal_filters = 4
      [(google.api.field_behavior) = OPTIONAL];

  // Optional. A field that specifies the sort order of the results.
  //
  // The following fields are sortable:
  //   * full_resource_name
  //   * product.type
  //   * product.engine
  //   * product.version
  //   * container
  //   * issue_count
  //   * machine_config.vcpu_count
  //   * machine_config.memory_size_bytes
  //   * machine_config.shard_count
  //   * resource_name
  //   * issue_severity
  //   * signal_type
  //   * location
  //   * resource_type
  //   * instance_type
  //   * edition
  //   * metrics.p99_cpu_utilization
  //   * metrics.p95_cpu_utilization
  //   * metrics.current_storage_used_bytes
  //   * metrics.node_count
  //   * metrics.processing_unit_count
  //   * metrics.current_memory_used_bytes
  //   * metrics.peak_storage_utilization
  //   * metrics.peak_number_connections
  //   * metrics.peak_memory_utilization
  //
  // The default order is ascending. Add "DESC" after the field name to indicate
  // descending order. Add "ASC" after the field name to indicate ascending
  // order. It only supports a single field at a time.
  //
  // For example:
  //  `order_by = "full_resource_name"` sorts response in ascending order
  //  `order_by = "full_resource_name DESC"` sorts response in descending order
  //  `order_by = "issue_count DESC"` sorts response in descending order of
  //  count of all issues associated with a resource.
  //
  // More explicitly, `order_by = "full_resource_name, product"` is not
  // supported.
  string order_by = 5 [(google.api.field_behavior) = OPTIONAL];

  // Optional. If unspecified, at most 50 resource groups will be returned.
  // The maximum value is 1000; values above 1000 will be coerced to 1000.
  int32 page_size = 6 [(google.api.field_behavior) = OPTIONAL];

  // Optional. A page token, received from a previous
  // `QueryDatabaseResourceGroupsRequest` call. Provide this to retrieve the
  // subsequent page. All parameters except page_token should match the
  // parameters in the call that provided the page page token.
  string page_token = 7 [(google.api.field_behavior) = OPTIONAL];
}

// QueryDatabaseResourceGroupsResponse represents the response message
// containing a list of resource groups.
message QueryDatabaseResourceGroupsResponse {
  // List of database resource groups that pass the filter.
  repeated DatabaseResourceGroup resource_groups = 1;

  // A token that can be sent as `page_token` to retrieve the next page.
  // If this field is omitted, there are no subsequent pages.
  string next_page_token = 2;

  // Unordered list. List of unreachable regions from where data could not be
  // retrieved.
  repeated string unreachable = 3
      [(google.api.field_behavior) = UNORDERED_LIST];
}

// DatabaseResourceGroup represents all resources that serve a common data set.
// It is considered notionally as a single entity, powered by any number of
// units of compute and storage.
message DatabaseResourceGroup {
  // A database resource that serves as a root of the group of database
  // resources. It is repeated just in case we have the concept of multiple
  // roots in the future, however, it will only be populated with a single value
  // for now.
  repeated DatabaseResource root_resources = 1;

  // The filtered signal groups and the count of issues associated with the
  // resources that have been filtered in.
  repeated IssueCount signal_groups = 2;
}

// DatabaseResource represents every individually configured database unit
// representing compute and/or storage.
message DatabaseResource {
  // List of children associated with a database group.
  repeated DatabaseResource child_resources = 1;

  // The full resource name, based on CAIS resource name format
  // https://cloud.google.com/asset-inventory/docs/resource-name-format
  //
  // Example:
  //
  //  `//cloudsql.googleapis.com/projects/project-number/instances/mysql-1`
  //  `//cloudsql.googleapis.com/projects/project-number/instances/postgres-1`
  //  `//spanner.googleapis.com/projects/project-number/instances/spanner-instance-1`
  //  `//alloydb.googleapis.com/projects/project-number/locations/us-central1/clusters/c1`
  //  `//alloydb.googleapis.com/projects/project-number/locations/us-central1/clusters/c1/instances/i1`
  string full_resource_name = 3;

  // Specifies where the resource is created. For Google Cloud resources, it is
  // the full name of the project.
  string container = 4;

  // The product this resource represents.
  Product product = 5;

  // The location of the resources. It supports returning only regional
  // locations in Google Cloud. These are of the form: "us-central1",
  // "us-east1", etc. See https://cloud.google.com/about/locations for a list of
  // such regions.
  string location = 6;

  // Labels applied on the resource. The requirements for labels assigned to
  // Google Cloud resources may be found at
  // https://cloud.google.com/resource-manager/docs/labels-overview#requirements
  repeated Label labels = 7;

  // Tags applied on the resource. The requirements for tags assigned to
  // Google Cloud resources may be found at
  // https://cloud.google.com/resource-manager/docs/tags/tags-overview
  repeated Tag tags = 16;

  // The type of resource defined according to the pattern:
  // {Service Name}/{Type}. Ex:
  // sqladmin.googleapis.com/Instance
  // alloydb.googleapis.com/Cluster
  // alloydb.googleapis.com/Instance
  // spanner.googleapis.com/Instance
  string resource_type = 8;

  // Subtype of the resource specified at creation time.
  SubResourceType sub_resource_type = 9;

  // Machine configuration like CPU, memory, etc for the resource.
  MachineConfig machine_config = 12;

  // The list of signal groups and count of issues related to the resource.
  // Only those signals which have been requested would be included.
  repeated SignalGroup signal_groups = 10;

  // Observable metrics for the resource e.g. CPU utilization, memory
  // utilization, etc.
  Metrics metrics = 13;

  // The category of the resource.
  ResourceCategory resource_category = 14;

  // The name of the resource(The last part of the full resource name).
  // Example:
  // For full resource name -
  // `//cloudsql.googleapis.com/projects/project-number/instances/mysql-1`,
  // resource name - `mysql-1`
  // For full resource name -
  // `//cloudsql.googleapis.com/projects/project-number/instances/postgres-1` ,
  // resource name - `postgres-1`
  // Note: In some cases, there might be more than one resource with the same
  // resource name.
  string resource_name = 15;

  // Optional. Backup and disaster recovery details for the resource.
  BackupDRConfig backupdr_config = 17 [(google.api.field_behavior) = OPTIONAL];

  // The edition of the resource.
  Edition edition = 18;

  // Optional. The maintenance information of the resource.
  MaintenanceInfo maintenance_info = 19
      [(google.api.field_behavior) = OPTIONAL];

  // Optional. Affiliation details of the resource.
  repeated Affiliation affiliations = 20
      [(google.api.field_behavior) = OPTIONAL];
}

// AggregateIssueStatsRequest represents the input to the AggregateIssueStats
// method.
message AggregateIssueStatsRequest {
  // Required. Parent can be a project, a folder, or an organization. The search
  // is limited to the resources within the `scope`.
  //
  // The allowed values are:
  //
  // * projects/{PROJECT_ID} (e.g., "projects/foo-bar")
  // * projects/{PROJECT_NUMBER} (e.g., "projects/12345678")
  // * folders/{FOLDER_NUMBER} (e.g., "folders/1234567")
  // * organizations/{ORGANIZATION_NUMBER} (e.g., "organizations/123456")
  string parent = 1 [(google.api.field_behavior) = REQUIRED];

  // Optional. The expression to filter resources.
  //
  // Supported fields are: `full_resource_name`, `resource_type`, `container`,
  //   `product.type`, `product.engine`, `product.version`, `location`,
  //   `labels`, `issues`, fields of availability_info,
  //   data_protection_info,'resource_name', etc.
  //
  // The expression is a list of zero or more restrictions combined via logical
  // operators `AND` and `OR`. When `AND` and `OR` are both used in the
  // expression, parentheses must be appropriately used to group the
  // combinations.
  //
  // Example: `location="us-east1"`
  // Example: `container="projects/123" OR container="projects/456"`
  // Example: `(container="projects/123" OR
  //           container="projects/456") AND location="us-east1"`
  string filter = 2 [(google.api.field_behavior) = OPTIONAL];

  // Optional. Lists of signal types that are issues.
  repeated SignalTypeGroup signal_type_groups = 3
      [(google.api.field_behavior) = OPTIONAL];

  // Optional. The baseline date w.r.t. which the delta counts are calculated.
  // If not set, delta counts are not included in the response and the response
  // indicates the current state of the fleet.
  optional google.type.Date baseline_date = 4
      [(google.api.field_behavior) = OPTIONAL];
}

// AggregateQueryStatsRequest represents the input to the AggregateQueryStats
// method.
message AggregateQueryStatsRequest {
  // Required. Parent can be a project, a folder, or an organization. The search
  // is limited to the resources within the `parent`.
  //
  // The allowed values are:
  //
  // * projects/{PROJECT_ID} (e.g., "projects/foo-bar")
  // * projects/{PROJECT_NUMBER} (e.g., "projects/12345678")
  // * folders/{FOLDER_NUMBER} (e.g., "folders/1234567")
  // * organizations/{ORGANIZATION_NUMBER} (e.g., "organizations/123456")
  string parent = 1 [(google.api.field_behavior) = REQUIRED];

  // Optional. The expression to order the results by.
  // Example: `order_by="execution_count"`
  // Example: `order_by="execution_count desc"`
  // Supported order by fields are `execution_count`, `rows_processed`,
  // `total_cpu_time`, `avg_cpu_time`.
  string order_by = 2 [(google.api.field_behavior) = OPTIONAL];

  // Optional. The expression to filter resources.
  //
  // Supported fields are: `full_resource_name`, `resource_type`, `container`,
  //   `product.type`, `product.engine`, `product.version`, `location`,
  //   `labels`, `issues`, fields of availability_info,
  //   data_protection_info,'resource_name', etc.
  //
  // The expression is a list of zero or more restrictions combined via logical
  // operators `AND` and `OR`. When `AND` and `OR` are both used in the
  // expression, parentheses must be appropriately used to group the
  // combinations.
  //
  // Example: `location="us-east1"`
  // Example: `container="projects/123" OR container="projects/456"`
  // Example: `(container="projects/123" OR
  //           container="projects/456") AND location="us-east1"`
  // Additional specific fields for query stats are: `metric_window`,
  // `query_hash`, `normalized_query`.
  // Example: `metric_window="LAST_ONE_DAY"`
  // (Possible values  for `metric_window` are: `LAST_ONE_DAY`,
  // `LAST_ONE_WEEK`, `LAST_TWO_WEEKS`)
  // Example: `query_hash="12345678"`
  // Example: `normalized_query="SELECT * FROM table"`
  string filter = 3 [(google.api.field_behavior) = OPTIONAL];

  // Optional. If unspecified, at most 100 query stats will be returned.
  // The maximum value is 1000; values above 1000 will be coerced to 1000.
  int32 page_size = 4 [(google.api.field_behavior) = OPTIONAL];

  // Optional. A page token, received from a previous
  // `AggregateQueryStatsRequest` call. Provide this to retrieve the subsequent
  // page. All parameters except page_token should match the parameters in the
  // call that provided the page token.
  string page_token = 5 [(google.api.field_behavior) = OPTIONAL];
}

// The response message containing relevant query stats
// for database resources.
message AggregateQueryStatsResponse {
  // List of query stats where each group contains stats for resources having a
  // particular combination of relevant query stats.
  repeated QueryStatsInfo query_stats = 1;

  // A token that can be sent as `page_token` to retrieve the next page.
  // If this field is omitted, there are no subsequent pages.
  string next_page_token = 2;

  // Unordered list. List of unreachable regions from where data could not be
  // retrieved.
  repeated string unreachable = 3
      [(google.api.field_behavior) = UNORDERED_LIST];
}

// The response message containing one of more group of relevant health issues
// for database resources.
message AggregateIssueStatsResponse {
  // List of issue group stats where each group contains stats for resources
  // having a particular combination of relevant issues.
  repeated IssueGroupStats issue_group_stats = 1;

  // Total count of the resources filtered in based on the user given filter.
  int32 total_resources_count = 2;

  // Total count of the resource filtered in based on the user given filter.
  int32 total_resource_groups_count = 3;

  // Unordered list. List of unreachable regions from where data could not be
  // retrieved.
  repeated string unreachable = 4
      [(google.api.field_behavior) = UNORDERED_LIST];
}

// IssueGroupStats refers to stats for a particulare combination of relevant
// health issues of database resources.
message IssueGroupStats {
  // Database resource level health card name. This will corresponds to one of
  // the requested input group names.
  string display_name = 1;

  // Total count of the groups of resources returned by the filter that
  // also have one or more resources for which any of the specified issues
  // are applicable.
  int32 resource_groups_count = 2;

  // Total count of resources returned by the filter for which any of the
  // specified issues are applicable.
  int32 resources_count = 3;

  // The number of resource groups from the total groups as defined above
  // that are healthy with respect to all of the specified issues.
  int32 healthy_resource_groups_count = 4;

  // The number of resources from the total defined above in field
  // total_resources_count that are healthy with respect to all of the specified
  // issues.
  int32 healthy_resources_count = 5;

  // List of issues stats containing count of resources having particular issue
  // category.
  repeated IssueStats issue_stats = 6;
}

// IssueStats holds stats for a particular signal category.
message IssueStats {
  // Type of signal which is an issue.
  SignalType signal_type = 1;

  // Number of resources having issues of a given type.
  int32 resource_count = 2;

  // Optional. Delta counts and details of resources for which issue was raised
  // or fixed.
  optional DeltaDetails delta_details = 3
      [(google.api.field_behavior) = OPTIONAL];

  // Severity of the issue.
  optional IssueSeverity issue_severity = 4;
}

// Label is a key value pair applied to a resource.
message Label {
  // The key part of the label.
  string key = 1;

  // The value part of the label.
  string value = 2;

  // The source of the Label. Source is empty if the label is directly attached
  // to the resource and not inherited.
  string source = 3;
}

// The request message to aggregate fleet which are grouped by a field.
message AggregateFleetRequest {
  // Required. Parent can be a project, a folder, or an organization. The search
  // is limited to the resources within the `scope`.
  //
  // The allowed values are:
  //
  // * projects/{PROJECT_ID} (e.g., "projects/foo-bar")
  // * projects/{PROJECT_NUMBER} (e.g., "projects/12345678")
  // * folders/{FOLDER_NUMBER} (e.g., "folders/1234567")
  // * organizations/{ORGANIZATION_NUMBER} (e.g.,
  // "organizations/123456")
  string parent = 1 [(google.api.field_behavior) = REQUIRED];

  // Optional. The expression to filter resources.
  //
  // Supported fields are: `full_resource_name`, `resource_type`, `container`,
  //   `product.type`, `product.engine`, `product.version`, `location`,
  //   `labels`, `issues`, fields of availability_info, data_protection_info,
  //   'resource_name', etc.
  //
  // The expression is a list of zero or more restrictions combined via logical
  // operators `AND` and `OR`. When `AND` and `OR` are both used in the
  // expression, parentheses must be appropriately used to group the
  // combinations.
  //
  // Example: `location="us-east1"`
  // Example: `container="projects/123" OR container="projects/456"`
  // Example: `(container="projects/123" OR
  //           container="projects/456") AND location="us-east1"`
  string filter = 2 [(google.api.field_behavior) = OPTIONAL];

  // Optional. A field that statistics are grouped by.
  // Valid values are any combination of the following:
  //   * container
  //   * product.type
  //   * product.engine
  //   * product.version
  //   * location
  //   * sub_resource_type
  //   * management_type
  //   * tag.key
  //   * tag.value
  //   * tag.source
  //   * tag.inherited
  //   * label.key
  //   * label.value
  //   * label.source
  //   * has_maintenance_schedule
  //   * has_deny_maintenance_schedules
  // Comma separated list.
  string group_by = 3 [(google.api.field_behavior) = OPTIONAL];

  // Optional. Valid values to order by are:
  //   * resource_groups_count
  //   * resources_count
  //   * and all fields supported by `group_by`
  // The default order is ascending. Add "DESC" after the field name to indicate
  // descending order. Add "ASC" after the field name to indicate ascending
  // order. It supports ordering using multiple fields.
  // For example:
  //  `order_by = "resource_groups_count"` sorts response in ascending order
  //  `order_by = "resource_groups_count DESC"` sorts response in descending
  //  order
  //  `order_by = "product.type, product.version DESC, location"` orders by type
  //  in ascending order, version in descending order and location in ascending
  //  order
  string order_by = 4 [(google.api.field_behavior) = OPTIONAL];

  // Optional. If unspecified, at most 50 items will be returned.
  // The maximum value is 1000; values above 1000 will be coerced to 1000.
  int32 page_size = 5 [(google.api.field_behavior) = OPTIONAL];

  // Optional. A page token, received from a previous `AggregateFleet` call.
  // Provide this to retrieve the subsequent page.
  // All other parameters should match the parameters in the call that provided
  // the page token except for page_size which can be different.
  string page_token = 6 [(google.api.field_behavior) = OPTIONAL];

  // Optional. The baseline date w.r.t. which the delta counts are calculated.
  // If not set, delta counts are not included in the response and the response
  // indicates the current state of the fleet.
  optional google.type.Date baseline_date = 7
      [(google.api.field_behavior) = OPTIONAL];
}

// QueryStatsInfo contains the aggregated and detailed query stats for a
// particular combination of relevant query stats for queries having same
// normalized query.
message QueryStatsInfo {
  // Aggregated query stats for the resources for same normalized query.
  QueryStats aggregated_query_stats = 1;

  // List of query stats for the resources in the group.
  // This stats is stats at resource level for the resources having same
  // normalized query.
  repeated QueryStats query_stats = 2;
}

// ResourceId contains the identifier for a database resource,
// including the full resource name, resource type, and product.
message ResourceId {
  // The full resource name of the resource.
  string full_resource_name = 1;

  // The type of the resource.
  // sqladmin.googleapis.com/Instance
  // alloydb.googleapis.com/Cluster
  // alloydb.googleapis.com/Instance
  string resource_type = 2;

  // The product of the resource, including the type, engine, and version.
  Product product = 3;
}

// QueryStats contains the stats for a particular combination of query_hash,
// query_string and resource_type.
message QueryStats {
  // The query hash of the query.
  string query_hash = 1;

  // The query string is normalized query without any PII data.
  string normalized_query = 2;

  // The type of the resource.
  // sqladmin.googleapis.com/Instance
  // alloydb.googleapis.com/Cluster
  // alloydb.googleapis.com/Instance
  string resource_type = 4 [(google.api.resource_reference) = { type: "*" }];

  // The resource ids for which the query stats are collected.
  repeated ResourceId resource_ids = 5;

  // Metrics related to the query performance.
  QueryMetrics query_metrics = 6;

  // Information about inefficient query.
  InefficientQueryInfo inefficient_query_info = 7;
}

// QueryMetrics contains the metrics related to the query execution.
message QueryMetrics {
  // Enum to represent the window over which the metrics are aggregated.
  enum MetricsWindow {
    // Unspecified. Default value.
    METRICS_WINDOW_UNSPECIFIED = 0;

    // Metrics are aggregated over the last 1 day.
    LAST_ONE_DAY = 1;

    // Metrics are aggregated over the last 7 days.
    LAST_ONE_WEEK = 2;

    // Metrics are aggregated over the last 14 days.
    LAST_TWO_WEEKS = 3;
  }

  // The number of times the query was executed.
  int64 execution_count = 1;

  // The average execution period of the query across all runs.
  google.protobuf.Duration avg_cpu_time = 2;

  // The total CPU time consumed by the query across all runs.
  google.protobuf.Duration total_cpu_time = 3;

  // The average number of rows processed by the query across all runs.
  int64 rows_processed = 4;

  // The window over which the metrics are aggregated.
  MetricsWindow metrics_window = 5;
}

// The response message to aggregate a fleet by some group by
// fields.
message AggregateFleetResponse {
  // Represents a row grouped by the fields in the input.
  repeated AggregateFleetRow rows = 1;

  // Count of all resource groups in the fleet. This includes counts from all
  // pages.
  int32 resource_groups_total_count = 2;

  // Count of all resources in the fleet. This includes counts from all pages.
  int32 resource_total_count = 3;

  // A token that can be sent as `page_token` to retrieve the next page.
  // If this field is omitted, there are no subsequent pages.
  string next_page_token = 4;

  // Unordered list. List of unreachable regions from where data could not be
  // retrieved.
  repeated string unreachable = 5
      [(google.api.field_behavior) = UNORDERED_LIST];
}

// Individual row grouped by a particular dimension.
message AggregateFleetRow {
  // Group by dimension.
  repeated Dimension dimension = 1;

  // Number of resource groups that have a particular dimension.
  int32 resource_groups_count = 2;

  // Number of resources that have a particular dimension.
  int32 resources_count = 3;

  // Optional. Delta counts and details of resources which were added to/deleted
  // from fleet.
  optional DeltaDetails delta_details = 4
      [(google.api.field_behavior) = OPTIONAL];
}

// Dimension used to aggregate the fleet.
message Dimension {
  // Followings are the dimensions to be used to aggregate the fleet.
  oneof dimension {
    // Specifies where the resource is created. For Google Cloud resources, it
    // is the full name of the project.
    string container = 2;

    // Type to identify a product
    ProductType product_type = 3;

    // Engine refers to underlying database binary running in an instance.
    Engine product_engine = 4;

    // Version of the underlying database engine
    string product_version = 5;

    // The location of the resources. It supports returning only regional
    // locations in Google Cloud.
    string location = 6;

    // The type of resource defined according to the pattern:
    // {Service Name}/{Type}. Ex:
    // sqladmin.googleapis.com/Instance
    // alloydb.googleapis.com/Cluster
    // alloydb.googleapis.com/Instance
    // spanner.googleapis.com/Instance
    string resource_type = 7;

    // Subtype of the resource specified at creation time.
    SubResourceType sub_resource_type = 8;

    // The category of the resource.
    ResourceCategory resource_category = 9;

    // The management type of the resource.
    ManagementType management_type = 10;

    // The edition of the resource.
    Edition edition = 11;

    // Tag key of the resource.
    string tag_key = 12;

    // Tag value of the resource.
    string tag_value = 13;

    // Tag source of the resource.
    string tag_source = 14;

    // Tag inheritance value of the resource.
    bool tag_inherited = 15;

    // Label key of the resource.
    string label_key = 16;

    // Label value of the resource.
    string label_value = 17;

    // Label source of the resource.
    string label_source = 18;

    // Whether the resource has a maintenance schedule.
    bool has_maintenance_schedule = 19;

    // Whether the resource has deny maintenance schedules.
    bool has_deny_maintenance_schedules = 20;
  }
}

// BackupDRConfig to capture the backup and disaster recovery details of
// database resource.
message BackupDRConfig {
  // Indicates if the resource is managed by BackupDR.
  optional bool backupdr_managed = 1;
}

// QueryIssuesRequest is the request to get a list of issues.
message QueryIssuesRequest {
  // Required. Parent can be a project, a folder, or an organization. The list
  // is limited to the one attached to resources within the `scope` that a user
  // has access to.
  //
  // The allowed values are:
  //
  // * projects/{PROJECT_ID} (e.g., "projects/foo-bar")
  // * projects/{PROJECT_NUMBER} (e.g., "projects/12345678")
  // * folders/{FOLDER_NUMBER} (e.g., "folders/1234567")
  // * organizations/{ORGANIZATION_NUMBER} (e.g., "organizations/123456")
  string parent = 1 [(google.api.field_behavior) = REQUIRED];

  // Optional.
  // Supported fields are:
  // 'product',
  // `location`,
  // `issue_severity`,
  // 'tags',
  // 'labels',
  string filter = 2 [(google.api.field_behavior) = OPTIONAL];

  // Optional. Filters based on signal and product. The filter list will be ORed
  // across pairs and ANDed within a signal and products pair.
  repeated SignalProductsFilters signal_products_filters = 3
      [(google.api.field_behavior) = OPTIONAL];

  // Optional. Following fields are sortable:
  // SignalType
  // Product
  // Location
  // IssueSeverity
  //
  // The default order is ascending. Add "DESC" after the field name to indicate
  // descending order. Add "ASC" after the field name to indicate ascending
  // order. It only supports a single field at a time.
  string order_by = 4 [(google.api.field_behavior) = OPTIONAL];

  // Optional. If unspecified, at most 50 issues will be returned.
  // The maximum value is 1000; values above 1000 will be coerced to 1000.
  int32 page_size = 5 [(google.api.field_behavior) = OPTIONAL];

  // Optional. A page token, received from a previous `QueryIssues` call.
  // Provide this to retrieve the subsequent page.
  // All parameters except page size should match the parameters used in the
  // call that provided the page token.
  string page_token = 6 [(google.api.field_behavior) = OPTIONAL];
}

// SignalProductsFilters represents a signal and list of supported products.
message SignalProductsFilters {
  // Optional. The type of signal.
  SignalType signal_type = 1 [(google.api.field_behavior) = OPTIONAL];

  // Optional. Product type of the resource. The version of the product will be
  // ignored in filtering.
  repeated Product products = 2 [(google.api.field_behavior) = OPTIONAL];
}

// QueryIssuesResponse is the response containing a list of issues.
message QueryIssuesResponse {
  // List of issues and resource details.
  repeated DatabaseResourceIssue resource_issues = 1;

  // A token that can be sent as `page_token` to retrieve the next page.
  // If this field is omitted, there are no subsequent pages.
  string next_page_token = 2;

  // Unordered list. List of unreachable regions from where data could not be
  // retrieved.
  repeated string unreachable = 3
      [(google.api.field_behavior) = UNORDERED_LIST];
}

// DatabaseResource and Issue associated with it.
message DatabaseResourceIssue {
  // Signal associated with the issue.
  Signal signal = 1;

  // Resource associated with the issue.
  DatabaseResource resource = 2;
}

// Tag is a key value pair attached to a resource.
message Tag {
  string key = 1;

  // The value part of the tag.
  string value = 2;

  // The source of the tag. According to
  // https://cloud.google.com/resource-manager/docs/tags/tags-overview#tags_and_labels,
  // tags can be created only at the project or organization level. Tags can be
  // inherited from different project as well not just the current project where
  // the database resource is present.
  // Format:
  // "projects/{PROJECT_ID}",
  // "projects/{PROJECT_NUMBER}",
  // "organizations/{ORGANIZATION_ID}"
  string source = 3;

  // Indicates the inheritance status of a tag value
  // attached to the given resource. If the tag value is inherited from one of
  // the resource's ancestors, inherited will be true. If false, then the tag
  // value is directly attached to the resource.
  bool inherited = 4;
}

// Capture the resource details for resources that are included in the delta
// counts.
message ResourceDetails {
  // Full resource name of the resource.
  string full_resource_name = 1;

  // Specifies where the resource is created. For Google Cloud resources, it is
  // the full name of the project.
  string container = 2;

  // Product type of the resource.
  Product product = 3;

  // Location of the resource.
  string location = 4;
}

// Captures the details of items that have increased or decreased in some bucket
// when compared to some point in history.
// It is currently used to capture the delta of resources that have been added
// or removed in the fleet as well as to capture the resources that have a
// change in Issue/Signal status.
message DeltaDetails {
  // Details of resources that have increased.
  repeated ResourceDetails increased_resources = 1;

  // Details of resources that have decreased.
  repeated ResourceDetails decreased_resources = 2;
}
