Local evaluation buckets percentage splits with the server key, so results differ from Flagsmith
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 75/100
Hướng nghiên cứu
Bắt đầu với Client#get_identity_model trong lib/flagsmith.rb, đặc biệt là cách tạo khóa ghép được liên kết trong issue, và theo dõi cách khóa API của môi trường được cung cấp trong quá trình đánh giá cục bộ. So sánh khóa tạo ra với giá trị mong đợi client_key_account_two trong bước tái hiện. Cập nhật các bài kiểm thử tập trung cho việc đánh giá Percentage Splits cục bộ và chạy chúng; hoàn tất khi SDK khớp với kết quả split của dashboard.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- Ruby
- Star
- 12
- Fork
- 6
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của Flagsmith/flagsmith-ruby-client
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 55/100
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
-
Dependency DashboardĐang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 15/100
-
Local evaluation silently drops identity overrides on large environmentsCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 55/100
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 42/100
Tất cả issue của Flagsmith/flagsmith-ruby-client
Issue tương tự
-
Add Nagoya Ruby Kaigi 05Đang mởcontent good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
rubyevents/rubyevents#2182 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Homebrew/homebrew-cask#293134 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
notch8/iiif_print#430 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
Maintainer thường phản hồi trong vòng 1 ngày