Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Use correct flag version in evaluation events. #166

Merged
merged 1 commit into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/flutter_client_contract_test_service/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ packages:
path: "../../packages/flutter_client_sdk"
relative: true
source: path
version: "4.6.0"
version: "4.7.0"
Copy link
Member Author

Choose a reason for hiding this comment

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

Change from melos bs.

lints:
dependency: "direct dev"
description:
Expand Down
11 changes: 9 additions & 2 deletions packages/common/lib/src/ld_evaluation_result.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ final class LDEvaluationResult {
/// Incremented by LaunchDarkly each time the flag's state changes.
final int version;

/// The version of the flag. Changes when modifications are made to the flag.
final int? flagVersion;

/// True if a client SDK should track events for this flag.
final bool trackEvents;

Expand All @@ -24,15 +27,17 @@ final class LDEvaluationResult {

const LDEvaluationResult(
{required this.version,
this.flagVersion,
required this.detail,
this.trackEvents = false,
this.trackReason = false,
this.debugEventsUntilDate});

@override
String toString() {
return 'LDEvaluationResult{version: $version, trackEvents: $trackEvents, '
'trackReason: $trackReason, debugEventsUntilDate: $debugEventsUntilDate,'
return 'LDEvaluationResult{version: $version, flagVersion: $flagVersion,'
' trackEvents: $trackEvents, trackReason: $trackReason,'
' debugEventsUntilDate: $debugEventsUntilDate,'
' detail: $detail}';
}

Expand All @@ -41,6 +46,7 @@ final class LDEvaluationResult {
identical(this, other) ||
other is LDEvaluationResult &&
version == other.version &&
flagVersion == other.flagVersion &&
trackEvents == other.trackEvents &&
trackReason == other.trackReason &&
debugEventsUntilDate == other.debugEventsUntilDate &&
Expand All @@ -49,6 +55,7 @@ final class LDEvaluationResult {
@override
int get hashCode =>
version.hashCode ^
flagVersion.hashCode ^
trackEvents.hashCode ^
trackReason.hashCode ^
debugEventsUntilDate.hashCode ^
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import '../../launchdarkly_dart_common.dart';
final class LDEvaluationResultSerialization {
static LDEvaluationResult fromJson(Map<String, dynamic> json) {
final version = json['version'] as num;
final flagVersion = json['flagVersion'] as num?;
final trackEvents = (json['trackEvents'] ?? false) as bool;
final trackReason = (json['trackReason'] ?? false) as bool;
final debugEventsUntilDateRaw = json['debugEventsUntilDate'] as num?;
Expand All @@ -19,6 +20,7 @@ final class LDEvaluationResultSerialization {

return LDEvaluationResult(
version: version.toInt(),
flagVersion: flagVersion?.toInt(),
detail: LDEvaluationDetail(value, variationIndex, reason),
trackEvents: trackEvents,
trackReason: trackReason,
Expand Down
5 changes: 3 additions & 2 deletions packages/common/test/ld_evaluation_result_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,14 @@ void main() {

test('it produces the expected string', () {
final a = LDEvaluationResult(
version: 1,
version: 11,
flagVersion: 1,
detail: LDEvaluationDetail<LDValue>(
LDValue.ofString('toast'), null, LDEvaluationReason.targetMatch()));

expect(
a.toString(),
'LDEvaluationResult{version: 1, trackEvents: false, trackReason: false,'
'LDEvaluationResult{version: 11, flagVersion: 1, trackEvents: false, trackReason: false,'
' debugEventsUntilDate: null, detail: LDEvaluationDetail{value:'
' LDValue{_value: toast}, variationIndex: null, reason:'
' LDEvaluationReason{kind: TARGET_MATCH, ruleIndex: null,'
Expand Down
2 changes: 1 addition & 1 deletion packages/common_client/lib/src/ld_common_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ final class LDCommonClient {
? DateTime.fromMillisecondsSinceEpoch(
evalResult!.flag!.debugEventsUntilDate!)
: null,
version: evalResult?.version));
version: evalResult?.flag?.flagVersion ?? evalResult?.version));
Copy link
Member Author

Choose a reason for hiding this comment

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

Primary change of importance.


return detail;
}
Expand Down
3 changes: 2 additions & 1 deletion packages/common_client/test/ld_dart_client_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ final class TestDataSource implements DataSource {
_eventController.sink.add(DataEvent(
'put',
'{"flagA":{'
'"version":1,'
'"version":11,'
'"flagVersion":1,'
'"value":"datasource",'
'"variation":0,'
'"reason":{"kind":"OFF"}'
Expand Down
Loading