feat: Added Service Controller v2 API

PiperOrigin-RevId: 431525317
pull/706/head
Google APIs 3 years ago committed by Copybara-Service
parent dbfbfdb38a
commit 43930af62a
  1. 355
      google/api/servicecontrol/v2/BUILD.bazel
  2. 186
      google/api/servicecontrol/v2/service_controller.proto
  3. 171
      google/api/servicecontrol/v2/servicecontrol.yaml
  4. 20
      google/api/servicecontrol/v2/servicecontrol_grpc_service_config.json

@ -0,0 +1,355 @@
# This file was automatically generated by BuildFileGenerator
# https://github.com/googleapis/rules_gapic/tree/master/bazel
# Most of the manual changes to this file will be overwritten.
# It's **only** allowed to change the following rule attribute values:
# - names of *_gapic_assembly_* rules
# - certain parameters of *_gapic_library rules, including but not limited to:
# * extra_protoc_parameters
# * extra_protoc_file_parameters
# The complete list of preserved parameters can be found in the source code.
# This is an API workspace, having public visibility by default makes perfect sense.
package(default_visibility = ["//visibility:public"])
##############################################################################
# Common
##############################################################################
load("@rules_proto//proto:defs.bzl", "proto_library")
load("@com_google_googleapis_imports//:imports.bzl", "proto_library_with_info")
proto_library(
name = "servicecontrol_proto",
srcs = [
"service_controller.proto",
],
deps = [
"//google/api:annotations_proto",
"//google/api:client_proto",
"//google/rpc/context:attribute_context_proto",
"//google/rpc:status_proto",
],
)
proto_library_with_info(
name = "servicecontrol_proto_with_info",
deps = [
":servicecontrol_proto",
"//google/cloud:common_resources_proto",
],
)
##############################################################################
# Java
##############################################################################
load(
"@com_google_googleapis_imports//:imports.bzl",
"java_gapic_assembly_gradle_pkg",
"java_gapic_library",
"java_gapic_test",
"java_grpc_library",
"java_proto_library",
)
java_proto_library(
name = "servicecontrol_java_proto",
deps = [":servicecontrol_proto"],
)
java_grpc_library(
name = "servicecontrol_java_grpc",
srcs = [":servicecontrol_proto"],
deps = [":servicecontrol_java_proto"],
)
java_gapic_library(
name = "servicecontrol_java_gapic",
srcs = [":servicecontrol_proto_with_info"],
gapic_yaml = None,
grpc_service_config = "servicecontrol_grpc_service_config.json",
service_yaml = "servicecontrol.yaml",
test_deps = [
":servicecontrol_java_grpc",
],
deps = [
":servicecontrol_java_proto",
"//google/api:api_java_proto",
"//google/rpc/context:attribute_context_java_proto",
],
)
java_gapic_test(
name = "servicecontrol_java_gapic_test_suite",
test_classes = [
"com.google.api.servicecontrol.v2.ServiceControllerClientTest",
],
runtime_deps = [":servicecontrol_java_gapic_test"],
)
# Open Source Packages
java_gapic_assembly_gradle_pkg(
name = "google-cloud-api-servicecontrol-v2-java",
deps = [
":servicecontrol_java_gapic",
":servicecontrol_java_grpc",
":servicecontrol_java_proto",
":servicecontrol_proto",
],
)
##############################################################################
# Go
##############################################################################
load(
"@com_google_googleapis_imports//:imports.bzl",
"go_gapic_assembly_pkg",
"go_gapic_library",
"go_proto_library",
"go_test",
)
go_proto_library(
name = "servicecontrol_go_proto",
compilers = ["@io_bazel_rules_go//proto:go_grpc"],
importpath = "google.golang.org/genproto/googleapis/api/servicecontrol/v2",
protos = [":servicecontrol_proto"],
deps = [
"//google/api:annotations_go_proto",
"//google/rpc/context:attribute_context_go_proto",
"//google/rpc:status_go_proto",
],
)
go_gapic_library(
name = "servicecontrol_go_gapic",
srcs = [":servicecontrol_proto_with_info"],
grpc_service_config = "servicecontrol_grpc_service_config.json",
importpath = "cloud.google.com/go/api/servicecontrol/apiv2;servicecontrol",
service_yaml = "servicecontrol.yaml",
metadata = True,
deps = [
":servicecontrol_go_proto",
],
)
go_test(
name = "servicecontrol_go_gapic_test",
srcs = [":servicecontrol_go_gapic_srcjar_test"],
embed = [":servicecontrol_go_gapic"],
importpath = "cloud.google.com/go/api/servicecontrol/apiv2",
)
# Open Source Packages
go_gapic_assembly_pkg(
name = "gapi-cloud-api-servicecontrol-v2-go",
deps = [
":servicecontrol_go_gapic",
":servicecontrol_go_gapic_srcjar-test.srcjar",
":servicecontrol_go_gapic_srcjar-metadata.srcjar",
":servicecontrol_go_proto",
],
)
##############################################################################
# Python
##############################################################################
load(
"@com_google_googleapis_imports//:imports.bzl",
"py_gapic_assembly_pkg",
"py_gapic_library",
)
py_gapic_library(
name = "servicecontrol_py_gapic",
srcs = [":servicecontrol_proto"],
grpc_service_config = "servicecontrol_grpc_service_config.json",
)
# Open Source Packages
py_gapic_assembly_pkg(
name = "api-servicecontrol-v2-py",
deps = [
":servicecontrol_py_gapic",
],
)
##############################################################################
# PHP
##############################################################################
load(
"@com_google_googleapis_imports//:imports.bzl",
"php_gapic_assembly_pkg",
"php_gapic_library",
"php_grpc_library",
"php_proto_library",
)
php_proto_library(
name = "servicecontrol_php_proto",
deps = [":servicecontrol_proto"],
)
php_grpc_library(
name = "servicecontrol_php_grpc",
srcs = [":servicecontrol_proto"],
deps = [":servicecontrol_php_proto"],
)
php_gapic_library(
name = "servicecontrol_php_gapic",
srcs = [":servicecontrol_proto_with_info"],
grpc_service_config = "servicecontrol_grpc_service_config.json",
service_yaml = "servicecontrol.yaml",
deps = [
":servicecontrol_php_grpc",
":servicecontrol_php_proto",
],
)
# Open Source Packages
php_gapic_assembly_pkg(
name = "google-cloud-api-servicecontrol-v2-php",
deps = [
":servicecontrol_php_gapic",
":servicecontrol_php_grpc",
":servicecontrol_php_proto",
],
)
##############################################################################
# Node.js
##############################################################################
load(
"@com_google_googleapis_imports//:imports.bzl",
"nodejs_gapic_assembly_pkg",
"nodejs_gapic_library",
)
nodejs_gapic_library(
name = "servicecontrol_nodejs_gapic",
package_name = "@google-cloud/servicecontrol",
src = ":servicecontrol_proto_with_info",
extra_protoc_parameters = ["metadata"],
grpc_service_config = "servicecontrol_grpc_service_config.json",
package = "google.api.servicecontrol.v2",
service_yaml = "servicecontrol.yaml",
deps = [],
)
nodejs_gapic_assembly_pkg(
name = "api-servicecontrol-v2-nodejs",
deps = [
":servicecontrol_nodejs_gapic",
":servicecontrol_proto",
],
)
##############################################################################
# Ruby
##############################################################################
load(
"@com_google_googleapis_imports//:imports.bzl",
"ruby_gapic_assembly_pkg",
"ruby_cloud_gapic_library",
"ruby_grpc_library",
"ruby_proto_library",
)
ruby_proto_library(
name = "servicecontrol_ruby_proto",
deps = [":servicecontrol_proto"],
)
ruby_grpc_library(
name = "servicecontrol_ruby_grpc",
srcs = [":servicecontrol_proto"],
deps = [":servicecontrol_ruby_proto"],
)
ruby_cloud_gapic_library(
name = "servicecontrol_ruby_gapic",
srcs = [":servicecontrol_proto_with_info"],
extra_protoc_parameters = [
"ruby-cloud-gem-name=google-cloud-api-servicecontrol-v2",
],
grpc_service_config = "servicecontrol_grpc_service_config.json",
deps = [
":servicecontrol_ruby_grpc",
":servicecontrol_ruby_proto",
],
)
# Open Source Packages
ruby_gapic_assembly_pkg(
name = "google-cloud-api-servicecontrol-v2-ruby",
deps = [
":servicecontrol_ruby_gapic",
":servicecontrol_ruby_grpc",
":servicecontrol_ruby_proto",
],
)
##############################################################################
# C#
##############################################################################
load(
"@com_google_googleapis_imports//:imports.bzl",
"csharp_gapic_assembly_pkg",
"csharp_gapic_library",
"csharp_grpc_library",
"csharp_proto_library",
)
csharp_proto_library(
name = "servicecontrol_csharp_proto",
deps = [":servicecontrol_proto"],
)
csharp_grpc_library(
name = "servicecontrol_csharp_grpc",
srcs = [":servicecontrol_proto"],
deps = [":servicecontrol_csharp_proto"],
)
csharp_gapic_library(
name = "servicecontrol_csharp_gapic",
srcs = [":servicecontrol_proto_with_info"],
common_resources_config = "@gax_dotnet//:Google.Api.Gax/ResourceNames/CommonResourcesConfig.json",
grpc_service_config = "servicecontrol_grpc_service_config.json",
service_yaml = "servicecontrol.yaml",
deps = [
":servicecontrol_csharp_grpc",
":servicecontrol_csharp_proto",
],
)
# Open Source Packages
csharp_gapic_assembly_pkg(
name = "google-cloud-api-servicecontrol-v2-csharp",
deps = [
":servicecontrol_csharp_gapic",
":servicecontrol_csharp_grpc",
":servicecontrol_csharp_proto",
],
)
##############################################################################
# C++
##############################################################################
load(
"@com_google_googleapis_imports//:imports.bzl",
"cc_grpc_library",
"cc_proto_library",
)
cc_proto_library(
name = "servicecontrol_cc_proto",
deps = [":servicecontrol_proto"],
)
cc_grpc_library(
name = "servicecontrol_cc_grpc",
srcs = [":servicecontrol_proto"],
grpc_only = True,
deps = [":servicecontrol_cc_proto"],
)

@ -0,0 +1,186 @@
// Copyright 2022 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.api.servicecontrol.v2;
import "google/api/annotations.proto";
import "google/api/client.proto";
import "google/rpc/context/attribute_context.proto";
import "google/rpc/status.proto";
option cc_enable_arenas = true;
option csharp_namespace = "Google.Cloud.ServiceControl.V2";
option go_package = "google.golang.org/genproto/googleapis/api/servicecontrol/v2;servicecontrol";
option java_multiple_files = true;
option java_outer_classname = "ServiceControllerProto";
option java_package = "com.google.api.servicecontrol.v2";
option objc_class_prefix = "GASC";
option php_namespace = "Google\\Cloud\\ServiceControl\\V2";
option ruby_package = "Google::Cloud::ServiceControl::V2";
// [Service Control API v2](/service-infrastructure/docs/service-control)
//
// Private Preview. This feature is only available for approved services.
//
// This API provides admission control and telemetry reporting for services
// that are integrated with [Service Infrastructure](/service-infrastructure).
service ServiceController {
option (google.api.default_host) = "servicecontrol.googleapis.com";
option (google.api.oauth_scopes) =
"https://www.googleapis.com/auth/cloud-platform,"
"https://www.googleapis.com/auth/servicecontrol";
// Private Preview. This feature is only available for approved services.
//
// This method provides admission control for services that are integrated
// with [Service Infrastructure](/service-infrastructure). It checks whether
// an operation should be allowed based on the service configuration and
// relevant policies. It must be called before the operation is executed.
// For more information, see
// [Admission Control](/service-infrastructure/docs/admission-control).
//
// NOTE: The admission control has an expected policy propagation delay of
// 60s. The caller **must** not depend on the most recent policy changes.
//
// NOTE: The admission control has a hard limit of 1 referenced resources
// per call. If an operation refers to more than 1 resources, the caller
// must call the Check method multiple times.
//
// This method requires the `servicemanagement.services.check` permission
// on the specified service. For more information, see
// [Service Control API Access
// Control](https://cloud.google.com/service-infrastructure/docs/service-control/access-control).
rpc Check(CheckRequest) returns (CheckResponse) {
option (google.api.http) = {
post: "/v2/services/{service_name}:check"
body: "*"
};
}
// Private Preview. This feature is only available for approved services.
//
// This method provides telemetry reporting for services that are integrated
// with [Service Infrastructure](/service-infrastructure). It reports a list
// of operations that have occurred on a service. It must be called after the
// operations have been executed. For more information, see
// [Telemetry Reporting](/service-infrastructure/docs/telemetry-reporting).
//
// NOTE: The telemetry reporting has a hard limit of 1000 operations and 1MB
// per Report call. It is recommended to have no more than 100 operations per
// call.
//
// This method requires the `servicemanagement.services.report` permission
// on the specified service. For more information, see
// [Service Control API Access
// Control](https://cloud.google.com/service-infrastructure/docs/service-control/access-control).
rpc Report(ReportRequest) returns (ReportResponse) {
option (google.api.http) = {
post: "/v2/services/{service_name}:report"
body: "*"
};
}
}
// Request message for the Check method.
message CheckRequest {
// The service name as specified in its service configuration. For example,
// `"pubsub.googleapis.com"`.
//
// See
// [google.api.Service](https://cloud.google.com/service-management/reference/rpc/google.api#google.api.Service)
// for the definition of a service name.
string service_name = 1;
// Specifies the version of the service configuration that should be used to
// process the request. Must not be empty. Set this field to 'latest' to
// specify using the latest configuration.
string service_config_id = 2;
// Describes attributes about the operation being executed by the service.
google.rpc.context.AttributeContext attributes = 3;
// Describes the resources and the policies applied to each resource.
repeated ResourceInfo resources = 4;
// Optional. Contains a comma-separated list of flags.
string flags = 5;
}
// Describes a resource referenced in the request.
message ResourceInfo {
// The name of the resource referenced in the request.
string name = 1;
// The resource type in the format of "{service}/{kind}".
string type = 2;
// The resource permission needed for this request.
// The format must be "{service}/{plural}.{verb}".
string permission = 3;
// Optional. The identifier of the container of this resource. For Google
// Cloud APIs, the resource container must be one of the following formats:
// - `projects/<project-id or project-number>`
// - `folders/<folder-id>`
// - `organizations/<organization-id>`
// For the policy enforcement on the container level (VPCSC and Location
// Policy check), this field takes precedence on the container extracted from
// name when presents.
string container = 4;
// Optional. The location of the resource. The value must be a valid zone,
// region or multiregion. For example: "europe-west4" or
// "northamerica-northeast1-a"
string location = 5;
}
// Response message for the Check method.
message CheckResponse {
// Operation is allowed when this field is not set. Any non-'OK' status
// indicates a denial; [google.rpc.Status.details]() would contain additional
// details about the denial.
google.rpc.Status status = 1;
// Returns a set of request contexts generated from the `CheckRequest`.
map<string, string> headers = 2;
}
// Request message for the Report method.
message ReportRequest {
// The service name as specified in its service configuration. For example,
// `"pubsub.googleapis.com"`.
//
// See
// [google.api.Service](https://cloud.google.com/service-management/reference/rpc/google.api#google.api.Service)
// for the definition of a service name.
string service_name = 1;
// Specifies the version of the service configuration that should be used to
// process the request. Must not be empty. Set this field to 'latest' to
// specify using the latest configuration.
string service_config_id = 2;
// Describes the list of operations to be reported. Each operation is
// represented as an AttributeContext, and contains all attributes around an
// API access.
repeated google.rpc.context.AttributeContext operations = 3;
}
// Response message for the Report method.
// If the request contains any invalid data, the server returns an RPC error.
message ReportResponse {
}

@ -0,0 +1,171 @@
type: google.api.Service
config_version: 3
name: servicecontrol.googleapis.com
title: Service Control API
apis:
- name: google.api.servicecontrol.v2.ServiceController
documentation:
summary: |-
Provides admission control and telemetry reporting for services integrated
with Service Infrastructure.
overview: |-
Google Service Control provides control plane functionality to managed
services, such as logging, monitoring, and status checks. This page
provides an overview of what it does and how it works.
## Why use Service Control?
When you develop a cloud service, you typically start with the business
requirements and the architecture design, then proceed with API definition
and implementation. Before you put your service into production, you
need to deal with many control plane issues:
* How to control access to your service.
* How to send logging and monitoring data to both consumers and producers.
* How to create and manage dashboards to visualize this data.
* How to automatically scale the control plane components with your
service.
Service Control is a mature and feature-rich control plane provider
that addresses these needs with high efficiency, high scalability,
and high availability. It provides a simple public API that can be
accessed from anywhere using JSON REST and gRPC clients, so when you move
your service from on-premise to a cloud provider, or from one cloud
provider to another, you don't need to change the control plane provider.
Services built using Google Cloud Endpoints already take advantage of
Service Control. Cloud Endpoints sends logging and monitoring data
through Google Service Control for every request arriving at its
proxy. If you need to report any additional logging and monitoring data
for your Cloud Endpoints service, you can call the Service Control API
directly from your service.
The Service Control API definition is open sourced and available on
[GitHub](https://github.com/googleapis/googleapis/tree/master/google/api/servicecontrol). By
changing the DNS name, you can easily use alternative implementations
of the Service Control API.
## Architecture
Google Service Control works with a set of *managed services* and their
*operations* (activities), *checks* whether an operation is allowed to
proceed, and *reports* completed operations. Behind the scenes, it
leverages other
Google Cloud services, such as
[Google Service
Management](https://cloud.google.com/service-infrastructure/docs/service-management/getting-started), [Stackdriver
Logging](https://cloud.google.com/products/operations), and [Stackdriver
Monitoring](https://cloud.google.com/monitoring), while hiding their
complexity from service producers. It enables service
producers to send telemetry data to their consumers. It uses caching,
batching, aggregation, and retries to deliver higher performance and
availability than the individual backend systems it encapsulates.
<figure id="fig-arch" class="center">
<div style="width: 70%;margin: auto">
<img src="/service-infrastructure/docs/service-control/images/arch.svg"
alt="The overall architecture of a service that uses Google Service
Control."> </div> <figcaption><b>Figure 1</b>: Using Google Service
Control.</figcaption> </figure>
The Service Control API provides two methods:
*
[`services.check`](https://cloud.google.com/service-infrastructure/docs/service-control/reference/rest/v1/services/check),
used for:
* Ensuring valid consumer status
* Validating API keys
*
[`services.report`](https://cloud.google.com/service-infrastructure/docs/service-control/reference/rest/v1/services/report),
used for:
* Sending logs to Stackdriver Logging
* Sending metrics to Stackdriver Monitoring
We'll look at these in more detail in the rest of this overview.
## Managed services
A [managed
service](https://cloud.google.com/service-infrastructure/docs/service-control/reference/rest/v1/services) is
a network service managed by
[Google Service
Management](https://cloud.google.com/service-infrastructure/docs/service-management/getting-started). Each
managed service has a unique name, such as `example.googleapis.com`,
which must be a valid fully-qualified DNS name, as per RFC 1035.
For example:
* Google Cloud Pub/Sub (`pubsub.googleapis.com`)
* Google Cloud Vision (`vision.googleapis.com`)
* Google Cloud Bigtable (`bigtable.googleapis.com`)
* Google Cloud Datastore (`datastore.googleapis.com`)
Google Service Management manages the lifecycle of each service's
configuration, which is used to customize Google Service Control's
behavior. Service configurations are also used by Google Cloud Console for
displaying APIs and their settings, enabling/disabling APIs, and more.
## Operations
Google Service Control uses the generic concept of an *operation*
to represent the activities of a managed service, such as API calls and
resource usage. Each operation is associated with a managed service and a
specific service consumer, and has a set of properties that describe the
operation, such as the API method name and resource usage amount. For more
information, see the
[Operation
definition](https://cloud.google.com/service-infrastructure/docs/service-control/reference/rest/v1/Operation). ##
Check
The
[`services.check`](https://cloud.google.com/service-infrastructure/docs/service-control/reference/rest/v1/services/check) method
determines whether an operation should be allowed to proceed for a
managed service.
For example:
* Check if the consumer is still active.
* Check if the consumer has enabled the service.
* Check if the API key is still valid.
By performing multiple checks within a single method call, it provides
better performance, higher reliability, and reduced development cost to
service producers compared to checking with multiple backend systems.
## Report
The
[`services.report`](https://cloud.google.com/service-infrastructure/docs/service-control/reference/rest/v1/services/report) method
reports completed operations for a managed service to backend
systems, such as logging and monitoring. The reported data can be seen in
Google API Console and Google Cloud Console, and retrieved with
appropriate APIs, such as the Stackdriver Logging and Stackdriver
Monitoring APIs.
## Next steps
* Read our [Getting Started
guide](https://cloud.google.com/service-infrastructure/docs/service-control/getting-started)
to find out how to set up and use the Google Service Control API.
backend:
rules:
- selector: google.api.servicecontrol.v2.ServiceController.Check
deadline: 5.0
- selector: google.api.servicecontrol.v2.ServiceController.Report
deadline: 5.0
authentication:
rules:
- selector: google.api.servicecontrol.v2.ServiceController.Check
oauth:
canonical_scopes: |-
https://www.googleapis.com/auth/cloud-platform,
https://www.googleapis.com/auth/servicecontrol
- selector: google.api.servicecontrol.v2.ServiceController.Report
oauth:
canonical_scopes: |-
https://www.googleapis.com/auth/cloud-platform,
https://www.googleapis.com/auth/servicecontrol

@ -0,0 +1,20 @@
{
"methodConfig": [
{
"name": [
{
"service": "google.api.servicecontrol.v2.ServiceController",
"method": "Check"
}
],
"timeout": "5s",
"retryPolicy": {
"maxAttempts": 5,
"initialBackoff": "1s",
"maxBackoff": "10s",
"backoffMultiplier": 1.3,
"retryableStatusCodes": ["UNAVAILABLE"]
}
}
]
}
Loading…
Cancel
Save