Skip to content

Commit

Permalink
Make sure we include end_value in generated Prometheus buckets (#3363)
Browse files Browse the repository at this point in the history
Right now we're generating the buckets, but it's not in an inclusive way, and it should be. For latency metrics, for example, you have `end_value` being 500ms, but one of the buckets is 159. Since we're using a multiplication factor of 3, the next bucket would go over 500ms, so we don't include it...

Make sure we always include the `end_value` bucket

CI + start a network locally and see the correct buckets exported

- Nothing to do / These changes follow the usual release cycle.
  • Loading branch information
ndr-ds committed Feb 24, 2025
1 parent d021729 commit e59f5fd
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 2 deletions.
75 changes: 75 additions & 0 deletions .cursor/rules/location.mdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
---
description: Cursor Rules Location
globs: *.mdc
---
# Cursor Rules Location

Rules for placing and organizing Cursor rule files in the repository.

<rule>
name: cursor_rules_location
description: Standards for placing Cursor rule files in the correct directory
filters:
# Match any .mdc files
- type: file_extension
pattern: "\\.mdc$"
# Match files that look like Cursor rules
- type: content
pattern: "(?s)<rule>.*?</rule>"
# Match file creation events
- type: event
pattern: "file_create"

actions:
- type: reject
conditions:
- pattern: "^(?!\\.\\/\\.cursor\\/rules\\/.*\\.mdc$)"
message: "Cursor rule files (.mdc) must be placed in the .cursor/rules directory"

- type: suggest
message: |
When creating Cursor rules:

1. Always place rule files in PROJECT_ROOT/.cursor/rules/:
```
.cursor/rules/
├── your-rule-name.mdc
├── another-rule.mdc
└── ...
```

2. Follow the naming convention:
- Use kebab-case for filenames
- Always use .mdc extension
- Make names descriptive of the rule's purpose

3. Directory structure:
```
PROJECT_ROOT/
├── .cursor/
│ └── rules/
│ ├── your-rule-name.mdc
│ └── ...
└── ...
```

4. Never place rule files:
- In the project root
- In subdirectories outside .cursor/rules
- In any other location

examples:
- input: |
# Bad: Rule file in wrong location
rules/my-rule.mdc
my-rule.mdc
.rules/my-rule.mdc

# Good: Rule file in correct location
.cursor/rules/my-rule.mdc
output: "Correctly placed Cursor rule file"

metadata:
priority: high
version: 1.0
</rule>
25 changes: 23 additions & 2 deletions linera-base/src/prometheus_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
//! This module defines util functions for interacting with Prometheus (logging metrics, etc)
use prometheus::{
histogram_opts, register_histogram_vec, register_int_counter_vec, Error, HistogramVec,
IntCounterVec, Opts,
exponential_buckets, histogram_opts, register_histogram_vec, register_int_counter_vec, Error,
HistogramVec, IntCounterVec, Opts,
};

use crate::time::Instant;
Expand Down Expand Up @@ -38,6 +38,27 @@ pub fn register_histogram_vec(
register_histogram_vec!(histogram_opts, label_names)
}

/// Construct the bucket interval starting from a value and an ending value.
pub fn bucket_interval(start_value: f64, end_value: f64) -> Option<Vec<f64>> {
let quot = end_value / start_value;
let factor = 3.0_f64;
let count_approx = quot.ln() / factor.ln();
let count = count_approx.round() as usize;
let mut buckets = exponential_buckets(start_value, factor, count)
.expect("Exponential buckets creation should not fail!");
if let Some(last) = buckets.last() {
if *last < end_value {
buckets.push(end_value);
}
}
Some(buckets)
}

/// Construct the latencies starting from 0.0001 and ending at the maximum latency
pub fn bucket_latencies(max_latency: f64) -> Option<Vec<f64>> {
bucket_interval(0.0001_f64, max_latency)
}

/// A guard for an active latency measurement.
///
/// Finishes the measurement when dropped, and then updates the `Metric`.
Expand Down

0 comments on commit e59f5fd

Please sign in to comment.