google_cloud_profiler_v2/client.rs
1// Copyright 2025 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// https://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//
15// Code generated by sidekick. DO NOT EDIT.
16#![allow(rustdoc::redundant_explicit_links)]
17#![allow(rustdoc::broken_intra_doc_links)]
18
19/// Implements a client for the Cloud Profiler API.
20///
21/// # Example
22/// ```
23/// # use google_cloud_profiler_v2::client::ProfilerService;
24/// use google_cloud_profiler_v2::model::Profile;
25/// # async fn sample() -> Result<(), Box<dyn std::error::Error>> {
26/// let client = ProfilerService::builder().build().await?;
27/// let parent = "parent_value";
28/// let response = client.create_offline_profile()
29/// .set_parent(parent)
30/// .set_profile(
31/// Profile::new()/* set fields */
32/// )
33/// .send().await?;
34/// println!("response {:?}", response);
35/// # Ok(()) }
36/// ```
37///
38/// # Service Description
39///
40/// Manage the collection of continuous profiling data provided by profiling
41/// agents running in the cloud or by an offline provider of profiling data.
42///
43/// __The APIs listed in this service are intended for use within our profiler
44/// agents only.__
45///
46/// # Configuration
47///
48/// To configure `ProfilerService` use the `with_*` methods in the type returned
49/// by [builder()][ProfilerService::builder]. The default configuration should
50/// work for most applications. Common configuration changes include
51///
52/// * [with_endpoint()]: by default this client uses the global default endpoint
53/// (`https://cloudprofiler.googleapis.com`). Applications using regional
54/// endpoints or running in restricted networks (e.g. a network configured
55// with [Private Google Access with VPC Service Controls]) may want to
56/// override this default.
57/// * [with_credentials()]: by default this client uses
58/// [Application Default Credentials]. Applications using custom
59/// authentication may need to override this default.
60///
61/// [with_endpoint()]: super::builder::profiler_service::ClientBuilder::with_endpoint
62/// [with_credentials()]: super::builder::profiler_service::ClientBuilder::with_credentials
63/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
64/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
65///
66/// # Pooling and Cloning
67///
68/// `ProfilerService` holds a connection pool internally, it is advised to
69/// create one and reuse it. You do not need to wrap `ProfilerService` in
70/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
71/// already uses an `Arc` internally.
72#[derive(Clone, Debug)]
73pub struct ProfilerService {
74 inner: std::sync::Arc<dyn super::stub::dynamic::ProfilerService>,
75}
76
77impl ProfilerService {
78 /// Returns a builder for [ProfilerService].
79 ///
80 /// ```
81 /// # async fn sample() -> google_cloud_gax::client_builder::Result<()> {
82 /// # use google_cloud_profiler_v2::client::ProfilerService;
83 /// let client = ProfilerService::builder().build().await?;
84 /// # Ok(()) }
85 /// ```
86 pub fn builder() -> super::builder::profiler_service::ClientBuilder {
87 crate::new_client_builder(super::builder::profiler_service::client::Factory)
88 }
89
90 /// Creates a new client from the provided stub.
91 ///
92 /// The most common case for calling this function is in tests mocking the
93 /// client's behavior.
94 pub fn from_stub<T>(stub: T) -> Self
95 where
96 T: super::stub::ProfilerService + 'static,
97 {
98 Self {
99 inner: std::sync::Arc::new(stub),
100 }
101 }
102
103 pub(crate) async fn new(
104 config: gaxi::options::ClientConfig,
105 ) -> crate::ClientBuilderResult<Self> {
106 let inner = Self::build_inner(config).await?;
107 Ok(Self { inner })
108 }
109
110 async fn build_inner(
111 conf: gaxi::options::ClientConfig,
112 ) -> crate::ClientBuilderResult<std::sync::Arc<dyn super::stub::dynamic::ProfilerService>> {
113 if gaxi::options::tracing_enabled(&conf) {
114 return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
115 }
116 Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
117 }
118
119 async fn build_transport(
120 conf: gaxi::options::ClientConfig,
121 ) -> crate::ClientBuilderResult<impl super::stub::ProfilerService> {
122 super::transport::ProfilerService::new(conf).await
123 }
124
125 async fn build_with_tracing(
126 conf: gaxi::options::ClientConfig,
127 ) -> crate::ClientBuilderResult<impl super::stub::ProfilerService> {
128 Self::build_transport(conf)
129 .await
130 .map(super::tracing::ProfilerService::new)
131 }
132
133 /// CreateProfile creates a new profile resource in the online mode.
134 ///
135 /// _Direct use of this API is discouraged, please use a [supported
136 /// profiler
137 /// agent](https://cloud.google.com/profiler/docs/about-profiler#profiling_agent)
138 /// instead for profile collection._
139 ///
140 /// The server ensures that the new profiles are created at a constant rate per
141 /// deployment, so the creation request may hang for some time until the next
142 /// profile session is available.
143 ///
144 /// The request may fail with ABORTED error if the creation is not available
145 /// within ~1m, the response will indicate the duration of the backoff the
146 /// client should take before attempting creating a profile again. The backoff
147 /// duration is returned in google.rpc.RetryInfo extension on the response
148 /// status. To a gRPC client, the extension will be return as a
149 /// binary-serialized proto in the trailing metadata item named
150 /// "google.rpc.retryinfo-bin".
151 ///
152 /// # Example
153 /// ```
154 /// # use google_cloud_profiler_v2::client::ProfilerService;
155 /// use google_cloud_profiler_v2::Result;
156 /// async fn sample(
157 /// client: &ProfilerService
158 /// ) -> Result<()> {
159 /// let response = client.create_profile()
160 /// /* set fields */
161 /// .send().await?;
162 /// println!("response {:?}", response);
163 /// Ok(())
164 /// }
165 /// ```
166 pub fn create_profile(&self) -> super::builder::profiler_service::CreateProfile {
167 super::builder::profiler_service::CreateProfile::new(self.inner.clone())
168 }
169
170 /// CreateOfflineProfile creates a new profile resource in the offline
171 /// mode. The client provides the profile to create along with the profile
172 /// bytes, the server records it.
173 ///
174 /// _Direct use of this API is discouraged, please use a [supported
175 /// profiler
176 /// agent](https://cloud.google.com/profiler/docs/about-profiler#profiling_agent)
177 /// instead for profile collection._
178 ///
179 /// # Example
180 /// ```
181 /// # use google_cloud_profiler_v2::client::ProfilerService;
182 /// use google_cloud_profiler_v2::model::Profile;
183 /// use google_cloud_profiler_v2::Result;
184 /// async fn sample(
185 /// client: &ProfilerService, parent: &str
186 /// ) -> Result<()> {
187 /// let response = client.create_offline_profile()
188 /// .set_parent(parent)
189 /// .set_profile(
190 /// Profile::new()/* set fields */
191 /// )
192 /// .send().await?;
193 /// println!("response {:?}", response);
194 /// Ok(())
195 /// }
196 /// ```
197 pub fn create_offline_profile(&self) -> super::builder::profiler_service::CreateOfflineProfile {
198 super::builder::profiler_service::CreateOfflineProfile::new(self.inner.clone())
199 }
200
201 /// UpdateProfile updates the profile bytes and labels on the profile resource
202 /// created in the online mode. Updating the bytes for profiles created in the
203 /// offline mode is currently not supported: the profile content must be
204 /// provided at the time of the profile creation.
205 ///
206 /// _Direct use of this API is discouraged, please use a [supported
207 /// profiler
208 /// agent](https://cloud.google.com/profiler/docs/about-profiler#profiling_agent)
209 /// instead for profile collection._
210 ///
211 /// # Example
212 /// ```
213 /// # use google_cloud_profiler_v2::client::ProfilerService;
214 /// # extern crate wkt as google_cloud_wkt;
215 /// use google_cloud_wkt::FieldMask;
216 /// use google_cloud_profiler_v2::model::Profile;
217 /// use google_cloud_profiler_v2::Result;
218 /// async fn sample(
219 /// client: &ProfilerService, name: &str
220 /// ) -> Result<()> {
221 /// let response = client.update_profile()
222 /// .set_profile(
223 /// Profile::new().set_name(name)/* set fields */
224 /// )
225 /// .set_update_mask(FieldMask::default().set_paths(["updated.field.path1", "updated.field.path2"]))
226 /// .send().await?;
227 /// println!("response {:?}", response);
228 /// Ok(())
229 /// }
230 /// ```
231 pub fn update_profile(&self) -> super::builder::profiler_service::UpdateProfile {
232 super::builder::profiler_service::UpdateProfile::new(self.inner.clone())
233 }
234}
235
236/// Implements a client for the Cloud Profiler API.
237///
238/// # Example
239/// ```
240/// # use google_cloud_profiler_v2::client::ExportService;
241/// use google_cloud_gax::paginator::ItemPaginator as _;
242/// # async fn sample() -> Result<(), Box<dyn std::error::Error>> {
243/// let client = ExportService::builder().build().await?;
244/// let parent = "parent_value";
245/// let mut list = client.list_profiles()
246/// .set_parent(parent)
247/// .by_item();
248/// while let Some(item) = list.next().await.transpose()? {
249/// println!("{:?}", item);
250/// }
251/// # Ok(()) }
252/// ```
253///
254/// # Service Description
255///
256/// Service allows existing Cloud Profiler customers to export their profile data
257/// out of Google Cloud.
258///
259/// # Configuration
260///
261/// To configure `ExportService` use the `with_*` methods in the type returned
262/// by [builder()][ExportService::builder]. The default configuration should
263/// work for most applications. Common configuration changes include
264///
265/// * [with_endpoint()]: by default this client uses the global default endpoint
266/// (`https://cloudprofiler.googleapis.com`). Applications using regional
267/// endpoints or running in restricted networks (e.g. a network configured
268// with [Private Google Access with VPC Service Controls]) may want to
269/// override this default.
270/// * [with_credentials()]: by default this client uses
271/// [Application Default Credentials]. Applications using custom
272/// authentication may need to override this default.
273///
274/// [with_endpoint()]: super::builder::export_service::ClientBuilder::with_endpoint
275/// [with_credentials()]: super::builder::export_service::ClientBuilder::with_credentials
276/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
277/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
278///
279/// # Pooling and Cloning
280///
281/// `ExportService` holds a connection pool internally, it is advised to
282/// create one and reuse it. You do not need to wrap `ExportService` in
283/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
284/// already uses an `Arc` internally.
285#[derive(Clone, Debug)]
286pub struct ExportService {
287 inner: std::sync::Arc<dyn super::stub::dynamic::ExportService>,
288}
289
290impl ExportService {
291 /// Returns a builder for [ExportService].
292 ///
293 /// ```
294 /// # async fn sample() -> google_cloud_gax::client_builder::Result<()> {
295 /// # use google_cloud_profiler_v2::client::ExportService;
296 /// let client = ExportService::builder().build().await?;
297 /// # Ok(()) }
298 /// ```
299 pub fn builder() -> super::builder::export_service::ClientBuilder {
300 crate::new_client_builder(super::builder::export_service::client::Factory)
301 }
302
303 /// Creates a new client from the provided stub.
304 ///
305 /// The most common case for calling this function is in tests mocking the
306 /// client's behavior.
307 pub fn from_stub<T>(stub: T) -> Self
308 where
309 T: super::stub::ExportService + 'static,
310 {
311 Self {
312 inner: std::sync::Arc::new(stub),
313 }
314 }
315
316 pub(crate) async fn new(
317 config: gaxi::options::ClientConfig,
318 ) -> crate::ClientBuilderResult<Self> {
319 let inner = Self::build_inner(config).await?;
320 Ok(Self { inner })
321 }
322
323 async fn build_inner(
324 conf: gaxi::options::ClientConfig,
325 ) -> crate::ClientBuilderResult<std::sync::Arc<dyn super::stub::dynamic::ExportService>> {
326 if gaxi::options::tracing_enabled(&conf) {
327 return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
328 }
329 Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
330 }
331
332 async fn build_transport(
333 conf: gaxi::options::ClientConfig,
334 ) -> crate::ClientBuilderResult<impl super::stub::ExportService> {
335 super::transport::ExportService::new(conf).await
336 }
337
338 async fn build_with_tracing(
339 conf: gaxi::options::ClientConfig,
340 ) -> crate::ClientBuilderResult<impl super::stub::ExportService> {
341 Self::build_transport(conf)
342 .await
343 .map(super::tracing::ExportService::new)
344 }
345
346 /// Lists profiles which have been collected so far and for which the caller
347 /// has permission to view.
348 ///
349 /// # Example
350 /// ```
351 /// # use google_cloud_profiler_v2::client::ExportService;
352 /// use google_cloud_gax::paginator::ItemPaginator as _;
353 /// use google_cloud_profiler_v2::Result;
354 /// async fn sample(
355 /// client: &ExportService, parent: &str
356 /// ) -> Result<()> {
357 /// let mut list = client.list_profiles()
358 /// .set_parent(parent)
359 /// .by_item();
360 /// while let Some(item) = list.next().await.transpose()? {
361 /// println!("{:?}", item);
362 /// }
363 /// Ok(())
364 /// }
365 /// ```
366 pub fn list_profiles(&self) -> super::builder::export_service::ListProfiles {
367 super::builder::export_service::ListProfiles::new(self.inner.clone())
368 }
369}