Skip to content

Conversation

@erenatas
Copy link
Contributor

@erenatas erenatas commented Dec 12, 2025

This PR

is mostly improvements on gRPC streaming performance, file watching, and code quality

gRPC Streaming Performance

Reduces latency on reconnects and improves connection reliability:

  • Add channel reuse to avoid connection overhead on reconnects
  • Add HTTP/2 adaptive flow control for better throughput
  • Add TCP keepalive (60s) for OS-level dead connection detection
  • Add explicit connect_timeout separate from request timeout
  • Add configurable HTTP/2 keepalive (keep_alive_time_ms option)
  • Invalidate cached channel on stream end/error for fresh reconnection
  • Reset backoff delay on graceful stream closure
  • New: Add Unix socket support for in-process gRPC connections (This was not done)

File Watching & Storage

  • Replace file connector polling with notify crate for OS-level file watching (we used to poll in time interval, now it will be realtime)
  • Broaden event matching to handle atomic writes (temp file → rename)
  • Track changed flag keys in storage state changes for selective cache invalidation
  • Add graceful shutdown propagation through FlagStore and connectors
  • Send initial StorageStateChange after FlagStore.init() to fix race condition

Configuration Alignment with Go Provider

  • Make gRPC authority optional (only needed for envoy:// URIs)
  • Add keep_alive_time_ms option (FLAGD_KEEP_ALIVE_TIME_MS env var)

Dependency Optimization

  • Remove futures crate, replace with tokio-stream
  • Replace anyhow with thiserror for typed error handling
  • Use minimal tokio features instead of "full"
  • Optimize tonic, tower features with default-features = false

Code Quality

  • Fix struct value serialization in targeting context (proper nested JSON)
  • Improve error handling with descriptive messages in stream listener
  • Add Clone, Copy, Eq, Hash, Default traits to public types
  • Add documentation to Connector trait, storage types, and Operator
  • Add unit tests for storage, targeting, and file connector modules

Examples

  • Add in_process.rs example using testcontainers for flagd server
  • Add common/mod.rs with flagd container helper
  • Add flags/basic-flags.json sample configuration

Breaking Changes (Behavioral)

  • Caching disabled for in-process mode: Previously cached by default, now
    evaluates fresh each time. Users can re-enable with cache_settings: Some(...) it was cache_settings: Some(CacheSettings::default()),.

Follow-up Tasks

I plan to follow up with an optional opentelemetry feature for metrics. tracing crate (for logging) already subscribes to otel for logs automatically

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @erenatas, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly refines the in-process evaluation mode of flagd by overhauling its core mechanisms for configuration management and inter-component communication. The changes aim to enhance the system's responsiveness to flag updates, improve resource efficiency through optimized dependency usage and graceful shutdowns, and bolster overall reliability with more robust error handling and precise cache invalidation. These improvements collectively contribute to a more performant and maintainable flagd client.

Highlights

  • File Watching Mechanism: Replaced the previous file connector polling with the notify crate for more efficient and OS-level file watching, improving responsiveness to configuration changes.
  • Cache Invalidation Optimization: Implemented tracking of changed flag keys during storage state updates, enabling selective cache invalidation rather than full cache resets, which enhances performance.
  • Graceful Shutdown: Added graceful shutdown propagation through the FlagStore and various connectors, ensuring resources are properly released upon termination.
  • Targeting Context Serialization Fix: Corrected the serialization of StructValue within the targeting context to properly handle nested JSON structures, ensuring accurate evaluation.
  • Unix Socket Support: Introduced support for Unix sockets for in-process gRPC connections, offering an alternative communication method.
  • Improved Error Handling: Migrated from anyhow to thiserror for typed error handling, providing more descriptive and structured error messages across the codebase.
  • Dependency Optimization: Streamlined dependencies by removing the futures crate, replacing it with tokio-stream, using minimal tokio features, and optimizing tonic and tower features, reducing binary size and compile times.
  • Code Quality Enhancements: Added Clone, Copy, Eq, Hash, Default traits to public types, improved documentation for key traits and types, and expanded unit test coverage for storage, targeting, and file connector modules.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This is an excellent pull request that brings a host of significant improvements to the flagd crate. The migration from anyhow to thiserror for typed error handling, dependency optimizations, and the introduction of notify for efficient file watching are all major wins for robustness and performance. The addition of features like graceful shutdown, Unix socket support, and selective cache invalidation further enhance the library's capabilities. The fix for struct serialization in the targeting context is a crucial correctness improvement. The code is well-structured, and the addition of documentation and extensive unit tests is commendable. I have one suggestion to improve the file watcher's reliability.

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