Local evaluation buckets percentage splits with the server key, so results differ from Flagsmith
まだ誰も着手していません。
評価
調査の方向性
lib/flagsmith.rb の Client#get_identity_model から始め、特に issue でリンクされている複合キーの構築を確認し、ローカル評価で環境 API キーがどのように利用可能になるかを追ってください。生成されたキーを、再現例で期待される client_key_account_two と比較してください。ローカルでの Percentage Splits 評価に関する対象を絞ったテストを更新して実行してください。SDK がダッシュボードの split 結果と一致すれば完了です。
索引モデルが issue の本文から書いたものです。
説明
In local evaluation mode, the client builds the identity's composite key from the environment_key it was configured with:
Local evaluation requires a server-side key, so environment_key is always ser.…. The composite key ends up as ser.<env key>_<identifier>, and that's what PERCENTAGE_SPLIT conditions hash, together with the segment ID.
Flagsmith itself appears to hash splits with the environment's client-side key, the api_key field of the environment document, giving <env key>_<identifier>. The two keys produce different percentages, so the SDK puts a different set of identities in every partial percentage split than the Flagsmith dashboard shows for the same identity and traits.
We found this when an identity that the dashboard showed in a 5% split segment evaluated as outside it in our app. Hashing <env key>_<identifier> gave 1.36 (in the percentage-based segment). Hashing ser.<env key>_<identifier>, what the SDK uses, gave 5.23 (outside the segment).
Reproduction
require "flagsmith"
document = {
id: 1,
api_key: "client_key",
project: {
id: 1, name: "Project", hide_disabled_flags: false,
organisation: {id: 1, name: "Org", feature_analytics: false, stop_serving_flags: false, persist_trait_data: true},
segments: [{
id: 1, name: "60% rollout",
rules: [{type: "ALL", rules: [], conditions: [{operator: "PERCENTAGE_SPLIT", value: "60", property_: "$.identity.key"}]}],
feature_states: [{django_id: 2, featurestate_uuid: "segment-state", enabled: true, feature_state_value: nil,
feature: {id: 1, name: "rollout", type: "STANDARD"}, multivariate_feature_state_values: []}]
}]
},
feature_states: [{django_id: 1, featurestate_uuid: "default-state", enabled: false, feature_state_value: nil,
feature: {id: 1, name: "rollout", type: "STANDARD"}, multivariate_feature_state_values: []}],
identity_overrides: []
}
environment = Flagsmith::Engine::Environment.build(document)
handler = Object.new
handler.define_singleton_method(:environment) { environment }
client = Flagsmith::Client.new(
environment_key: "ser.server_key",
offline_mode: true,
offline_handler: handler,
enable_local_evaluation: true
)
client.get_identity_flags("account_two").is_feature_enabled("rollout")
# => false. Hashing "client_key_account_two" gives 57.05, which is inside the 60% split;
# the SDK hashes "ser.server_key_account_two", which gives 62.53.
Expected
The SDK should match the dashboard and the other evaluation paths by building the composite key from environment.api_key.
Affected versions
4.1.1 and 4.3.0 (latest on RubyGems). It's also present in v5.0.0 and on main. In v5, Mappers::Identity.build_environment_context sets key: identity.composite_key, so the correct fallback in Segments::Evaluator.get_enriched_context, which builds "#{context[:environment][:key]}_#{identifier}" from the environment's api_key, never runs.
Suggested fix
In Client#get_identity_model, pass environment_api_key: environment.api_key instead of environment_key. We're running that change as a monkeypatch.
- 主要言語
- Ruby
- スター
- 12
- フォーク
- 6
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
Flagsmith/flagsmith-ruby-client のほかの issue
-
難易度 4/5 3〜5日 初心者へのやさしさ 55/100
-
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
-
Dependency Dashboardオープン
難易度 3/5 1〜2日 初心者へのやさしさ 15/100
-
難易度 4/5 3〜5日 初心者へのやさしさ 55/100
-
難易度 4/5 3〜5日 初心者へのやさしさ 42/100
Flagsmith/flagsmith-ruby-client の issue をすべて見る
似ている issue
-
Add Prestashopオープンrequest
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
endoflife-date/endoflife.date#11303 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
FreeTubeApp/FreeTube-Docs#245 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 85/100
TheOdinProject/curriculum#31458 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信