Skip to content

Implement feature flags system for subscriptions with bulk operations#5262

Merged
premun merged 17 commits intomainfrom
copilot/fix-5261
Sep 22, 2025
Merged

Implement feature flags system for subscriptions with bulk operations#5262
premun merged 17 commits intomainfrom
copilot/fix-5261

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Sep 10, 2025

This PR implements a complete feature flags system for the Product Construction Service (PCS) that enables subscription-specific feature toggles, gradual rollouts, and A/B testing capabilities with administrative bulk operations.

🎯 Key Features

Core Infrastructure

  • Predefined Feature Flags Registry: Static FeatureFlags class with rebase strategy flag and metadata
  • Redis-backed Storage: Subscription-scoped feature flags with optional expiration support using existing IRedisCacheFactory
  • Type-safe Access: Strongly-typed IFeatureFlagClient with compile-time validation and per-request caching
  • Comprehensive Validation: All flag operations validate against the predefined registry
  • Simplified Model: Streamlined FeatureFlagValue with only essential fields (SubscriptionId, FlagName, Value, CreatedAt)

REST API Endpoints

Added FeatureFlagsController in the v2020_02_20 API with full CRUD operations:

  • POST /api/feature-flags - Set feature flags with optional expiry
  • GET /api/feature-flags/{subscriptionId} - Get all flags for a subscription
  • GET /api/feature-flags/{subscriptionId}/{flagName} - Get specific flag
  • DELETE /api/feature-flags/{subscriptionId}/{flagName} - Remove flag
  • GET /api/feature-flags - Admin endpoint to list all flags
  • GET /api/feature-flags/available - List available flags with metadata
  • GET /api/feature-flags/by-flag/{flagName} - List all subscriptions with a specific flag
  • DELETE /api/feature-flags/by-flag/{flagName} - Remove flag from all subscriptions (admin)

CLI Integration

Integrated 7 new commands into the existing PCS CLI tool using the ProductConstructionServiceApi client:

# Set the rebase strategy flag with optional expiry
pcs feature-flag-set --subscription-id "guid" --flag "enable-rebase-strategy" --value "true" --expiry-days 30

# Get flags for a subscription
pcs feature-flag-get --subscription-id "guid" [--flag "specific-flag"]

# Remove a flag
pcs feature-flag-remove --subscription-id "guid" --flag "flag-name"

# List flags (admin operation)
pcs feature-flag-list [--subscription-id "guid"]

# Show available flags with descriptions
pcs feature-flag-available

# List subscriptions that have a specific flag
pcs feature-flag-list-by-flag --flag "enable-rebase-strategy"

# Remove flag from all subscriptions (admin)
pcs feature-flag-remove-from-all --flag "enable-rebase-strategy"

🏗️ Technical Implementation

Simplified Feature Flag Model

  • Streamlined Structure: FeatureFlagValue(SubscriptionId, FlagName, Value, CreatedAt)
  • Removed Complexity: Eliminated Expiry and UpdatedAt fields from the model
  • Redis-only Expiration: Expiration handled entirely by Redis TTL, no manual validation needed
  • Default Behavior: Feature flags never expire by default (Redis TTL = null)
  • User Control: Optional ExpiryDays parameter in API allows custom expiration when needed

Bulk Operations

Added two new service methods for administrative operations:

  • GetSubscriptionsWithFlagAsync() - Find all subscriptions with a specific flag using Redis pattern FeatureFlags_*:{flagName}
  • RemoveFlagFromAllSubscriptionsAsync() - Remove a flag from all subscriptions and return count of removed flags

Redis Key Structure

Uses consistent key pattern: FeatureFlags_{subscriptionId}:{flagName} with automatic expiration cleanup handled by Redis TTL.

CLI Architecture

The CLI commands use the generated ProductConstructionServiceApi client and follow established patterns:

  • All feature flag operations inherit from PcsStatusOptions for consistent authentication
  • Commands use standard PCS authentication options (--isCi, --pcsUri) instead of direct Redis access
  • Operations use _client.FeatureFlags.* methods to interact with the API
  • Consistent Logging: All CLI operations use ILogger instead of Console.WriteLine following PCS CLI patterns

Service Integration

The IFeatureFlagClient is designed for easy integration into existing PCS components:

public async Task ProcessSubscription(Guid subscriptionId)
{
    await _featureFlagClient.InitializeAsync(subscriptionId);
    
    var useRebaseStrategy = await _featureFlagClient.GetBooleanFlagAsync(
        FeatureFlags.EnableRebaseStrategy, defaultValue: false);
    
    if (useRebaseStrategy)
    {
        // Use rebase strategy for codeflow conflicts
    }
    else
    {
        // Use standard merge strategy
    }
}

