Skip to content

feat: Add cohort evaluation support for local feature flag evaluation#74

Merged
haacked merged 7 commits intomainfrom
haacked/73-cohort-evaluation
Aug 13, 2025
Merged

feat: Add cohort evaluation support for local feature flag evaluation#74
haacked merged 7 commits intomainfrom
haacked/73-cohort-evaluation

Conversation

@haacked
Copy link
Copy Markdown
Contributor

@haacked haacked commented Aug 8, 2025

Implements comprehensive cohort evaluation to enable full local evaluation of feature flags that depend on cohorts, bringing the Ruby SDK to feature parity with other server-side SDKs (Python, Node.js, Go, PHP, .NET).

Key changes:

  • Add send_cohorts parameter to local evaluation requests
  • Implement cohort storage and management in FeatureFlagsPoller
  • Add match_cohort() and match_property_group() methods for cohort evaluation
  • Support nested property groups with AND/OR logic
  • Handle cohort-type properties in match_property()
  • Update flag evaluation chain to pass cohort properties
  • Add comprehensive test coverage for all cohort scenarios
  • Update all test stubs to expect new URL format

This enables local evaluation of flags with cohorts, reducing API calls and improving performance while maintaining backward compatibility.

Fixes #73

@haacked haacked requested review from a team, Copilot and rafaeelaudibert August 8, 2025 23:25
@dmarticus dmarticus moved this to In Review in Feature Flags Aug 8, 2025
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 comprehensive cohort evaluation support for local feature flag evaluation in the Ruby SDK, bringing it to feature parity with other server-side SDKs (Python, Node.js, Go, PHP, .NET). The implementation enables full local evaluation of feature flags that depend on cohorts, eliminating the need for additional API calls and improving performance.

  • Adds send_cohorts parameter to local evaluation requests to retrieve cohort definitions
  • Implements match_cohort() and match_property_group() methods for evaluating complex nested cohort logic
  • Updates the feature flag evaluation chain to support cohort properties alongside regular properties

Reviewed Changes

Copilot reviewed 7 out of 8 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
lib/posthog/feature_flags.rb Core implementation of cohort evaluation logic with nested property group support
spec/posthog/flags_spec.rb Comprehensive test coverage for cohort evaluation scenarios including edge cases
spec/posthog/feature_flag_spec.rb Updates test stubs to include new send_cohorts=true parameter
spec/posthog/client_spec.rb Updates test stubs to match new URL format with cohort parameter
example.rb Enhanced demo script with interactive menu and complex cohort examples
EXAMPLE_SETUP.md Documentation for setting up the example script with cohort configurations
.env.example Environment configuration template for the example script

Comment thread lib/posthog/feature_flags.rb Outdated
Comment thread lib/posthog/feature_flags.rb
Comment thread lib/posthog/feature_flags.rb
haacked added 2 commits August 8, 2025 16:31
Implements comprehensive cohort evaluation to enable full local evaluation of feature flags that depend on cohorts, bringing the Ruby SDK to feature parity with other server-side SDKs (Python, Node.js, Go, PHP, .NET).

Key changes:
- Add `send_cohorts` parameter to local evaluation requests
- Implement cohort storage and management in FeatureFlagsPoller
- Add `match_cohort()` and `match_property_group()` methods for cohort evaluation
- Support nested property groups with AND/OR logic
- Handle cohort-type properties in match_property()
- Update flag evaluation chain to pass cohort properties
- Add comprehensive test coverage for all cohort scenarios
- Update all test stubs to expect new URL format

This enables local evaluation of flags with cohorts, reducing API calls and improving performance while maintaining backward compatibility.

Fixes #73
@haacked haacked force-pushed the haacked/73-cohort-evaluation branch from 594f41b to 25258b7 Compare August 8, 2025 23:31
@haacked haacked force-pushed the haacked/73-cohort-evaluation branch from c1f0807 to bec6ddd Compare August 8, 2025 23:38
haacked added 2 commits August 8, 2025 16:45
Ran bin/fmt. Had to manually fix some.
@haacked haacked force-pushed the haacked/73-cohort-evaluation branch from cb28927 to 47cdee0 Compare August 8, 2025 23:59
Comment thread EXAMPLE_SETUP.md Outdated
POSTHOG_PERSONAL_API_KEY=phx_your_personal_key_here

# PostHog host URL
POSTHOG_HOST=https://app.posthog.com # or your self-hosted URL
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

shouldn't this be us.posthog.com or eu.posthog.com?

Comment thread .env.example Outdated
Comment thread bin/fmt
- Change default from app.posthog.com to us.posthog.com in examples
- Add eu.posthog.com option in comments for EU users
- Update both .env.example and EXAMPLE_SETUP.md
@haacked haacked requested a review from andyzzhao August 11, 2025 19:01
@github-project-automation github-project-automation Bot moved this from In Review to Approved in Feature Flags Aug 13, 2025
@haacked haacked merged commit d0a3632 into main Aug 13, 2025
8 checks passed
@haacked haacked deleted the haacked/73-cohort-evaluation branch August 13, 2025 19:43
@github-project-automation github-project-automation Bot moved this from Approved to Done in Feature Flags Aug 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Add cohort evaluation support for local feature flag evaluation

4 participants