diff --git a/.cursor/rules/location.mdc b/.cursor/rules/location.mdc new file mode 100644 index 000000000000..451eda16a334 --- /dev/null +++ b/.cursor/rules/location.mdc @@ -0,0 +1,75 @@ +--- +description: Cursor Rules Location +globs: *.mdc +--- +# Cursor Rules Location + +Rules for placing and organizing Cursor rule files in the repository. + + +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).*?" + # 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 + diff --git a/linera-base/src/prometheus_util.rs b/linera-base/src/prometheus_util.rs index bc6d9be54488..3a42f35f3d44 100644 --- a/linera-base/src/prometheus_util.rs +++ b/linera-base/src/prometheus_util.rs @@ -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; @@ -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> { + 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> { + bucket_interval(0.0001_f64, max_latency) +} + /// A guard for an active latency measurement. /// /// Finishes the measurement when dropped, and then updates the `Metric`.