Skip to content
This repository was archived by the owner on Feb 16, 2026. It is now read-only.

test: metrics#297

Merged
infiniteregrets merged 7 commits intomainfrom
m/metric-tests
Feb 10, 2026
Merged

test: metrics#297
infiniteregrets merged 7 commits intomainfrom
m/metric-tests

Conversation

@infiniteregrets
Copy link
Member

@infiniteregrets infiniteregrets commented Feb 9, 2026

LLM (codex) generated based on the test spec

@infiniteregrets infiniteregrets requested a review from a team as a code owner February 9, 2026 18:51
@greptile-apps
Copy link

greptile-apps bot commented Feb 9, 2026

Greptile Overview

Greptile Summary

This PR adds new integration tests that exercise the metrics endpoints (account/basin/stream), including validation of metric units/interval defaults and server-side error handling for invalid time ranges. It also extends the test harness types in tests/common/mod.rs to expose basin and stream names required to call basin/stream metrics APIs.

The tests fit into the existing test_context-based integration test pattern by provisioning an S2Stream (via a shared basin + per-test stream), performing a small append/read to generate activity, and then calling the relevant get_*_metrics APIs under a timeout before asserting response shapes.

Confidence Score: 4/5

  • This PR is likely safe to merge once the timestamp truncation in the new metrics tests is addressed.
  • Changes are limited to tests and small accessor additions, but metrics_ops.rs uses unix_timestamp() as u32, which can wrap on pre-epoch clocks and make invalid-range assertions unreliable; fixing that would make the test suite more deterministic.
  • tests/metrics_ops.rs

Important Files Changed

Filename Overview
tests/common/mod.rs Adds basin_name()/stream_name() accessors on test wrapper types to support new metrics integration tests; no behavioral changes beyond exposing names.
tests/metrics_ops.rs Adds new integration tests for account/basin/stream metrics endpoints, including invalid time range cases; contains a likely bug from casting unix_timestamp() to u32 (wraps for pre-epoch clocks) which can make tests behave incorrectly.

Sequence Diagram

sequenceDiagram
    participant Test as metrics_ops.rs test
    participant Ctx as test_context(S2Stream)
    participant Common as tests/common/mod.rs
    participant Stream as s2_sdk::S2Stream
    participant Client as s2_sdk::S2
    participant MetricsAPI as S2 metrics endpoints

    Test->>Ctx: setup S2Stream
    Ctx->>Common: SharedS2Basin::setup()
    Common->>Client: S2::new(config)
    Common->>Client: create_basin()
    Common->>Client: create_stream()
    Ctx-->>Test: &S2Stream

    Test->>Stream: append_sample() / read_sample()
    Test->>Client: get_*_metrics(TimeRange/Interval)
    Client->>MetricsAPI: HTTP request
    MetricsAPI-->>Client: Vec<Metric> / ErrorResponse
    Client-->>Test: Result
    Test->>Test: assert units/intervals or invalid code

    Test->>Ctx: teardown
    Ctx->>Common: delete_stream() (best effort)
    Common->>Client: delete_basin() (when last user)
