Skip to content

v2.1.1

Choose a tag to compare

@github-actions github-actions released this 08 Nov 01:32
· 1201 commits to main since this release
68b0c05
fix (metrics) (#688)

## Description
<!-- Provide a brief description of the changes in this PR -->

## Related Issues
<!-- Link to any related issues using #issue_number -->

Closes #

## Checklist when merging to main
<!-- Mark items with "x" when completed -->

- [ ] No compiler warnings (if applicable)
- [ ] Code is formatted with `rustfmt`
- [ ] No useless or dead code (if applicable)
- [ ] Code is easy to understand
- [ ] Doc comments are used for all functions, enums, structs, and
fields (where appropriate)
- [ ] All tests pass
- [ ] Performance has not regressed (assuming change was not to fix a
bug)
- [ ] Version number has been updated in `helix-cli/Cargo.toml` and
`helixdb/Cargo.toml`

## Additional Notes
<!-- Add any additional information that would be helpful for reviewers
-->

<!-- greptile_comment -->

<h2>Greptile Overview</h2>

Updated On: 2025-11-08 00:48:52 UTC

<h3>Greptile Summary</h3>


Fixed metrics system by adding graceful shutdown, switching to NDJSON
format, and updating to `/v2` endpoint.

## Key Changes
- **Metrics endpoint**: Updated from `https://logs.helix-db.com` to
`https://logs.helix-db.com/v2`
- **Serialization format**: Changed from JSON array to NDJSON
(newline-delimited JSON) with `application/x-ndjson` content type
- **Graceful shutdown**: Added `shutdown_metrics_system()` function with
shutdown channel to properly flush metrics on server shutdown
- **Error handling**: Improved HTTP error logging with response status
and body
- **Batch threshold**: Reduced `DEFAULT_THRESHOLD_BATCHES` from 32,000
to 10
- **Gateway integration**: Added 5-second timeout for metrics shutdown
in gateway

## Issues Found
- **Critical**: `shutdown_metrics_system()` doesn't await the spawned
HTTP task handle, potentially losing final metrics batch during shutdown
- **Performance**: Threshold reduction from 32,000 to 10 causes 3200x
more sender task wakeups, significantly increasing CPU usage and
notification overhead

<details><summary><h3>Important Files Changed</h3></summary>



File Analysis



| Filename | Score | Overview |
|----------|-------|----------|
| metrics/src/lib.rs | 2/5 | Changed metrics endpoint to `/v2`, added
graceful shutdown, switched to NDJSON format, and reduced batch
threshold from 32,000 to 10 (causing 3200x more task wakeups). Shutdown
doesn't await HTTP completion. |
| helix-db/src/helix_gateway/gateway.rs | 4/5 | Added graceful metrics
shutdown after server stops with 5-second timeout and proper logging |

</details>


</details>


<details><summary><h3>Sequence Diagram</h3></summary>

```mermaid
sequenceDiagram
    participant App as Application Thread
    participant Buffer as Thread-Local Buffer
    participant Channel as Global Channel
    participant Sender as Sender Task
    participant HTTP as Metrics Server (v2)
    participant Gateway as Gateway Shutdown

    Note over App,Buffer: Event Logging Phase
    App->>Buffer: log_event()
    Buffer->>Buffer: Buffer events locally
    
    alt Buffer reaches 65536 events
        Buffer->>Channel: flush_local_buffer()
        Buffer->>Channel: Send batch of events
        
        alt Channel has ≥10 batches (NEW)
            Channel->>Sender: notify (wake up)
        end
    end

    Note over Sender,HTTP: Background Processing
    loop Every 1 second or on notification
        Sender->>Channel: drain all batches
        Sender->>Sender: Flatten to single Vec
        Sender->>Sender: Spawn HTTP task
        
        par HTTP Request (async)
            Sender->>Sender: Serialize to NDJSON (NEW)
            Sender->>HTTP: POST application/x-ndjson (NEW)
            HTTP-->>Sender: Response
        end
    end

    Note over Gateway,HTTP: Graceful Shutdown (NEW)
    Gateway->>Sender: shutdown_tx.send()
    Sender->>Channel: process_batch() final flush
    Sender->>HTTP: POST remaining events
    Note over Sender: HTTP task NOT awaited (BUG)
    Gateway->>Gateway: Wait up to 5s timeout
```
</details>


<!-- greptile_other_comments_section -->

<!-- /greptile_comment -->