Available Feature Flag

  • enable-rebase-strategy - Enables rebase strategy for codeflow conflict resolution instead of merge

🧪 Testing

Added comprehensive unit tests (17 tests) covering:

  • API controller endpoints with mocked dependencies
  • Service layer functionality with Redis integration
  • CLI command integration and error handling
  • Feature flag validation and type safety
  • Bulk operations for administrative use cases

🔄 Integration with Existing Systems

  • Leverages existing Redis infrastructure (IRedisCacheFactory)
  • CLI follows established patterns with the ProductConstructionServiceApi client and Azure authentication
  • Uses existing dependency injection and logging patterns
  • Maintains API versioning consistency
  • Simplified internal implementation with Redis handling all expiration logic
  • Improved Error Handling: Proper exception propagation in bulk operations with detailed logging

📝 Recent Updates

  • Removed Success Field: Eliminated redundant Success boolean from RemoveFlagFromAllResponse - HTTP status codes indicate success/failure
  • Better Error Handling: RemoveFlagFromAllSubscriptionsAsync now properly propagates exceptions instead of silently continuing
  • Consistent CLI Logging: All feature flag CLI operations now use ILogger following established PCS patterns
  • Improved Documentation: Updated API documentation to be more precise about return values

This implementation provides a robust foundation for enabling rebase strategy in codeflow conflict resolution on a per-subscription basis, with administrative capabilities for bulk flag management across all subscriptions. The streamlined model reduces complexity while maintaining full functionality.

Fixes #5261.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Feature Flags Support for Product Construction Service using Redis Implement comprehensive feature flags system for Product Construction Service Sep 10, 2025
Copilot AI requested a review from premun September 10, 2025 13:31
Copy link
Copy Markdown
Member

@premun premun left a comment

Choose a reason for hiding this comment

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

@copilot there will be a specific feature flag I have in mind added so we can remove the example ones and use this one.

It is about using rebase strategy when dealing with codeflow conflicts. So please pick a suitable short name.

- Replace 5 example feature flags with single `enable-rebase-strategy` flag for codeflow conflict resolution
- Update all tests to use the new flag appropriately
- Update CLI example to use the new flag
- Maintain all existing functionality while focusing on the specific use case

Co-authored-by: premun <[email protected]>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Sep 10, 2025

@copilot there will be a specific feature flag I have in mind added so we can remove the example ones and use this one.

It is about using rebase strategy when dealing with codeflow conflicts. So pl...

I've replaced all the example feature flags with a single enable-rebase-strategy flag specifically for using rebase strategy when dealing with codeflow conflicts. The flag name follows the existing naming convention and is focused on the specific use case you mentioned.

The changes include:

  • Replaced 5 example flags with the single rebase strategy flag
  • Updated all tests to work with the new flag
  • Updated CLI examples and integration code
  • Maintained all existing functionality while focusing on the specific rebase strategy use case

Commit: e4cf109

Copilot AI requested a review from premun September 10, 2025 14:08
Copy link
Copy Markdown
Member

@premun premun left a comment

Choose a reason for hiding this comment

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

@copilot the PCS.Cli project cannot use the Redis wrapper class directly. It needs to use the ProductConstructionClient class like the rest of the Cli project does.
I have added the feature flag support to the PCS client class in the last commit.

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Sep 10, 2025

@copilot the PCS.Cli project cannot use the Redis wrapper class directly. It needs to use the ProductConstructionClient class like the rest of the Cli project does.
I have added the feature flag su...

Updated the PCS CLI to use the ProductConstructionServiceApi client instead of direct Redis access. All feature flag operations now inherit from PcsStatusOptions and use the generated client's FeatureFlags property to make API calls, following the same pattern as other CLI operations like GetPcsStatusOperation.

Key changes:

  • Removed Redis connection string requirement from all feature flag CLI commands
  • Updated all operations to use IProductConstructionServiceApi and _client.FeatureFlags.* methods
  • Fixed missing using System.Collections.Generic; in generated client models
  • All commands now use standard PCS authentication patterns

The CLI builds successfully and all feature flag commands are available with the correct options (--isCi, --pcsUri) instead of the Redis connection string.

Commit: 68e43ae

Copilot AI requested a review from premun September 10, 2025 15:31
@premun premun changed the title Implement comprehensive feature flags system for Product Construction Service Implement feature flags system for subscriptions Sep 10, 2025
@premun premun marked this pull request as ready for review September 11, 2025 08:59
Copilot AI review requested due to automatic review settings September 11, 2025 08:59
Copy link
Copy Markdown
Contributor

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 a comprehensive feature flags system for the Product Construction Service (PCS), enabling subscription-specific feature toggles through a Redis-backed storage system with full CLI and API integration.

