Skip to content

Conversation

@ArtemHoruzhenko
Copy link
Contributor

@ArtemHoruzhenko ArtemHoruzhenko commented Jan 2, 2026

What

This PR implements the RDI statistics functionality for the API v2 client, adding support for fetching and transforming statistics data from RDI API v2 endpoints.

Key Changes

Backend (API)

  • New Statistics Client Methods:

    • Added getStatistics() method to ApiV2RdiClient for fetching statistics from RDI API v2
    • Implemented proper error handling and response transformation
    • Integrated with existing RDI client architecture
  • Statistics Transformers:

    • Created RdiStatisticsTransformer to convert API v2 responses to internal DTOs
    • Implemented transformation logic for:
      • Client connection statistics
      • Stream processing metrics
      • Performance data
      • Ingestion statistics
    • Added proper type mapping and data validation
  • DTOs and Interfaces:

    • Defined API v2 statistics response interfaces
    • Created transformation mappings between API v2 format and internal format
    • Ensured type safety across the statistics pipeline

Testing

  • Unit Tests:
    • Added comprehensive tests for ApiV2RdiClient.getStatistics()
    • Created tests for RdiStatisticsTransformer
    • Covered edge cases and error scenarios
    • Verified proper data transformation

Technical Decisions

  1. Transformer Pattern: Used a dedicated transformer class to separate API response parsing from business logic, making the code more maintainable and testable

  2. Type Safety: Defined strict TypeScript interfaces for API v2 responses to catch type mismatches early

  3. Error Handling: Implemented robust error handling to gracefully handle API failures and malformed responses

  4. Separation of Concerns: Kept the client focused on HTTP communication while delegating transformation logic to specialized transformers

Dependencies

This PR builds on top of:

Integration

The statistics client integrates with:

  • RdiClientProvider - uses this client to fetch statistics
  • RDI statistics DTOs - transforms API responses into these models
  • RDI statistics controller - serves transformed data to the frontend

Testing

Automation Tests

  • Unit tests for ApiV2RdiClient.getStatistics() method
  • Unit tests for RdiStatisticsTransformer
  • Tests cover successful responses, error cases, and edge cases
  • Integration tests with actual RDI API v2 endpoint

Manual Testing

  • Verify statistics are correctly fetched from RDI API v2
  • Test with different RDI configurations
  • Verify error handling when RDI is unavailable or returns errors
  • Check data transformation accuracy

Test Coverage

  • New files have comprehensive unit test coverage
  • All transformation logic is tested
  • Error scenarios are covered

Note

Introduces API v2 statistics support and converts v2 metrics into existing statistics sections.

  • Adds getStatistics() to ApiV2RdiClient using GET api/v2/pipelines/{name}/metric-collections, returning RdiStatisticsResult with transformed sections
  • Defines v2 response types (metrics-collections.response.ts) and exports in responses index
  • Implements transformers for v2: transformMetricsCollectionResponse (reuses v1 transformers) and extended transformProcessingPerformance (adds transform_time_avg, write_time_avg)
  • Adds v2 URL builder RdiUrlV2.GetMetricsCollections in constants
  • Includes unit tests for transformers covering ordering, types, new fields, and edge cases

Written by Cursor Bugbot for commit 4eda927. This will update automatically on new commits. Configure here.

@github-actions
Copy link
Contributor

github-actions bot commented Jan 2, 2026

Code Coverage - Integration Tests

Status Category Percentage Covered / Total
🟢 Statements 81.43% 16433/20179
🟡 Branches 64.49% 7487/11609
🟡 Functions 70.36% 2305/3276
🟢 Lines 81.06% 15457/19068

@github-actions
Copy link
Contributor

github-actions bot commented Jan 2, 2026

Code Coverage - Backend unit tests

St.
Category Percentage Covered / Total
🟢 Statements 92.42% 14099/15256
🟡 Branches 74.88% 4391/5864
🟢 Functions 86.03% 2173/2526
🟢 Lines 92.23% 13476/14612

Test suite run success

3077 tests passing in 292 suites.

Report generated by 🧪jest coverage report action from 4eda927

@github-actions
Copy link
Contributor

github-actions bot commented Jan 2, 2026

Code Coverage - Frontend unit tests

St.
Category Percentage Covered / Total
🟢 Statements 82.89% 21198/25574
🟡 Branches 68.16% 8954/13136
🟡 Functions 78.08% 5802/7431
🟢 Lines 83.28% 20756/24924

Test suite run success

5556 tests passing in 704 suites.

Report generated by 🧪jest coverage report action from 4eda927

Base automatically changed from feature/RI-7632-rdi-api-v2-statistics-rework to feature/RI-7632-rdi-api-v2-support January 23, 2026 07:24
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.


describe('transformMetricsCollectionResponse', () => {
const mockProcessorMetrics: ProcessorMetricsResponse = {
name: 'processor_metrics' as any,
Copy link

Choose a reason for hiding this comment

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

Type definitions require bypassing with type casts

Low Severity

The ComponentMetricsCollections enum defines values with hyphens ('processor-metrics', 'collector-metrics'), but test mocks use underscores ('processor_metrics', 'collector-source_metrics'), requiring as any casts at lines 101, 180, and 226 to bypass type checking. This suggests the type definitions don't match the actual API response format or are unnecessarily strict, reducing type safety.

Additional Locations (1)

Fix in Cursor Fix in Web

@@ -0,0 +1,90 @@
export enum ComponentMetricsCollections {
processorMetrics = 'processor-metrics',
Copy link
Member

Choose a reason for hiding this comment

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

nit: Very very minor, but just for consistency - in most places we use capitalized enums, so better to stick to it.

export interface ProcessorMetricsResponse extends ComponentMetricsResponse {
name: ComponentMetricsCollections.processorMetrics;
metrics: {
processing_performance: {
Copy link
Member

Choose a reason for hiding this comment

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

I didn't compare the interfaces between v1 and v2, I just wonder whether we have matching parts or they're complete independant from each other?

Because, if we have matching sub-parts, maybe we don't have to redeclare them here again?

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.

3 participants