Skip to content

fix(query-engine): SimpleEngine truncates seconds to milliseconds; use one rounding conversion #939

Backlog

Description

@milindsrivastava1997

Problem

SimpleEngine converts query times from seconds to milliseconds by truncating:

  • asap-query-engine/src/engines/simple_engine/mod.rs:553, convert_query_time_to_data_time: (query_time * 1000.0) as u64
  • asap-query-engine/src/engines/simple_engine/promql.rs:614: let step_ms = (step * 1000.0) as u64;

Floating-point error makes some millisecond-aligned times land just below the integer: e.g. 1095211880.820 * 1000.0 == 1095211880819.9998, which truncates to ...819. About 0.6% of millisecond-aligned query times are evaluated 1 ms early, and a range step can lose 1 ms the same way.

Two other call sites already round, each in its own way: simple_engine/sql.rs:255 and :508 ((… * 1000.0).round() as u64).

Proposal

Use one function for every protocol-seconds → milliseconds conversion: engine_api::secs_to_ms, which rounds to the nearest millisecond, and ms_to_secs for the other direction. Both are added in #937. Replace the four sites above with it (with a cast to u64 where the caller needs one), and add a regression test with 1095211880.820.

Found while reviewing #937. The new QueryEngine takes milliseconds directly from QueryRequest, so this only affects the old engine path until it is deleted.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions