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