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