pika icon indicating copy to clipboard operation
pika copied to clipboard

feat:slow log field

Open chejinge opened this issue 1 month ago • 1 comments

Summary by CodeRabbit

Release Notes

  • New Features
    • Enhanced slowlog to track and display element counts for complex data types (hashes, sets, lists, sorted sets), providing better visibility into command performance metrics.

✏️ Tip: You can customize this high-level summary in your review settings.

chejinge avatar Nov 27 '25 09:11 chejinge

Walkthrough

The slowlog system is extended to track element counts for complex data types. A new element_count field is added to the SlowlogEntry structure, the SlowlogPushEntry method signature is updated to accept this parameter, and slowlog capturing logic now queries database storage to obtain element counts for hashes, sets, lists, and sorted sets when commands exceed slowlog thresholds.

Changes

Cohort / File(s) Summary
Data Structure & Interface Definitions
include/pika_define.h, include/pika_server.h
Added element_count (int64\_t, default -1) member to SlowlogEntry struct; added default constructor to SlowlogEntry; updated SlowlogPushEntry method signature to include optional element_count parameter
Slowlog Capture & Element Counting
src/pika_client_conn.cc
Enhanced slowlog processing to capture element counts by inspecting command names, querying DB storage (HLen, SCard, LLen, ZCard) for complex types, and passing element\_count to SlowlogPushEntry
Slowlog Serialization & Storage
src/pika_admin.cc, src/pika_server.cc
Updated slowlog entry serialization to conditionally include element\_count field in output; modified SlowlogPushEntry implementation to store element\_count in slowlog entry

Sequence Diagram

sequenceDiagram
    participant Client
    participant PikaClientConn
    participant DB as Storage
    participant SlowlogCmd
    
    Client->>PikaClientConn: Execute command
    PikaClientConn->>PikaClientConn: Command exceeds slowlog threshold
    PikaClientConn->>PikaClientConn: Inspect command type
    alt Complex Type (hash, set, list, zset)
        PikaClientConn->>DB: Query element count<br/>(HLen/SCard/LLen/ZCard)
        DB-->>PikaClientConn: Return count
        PikaClientConn->>PikaClientConn: element_count = count
    else Other Type
        PikaClientConn->>PikaClientConn: element_count = -1
    end
    PikaClientConn->>PikaClientConn: SlowlogPushEntry(argv, time, duration, element_count)
    PikaClientConn->>SlowlogCmd: Store entry with metadata
    SlowlogCmd->>SlowlogCmd: Serialize with element_count if ≥ 0

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Element counting logic in pika_client_conn.cc: Verify that DB queries (HLen, SCard, LLen, ZCard) are correctly matched to command types and that element count retrieval doesn't introduce performance overhead
  • Type-specific command filtering: Ensure the command name inspection logic correctly identifies all relevant complex data types and doesn't miss edge cases
  • Default value propagation: Confirm that the -1 default for element_count is consistently used and doesn't inadvertently hide missing data

Poem

🐰 Hops through slowlogs with counting glee,
Tracking hashes, sets, and lists with spree,
Element counts now dance in the log,
No more mystery in the database fog! 🌲

Pre-merge checks and finishing touches

❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Title check ❓ Inconclusive The title 'feat:slow log field' is vague and generic, using non-descriptive phrasing that doesn't clearly convey the specific change being made. Use a more descriptive title that specifies what was added to the slowlog, such as 'feat: add element_count field to slowlog entries' or 'feat: track element counts in slowlog for complex data types'.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • [ ] 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • [ ] Create PR with unit tests
  • [ ] Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot] avatar Nov 27 '25 09:11 coderabbitai[bot]