Skip to content

Commit

Permalink
Merge pull request paritytech#3 from availproject/marko/fix-unlimited…
Browse files Browse the repository at this point in the history
…-interval-buffer

Fixed custom telemetry constraints usage
  • Loading branch information
markopoloparadox authored May 7, 2024
2 parents c116e1e + 7790901 commit bd728ff
Showing 1 changed file with 32 additions and 33 deletions.
65 changes: 32 additions & 33 deletions substrate/client/telemetry/src/custom_telemetry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ impl BlockMetrics {
return;
};

if lock.partial_intervals.len() >= MAXIMUM_INTERVALS_LENGTH {
lock.partial_intervals.remove(0);
if lock.intervals.len() >= MAXIMUM_INTERVALS_LENGTH {
lock.intervals.remove(0);
}

lock.intervals.push(value);
Expand All @@ -96,43 +96,42 @@ impl BlockMetrics {
timestamp: u64,
is_start: bool,
) {
let Ok(mut lock) = BLOCK_METRICS.lock() else {
return;
};

if is_start {
if lock.partial_intervals.len() >= MAXIMUM_INTERVALS_LENGTH {
lock.partial_intervals.remove(0);
let mut entry = {
let Ok(mut lock) = BLOCK_METRICS.lock() else {
return;
};

if is_start {
if lock.partial_intervals.len() >= MAXIMUM_INTERVALS_LENGTH {
lock.partial_intervals.remove(0);
}

let value = IntervalWithBlockInformation {
kind,
block_number,
block_hash,
start_timestamp: timestamp,
end_timestamp: 0,
};

lock.partial_intervals.push(value);
return;
}

let value = IntervalWithBlockInformation {
kind,
block_number,
block_hash,
start_timestamp: timestamp,
end_timestamp: 0,
let existing_entry_pos = lock.partial_intervals.iter_mut().position(|v| {
v.block_hash == block_hash && v.block_number == block_number && v.kind == kind
});

let Some(pos) = existing_entry_pos else {
return;
};

lock.partial_intervals.push(value);
return;
}

let existing_entry_pos = lock.partial_intervals.iter_mut().position(|v| {
v.block_hash == block_hash && v.block_number == block_number && v.kind == kind
});

let Some(pos) = existing_entry_pos else {
return;

lock.partial_intervals.remove(pos)
};

let mut entry = lock.partial_intervals.remove(pos);
entry.end_timestamp = timestamp;

if lock.partial_intervals.len() >= MAXIMUM_INTERVALS_LENGTH {
lock.partial_intervals.remove(0);
}

lock.intervals.push(entry);
Self::observe_interval(entry);
}

///
Expand Down

0 comments on commit bd728ff

Please sign in to comment.