// Copyright 2017 Istio Authors
//
// 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";

// $title: Service Control
// $description: Adapter that delivers logs and metrics to Google Service Control
// $location: https://istio.io/docs/reference/config/policy-and-telemetry/adapters/servicecontrol.html
// $aliases:
// $  - /docs/reference/config/adapters/servicecontrol.html

// The `servicecontrol` adapter delivers logs and metrics to
// [Google Service Control](https://cloud.google.com/service-control).
//
// This adapter supports the [servicecontrolreport template](https://istio.io/docs/reference/config/policy-and-telemetry/templates/servicecontrolreport/),
// the [quota template](https://istio.io/docs/reference/config/policy-and-telemetry/templates/quota/),
// and the [apikey template](https://istio.io/docs/reference/config/policy-and-telemetry/templates/apikey/).
package adapter.servicecontrol.config;

import "gogoproto/gogo.proto";
import "google/protobuf/duration.proto";

option go_package = "config";
option (gogoproto.goproto_getters_all) = false;
option (gogoproto.equal_all) = false;
option (gogoproto.gostring_all) = false;

// Adapter runtime config paramters.
message RuntimeConfig {
    int32 check_cache_size = 1;
    google.protobuf.Duration check_result_expiration = 2;
}

message Quota {
    // Istio quota name.
    string name = 1;
    // The corresponding Google quota metric name.
    string google_quota_metric_name = 2;
    // Quota token expiration time period.
    google.protobuf.Duration expiration = 3;
}

// Adapter setting for a managed GCP service.
message GcpServiceSetting {
    // Local service name on the mesh, which matches destination.service attribute.
    string mesh_service_name = 1;

    // Fully qualified GCP service name.
    string google_service_name = 2;

    // Quota configs
    repeated Quota quotas = 3;
}

// Configuration format for the `servicecontrol` adapter.
//
// Sample adapter config:
//
// ```yaml
// apiVersion: "config.istio.io/v1alpha2"
// kind: servicecontrol
// metadata:
//   name: testhandler
//   namespace: istio-system
// spec:
//   runtime_config:
//     check_cache_size: 200
//     check_result_expiration: 60s
//   credential_path: "/path/to/token.json"
//   service_configs:
//     - mesh_service_name: "echo.local.svc"
//       google_service_name: "echo.endpoints.cloud.goog"
//       quotas:
//         - name: ratelimit.quota.istio-system
//           google_quota_metric_name: read-requests
//           expiration: 1m
// ```
message Params {
    RuntimeConfig runtime_config = 1;
    // A path to JSON token file, usually mounted as Kubernetes secret on pod.
    string credential_path = 2;
    repeated GcpServiceSetting service_configs = 3;
}
