1// Copyright 2023 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15syntax = "proto3";
16
17package google.devtools.cloudprofiler.v2;
18
19import "google/api/annotations.proto";
20import "google/api/client.proto";
21import "google/api/field_behavior.proto";
22import "google/api/resource.proto";
23import "google/protobuf/duration.proto";
24import "google/protobuf/field_mask.proto";
25
26option csharp_namespace = "Google.Cloud.Profiler.V2";
27option go_package = "google.golang.org/genproto/googleapis/devtools/cloudprofiler/v2;cloudprofiler";
28option java_multiple_files = true;
29option java_outer_classname = "ProfilerProto";
30option java_package = "com.google.devtools.cloudprofiler.v2";
31option php_namespace = "Google\\Cloud\\Profiler\\V2";
32option ruby_package = "Google::Cloud::Profiler::V2";
33
34// Manage the collection of continuous profiling data provided by profiling
35// agents running in the cloud or by an offline provider of profiling data.
36//
37// General guidelines:
38// * Profiles for a single deployment must be created in ascending time order.
39// * Profiles can be created in either online or offline mode, see below.
40service ProfilerService {
41  option (google.api.default_host) = "cloudprofiler.googleapis.com";
42  option (google.api.oauth_scopes) =
43      "https://www.googleapis.com/auth/cloud-platform,"
44      "https://www.googleapis.com/auth/monitoring,"
45      "https://www.googleapis.com/auth/monitoring.write";
46
47  // CreateProfile creates a new profile resource in the online mode.
48  //
49  // The server ensures that the new profiles are created at a constant rate per
50  // deployment, so the creation request may hang for some time until the next
51  // profile session is available.
52  //
53  // The request may fail with ABORTED error if the creation is not available
54  // within ~1m, the response will indicate the duration of the backoff the
55  // client should take before attempting creating a profile again. The backoff
56  // duration is returned in google.rpc.RetryInfo extension on the response
57  // status. To a gRPC client, the extension will be return as a
58  // binary-serialized proto in the trailing metadata item named
59  // "google.rpc.retryinfo-bin".
60  //
61  rpc CreateProfile(CreateProfileRequest) returns (Profile) {
62    option (google.api.http) = {
63      post: "/v2/{parent=projects/*}/profiles"
64      body: "*"
65    };
66  }
67
68  // CreateOfflineProfile creates a new profile resource in the offline mode.
69  // The client provides the profile to create along with the profile bytes, the
70  // server records it.
71  rpc CreateOfflineProfile(CreateOfflineProfileRequest) returns (Profile) {
72    option (google.api.http) = {
73      post: "/v2/{parent=projects/*}/profiles:createOffline"
74      body: "profile"
75    };
76    option (google.api.method_signature) = "parent,profile";
77  }
78
79  // UpdateProfile updates the profile bytes and labels on the profile resource
80  // created in the online mode. Updating the bytes for profiles created in the
81  // offline mode is currently not supported: the profile content must be
82  // provided at the time of the profile creation.
83  rpc UpdateProfile(UpdateProfileRequest) returns (Profile) {
84    option (google.api.http) = {
85      patch: "/v2/{profile.name=projects/*/profiles/*}"
86      body: "profile"
87    };
88    option (google.api.method_signature) = "profile,update_mask";
89  }
90}
91
92// CreateProfileRequest describes a profile resource online creation request.
93// The deployment field must be populated. The profile_type specifies the list
94// of profile types supported by the agent. The creation call will hang until a
95// profile of one of these types needs to be collected.
96//
97message CreateProfileRequest {
98  // Parent project to create the profile in.
99  string parent = 4 [(google.api.resource_reference) = {
100    type: "cloudresourcemanager.googleapis.com/Project"
101  }];
102
103  // Deployment details.
104  Deployment deployment = 1;
105
106  // One or more profile types that the agent is capable of providing.
107  repeated ProfileType profile_type = 2;
108}
109
110// CreateOfflineProfileRequest describes a profile resource offline creation
111// request.
112message CreateOfflineProfileRequest {
113  // Parent project to create the profile in.
114  string parent = 1 [(google.api.resource_reference) = {
115    type: "cloudresourcemanager.googleapis.com/Project"
116  }];
117
118  // Contents of the profile to create.
119  Profile profile = 2;
120}
121
122// UpdateProfileRequest contains the profile to update.
123message UpdateProfileRequest {
124  // Profile to update.
125  Profile profile = 1;
126
127  // Field mask used to specify the fields to be overwritten. Currently only
128  // profile_bytes and labels fields are supported by UpdateProfile, so only
129  // those fields can be specified in the mask. When no mask is provided, all
130  // fields are overwritten.
131  google.protobuf.FieldMask update_mask = 2;
132}
133
134// Profile resource.
135message Profile {
136  option (google.api.resource) = {
137    type: "cloudprofiler.googleapis.com/Profile"
138    pattern: "projects/{project}/profiles/{profile}"
139  };
140
141  // Output only. Opaque, server-assigned, unique ID for this profile.
142  string name = 1 [(google.api.field_behavior) = OUTPUT_ONLY];
143
144  // Type of profile.
145  // For offline mode, this must be specified when creating the profile. For
146  // online mode it is assigned and returned by the server.
147  ProfileType profile_type = 2;
148
149  // Deployment this profile corresponds to.
150  Deployment deployment = 3;
151
152  // Duration of the profiling session.
153  // Input (for the offline mode) or output (for the online mode).
154  // The field represents requested profiling duration. It may slightly differ
155  // from the effective profiling duration, which is recorded in the profile
156  // data, in case the profiling can't be stopped immediately (e.g. in case
157  // stopping the profiling is handled asynchronously).
158  google.protobuf.Duration duration = 4;
159
160  // Input only. Profile bytes, as a gzip compressed serialized proto, the
161  // format is https://github.com/google/pprof/blob/master/proto/profile.proto.
162  bytes profile_bytes = 5 [(google.api.field_behavior) = INPUT_ONLY];
163
164  // Input only. Labels associated to this specific profile. These labels will
165  // get merged with the deployment labels for the final data set. See
166  // documentation on deployment labels for validation rules and limits.
167  map<string, string> labels = 6 [(google.api.field_behavior) = INPUT_ONLY];
168}
169
170// Deployment contains the deployment identification information.
171message Deployment {
172  // Project ID is the ID of a cloud project.
173  // Validation regex: `^[a-z][-a-z0-9:.]{4,61}[a-z0-9]$`.
174  string project_id = 1;
175
176  // Target is the service name used to group related deployments:
177  // * Service name for App Engine Flex / Standard.
178  // * Cluster and container name for GKE.
179  // * User-specified string for direct Compute Engine profiling (e.g. Java).
180  // * Job name for Dataflow.
181  // Validation regex: `^[a-z0-9]([-a-z0-9_.]{0,253}[a-z0-9])?$`.
182  string target = 2;
183
184  // Labels identify the deployment within the user universe and same target.
185  // Validation regex for label names: `^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$`.
186  // Value for an individual label must be <= 512 bytes, the total
187  // size of all label names and values must be <= 1024 bytes.
188  //
189  // Label named "language" can be used to record the programming language of
190  // the profiled deployment. The standard choices for the value include "java",
191  // "go", "python", "ruby", "nodejs", "php", "dotnet".
192  //
193  // For deployments running on Google Cloud Platform, "zone" or "region" label
194  // should be present describing the deployment location. An example of a zone
195  // is "us-central1-a", an example of a region is "us-central1" or
196  // "us-central".
197  map<string, string> labels = 3;
198}
199
200// ProfileType is type of profiling data.
201// NOTE: the enumeration member names are used (in lowercase) as unique string
202// identifiers of profile types, so they must not be renamed.
203enum ProfileType {
204  // Unspecified profile type.
205  PROFILE_TYPE_UNSPECIFIED = 0;
206
207  // Thread CPU time sampling.
208  CPU = 1;
209
210  // Wallclock time sampling. More expensive as stops all threads.
211  WALL = 2;
212
213  // In-use heap profile. Represents a snapshot of the allocations that are
214  // live at the time of the profiling.
215  HEAP = 3;
216
217  // Single-shot collection of all thread stacks.
218  THREADS = 4;
219
220  // Synchronization contention profile.
221  CONTENTION = 5;
222
223  // Peak heap profile.
224  PEAK_HEAP = 6;
225
226  // Heap allocation profile. It represents the aggregation of all allocations
227  // made over the duration of the profile. All allocations are included,
228  // including those that might have been freed by the end of the profiling
229  // interval. The profile is in particular useful for garbage collecting
230  // languages to understand which parts of the code create most of the garbage
231  // collection pressure to see if those can be optimized.
232  HEAP_ALLOC = 7;
233}
234