Key changes:

  • Added predefined feature flags registry with rebase strategy flag and type-safe validation
  • Implemented Redis-backed feature flag service with expiration support and comprehensive CRUD operations
  • Created REST API endpoints for complete feature flag management in the v2020_02_20 API version

Reviewed Changes

Copilot reviewed 18 out of 27 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
tools/ProductConstructionService.Cli/Program.cs Registers new feature flag CLI command types
tools/ProductConstructionService.Cli/Options/*.cs Defines CLI options for all 5 feature flag operations (set, get, remove, list, available)
tools/ProductConstructionService.Cli/Operations/*.cs Implements CLI operations using ProductConstructionService API client
test/ProductConstructionService.Api.Tests/FeatureFlagsController20200220Tests.cs Comprehensive unit tests covering API controller functionality
src/ProductConstructionService/ProductConstructionService.Common/ProductConstructionServiceExtension.cs Registers feature flag service in dependency injection container
src/ProductConstructionService/ProductConstructionService.Common/IFeatureFlagService.cs Service interface defining feature flag operations
src/ProductConstructionService/ProductConstructionService.Common/FeatureFlags.cs Static registry of available feature flags with validation
src/ProductConstructionService/ProductConstructionService.Common/FeatureFlagService.cs Redis-backed implementation of feature flag service
src/ProductConstructionService/ProductConstructionService.Common/FeatureFlagModels.cs Data models for feature flag requests and responses
src/ProductConstructionService/ProductConstructionService.Api/Api/v2020_02_20/Controllers/FeatureFlagsController.cs REST API controller implementing complete feature flag management

Comment thread tools/ProductConstructionService.Cli/Operations/FeatureFlagGetOperation.cs Outdated
Comment thread tools/ProductConstructionService.Cli/Operations/FeatureFlagListOperation.cs Outdated
Comment thread tools/ProductConstructionService.Cli/Operations/FeatureFlagListOperation.cs Outdated
Comment thread test/ProductConstructionService.Api.Tests/FeatureFlagsController20200220Tests.cs Outdated
@premun premun changed the title Implement feature flags system for subscriptions with bulk operations Implement feature flags system for subscriptions Sep 11, 2025
@premun premun changed the title Implement feature flags system for subscriptions Implement feature flags system in PCS for subscriptions Sep 11, 2025
Copilot AI changed the title Implement feature flags system in PCS for subscriptions Implement feature flags system for subscriptions with bulk operations Sep 11, 2025
Comment thread src/ProductConstructionService/ProductConstructionService.Common/FeatureFlags.cs Outdated
Comment thread tools/ProductConstructionService.Cli/Operations/FeatureFlagAvailableOperation.cs Outdated
Comment thread tools/ProductConstructionService.Cli/Operations/FeatureFlagAvailableOperation.cs Outdated
Comment thread tools/ProductConstructionService.Cli/Operations/FeatureFlagGetOperation.cs Outdated
@premun
Copy link
Copy Markdown
Member

premun commented Sep 12, 2025

@copilot switch to using ILogger instead of Console.WriteLine in the new feature flag commands in the PCS CLI project

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Sep 12, 2025

@copilot switch to using ILogger instead of Console.WriteLine in the new feature flag commands in the PCS CLI project

Switched all feature flag commands in the PCS CLI project to use ILogger instead of Console.WriteLine, following the established patterns used throughout the rest of the CLI. All operations now use structured logging with proper message templates. Commit: d34a77c

Comment thread tools/ProductConstructionService.Cli/Operations/FeatureFlagAvailableOperation.cs Outdated
Comment thread tools/ProductConstructionService.Cli/Operations/FeatureFlagGetOperation.cs Outdated
Comment thread tools/ProductConstructionService.Cli/Operations/FeatureFlagGetOperation.cs Outdated
Comment thread tools/ProductConstructionService.Cli/Operations/FeatureFlagListByFlagOperation.cs Outdated
Comment thread tools/ProductConstructionService.Cli/Operations/FeatureFlagListByFlagOperation.cs Outdated
Comment thread tools/ProductConstructionService.Cli/Operations/FeatureFlagListOperation.cs Outdated
@premun premun requested a review from dkurepa September 12, 2025 08:58
@premun premun merged commit 9c6199d into main Sep 22, 2025
9 checks passed
@premun premun deleted the copilot/fix-5261 branch September 22, 2025 10:02
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.

Feature Flags Support for Product Construction Service using Redis

4 participants