Skip to content

Conversation

@pavelzotikov
Copy link
Contributor

This PR introduces a new Redis helper module designed to handle time-series (TS) operations and provides chart data aggregation for hourly and daily views.

- Replace days parameter with startDate/endDate/groupBy (minutes)
- Add RedisHelper class for TimeSeries operations
- Support minutely/hourly/daily aggregations based on groupBy value
- Add search parameter support in events queries (title/backtrace/context/addons)
- Update GraphQL schema and resolvers for new chart parameters
- Fallback to MongoDB when Redis data unavailable
@pavelzotikov pavelzotikov requested a review from neSpecc November 6, 2025 10:00
Copy link
Member

@neSpecc neSpecc left a comment

Choose a reason for hiding this comment

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

now when Redis is down, API is down as well. API should continue responding event without Redis.

pavelzotikov and others added 4 commits November 8, 2025 00:25
- Event.chartData: uses 'days' parameter, fetches data only from MongoDB
- Project.chartData: uses 'startDate', 'endDate', 'groupBy' parameters, fetches from Redis with MongoDB fallback
- Add getChartDataFromMongo method for Event-specific chart data
- Fix redisHelper comment to reflect TS.INCRBY usage
- Remove unused 'projectId' parameter from getChartDataFromMongo
- Implement singleton pattern for Redis client to use single connection
- Add exponential backoff reconnection strategy (1s to 30s max)
- Handle connection lifecycle events (ready, reconnecting, error, end)
- Initialize Redis on app startup alongside MongoDB and RabbitMQ
- Graceful degradation to MongoDB when Redis is unavailable
- Add comprehensive documentation in REDIS_RECONNECT.md

This fixes the issue where API lost Redis connection after pod restart
and required manual API pod restart to restore functionality.
Changes based on @neSpecc review:

1. TypeDefs improvements:
   - Use DateTime! instead of String! for date parameters in Project.chartData

2. Method renaming for clarity:
   - eventsFactory: getChartData → getProjectChartData
   - eventsFactory: getChartDataFromMongo → getEventDailyChart
   - Improved parameter order (main identifier first)

3. Code quality:
   - Remove duplication in try-catch blocks
   - Extract Redis key composition to utility functions

4. Architecture improvements:
   - Create ChartDataService to separate business logic from Redis client
   - Simplify RedisHelper to only low-level Redis operations
   - Add tsRange() method for TS.RANGE commands
   - Move chart data logic from redisHelper to dedicated service

5. New utilities:
   - src/utils/redisKeys.ts with composeTimeSeriesKey(), composeEventTimeSeriesKey()
   - Type-safe key composition with required parameters

Benefits:
- Clear separation of concerns (Data Access vs Business Logic vs Service)
- RedisHelper stays focused and doesn't grow
- Easier to test and maintain
- Better type safety and documentation
Changes based on @neSpecc review:

1. TypeDefs improvements:
   - Use DateTime! instead of String! for date parameters in Project.chartData

2. Method renaming for clarity:
   - eventsFactory: getChartData → getProjectChartData
   - eventsFactory: getChartDataFromMongo → getEventDailyChart
   - Improved parameter order (main identifier first)

3. Code quality:
   - Remove duplication in try-catch blocks
   - Extract Redis key composition to utility functions

4. Architecture improvements:
   - Create ChartDataService to separate business logic from Redis client
   - Simplify RedisHelper to only low-level Redis operations
   - Add tsRange() method for TS.RANGE commands
   - Move chart data logic from redisHelper to dedicated service

5. New utilities:
   - src/utils/redisKeys.ts with composeTimeSeriesKey(), composeEventTimeSeriesKey()
   - Type-safe key composition with required parameters

Benefits:
- Clear separation of concerns (Data Access vs Business Logic vs Service)
- RedisHelper stays focused and doesn't grow
- Easier to test and maintain
- Better type safety and documentation
…codex-team/hawk.api.nodejs into feature/redis-timeseries-helper

# Conflicts:
#	src/models/eventsFactory.js
@codecov-commenter
Copy link

codecov-commenter commented Nov 7, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 58.30%. Comparing base (0eced98) to head (9a57f76).
⚠️ Report is 152 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #576      +/-   ##
==========================================
- Coverage   66.66%   58.30%   -8.37%     
==========================================
  Files          11       19       +8     
  Lines         174      518     +344     
  Branches       24       95      +71     
==========================================
+ Hits          116      302     +186     
- Misses         54      216     +162     
+ Partials        4        0       -4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

pavelzotikov and others added 10 commits November 8, 2025 02:07
Better name that reflects the purpose - composing keys for chart data storage,
not just Redis-specific utilities.
Clearer naming that explicitly indicates:
- This is for project-level metrics (not event-level)
- Parameter renamed: suffix -> granularity (more descriptive)

Addresses PR review comment about unclear naming.
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.

4 participants