Skip to content

Commit bffc2ac

Browse files
committed
add traces to hottier
1 parent b07cc3d commit bffc2ac

10 files changed

Lines changed: 378 additions & 3 deletions

File tree

src/handlers/http/logstream.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,13 +413,21 @@ pub async fn get_stream_info(
413413
Ok((web::Json(stream_info), StatusCode::OK))
414414
}
415415

416+
#[tracing::instrument(
417+
name = "http.put_stream_hot_tier",
418+
skip(req, logstream, hottier),
419+
fields(stream = tracing::field::Empty, tenant = tracing::field::Empty, size = hottier.size)
420+
)]
416421
pub async fn put_stream_hot_tier(
417422
req: HttpRequest,
418423
logstream: Path<String>,
419424
Json(mut hottier): Json<StreamHotTier>,
420425
) -> Result<impl Responder, StreamError> {
421426
let stream_name = logstream.into_inner();
422427
let tenant_id = get_tenant_id_from_request(&req);
428+
tracing::Span::current()
429+
.record("stream", tracing::field::display(&stream_name))
430+
.record("tenant", tracing::field::debug(&tenant_id));
423431
// For query mode, if the stream not found in memory map,
424432
//check if it exists in the storage
425433
//create stream and schema from storage
@@ -478,12 +486,20 @@ pub async fn put_stream_hot_tier(
478486
))
479487
}
480488

489+
#[tracing::instrument(
490+
name = "http.get_stream_hot_tier",
491+
skip(req, logstream),
492+
fields(stream = tracing::field::Empty, tenant = tracing::field::Empty)
493+
)]
481494
pub async fn get_stream_hot_tier(
482495
req: HttpRequest,
483496
logstream: Path<String>,
484497
) -> Result<impl Responder, StreamError> {
485498
let stream_name = logstream.into_inner();
486499
let tenant_id = get_tenant_id_from_request(&req);
500+
tracing::Span::current()
501+
.record("stream", tracing::field::display(&stream_name))
502+
.record("tenant", tracing::field::debug(&tenant_id));
487503
// For query mode, if the stream not found in memory map,
488504
//check if it exists in the storage
489505
//create stream and schema from storage
@@ -504,12 +520,20 @@ pub async fn get_stream_hot_tier(
504520
Ok((web::Json(meta), StatusCode::OK))
505521
}
506522

523+
#[tracing::instrument(
524+
name = "http.delete_stream_hot_tier",
525+
skip(req, logstream),
526+
fields(stream = tracing::field::Empty, tenant = tracing::field::Empty)
527+
)]
507528
pub async fn delete_stream_hot_tier(
508529
req: HttpRequest,
509530
logstream: Path<String>,
510531
) -> Result<impl Responder, StreamError> {
511532
let stream_name = logstream.into_inner();
512533
let tenant_id = get_tenant_id_from_request(&req);
534+
tracing::Span::current()
535+
.record("stream", tracing::field::display(&stream_name))
536+
.record("tenant", tracing::field::debug(&tenant_id));
513537
// For query mode, if the stream not found in memory map,
514538
//check if it exists in the storage
515539
//create stream and schema from storage

src/handlers/http/modal/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,7 @@ pub type PrismMetadata = NodeMetadata;
626626
/// Initialize hot tier metadata files for streams that have hot tier configuration
627627
/// in their stream metadata but don't have local hot tier metadata files yet.
628628
/// This function is called once during query server startup.
629+
#[tracing::instrument(name = "hottier.init_metadata_startup", skip(hot_tier_manager))]
629630
pub async fn initialize_hot_tier_metadata_on_startup(
630631
hot_tier_manager: &HotTierManager,
631632
) -> anyhow::Result<()> {

src/hottier.rs

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,11 @@ impl HotTierManager {
144144
/// deletes parquet files that exist but are not in their date manifest,
145145
/// then recomputes `used_size` / `available_size` from the cleaned
146146
/// manifests and persists the updated `StreamHotTier`.
147+
#[tracing::instrument(
148+
name = "hottier.reconcile_stream",
149+
skip(self),
150+
fields(stream = %stream, tenant = ?tenant_id)
151+
)]
147152
async fn reconcile_stream(
148153
&self,
149154
stream: &str,
@@ -217,6 +222,11 @@ impl HotTierManager {
217222
Ok(sht)
218223
}
219224

225+
#[tracing::instrument(
226+
name = "hottier.drop_partials",
227+
skip(self, on_disk, partials_removed),
228+
fields(stream = %stream, tenant = ?tenant_id, date_dir = %date_dir.display())
229+
)]
220230
async fn drop_partials(
221231
&self,
222232
on_disk: &mut HashSet<String>,
@@ -264,6 +274,11 @@ impl HotTierManager {
264274
Ok(())
265275
}
266276

277+
#[tracing::instrument(
278+
name = "hottier.clean_manifest",
279+
skip(self, keep_names, total_used, entries_dropped),
280+
fields(stream = %stream, tenant = ?tenant_id, date_dir = %date_dir.display())
281+
)]
267282
async fn clean_manifest(
268283
&self,
269284
keep_names: &mut HashSet<String>,
@@ -327,6 +342,11 @@ impl HotTierManager {
327342
}
328343

329344
/// get the total hot tier size for all streams
345+
#[tracing::instrument(
346+
name = "hottier.get_hot_tiers_size",
347+
skip(self),
348+
fields(current_stream = %current_stream, current_tenant = ?current_tenant_id)
349+
)]
330350
pub async fn get_hot_tiers_size(
331351
&self,
332352
current_stream: &str,
@@ -358,6 +378,11 @@ impl HotTierManager {
358378
/// check disk usage and hot tier size of all other streams
359379
/// check if total hot tier size of all streams is less than max disk usage
360380
/// delete all the files from hot tier once validation is successful and hot tier is ready to be updated
381+
#[tracing::instrument(
382+
name = "hottier.validate_size",
383+
skip(self),
384+
fields(stream = %stream, tenant = ?tenant_id, size = stream_hot_tier_size)
385+
)]
361386
pub async fn validate_hot_tier_size(
362387
&self,
363388
stream: &str,
@@ -420,6 +445,11 @@ impl HotTierManager {
420445
}
421446

422447
/// get the hot tier metadata file for the stream
448+
#[tracing::instrument(
449+
name = "hottier.get_hot_tier",
450+
skip(self),
451+
fields(stream = %stream, tenant = ?tenant_id)
452+
)]
423453
pub async fn get_hot_tier(
424454
&self,
425455
stream: &str,
@@ -442,6 +472,11 @@ impl HotTierManager {
442472
Ok(stream_hot_tier)
443473
}
444474

475+
#[tracing::instrument(
476+
name = "hottier.delete_hot_tier",
477+
skip(self),
478+
fields(stream = %stream, tenant = ?tenant_id)
479+
)]
445480
pub async fn delete_hot_tier(
446481
&self,
447482
stream: &str,
@@ -466,6 +501,11 @@ impl HotTierManager {
466501

467502
/// put the hot tier metadata file for the stream
468503
/// set the updated_date_range in the hot tier metadata file
504+
#[tracing::instrument(
505+
name = "hottier.put_hot_tier",
506+
skip(self, hot_tier),
507+
fields(stream = %stream, tenant = ?tenant_id, size = hot_tier.size)
508+
)]
469509
pub async fn put_hot_tier(
470510
&self,
471511
stream: &str,
@@ -502,6 +542,7 @@ impl HotTierManager {
502542
/// Discover hot-tier-enabled streams at boot and spawn a per-stream pair
503543
/// of (Latest, Historic) loops for each. New streams added later acquire
504544
/// their own loops via `spawn_stream_tasks` from the PUT hot-tier handler.
545+
#[tracing::instrument(name = "hottier.startup", skip(self))]
505546
pub fn download_from_s3<'a>(&'a self) -> Result<(), HotTierError>
506547
where
507548
'a: 'static,
@@ -554,6 +595,11 @@ impl HotTierManager {
554595

555596
/// Spawn (Latest, Historic) loops for a single stream. Idempotent:
556597
/// if tasks already exist for this (tenant, stream), no-op.
598+
#[tracing::instrument(
599+
name = "hottier.spawn_stream_tasks",
600+
skip(self),
601+
fields(stream = %stream, tenant = ?tenant_id)
602+
)]
557603
pub async fn spawn_stream_tasks(&'static self, stream: String, tenant_id: Option<String>) {
558604
let key: StreamKey = (tenant_id.clone(), stream.clone());
559605
{
@@ -628,6 +674,11 @@ impl HotTierManager {
628674

629675
/// process the hot tier files for the stream
630676
/// delete the files from the hot tier directory if the available date range is outside the hot tier range
677+
#[tracing::instrument(
678+
name = "hottier.process_stream",
679+
skip(self),
680+
fields(stream = %stream, tenant = ?tenant_id, phase = ?phase)
681+
)]
631682
async fn process_stream(
632683
&self,
633684
stream: String,
@@ -681,6 +732,11 @@ impl HotTierManager {
681732
/// collect all manifests from metastore for the date, sort the parquet file list
682733
/// in order to download the latest files first
683734
/// download the parquet files if not present in hot tier directory
735+
#[tracing::instrument(
736+
name = "hottier.process_manifest",
737+
skip(self, manifest_files_to_download),
738+
fields(stream = %stream, tenant = ?tenant_id, phase = ?phase, dates = manifest_files_to_download.len())
739+
)]
684740
async fn process_manifest(
685741
&self,
686742
stream: &str,
@@ -809,6 +865,18 @@ impl HotTierManager {
809865
/// Returns false when no budget is available (caller should stop scheduling
810866
/// further work for this stream).
811867
#[allow(clippy::too_many_arguments)]
868+
#[tracing::instrument(
869+
name = "hottier.process_parquet_file",
870+
skip(self, parquet_file, parquet_path, state),
871+
fields(
872+
stream = %stream,
873+
tenant = ?tenant_id,
874+
phase = ?phase,
875+
date = %date,
876+
file = %parquet_file.file_path,
877+
file_size = parquet_file.file_size
878+
)
879+
)]
812880
async fn process_parquet_file_concurrent(
813881
&self,
814882
stream: &str,
@@ -999,6 +1067,11 @@ impl HotTierManager {
9991067
}
10001068

10011069
///fetch the list of dates available in the hot tier directory for the stream and sort them
1070+
#[tracing::instrument(
1071+
name = "hottier.fetch_dates",
1072+
skip(self),
1073+
fields(stream = %stream, tenant = ?tenant_id)
1074+
)]
10021075
pub async fn fetch_hot_tier_dates(
10031076
&self,
10041077
stream: &str,
@@ -1112,6 +1185,11 @@ impl HotTierManager {
11121185
}
11131186

11141187
///get the list of parquet files from the hot tier directory for the stream
1188+
#[tracing::instrument(
1189+
name = "hottier.get_parquet_files",
1190+
skip(self),
1191+
fields(stream = %stream, tenant = ?tenant_id)
1192+
)]
11151193
pub async fn get_hot_tier_parquet_files(
11161194
&self,
11171195
stream: &str,
@@ -1164,6 +1242,11 @@ impl HotTierManager {
11641242
/// check for the oldest entry to delete if the path exists in hot tier
11651243
/// update the used and available size in the hot tier metadata
11661244
/// loop if available size is still less than the parquet file size
1245+
#[tracing::instrument(
1246+
name = "hottier.cleanup_old_data",
1247+
skip(self, stream_hot_tier, download_file_path),
1248+
fields(stream = %stream, tenant = ?tenant_id, target_size = parquet_file_size)
1249+
)]
11671250
pub async fn cleanup_hot_tier_old_data(
11681251
&self,
11691252
stream: &str,
@@ -1408,6 +1491,7 @@ impl HotTierManager {
14081491
Ok(None)
14091492
}
14101493

1494+
#[tracing::instrument(name = "hottier.put_internal_stream", skip(self))]
14111495
pub async fn put_internal_stream_hot_tier(&self) -> Result<(), HotTierError> {
14121496
let tenants = if let Some(tenants) = PARSEABLE.list_tenants() {
14131497
tenants.into_iter().map(Some).collect()
@@ -1439,6 +1523,7 @@ impl HotTierManager {
14391523
}
14401524

14411525
/// Creates hot tier for pstats internal stream if the stream exists in storage
1526+
#[tracing::instrument(name = "hottier.create_pstats", skip(self))]
14421527
async fn create_pstats_hot_tier(&self) -> Result<(), HotTierError> {
14431528
let tenants = if let Some(tenants) = PARSEABLE.list_tenants() {
14441529
tenants.into_iter().map(Some).collect()

src/metrics/mod.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,18 @@ pub static STORAGE_REQUEST_RESPONSE_TIME: Lazy<HistogramVec> = Lazy::new(|| {
389389
.expect("metric can be created")
390390
});
391391

392+
pub static STORAGE_REQUESTS_INFLIGHT: Lazy<IntGaugeVec> = Lazy::new(|| {
393+
IntGaugeVec::new(
394+
Opts::new(
395+
"storage_requests_inflight",
396+
"Number of in-flight object store requests",
397+
)
398+
.namespace(METRICS_NAMESPACE),
399+
&["provider", "method"],
400+
)
401+
.expect("metric can be created")
402+
});
403+
392404
pub static TOTAL_METRICS_COLLECTED_BY_DATE: Lazy<IntCounterVec> = Lazy::new(|| {
393405
IntCounterVec::new(
394406
Opts::new(
@@ -565,6 +577,9 @@ fn custom_metrics(registry: &Registry) {
565577
registry
566578
.register(Box::new(STORAGE_REQUEST_RESPONSE_TIME.clone()))
567579
.expect("metric can be registered");
580+
registry
581+
.register(Box::new(STORAGE_REQUESTS_INFLIGHT.clone()))
582+
.expect("metric can be registered");
568583
registry
569584
.register(Box::new(TOTAL_METRICS_COLLECTED_BY_DATE.clone()))
570585
.expect("metric can be registered");

0 commit comments

Comments
 (0)