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