Skip to main content

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(
26///    parent: &str,
27/// ) -> anyhow::Result<()> {
28///     let client = ProfilerService::builder().build().await?;
29///     let response = client.create_offline_profile()
30///         .set_parent(parent)
31///         .set_profile(
32///             Profile::new()/* set fields */
33///         )
34///         .send().await?;
35///     println!("response {:?}", response);
36///     Ok(())
37/// }
38/// ```
39///
40/// # Service Description
41///
42/// Manage the collection of continuous profiling data provided by profiling
43/// agents running in the cloud or by an offline provider of profiling data.
44///
45/// __The APIs listed in this service are intended for use within our profiler
46/// agents only.__
47///
48/// # Configuration
49///
50/// To configure `ProfilerService` use the `with_*` methods in the type returned
51/// by [builder()][ProfilerService::builder]. The default configuration should
52/// work for most applications. Common configuration changes include
53///
54/// * [with_endpoint()]: by default this client uses the global default endpoint
55///   (`https://cloudprofiler.googleapis.com`). Applications using regional
56///   endpoints or running in restricted networks (e.g. a network configured
57//    with [Private Google Access with VPC Service Controls]) may want to
58///   override this default.
59/// * [with_credentials()]: by default this client uses
60///   [Application Default Credentials]. Applications using custom
61///   authentication may need to override this default.
62///
63/// [with_endpoint()]: super::builder::profiler_service::ClientBuilder::with_endpoint
64/// [with_credentials()]: super::builder::profiler_service::ClientBuilder::with_credentials
65/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
66/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
67///
68/// # Pooling and Cloning
69///
70/// `ProfilerService` holds a connection pool internally, it is advised to
71/// create one and reuse it. You do not need to wrap `ProfilerService` in
72/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
73/// already uses an `Arc` internally.
74#[derive(Clone, Debug)]
75pub struct ProfilerService {
76    inner: std::sync::Arc<dyn super::stub::dynamic::ProfilerService>,
77}
78
79impl ProfilerService {
80    /// Returns a builder for [ProfilerService].
81    ///
82    /// ```
83    /// # async fn sample() -> google_cloud_gax::client_builder::Result<()> {
84    /// # use google_cloud_profiler_v2::client::ProfilerService;
85    /// let client = ProfilerService::builder().build().await?;
86    /// # Ok(()) }
87    /// ```
88    pub fn builder() -> super::builder::profiler_service::ClientBuilder {
89        crate::new_client_builder(super::builder::profiler_service::client::Factory)
90    }
91
92    /// Creates a new client from the provided stub.
93    ///
94    /// The most common case for calling this function is in tests mocking the
95    /// client's behavior.
96    pub fn from_stub<T>(stub: impl Into<std::sync::Arc<T>>) -> Self
97    where
98        T: super::stub::ProfilerService + 'static,
99    {
100        Self { inner: stub.into() }
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, project_id: &str, profile_id: &str
220    /// ) -> Result<()> {
221    ///     let response = client.update_profile()
222    ///         .set_profile(
223    ///             Profile::new().set_name(format!("projects/{project_id}/profiles/{profile_id}"))/* 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(
243///    parent: &str,
244/// ) -> anyhow::Result<()> {
245///     let client = ExportService::builder().build().await?;
246///     let mut list = client.list_profiles()
247///         .set_parent(parent)
248///         .by_item();
249///     while let Some(item) = list.next().await.transpose()? {
250///         println!("{:?}", item);
251///     }
252///     Ok(())
253/// }
254/// ```
255///
256/// # Service Description
257///
258/// Service allows existing Cloud Profiler customers to export their profile data
259/// out of Google Cloud.
260///
261/// # Configuration
262///
263/// To configure `ExportService` use the `with_*` methods in the type returned
264/// by [builder()][ExportService::builder]. The default configuration should
265/// work for most applications. Common configuration changes include
266///
267/// * [with_endpoint()]: by default this client uses the global default endpoint
268///   (`https://cloudprofiler.googleapis.com`). Applications using regional
269///   endpoints or running in restricted networks (e.g. a network configured
270//    with [Private Google Access with VPC Service Controls]) may want to
271///   override this default.
272/// * [with_credentials()]: by default this client uses
273///   [Application Default Credentials]. Applications using custom
274///   authentication may need to override this default.
275///
276/// [with_endpoint()]: super::builder::export_service::ClientBuilder::with_endpoint
277/// [with_credentials()]: super::builder::export_service::ClientBuilder::with_credentials
278/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
279/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
280///
281/// # Pooling and Cloning
282///
283/// `ExportService` holds a connection pool internally, it is advised to
284/// create one and reuse it. You do not need to wrap `ExportService` in
285/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
286/// already uses an `Arc` internally.
287#[derive(Clone, Debug)]
288pub struct ExportService {
289    inner: std::sync::Arc<dyn super::stub::dynamic::ExportService>,
290}
291
292impl ExportService {
293    /// Returns a builder for [ExportService].
294    ///
295    /// ```
296    /// # async fn sample() -> google_cloud_gax::client_builder::Result<()> {
297    /// # use google_cloud_profiler_v2::client::ExportService;
298    /// let client = ExportService::builder().build().await?;
299    /// # Ok(()) }
300    /// ```
301    pub fn builder() -> super::builder::export_service::ClientBuilder {
302        crate::new_client_builder(super::builder::export_service::client::Factory)
303    }
304
305    /// Creates a new client from the provided stub.
306    ///
307    /// The most common case for calling this function is in tests mocking the
308    /// client's behavior.
309    pub fn from_stub<T>(stub: impl Into<std::sync::Arc<T>>) -> Self
310    where
311        T: super::stub::ExportService + 'static,
312    {
313        Self { inner: stub.into() }
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}