Skip to content

redis counters (page views / active users) - #5

Merged
Ret2Hell merged 1 commit into
mainfrom
dev
Mar 29, 2026
Merged

Ret2Hell merged 1 commit into
mainfrom
dev

Conversation

@Ret2Hell

@Ret2Hell Ret2Hell commented Mar 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • New Features

    • Integrated Redis-based analytics tracking to the pipeline, now capturing pageview counts, unique visitor metrics, and active user monitoring per site.
  • Improvements

    • Enhanced pipeline reliability by treating counter update failures as non-fatal, allowing continued processing when analytics tracking encounters issues.

@coderabbitai

coderabbitai Bot commented Mar 29, 2026 •

Copy link
Copy Markdown
ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Free

Run ID: 72601761-0ad5-4e1f-874e-fc6c4e596a8d

📥 Commits

Reviewing files that changed from the base of the PR and between a2091b5 and 2fa5f2c.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (7)
  • cmd/processor/main.go
  • go.mod
  • internal/consumer/consumer_test.go
  • internal/pipeline/pipeline.go
  • internal/pipeline/pipeline_test.go
  • internal/storage/redis.go
  • internal/storage/redis_test.go

📝 Walkthrough

Walkthrough

This pull request integrates Redis counter tracking into the data processing pipeline. A new RedisStore wrapper is introduced to manage pageview counters, visitor HyperLogLog tracking, and active user monitoring. The pipeline now accepts the Redis store dependency and invokes counter updates after each successful ClickHouse batch write, with non-fatal error handling.

Changes

Cohort / File(s) Summary
Pipeline Initialization
cmd/processor/main.go, go.mod
Pipeline constructor now receives redisStore parameter; Redis mocking library added as indirect dependency.
Pipeline Core Logic
internal/pipeline/pipeline.go, internal/pipeline/pipeline_test.go, internal/consumer/consumer_test.go
Pipeline struct gains redisStore field; NewPipeline signature extended to accept *storage.RedisStore; Process method calls p.redisStore.UpdateCounters(ctx, processed) after ClickHouse writes with non-fatal error logging; test constructors updated to pass nil placeholder.
Redis Store Implementation
internal/storage/redis.go, internal/storage/redis_test.go
New RedisStore type wraps *redis.Client with UpdateCounters method that batches hourly pageview increments, HyperLogLog visitor tracking (25-hour TTL), and active user sorted set management (5-minute window, 10-minute TTL); comprehensive unit tests validate pageview and non-pageview event handling.

Sequence Diagram

sequenceDiagram
    participant P as Pipeline.Process()
    participant CH as ClickHouse Writer
    participant Redis as RedisStore
    participant RC as Redis Client

    P->>CH: Write processed batch
    alt Write succeeds
        CH-->>P: Success
        P->>Redis: UpdateCounters(ctx, events)
        Redis->>RC: Build & execute pipeline
        Note over RC: Increment pageview counters<br/>Add to HyperLogLog (visitors)<br/>Update active user ZSET<br/>Clean expired entries<br/>Set TTLs
        RC-->>Redis: Results
        alt Pipeline executes
            Redis-->>P: nil (success)
            P-->>P: Return nil
        else Pipeline fails
            Redis-->>P: error (logged)
            P-->>P: Return nil (non-fatal)
        end
    else Write fails
        CH-->>P: Error
        P-->>P: Return error
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 With Redis now in our pipeline's sight,
We track the pageviews day and night,
Active users counted with ZSET care,
HyperLogLog visitors flowing through the air,
Non-fatal grace when counters slip—
Our data journey's taken quite the trip! 🚀


Note

🎁 Summarized by CodeRabbit Free

The PR author is not assigned a seat. To perform a comprehensive line-by-line review, please assign a seat to the pull request author through the subscription management page by visiting https://app.coderabbit.ai/login.

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

@sonarqubecloud

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2fa5f2cf6f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread internal/pipeline/pipeline.go Resolved
Comment thread internal/storage/redis.go Resolved
@Ret2Hell
Ret2Hell merged commit 7a9ae9d into main Mar 29, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant