Skip to content

Cosmos DB for Events - #1

Open
Hellebore wants to merge 4 commits into
base-sha/91409a45f0adbaa8a5aee2d81060cd6369656c44from
head-sha/0a7da87c37c33b271179f87aad4231b683564e1c/2025-05-02T11-41-11/963738
Open

Cosmos DB for Events#1
Hellebore wants to merge 4 commits into
base-sha/91409a45f0adbaa8a5aee2d81060cd6369656c44from
head-sha/0a7da87c37c33b271179f87aad4231b683564e1c/2025-05-02T11-41-11/963738

Conversation

@Hellebore

@Hellebore Hellebore commented May 2, 2025

Copy link
Copy Markdown

Type of change

- [ ] Bug fix
- [ ] New feature development
- [ ] Tech debt (refactoring, code cleanup, dependency upgrades, etc)
- [ ] Build/deploy pipeline (DevOps)
- [ ] Other

Objective

Code changes

  • file.ext: Description of what was changed and why

Before you submit

  • Please check for formatting errors (dotnet format --verify-no-changes) (required)
  • If making database changes - make sure you also update Entity Framework queries and/or migrations
  • Please add unit tests where it makes sense to do so (encouraged but not required)
  • If this change requires a documentation update - notify the documentation team
  • If this change has particular deployment requirements - notify the DevOps team

Greptile Summary

This pull request introduces Cosmos DB support for event handling in the server application, focusing on the implementation of a new EventItem class and EventRepository for Cosmos DB integration.

  • Added src/Core/Models/Data/EventItem.cs with a new EventItem class for Cosmos DB event data handling
  • Introduced src/Core/Repositories/Cosmos/EventRepository.cs for managing events in Cosmos DB
  • Modified src/EventsProcessor/AzureQueueHostedService.cs to support Cosmos DB alongside existing TableStorage
  • Updated src/SharedWeb/Utilities/ServiceCollectionExtensions.cs to register Cosmos DB EventRepository

Summary by Sourcery

Implement Cosmos DB support for event handling, replacing the existing Table Storage event repository with a new Cosmos DB-based implementation.

New Features:

  • Added Cosmos DB support for event storage and retrieval

Enhancements:

  • Introduced flexible event repository that can switch between Table Storage and Cosmos DB
  • Created a new EventItem class optimized for Cosmos DB storage

Chores:

  • Updated service configuration to support Cosmos DB event repository

@Hellebore

Copy link
Copy Markdown
Author

This is a benchmark review for experiment bakeoff.
Run ID: bakeoff/benchmark_2025-05-02T11-38-04_v1-36-0-dirty.

This pull request was cloned from https://github.com/grepdemos/server/pull/61. (Note: the URL is not a link to avoid triggering a notification on the original pull request.)

Experiment configuration
review_config:
  # User configuration for the review
  # - benchmark - use the user config from the benchmark reviews
  # - <value> - use the value directly
  user_review_config:
    enable_ai_review: true
    enable_rule_comments: false

    enable_complexity_comments: benchmark
    enable_security_comments: benchmark
    enable_tests_comments: benchmark
    enable_comment_suggestions: benchmark

    enable_pull_request_summary: benchmark
    enable_review_guide: benchmark

    enable_approvals: false
    base_branches: [base-sha.*]

  ai_review_config:
    # The model responses to use for the experiment
    # - benchmark - use the model responses from the benchmark reviews
    # - llm - call the language model to generate responses
    model_responses:
      comments_model: benchmark
      comment_validation_model: benchmark
      comment_suggestion_model: benchmark
      complexity_model: benchmark
      security_model: benchmark
      tests_model: benchmark
      pull_request_summary_model: benchmark
      review_guide_model: benchmark
      overall_comments_model: benchmark

# The pull request dataset to run the experiment on
pull_request_dataset:
# CodeRabbit
- https://github.com/neerajkumar161/node-coveralls-integration/pull/5
- https://github.com/gunner95/vertx-rest/pull/1
- https://github.com/Altinn/altinn-access-management-frontend/pull/1427
- https://github.com/theMr17/github-notifier/pull/14
- https://github.com/bearycool11/AI_memory_Loops/pull/142

# Greptile
- https://github.com/gumloop/guMCP/pull/119
- https://github.com/autoblocksai/python-sdk/pull/335
- https://github.com/grepdemos/ImageSharp/pull/6
- https://github.com/grepdemos/server/pull/61
- https://github.com/websentry-ai/pipelines/pull/25

# Graphite
- https://github.com/KittyCAD/modeling-app/pull/6648
- https://github.com/KittyCAD/modeling-app/pull/6628
- https://github.com/Varedis-Org/AI-Test-Repo/pull/2
- https://github.com/deeep-network/bedrock/pull/198
- https://github.com/Metta-AI/metta/pull/277

# Copilot
- https://github.com/hmcts/rpx-xui-webapp/pull/4438
- https://github.com/ganchdev/quez/pull/104
- https://github.com/xbcsmith/ymlfxr/pull/13
- https://github.com/tinapayy/B-1N1T/pull/36
- https://github.com/coder/devcontainer-features/pull/6

# Questions to ask to label the review comments
review_comment_labels: []
# - label: correct
#   question: Is this comment correct?

# Benchmark reviews generated by running
#   python -m scripts.experiment benchmark <experiment_name>
benchmark_reviews: []

@Hellebore

Copy link
Copy Markdown
Author

Reviewer's Guide

This pull request introduces support for storing events in Cosmos DB by implementing a new EventRepository using the Cosmos DB SDK, defining a corresponding EventItem data model, and updating dependency injection and the event processor to conditionally use the new repository.

File-Level Changes

Change Details Files
Implement event storage using Cosmos DB.
  • Defined the EventItem class as the data model for events stored in Cosmos DB, mapping IEvent properties to JSON fields.
  • Implemented the IEventRepository interface (EventRepository) using the Cosmos DB SDK.
  • Configured the CosmosClient with a custom System.Text.Json serializer and enabled bulk execution.
  • Implemented methods for creating single events (CreateAsync) and multiple events (CreateManyAsync) using bulk operations.
  • Implemented various paged query methods (GetManyBy...Async) using Cosmos DB SQL queries and iterators.
src/Core/Repositories/Cosmos/EventRepository.cs
src/Core/Models/Data/EventItem.cs
Integrate the new Cosmos DB repository into the application.
  • Updated ServiceCollectionExtensions to register Core.Repositories.Cosmos.EventRepository as the default IEventRepository.
  • Modified AzureQueueHostedService to check for a Cosmos DB connection string and instantiate either the Cosmos.EventRepository or the existing TableStorage.EventRepository accordingly.
src/EventsProcessor/AzureQueueHostedService.cs
src/SharedWeb/Utilities/ServiceCollectionExtensions.cs

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@Hellebore Hellebore left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Hey @Hellebore - I've reviewed your changes - here's some feedback:

  • Resolve the TODO comments within the new EventRepository.
  • Revisit the Cosmos DB partition key strategy chosen in EventRepository.
  • Consider managing the CosmosClient lifecycle via dependency injection.
Here's what I looked at during the review
  • 🟡 General issues: 2 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Documentation: all looks good

LangSmith trace

Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

}
else
{
services.AddSingleton<IEventRepository, TableStorageRepos.EventRepository>();

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

suggestion: Repository registration now always uses Cosmos implementation.

Ensure the DI setup still supports conditional selection as in AzureQueueHostedService. If different parts need varied repository implementations, centralize this logic.

Suggested implementation:

        }
        else
        {
            if(configuration.GetValue<bool>("UseCosmosEventRepository"))
            {
                services.AddSingleton<IEventRepository, Core.Repositories.Cosmos.EventRepository>();
                services.AddKeyedSingleton<IGrantRepository, Core.Auth.Repositories.Cosmos.GrantRepository>("cosmos");
            }
            else
            {
                services.AddSingleton<IEventRepository, TableStorageRepos.EventRepository>();
                services.AddKeyedSingleton<IGrantRepository, TableStorageRepos.GrantRepository>("tableStorage");
            }
            services.AddSingleton<IInstallationDeviceRepository, TableStorageRepos.InstallationDeviceRepository>();
        }

• Ensure that a configuration instance (IConfiguration configuration) is available in this context and passed in to the extension method if needed.
• Verify that TableStorageRepos.GrantRepository exists or adjust the repository implementation accordingly.
• Consider centralizing similar conditional repository registration logic into dedicated extension methods for consistency if multiple parts of the codebase require similar behavior.

Comment on lines +17 to +18
public EventRepository(GlobalSettings globalSettings)
: this("TODO")

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

issue (bug_risk): Placeholder 'TODO' in the GlobalSettings constructor.

Using 'TODO' will cause runtime failures if not replaced. Either remove this constructor until you have a valid connection string or provide a sensible default.

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