Skip to content

Conversation

AmanGIT07
Copy link
Contributor

@AmanGIT07 AmanGIT07 commented Sep 11, 2025

This PR adds an implementation of ListAuditRecords RPC. Additionally it supports filtering, pagination, ordering and groups as per RQL query. RQL related utility function have used.

Sample Request:

{
    "query": {
        "filters": [
            {
                "name": "event",
                "operator": "eq",
                "string_value": "officia"
            }
        ],
        "limit": 2,
        "offset": 0
    }
}

Sample Response:

{
    "audit_records": [
        {
            "id": "01991dac-1178-7910-b59a-f81417664451",
            "actor": {
                "id": "9a5a22f3-e464-4037-aaea-995d6644061e",
                "type": "app/user",
                "name": "",
                "metadata": {
                    "fields": {
                        "is_super_user": {
                            "bool_value": true
                        }
                    }
                }
            },
            "event": "officia",
            "resource": {
                "id": "in id minim aute elit",
                "type": "eu mollit aute esse incididunt",
                "name": "in sint Excepteur cupidatat",
                "metadata": {
                    "fields": {}
                }
            },
            "target": {
                "id": "sed do commodo id aliquip",
                "type": "et in aliquip mollit",
                "name": "nulla magna in officia",
                "metadata": {
                    "fields": {}
                }
            },
            "occurred_at": {
                "seconds": "5699219684",
                "nanos": 342566000
            },
            "org_id": "8d84a46a-723d-4e33-b298-7ea98c52d147",
            "req_id": "reprehenderit magna consectetur",
            "metadata": {
                "fields": {}
            },
            "created_at": {
                "seconds": "1757139439",
                "nanos": 986755000
            }
        },
        {
            "id": "01991dbb-6e80-71f3-a49b-b9547518bd11",
            "actor": {
                "id": "00000000-0000-0000-0000-000000000000",
                "type": "system",
                "name": "system",
                "metadata": {
                    "fields": {}
                }
            },
            "event": "officia",
            "resource": {
                "id": "in id minim aute elit",
                "type": "eu mollit aute esse incididunt",
                "name": "in sint Excepteur cupidatat",
                "metadata": {
                    "fields": {}
                }
            },
            "target": {
                "id": "sed do commodo id aliquip",
                "type": "et in aliquip mollit",
                "name": "nulla magna in officia",
                "metadata": {
                    "fields": {}
                }
            },
            "occurred_at": {
                "seconds": "5699219684",
                "nanos": 342566000
            },
            "org_id": "8d84a46a-723d-4e33-b298-7ea98c52d147",
            "req_id": "reprehenderit magna consectetur",
            "metadata": {
                "fields": {}
            },
            "created_at": {
                "seconds": "1757140446",
                "nanos": 842917000
            }
        }
    ],
    "pagination": {
        "offset": 0,
        "limit": 2,
        "total_count": 4
    },
    "group": null
}

Test: Unit tests and manual end to end test

Copy link

vercel bot commented Sep 11, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
frontier Ready Ready Preview Comment Sep 12, 2025 0:07am

@coveralls
Copy link

coveralls commented Sep 11, 2025

Pull Request Test Coverage Report for Build 17673929091

Details

  • 124 of 163 (76.07%) changed or added relevant lines in 4 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.2%) to 32.104%

Changes Missing Coverage Covered Lines Changed/Added Lines %
pkg/server/connect_interceptors/authorization.go 0 4 0.0%
internal/api/v1beta1connect/audit_record.go 43 51 84.31%
internal/store/postgres/audit_record_repository.go 78 105 74.29%
Totals Coverage Status
Change from base Build 17666813375: 0.2%
Covered Lines: 10940
Relevant Lines: 34077

💛 - Coveralls

@rohilsurana rohilsurana requested a review from Copilot September 11, 2025 12:07
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements the ListAuditRecords RPC endpoint with comprehensive RQL (Resource Query Language) support for filtering, pagination, ordering and grouping of audit records.

  • Adds ListAuditRecords RPC implementation supporting RQL queries with filters, search, pagination, sorting and grouping
  • Implements comprehensive repository layer with SQL query building for audit record listing operations
  • Includes extensive test coverage for API handlers, service layer, and repository functionality

Reviewed Changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
pkg/server/connect_interceptors/authorization.go Adds authorization checks for the new ListAuditRecords endpoint
internal/store/postgres/testdata/mock-audit-records.json Provides comprehensive test data fixture with 15 audit records for testing
internal/store/postgres/audit_record_repository_test.go Extensive test suite covering listing, filtering, searching, grouping and edge cases
internal/store/postgres/audit_record_repository.go Core repository implementation with RQL query processing and SQL generation
internal/api/v1beta1connect/mocks/audit_record_service.go Updated mock service with List method for testing
internal/api/v1beta1connect/audit_record_test.go Comprehensive API handler tests covering various scenarios and error cases
internal/api/v1beta1connect/audit_record.go API handler implementation with RQL validation and response transformation
core/auditrecord/service_test.go Service layer tests for the List functionality
core/auditrecord/service.go Simple service layer implementation delegating to repository
core/auditrecord/mocks/repository.go Updated mock repository with List method
core/auditrecord/errors.go Adds ErrRepositoryBadInput error for validation failures
core/auditrecord/auditrecord.go Enhanced data structures with JSON tags and RQL schema definition
Comments suppressed due to low confidence (1)

internal/api/v1beta1connect/audit_record.go:1

  • The error message 'failed to read rql query' doesn't match what the code is actually doing (transforming proto to RQL). It should be 'failed to transform rql query' to be consistent with the actual operation.
package v1beta1connect

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@AmanGIT07 AmanGIT07 merged commit 1dfd1d1 into main Sep 16, 2025
7 checks passed
@AmanGIT07 AmanGIT07 deleted the implement-ListAuditRecords-rpc branch September 16, 2025 05:41
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