LCOV - code coverage report
Current view: top level - storage_controller/src - pageserver_client.rs (source / functions) Coverage Total Hit
Test: 6a14b070dc6eeeeb359cfa8817925ac37a02fab4.info Lines: 0.0 % 274 0
Test Date: 2025-03-31 22:46:13 Functions: 0.0 % 43 0

            Line data    Source code
       1              : use pageserver_api::models::detach_ancestor::AncestorDetached;
       2              : use pageserver_api::models::{
       3              :     DetachBehavior, LocationConfig, LocationConfigListResponse, LsnLease, PageserverUtilization,
       4              :     SecondaryProgress, TenantScanRemoteStorageResponse, TenantShardSplitRequest,
       5              :     TenantShardSplitResponse, TenantWaitLsnRequest, TimelineArchivalConfigRequest,
       6              :     TimelineCreateRequest, TimelineInfo, TopTenantShardsRequest, TopTenantShardsResponse,
       7              : };
       8              : use pageserver_api::shard::TenantShardId;
       9              : use pageserver_client::BlockUnblock;
      10              : use pageserver_client::mgmt_api::{Client, Result};
      11              : use reqwest::StatusCode;
      12              : use utils::id::{NodeId, TenantId, TimelineId};
      13              : use utils::lsn::Lsn;
      14              : 
      15              : /// Thin wrapper around [`pageserver_client::mgmt_api::Client`]. It allows the storage
      16              : /// controller to collect metrics in a non-intrusive manner.
      17              : #[derive(Debug, Clone)]
      18              : pub(crate) struct PageserverClient {
      19              :     inner: Client,
      20              :     node_id_label: String,
      21              : }
      22              : 
      23              : macro_rules! measured_request {
      24              :     ($name:literal, $method:expr, $node_id: expr, $invoke:expr) => {{
      25              :         let labels = crate::metrics::PageserverRequestLabelGroup {
      26              :             pageserver_id: $node_id,
      27              :             path: $name,
      28              :             method: $method,
      29              :         };
      30              : 
      31              :         let latency = &crate::metrics::METRICS_REGISTRY
      32              :             .metrics_group
      33              :             .storage_controller_pageserver_request_latency;
      34              :         let _timer_guard = latency.start_timer(labels.clone());
      35              : 
      36              :         let res = $invoke;
      37              : 
      38              :         if res.is_err() {
      39              :             let error_counters = &crate::metrics::METRICS_REGISTRY
      40              :                 .metrics_group
      41              :                 .storage_controller_pageserver_request_error;
      42              :             error_counters.inc(labels)
      43              :         }
      44              : 
      45              :         res
      46              :     }};
      47              : }
      48              : 
      49              : impl PageserverClient {
      50            0 :     pub(crate) fn new(
      51            0 :         node_id: NodeId,
      52            0 :         raw_client: reqwest::Client,
      53            0 :         mgmt_api_endpoint: String,
      54            0 :         jwt: Option<&str>,
      55            0 :     ) -> Self {
      56            0 :         Self {
      57            0 :             inner: Client::new(raw_client, mgmt_api_endpoint, jwt),
      58            0 :             node_id_label: node_id.0.to_string(),
      59            0 :         }
      60            0 :     }
      61              : 
      62            0 :     pub(crate) async fn tenant_delete(&self, tenant_shard_id: TenantShardId) -> Result<StatusCode> {
      63            0 :         measured_request!(
      64            0 :             "tenant",
      65            0 :             crate::metrics::Method::Delete,
      66            0 :             &self.node_id_label,
      67            0 :             self.inner.tenant_delete(tenant_shard_id).await
      68            0 :         )
      69            0 :     }
      70              : 
      71            0 :     pub(crate) async fn tenant_time_travel_remote_storage(
      72            0 :         &self,
      73            0 :         tenant_shard_id: TenantShardId,
      74            0 :         timestamp: &str,
      75            0 :         done_if_after: &str,
      76            0 :     ) -> Result<()> {
      77            0 :         measured_request!(
      78            0 :             "tenant_time_travel_remote_storage",
      79            0 :             crate::metrics::Method::Put,
      80            0 :             &self.node_id_label,
      81            0 :             self.inner
      82            0 :                 .tenant_time_travel_remote_storage(tenant_shard_id, timestamp, done_if_after)
      83            0 :                 .await
      84            0 :         )
      85            0 :     }
      86              : 
      87            0 :     pub(crate) async fn tenant_scan_remote_storage(
      88            0 :         &self,
      89            0 :         tenant_id: TenantId,
      90            0 :     ) -> Result<TenantScanRemoteStorageResponse> {
      91            0 :         measured_request!(
      92            0 :             "tenant_scan_remote_storage",
      93            0 :             crate::metrics::Method::Get,
      94            0 :             &self.node_id_label,
      95            0 :             self.inner.tenant_scan_remote_storage(tenant_id).await
      96            0 :         )
      97            0 :     }
      98              : 
      99            0 :     pub(crate) async fn tenant_secondary_download(
     100            0 :         &self,
     101            0 :         tenant_id: TenantShardId,
     102            0 :         wait: Option<std::time::Duration>,
     103            0 :     ) -> Result<(StatusCode, SecondaryProgress)> {
     104            0 :         measured_request!(
     105            0 :             "tenant_secondary_download",
     106            0 :             crate::metrics::Method::Post,
     107            0 :             &self.node_id_label,
     108            0 :             self.inner.tenant_secondary_download(tenant_id, wait).await
     109            0 :         )
     110            0 :     }
     111              : 
     112            0 :     pub(crate) async fn tenant_secondary_status(
     113            0 :         &self,
     114            0 :         tenant_shard_id: TenantShardId,
     115            0 :     ) -> Result<SecondaryProgress> {
     116            0 :         measured_request!(
     117            0 :             "tenant_secondary_status",
     118            0 :             crate::metrics::Method::Get,
     119            0 :             &self.node_id_label,
     120            0 :             self.inner.tenant_secondary_status(tenant_shard_id).await
     121            0 :         )
     122            0 :     }
     123              : 
     124            0 :     pub(crate) async fn tenant_heatmap_upload(&self, tenant_id: TenantShardId) -> Result<()> {
     125            0 :         measured_request!(
     126            0 :             "tenant_heatmap_upload",
     127            0 :             crate::metrics::Method::Post,
     128            0 :             &self.node_id_label,
     129            0 :             self.inner.tenant_heatmap_upload(tenant_id).await
     130            0 :         )
     131            0 :     }
     132              : 
     133            0 :     pub(crate) async fn location_config(
     134            0 :         &self,
     135            0 :         tenant_shard_id: TenantShardId,
     136            0 :         config: LocationConfig,
     137            0 :         flush_ms: Option<std::time::Duration>,
     138            0 :         lazy: bool,
     139            0 :     ) -> Result<()> {
     140            0 :         measured_request!(
     141            0 :             "location_config",
     142            0 :             crate::metrics::Method::Put,
     143            0 :             &self.node_id_label,
     144            0 :             self.inner
     145            0 :                 .location_config(tenant_shard_id, config, flush_ms, lazy)
     146            0 :                 .await
     147            0 :         )
     148            0 :     }
     149              : 
     150            0 :     pub(crate) async fn list_location_config(&self) -> Result<LocationConfigListResponse> {
     151            0 :         measured_request!(
     152            0 :             "location_configs",
     153            0 :             crate::metrics::Method::Get,
     154            0 :             &self.node_id_label,
     155            0 :             self.inner.list_location_config().await
     156            0 :         )
     157            0 :     }
     158              : 
     159            0 :     pub(crate) async fn get_location_config(
     160            0 :         &self,
     161            0 :         tenant_shard_id: TenantShardId,
     162            0 :     ) -> Result<Option<LocationConfig>> {
     163            0 :         measured_request!(
     164            0 :             "location_config",
     165            0 :             crate::metrics::Method::Get,
     166            0 :             &self.node_id_label,
     167            0 :             self.inner.get_location_config(tenant_shard_id).await
     168            0 :         )
     169            0 :     }
     170              : 
     171            0 :     pub(crate) async fn timeline_create(
     172            0 :         &self,
     173            0 :         tenant_shard_id: TenantShardId,
     174            0 :         req: &TimelineCreateRequest,
     175            0 :     ) -> Result<TimelineInfo> {
     176            0 :         measured_request!(
     177            0 :             "timeline",
     178            0 :             crate::metrics::Method::Post,
     179            0 :             &self.node_id_label,
     180            0 :             self.inner.timeline_create(tenant_shard_id, req).await
     181            0 :         )
     182            0 :     }
     183              : 
     184            0 :     pub(crate) async fn timeline_delete(
     185            0 :         &self,
     186            0 :         tenant_shard_id: TenantShardId,
     187            0 :         timeline_id: TimelineId,
     188            0 :     ) -> Result<StatusCode> {
     189            0 :         measured_request!(
     190            0 :             "timeline",
     191            0 :             crate::metrics::Method::Delete,
     192            0 :             &self.node_id_label,
     193            0 :             self.inner
     194            0 :                 .timeline_delete(tenant_shard_id, timeline_id)
     195            0 :                 .await
     196            0 :         )
     197            0 :     }
     198              : 
     199            0 :     pub(crate) async fn timeline_lease_lsn(
     200            0 :         &self,
     201            0 :         tenant_shard_id: TenantShardId,
     202            0 :         timeline_id: TimelineId,
     203            0 :         lsn: Lsn,
     204            0 :     ) -> Result<LsnLease> {
     205            0 :         measured_request!(
     206            0 :             "timeline_lease_lsn",
     207            0 :             crate::metrics::Method::Post,
     208            0 :             &self.node_id_label,
     209            0 :             self.inner
     210            0 :                 .timeline_init_lsn_lease(tenant_shard_id, timeline_id, lsn)
     211            0 :                 .await
     212            0 :         )
     213            0 :     }
     214              : 
     215            0 :     pub(crate) async fn tenant_shard_split(
     216            0 :         &self,
     217            0 :         tenant_shard_id: TenantShardId,
     218            0 :         req: TenantShardSplitRequest,
     219            0 :     ) -> Result<TenantShardSplitResponse> {
     220            0 :         measured_request!(
     221            0 :             "tenant_shard_split",
     222            0 :             crate::metrics::Method::Put,
     223            0 :             &self.node_id_label,
     224            0 :             self.inner.tenant_shard_split(tenant_shard_id, req).await
     225            0 :         )
     226            0 :     }
     227              : 
     228            0 :     pub(crate) async fn timeline_list(
     229            0 :         &self,
     230            0 :         tenant_shard_id: &TenantShardId,
     231            0 :     ) -> Result<Vec<TimelineInfo>> {
     232            0 :         measured_request!(
     233            0 :             "timelines",
     234            0 :             crate::metrics::Method::Get,
     235            0 :             &self.node_id_label,
     236            0 :             self.inner.timeline_list(tenant_shard_id).await
     237            0 :         )
     238            0 :     }
     239              : 
     240            0 :     pub(crate) async fn timeline_archival_config(
     241            0 :         &self,
     242            0 :         tenant_shard_id: TenantShardId,
     243            0 :         timeline_id: TimelineId,
     244            0 :         req: &TimelineArchivalConfigRequest,
     245            0 :     ) -> Result<()> {
     246            0 :         measured_request!(
     247            0 :             "timeline_archival_config",
     248            0 :             crate::metrics::Method::Put,
     249            0 :             &self.node_id_label,
     250            0 :             self.inner
     251            0 :                 .timeline_archival_config(tenant_shard_id, timeline_id, req)
     252            0 :                 .await
     253            0 :         )
     254            0 :     }
     255              : 
     256            0 :     pub(crate) async fn timeline_detach_ancestor(
     257            0 :         &self,
     258            0 :         tenant_shard_id: TenantShardId,
     259            0 :         timeline_id: TimelineId,
     260            0 :         behavior: Option<DetachBehavior>,
     261            0 :     ) -> Result<AncestorDetached> {
     262            0 :         measured_request!(
     263            0 :             "timeline_detach_ancestor",
     264            0 :             crate::metrics::Method::Put,
     265            0 :             &self.node_id_label,
     266            0 :             self.inner
     267            0 :                 .timeline_detach_ancestor(tenant_shard_id, timeline_id, behavior)
     268            0 :                 .await
     269            0 :         )
     270            0 :     }
     271              : 
     272            0 :     pub(crate) async fn timeline_block_unblock_gc(
     273            0 :         &self,
     274            0 :         tenant_shard_id: TenantShardId,
     275            0 :         timeline_id: TimelineId,
     276            0 :         dir: BlockUnblock,
     277            0 :     ) -> Result<()> {
     278            0 :         // measuring these makes no sense because we synchronize with the gc loop and remote
     279            0 :         // storage on block_gc so there should be huge outliers
     280            0 :         measured_request!(
     281            0 :             "timeline_block_unblock_gc",
     282            0 :             crate::metrics::Method::Post,
     283            0 :             &self.node_id_label,
     284            0 :             self.inner
     285            0 :                 .timeline_block_unblock_gc(tenant_shard_id, timeline_id, dir)
     286            0 :                 .await
     287            0 :         )
     288            0 :     }
     289              : 
     290            0 :     pub(crate) async fn timeline_download_heatmap_layers(
     291            0 :         &self,
     292            0 :         tenant_shard_id: TenantShardId,
     293            0 :         timeline_id: TimelineId,
     294            0 :         concurrency: Option<usize>,
     295            0 :         recurse: bool,
     296            0 :     ) -> Result<()> {
     297            0 :         measured_request!(
     298            0 :             "download_heatmap_layers",
     299            0 :             crate::metrics::Method::Post,
     300            0 :             &self.node_id_label,
     301            0 :             self.inner
     302            0 :                 .timeline_download_heatmap_layers(
     303            0 :                     tenant_shard_id,
     304            0 :                     timeline_id,
     305            0 :                     concurrency,
     306            0 :                     recurse
     307            0 :                 )
     308            0 :                 .await
     309            0 :         )
     310            0 :     }
     311              : 
     312            0 :     pub(crate) async fn get_utilization(&self) -> Result<PageserverUtilization> {
     313            0 :         measured_request!(
     314            0 :             "utilization",
     315            0 :             crate::metrics::Method::Get,
     316            0 :             &self.node_id_label,
     317            0 :             self.inner.get_utilization().await
     318            0 :         )
     319            0 :     }
     320              : 
     321            0 :     pub(crate) async fn top_tenant_shards(
     322            0 :         &self,
     323            0 :         request: TopTenantShardsRequest,
     324            0 :     ) -> Result<TopTenantShardsResponse> {
     325            0 :         measured_request!(
     326            0 :             "top_tenants",
     327            0 :             crate::metrics::Method::Post,
     328            0 :             &self.node_id_label,
     329            0 :             self.inner.top_tenant_shards(request).await
     330            0 :         )
     331            0 :     }
     332              : 
     333            0 :     pub(crate) async fn wait_lsn(
     334            0 :         &self,
     335            0 :         tenant_shard_id: TenantShardId,
     336            0 :         request: TenantWaitLsnRequest,
     337            0 :     ) -> Result<StatusCode> {
     338            0 :         measured_request!(
     339            0 :             "wait_lsn",
     340            0 :             crate::metrics::Method::Post,
     341            0 :             &self.node_id_label,
     342            0 :             self.inner.wait_lsn(tenant_shard_id, request).await
     343            0 :         )
     344            0 :     }
     345              : }
        

Generated by: LCOV version 2.1-beta