Skip to content

Commit

Permalink
feat: Release of query system
Browse files Browse the repository at this point in the history
Committer: lvv@

PiperOrigin-RevId: 466748663
  • Loading branch information
Google APIs authored and Copybara-Service committed Aug 10, 2022
1 parent c2674a3 commit 80d630f
Show file tree
Hide file tree
Showing 2 changed files with 221 additions and 17 deletions.
221 changes: 221 additions & 0 deletions google/cloud/asset/v1/asset_service.proto
Expand Up @@ -26,6 +26,7 @@ import "google/longrunning/operations.proto";
import "google/protobuf/duration.proto";
import "google/protobuf/empty.proto";
import "google/protobuf/field_mask.proto";
import "google/protobuf/struct.proto";
import "google/protobuf/timestamp.proto";
import "google/rpc/status.proto";
import "google/type/expr.proto";
Expand Down Expand Up @@ -197,6 +198,27 @@ service AssetService {
};
}

// Issue a job that queries assets using a SQL statement compatible with
// [BigQuery Standard
// SQL](http://cloud/bigquery/docs/reference/standard-sql/enabling-standard-sql).
//
// If the query execution finishes within timeout and there's no pagination,
// the full query results will be returned in the `QueryAssetsResponse`.
//
// Otherwise, full query results can be obtained by issuing extra requests
// with the `job_reference` from the a previous `QueryAssets` call.
//
// Note, the query result has approximately 10 GB limitation enforced by
// BigQuery
// https://cloud.google.com/bigquery/docs/best-practices-performance-output,
// queries return larger results will result in errors.
rpc QueryAssets(QueryAssetsRequest) returns (QueryAssetsResponse) {
option (google.api.http) = {
post: "/v1/{parent=*/*}:queryAssets"
body: "*"
};
}

// Creates a saved query in a parent project/folder/organization.
rpc CreateSavedQuery(CreateSavedQueryRequest) returns (SavedQuery) {
option (google.api.http) = {
Expand Down Expand Up @@ -1738,6 +1760,205 @@ message MoveImpact {
string detail = 1;
}

// Output configuration query assets.
message QueryAssetsOutputConfig {
// BigQuery destination.
message BigQueryDestination {
// Required. The BigQuery dataset where the query results will be saved. It
// has the format of "projects/{projectId}/datasets/{datasetId}".
string dataset = 1 [(google.api.field_behavior) = REQUIRED];

// Required. The BigQuery table where the query results will be saved. If
// this table does not exist, a new table with the given name will be
// created.
string table = 2 [(google.api.field_behavior) = REQUIRED];

// Specifies the action that occurs if the destination table or partition
// already exists. The following values are supported:
//
// * WRITE_TRUNCATE: If the table or partition already exists, BigQuery
// overwrites the entire table or all the partitions data.
// * WRITE_APPEND: If the table or partition already exists, BigQuery
// appends the data to the table or the latest partition.
// * WRITE_EMPTY: If the table already exists and contains data, an error is
// returned.
string write_disposition = 3;
}

// BigQuery destination where the query results will be saved.
BigQueryDestination bigquery_destination = 1;
}

// QueryAssets request.
message QueryAssetsRequest {
// Required. The relative name of the root asset. This can only be an
// organization number (such as "organizations/123"), a project ID (such as
// "projects/my-project-id"), or a project number (such as "projects/12345"),
// or a folder number (such as "folders/123").
//
// Only assets belonging to the `parent` will be returned.
string parent = 1 [
(google.api.field_behavior) = REQUIRED,
(google.api.resource_reference) = {
child_type: "cloudasset.googleapis.com/Asset"
}
];

oneof query {
// Optional. A SQL statement that's compatible with [BigQuery Standard
// SQL](http://cloud/bigquery/docs/reference/standard-sql/enabling-standard-sql).
string statement = 2 [(google.api.field_behavior) = OPTIONAL];

// Optional. Reference to the query job, which is from the
// `QueryAssetsResponse` of previous `QueryAssets` call.
string job_reference = 3 [(google.api.field_behavior) = OPTIONAL];
}

// Optional. The maximum number of rows to return in the results. Responses
// are limited to 10 MB and 1000 rows.
//
// By default, the maximum row count is 1000. When the byte or row count limit
// is reached, the rest of the query results will be paginated.
//
// The field will be ignored when [output_config] is specified.
int32 page_size = 4 [(google.api.field_behavior) = OPTIONAL];

// Optional. A page token received from previous `QueryAssets`.
//
// The field will be ignored when [output_config] is specified.
string page_token = 5 [(google.api.field_behavior) = OPTIONAL];

// Optional. Specifies the maximum amount of time that the client is willing
// to wait for the query to complete. By default, this limit is 5 min for the
// first query, and 1 minute for the following queries. If the query is
// complete, the `done` field in the `QueryAssetsResponse` is true, otherwise
// false.
//
// Like BigQuery [jobs.query
// API](https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs/query#queryrequest)
// The call is not guaranteed to wait for the specified timeout; it typically
// returns after around 200 seconds (200,000 milliseconds), even if the query
// is not complete.
//
// The field will be ignored when [output_config] is specified.
google.protobuf.Duration timeout = 6 [(google.api.field_behavior) = OPTIONAL];

// Specifies what time period or point in time to query asset metadata at.
// * unset - query asset metadata as it is right now
// * [read_time_window] - query asset metadata as it was at any point in time
// between [start_time] and [end_time].
// * [read_time] - query asset metadata as it was at that point in time.
// If data for the timestamp/date range selected does not exist,
// it will simply return a valid response with no rows.
oneof time {
// Optional. [start_time] is required. [start_time] must be less than
// [end_time] Defaults [end_time] to now if [start_time] is set and
// [end_time] isn't. Maximum permitted time range is 7 days.
TimeWindow read_time_window = 7 [(google.api.field_behavior) = OPTIONAL];

// Optional. Queries cloud assets as they appeared at the specified point in
// time.
google.protobuf.Timestamp read_time = 8
[(google.api.field_behavior) = OPTIONAL];
}

// Optional. Destination where the query results will be saved.
//
// When this field is specified, the query results won't be saved in the
// [QueryAssetsResponse.query_result]. Instead
// [QueryAssetsResponse.output_config] will be set.
//
// Meanwhile, [QueryAssetsResponse.job_reference] will be set and can be used
// to check the status of the query job when passed to a following
// [QueryAssets] API call.
QueryAssetsOutputConfig output_config = 9
[(google.api.field_behavior) = OPTIONAL];
}

// QueryAssets response.
message QueryAssetsResponse {
// Reference to a query job.
string job_reference = 1;

// The query response, which can be either an `error` or a valid `response`.
//
// If `done` == `false` and the query result is being saved in a output, the
// output_config field will be set.
// If `done` == `true`, exactly one of
// `error`, `query_result` or `output_config` will be set.
bool done = 2;

oneof response {
// Error status.
google.rpc.Status error = 3;

// Result of the query.
QueryResult query_result = 4;

// Output configuration which indicates instead of being returned in API
// response on the fly, the query result will be saved in a specific output.
QueryAssetsOutputConfig output_config = 5;
}
}

// Execution results of the query.
//
// The result is formatted as rows represented by BigQuery compatible [schema].
// When pagination is necessary, it will contains the page token to retrieve
// the results of following pages.
message QueryResult {
// Each row hold a query result in the format of `Struct`.
repeated google.protobuf.Struct rows = 1;

// Describes the format of the [rows].
TableSchema schema = 2;

// Token to retrieve the next page of the results.
string next_page_token = 3;

// Total rows of the whole query results.
int64 total_rows = 4;
}

// BigQuery Compatible table schema.
message TableSchema {
// Describes the fields in a table.
repeated TableFieldSchema fields = 1;
}

// A field in TableSchema.
message TableFieldSchema {
// The field name. The name must contain only letters (a-z, A-Z),
// numbers (0-9), or underscores (_), and must start with a letter or
// underscore. The maximum length is 128 characters.
string field = 1;

// The field data type. Possible values include
// * STRING
// * BYTES
// * INTEGER
// * FLOAT
// * BOOLEAN
// * TIMESTAMP
// * DATE
// * TIME
// * DATETIME
// * GEOGRAPHY,
// * NUMERIC,
// * BIGNUMERIC,
// * RECORD
// (where RECORD indicates that the field contains a nested schema).
string type = 2;

// The field mode. Possible values include NULLABLE, REQUIRED and
// REPEATED. The default value is NULLABLE.
string mode = 3;

// Describes the nested schema fields if the type property is set
// to RECORD.
repeated TableFieldSchema fields = 4;
}

// A request message for
// [AssetService.BatchGetEffectiveIamPolicies][google.cloud.asset.v1.AssetService.BatchGetEffectiveIamPolicies].
message BatchGetEffectiveIamPoliciesRequest {
Expand Down
17 changes: 0 additions & 17 deletions google/cloud/asset/v1/cloudasset_grpc_service_config.json
Expand Up @@ -126,23 +126,6 @@
"UNAVAILABLE"
]
}
},
{
"name": [
{
"service": "google.cloud.asset.v1.AssetService",
"method": "BatchGetEffectiveIamPolicies"
}
],
"timeout": "300s",
"retryPolicy": {
"initialBackoff": "0.100s",
"maxBackoff": "60s",
"backoffMultiplier": 1.3,
"retryableStatusCodes": [
"UNAVAILABLE"
]
}
}
]
}

0 comments on commit 80d630f

Please sign in to comment.