Loading

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Comment on lines +13 to +16
fn epoch_range(hours_ago: u32) -> (u32, u32) {
let end = OffsetDateTime::now_utc().unix_timestamp() as u32;
let start = end.saturating_sub(hours_ago * 3600);
(start, end)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Time truncation bug

epoch_range casts unix_timestamp() (an i64) to u32 (as u32). If the system clock is before 1970, this wraps to a huge positive value, making start/end nonsensical and causing the “invalid time range” tests to behave incorrectly (they may pass/fail for the wrong reason). Consider keeping timestamps as i64 (or validating non-negative) until constructing the API types.

Prompt To Fix With AI
This is a comment left during a code review.
Path: tests/metrics_ops.rs
Line: 13:16

Comment:
**Time truncation bug**

`epoch_range` casts `unix_timestamp()` (an `i64`) to `u32` (`as u32`). If the system clock is before 1970, this wraps to a huge positive value, making `start/end` nonsensical and causing the “invalid time range” tests to behave incorrectly (they may pass/fail for the wrong reason). Consider keeping timestamps as `i64` (or validating non-negative) until constructing the API types.


How can I resolve this? If you propose a fix, please make it concise.

Copy link
Member

@quettabit quettabit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@infiniteregrets infiniteregrets changed the title chore: metrics tests test: metrics Feb 10, 2026
@infiniteregrets infiniteregrets merged commit 4b7724c into main Feb 10, 2026
5 checks passed
@infiniteregrets infiniteregrets deleted the m/metric-tests branch February 10, 2026 05:39
@github-actions github-actions bot mentioned this pull request Feb 10, 2026
shikhar pushed a commit that referenced this pull request Feb 15, 2026
## 🤖 New release

* `s2-sdk`: 0.23.8 -> 0.24.0 (⚠ API breaking changes)

### ⚠ `s2-sdk` breaking changes

```text
--- failure inherent_method_missing: pub method removed or renamed ---

Description:
A publicly-visible method or associated fn is no longer available under its prior name. It may have been renamed or removed entirely.
        ref: https://doc.rust-lang.org/cargo/reference/semver.html#item-remove
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.46.0/src/lints/inherent_method_missing.ron

Failed in:
  CreateBasinInput::with_idempotency_token, previously in file /tmp/.tmpoNf48h/s2-sdk/src/types.rs:913
  CreateStreamInput::with_idempotency_token, previously in file /tmp/.tmpoNf48h/s2-sdk/src/types.rs:2583

--- failure struct_pub_field_missing: pub struct's pub field removed or renamed ---

Description:
A publicly-visible struct has at least one public field that is no longer available under its prior name. It may have been renamed or removed entirely.
        ref: https://doc.rust-lang.org/cargo/reference/semver.html#item-remove
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.46.0/src/lints/struct_pub_field_missing.ron

Failed in:
  field idempotency_token of struct CreateBasinInput, previously in file /tmp/.tmpoNf48h/s2-sdk/src/types.rs:882
  field idempotency_token of struct CreateStreamInput, previously in file /tmp/.tmpoNf48h/s2-sdk/src/types.rs:2561

--- failure struct_pub_field_now_doc_hidden: pub struct field is now #[doc(hidden)] ---

Description:
A pub field of a pub struct is now marked #[doc(hidden)] and is no longer part of the public API.
        ref: https://doc.rust-lang.org/rustdoc/write-documentation/the-doc-attribute.html#hidden
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.46.0/src/lints/struct_pub_field_now_doc_hidden.ron

Failed in:
  field CreateBasinInput.idempotency_token in file /tmp/.tmp5yfqnq/s2-sdk-rust/src/types.rs:868
  field CreateStreamInput.idempotency_token in file /tmp/.tmp5yfqnq/s2-sdk-rust/src/types.rs:2539
```

<details><summary><i><b>Changelog</b></i></summary><p>

<blockquote>

## [0.24.0] - 2026-02-15

### Features

- Add accessors for `AppendRecord`
([#305](#305))
- [**breaking**] Add lower bounds for `max_batch_bytes` and
`max_batch_records`
([#309](#309))
- [**breaking**] Reduce default `max_unacked_bytes` to `5MiB`
([#311](#311))

### Refactor

- Replace `reqwest` with `hyper-util` and add client pooling
([#298](#298))
- [**breaking**] Make `idempotency_token` private
([#306](#306))
- [**breaking**] Remove unnecessary `Result` from
`with_max_unacked_batches`
([#307](#307))
- Remove unnecessary compression for GET and DELETE requests
([#308](#308))
- Rename fields, methods, and vars related to `RetryBackoff`
([#310](#310))
- [**breaking**] Make `S2DateTime` conversion from
`time::OffsetDateTime` fallible
([#312](#312))

### Testing

- Metrics
([#297](#297))
- Basin & stream api
([#300](#300))

### Miscellaneous Tasks

- Bump dependencies
([#296](#296))
- Dep updates
([#314](#314))

<!-- generated by git-cliff -->
</blockquote>


</p></details>

---
This PR was generated with
[release-plz](https://github.com/release-plz/release-plz/).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants