// Copyright 2016 Google Inc.
//
// 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.monitoring.v3;

import "google/api/annotations.proto";
import "google/api/metric.proto";
import "google/api/monitored_resource.proto";
import "google/monitoring/v3/common.proto";
import "google/monitoring/v3/metric.proto";
import "google/protobuf/empty.proto";
import "google/rpc/status.proto";

option csharp_namespace = "Google.Cloud.Monitoring.V3";
option go_package = "google.golang.org/genproto/googleapis/monitoring/v3;monitoring";
option java_multiple_files = true;
option java_outer_classname = "MetricServiceProto";
option java_package = "com.google.monitoring.v3";


// Manages metric descriptors, monitored resource descriptors, and
// time series data.
service MetricService {
  // Lists monitored resource descriptors that match a filter. This method does not require a Stackdriver account.
  rpc ListMonitoredResourceDescriptors(ListMonitoredResourceDescriptorsRequest) returns (ListMonitoredResourceDescriptorsResponse) {
    option (google.api.http) = { get: "/v3/{name=projects/*}/monitoredResourceDescriptors" };
  }

  // Gets a single monitored resource descriptor. This method does not require a Stackdriver account.
  rpc GetMonitoredResourceDescriptor(GetMonitoredResourceDescriptorRequest) returns (google.api.MonitoredResourceDescriptor) {
    option (google.api.http) = { get: "/v3/{name=projects/*/monitoredResourceDescriptors/*}" };
  }

  // Lists metric descriptors that match a filter. This method does not require a Stackdriver account.
  rpc ListMetricDescriptors(ListMetricDescriptorsRequest) returns (ListMetricDescriptorsResponse) {
    option (google.api.http) = { get: "/v3/{name=projects/*}/metricDescriptors" };
  }

  // Gets a single metric descriptor. This method does not require a Stackdriver account.
  rpc GetMetricDescriptor(GetMetricDescriptorRequest) returns (google.api.MetricDescriptor) {
    option (google.api.http) = { get: "/v3/{name=projects/*/metricDescriptors/**}" };
  }

  // Creates a new metric descriptor.
  // User-created metric descriptors define
  // [custom metrics](/monitoring/custom-metrics).
  rpc CreateMetricDescriptor(CreateMetricDescriptorRequest) returns (google.api.MetricDescriptor) {
    option (google.api.http) = { post: "/v3/{name=projects/*}/metricDescriptors" body: "metric_descriptor" };
  }

  // Deletes a metric descriptor. Only user-created
  // [custom metrics](/monitoring/custom-metrics) can be deleted.
  rpc DeleteMetricDescriptor(DeleteMetricDescriptorRequest) returns (google.protobuf.Empty) {
    option (google.api.http) = { delete: "/v3/{name=projects/*/metricDescriptors/**}" };
  }

  // Lists time series that match a filter. This method does not require a Stackdriver account.
  rpc ListTimeSeries(ListTimeSeriesRequest) returns (ListTimeSeriesResponse) {
    option (google.api.http) = { get: "/v3/{name=projects/*}/timeSeries" };
  }

  // Creates or adds data to one or more time series.
  // The response is empty if all time series in the request were written.
  // If any time series could not be written, a corresponding failure message is
  // included in the error response.
  rpc CreateTimeSeries(CreateTimeSeriesRequest) returns (google.protobuf.Empty) {
    option (google.api.http) = { post: "/v3/{name=projects/*}/timeSeries" body: "*" };
  }
}

// The `ListMonitoredResourceDescriptors` request.
message ListMonitoredResourceDescriptorsRequest {
  // The project on which to execute the request. The format is
  // `"projects/{project_id_or_number}"`.
  string name = 5;

  // An optional [filter](/monitoring/api/v3/filters) describing
  // the descriptors to be returned.  The filter can reference
  // the descriptor's type and labels. For example, the
  // following filter returns only Google Compute Engine descriptors
  // that have an `id` label:
  //
  //     resource.type = starts_with("gce_") AND resource.label:id
  string filter = 2;

  // A positive number that is the maximum number of results to return.
  int32 page_size = 3;

  // If this field is not empty then it must contain the `nextPageToken` value
  // returned by a previous call to this method.  Using this field causes the
  // method to return additional results from the previous method call.
  string page_token = 4;
}

// The `ListMonitoredResourcDescriptors` response.
message ListMonitoredResourceDescriptorsResponse {
  // The monitored resource descriptors that are available to this project
  // and that match `filter`, if present.
  repeated google.api.MonitoredResourceDescriptor resource_descriptors = 1;

  // If there are more results than have been returned, then this field is set
  // to a non-empty value.  To see the additional results,
  // use that value as `pageToken` in the next call to this method.
  string next_page_token = 2;
}

// The `GetMonitoredResourceDescriptor` request.
message GetMonitoredResourceDescriptorRequest {
  // The monitored resource descriptor to get.  The format is
  // `"projects/{project_id_or_number}/monitoredResourceDescriptors/{resource_type}"`.
  // The `{resource_type}` is a predefined type, such as
  // `cloudsql_database`.
  string name = 3;
}

// The `ListMetricDescriptors` request.
message ListMetricDescriptorsRequest {
  // The project on which to execute the request. The format is
  // `"projects/{project_id_or_number}"`.
  string name = 5;

  // If this field is empty, all custom and
  // system-defined metric descriptors are returned.
  // Otherwise, the [filter](/monitoring/api/v3/filters)
  // specifies which metric descriptors are to be
  // returned. For example, the following filter matches all
  // [custom metrics](/monitoring/custom-metrics):
  //
  //     metric.type = starts_with("custom.googleapis.com/")
  string filter = 2;

  // A positive number that is the maximum number of results to return.
  int32 page_size = 3;

  // If this field is not empty then it must contain the `nextPageToken` value
  // returned by a previous call to this method.  Using this field causes the
  // method to return additional results from the previous method call.
  string page_token = 4;
}

// The `ListMetricDescriptors` response.
message ListMetricDescriptorsResponse {
  // The metric descriptors that are available to the project
  // and that match the value of `filter`, if present.
  repeated google.api.MetricDescriptor metric_descriptors = 1;

  // If there are more results than have been returned, then this field is set
  // to a non-empty value.  To see the additional results,
  // use that value as `pageToken` in the next call to this method.
  string next_page_token = 2;
}

// The `GetMetricDescriptor` request.
message GetMetricDescriptorRequest {
  // The metric descriptor on which to execute the request. The format is
  // `"projects/{project_id_or_number}/metricDescriptors/{metric_id}"`.
  // An example value of `{metric_id}` is
  // `"compute.googleapis.com/instance/disk/read_bytes_count"`.
  string name = 3;
}

// The `CreateMetricDescriptor` request.
message CreateMetricDescriptorRequest {
  // The project on which to execute the request. The format is
  // `"projects/{project_id_or_number}"`.
  string name = 3;

  // The new [custom metric](/monitoring/custom-metrics)
  // descriptor.
  google.api.MetricDescriptor metric_descriptor = 2;
}

// The `DeleteMetricDescriptor` request.
message DeleteMetricDescriptorRequest {
  // The metric descriptor on which to execute the request. The format is
  // `"projects/{project_id_or_number}/metricDescriptors/{metric_id}"`.
  // An example of `{metric_id}` is:
  // `"custom.googleapis.com/my_test_metric"`.
  string name = 3;
}

// The `ListTimeSeries` request.
message ListTimeSeriesRequest {
  // Controls which fields are returned by `ListTimeSeries`.
  enum TimeSeriesView {
    // Returns the identity of the metric(s), the time series,
    // and the time series data.
    FULL = 0;

    // Returns the identity of the metric and the time series resource,
    // but not the time series data.
    HEADERS = 1;
  }

  // The project on which to execute the request. The format is
  // "projects/{project_id_or_number}".
  string name = 10;

  // A [monitoring filter](/monitoring/api/v3/filters) that specifies which time
  // series should be returned.  The filter must specify a single metric type,
  // and can additionally specify metric labels and other information. For
  // example:
  //
  //     metric.type = "compute.googleapis.com/instance/cpu/usage_time" AND
  //         metric.label.instance_name = "my-instance-name"
  string filter = 2;

  // The time interval for which results should be returned. Only time series
  // that contain data points in the specified interval are included
  // in the response.
  TimeInterval interval = 4;

  // By default, the raw time series data is returned.
  // Use this field to combine multiple time series for different
  // views of the data.
  Aggregation aggregation = 5;

  // Specifies the order in which the points of the time series should
  // be returned.  By default, results are not ordered.  Currently,
  // this field must be left blank.
  string order_by = 6;

  // Specifies which information is returned about the time series.
  TimeSeriesView view = 7;

  // A positive number that is the maximum number of results to return.
  // When `view` field sets to `FULL`, it limits the number of `Points` server
  // will return; if `view` field is `HEADERS`, it limits the number of
  // `TimeSeries` server will return.
  int32 page_size = 8;

  // If this field is not empty then it must contain the `nextPageToken` value
  // returned by a previous call to this method.  Using this field causes the
  // method to return additional results from the previous method call.
  string page_token = 9;
}

// The `ListTimeSeries` response.
message ListTimeSeriesResponse {
  // One or more time series that match the filter included in the request.
  repeated TimeSeries time_series = 1;

  // If there are more results than have been returned, then this field is set
  // to a non-empty value.  To see the additional results,
  // use that value as `pageToken` in the next call to this method.
  string next_page_token = 2;
}

// The `CreateTimeSeries` request.
message CreateTimeSeriesRequest {
  // The project on which to execute the request. The format is
  // `"projects/{project_id_or_number}"`.
  string name = 3;

  // The new data to be added to a list of time series.
  // Adds at most one data point to each of several time series.  The new data
  // point must be more recent than any other point in its time series.  Each
  // `TimeSeries` value must fully specify a unique time series by supplying
  // all label values for the metric and the monitored resource.
  repeated TimeSeries time_series = 2;
}

// Describes the result of a failed request to write data to a time series.
message CreateTimeSeriesError {
  // The time series, including the `Metric`, `MonitoredResource`,
  // and `Point`s (including timestamp and value) that resulted
  // in the error. This field provides all of the context that
  // would be needed to retry the operation.
  TimeSeries time_series = 1;

  // The status of the requested write operation.
  google.rpc.Status status = 2;
}
