-
Notifications
You must be signed in to change notification settings - Fork 7
feat: Add Identify hooks to Client SDK #234
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
Merged
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
da37078
Plugin support for CliendSDK
abelonogov-ld 7aee7be
Plugin tests
abelonogov-ld f4a903b
defensive check
abelonogov-ld 6849630
Refactor LdClient cleanup logic to ensure proper disposal order of re…
abelonogov-ld efe371c
Merge branch 'main' into andrey/clientsdk-plugins-and-hooks
abelonogov-ld ebd9c5c
Flag Evaluations hook
abelonogov-ld 5c8ddd4
Refactor plugin registration logic in LdClient to ensure hooks are av…
abelonogov-ld e5d9dc0
remove unnecessary parameter
abelonogov-ld 55a0950
remove identify
abelonogov-ld 17e0c56
fix comment
abelonogov-ld 88078c3
remove files
abelonogov-ld b08463a
address feadback
abelonogov-ld f1f4046
Merge branch 'andrey/clientsdk-plugins-and-hooks' into andrey/clients…
abelonogov-ld 6311201
Merge branch 'main' into andrey/client-identify-hook
abelonogov-ld 451e890
Update IdentifyAsync method to include maxWaitTime parameter
abelonogov-ld 493f598
Identify in Hook interface
abelonogov-ld 61629a6
Fix IdentifyAsync method signature in LdClient documentation and impl…
abelonogov-ld c4bcf6f
make unneeded parameter internal
abelonogov-ld 283e9d2
Refactor IdentifySeriesContext to use TimeSpan for timeout
abelonogov-ld fe9d524
IdentifyWithHook
abelonogov-ld 551c275
return false
abelonogov-ld 0430db3
Use large wrapper
abelonogov-ld 167d6c8
noopexecetor
abelonogov-ld 11b9692
let's throw
abelonogov-ld b881e20
calling start after
abelonogov-ld File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| using System; | ||
|
|
||
| namespace LaunchDarkly.Sdk.Client.Hooks | ||
| { | ||
| /// <summary> | ||
| /// IdentifySeriesContext represents parameters associated with an identify operation. It is | ||
| /// made available in <see cref="Hook"/> stage callbacks. | ||
| /// </summary> | ||
| public sealed class IdentifySeriesContext | ||
| { | ||
| /// <summary> | ||
| /// The Context being identified. | ||
| /// </summary> | ||
| public Context Context { get; } | ||
|
|
||
| /// <summary> | ||
| /// The timeout for the identify operation. A value of <see cref="TimeSpan.Zero"/> indicates | ||
| /// that no timeout was specified. | ||
| /// </summary> | ||
| public TimeSpan Timeout { get; } | ||
|
|
||
| /// <summary> | ||
| /// Constructs a new IdentifySeriesContext. | ||
| /// </summary> | ||
| /// <param name="context">the context being identified</param> | ||
| /// <param name="timeout">the timeout for the identify operation</param> | ||
| public IdentifySeriesContext(Context context, TimeSpan timeout) | ||
| { | ||
| Context = context; | ||
| Timeout = timeout; | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| namespace LaunchDarkly.Sdk.Client.Hooks | ||
| { | ||
| /// <summary> | ||
| /// IdentifySeriesResult contains the outcome of an identify operation. | ||
| /// </summary> | ||
| public sealed class IdentifySeriesResult | ||
| { | ||
| /// <summary> | ||
| /// Represents the possible statuses of an identify operation. | ||
| /// </summary> | ||
| public enum IdentifySeriesStatus | ||
| { | ||
| /// <summary> | ||
| /// The identify operation completed successfully. | ||
| /// </summary> | ||
| Completed, | ||
|
|
||
| /// <summary> | ||
| /// The identify operation encountered an error. | ||
| /// </summary> | ||
| Error | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// The status of the identify operation. | ||
| /// </summary> | ||
| public IdentifySeriesStatus Status { get; } | ||
|
|
||
| /// <summary> | ||
| /// Constructs a new IdentifySeriesResult. | ||
| /// </summary> | ||
| /// <param name="status">the status of the identify operation</param> | ||
| public IdentifySeriesResult(IdentifySeriesStatus status) | ||
| { | ||
| Status = status; | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| using System; | ||
| using System; | ||
| using System.Threading.Tasks; | ||
| using LaunchDarkly.Sdk.Client.Interfaces; | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| using System; | ||
| using System; | ||
|
|
||
| namespace LaunchDarkly.Sdk.Client.Interfaces | ||
| { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
pkgs/sdk/client/src/Internal/Hooks/Series/IdentifySeries.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Collections.Immutable; | ||
| using System.Linq; | ||
| using LaunchDarkly.Logging; | ||
| using LaunchDarkly.Sdk.Client.Hooks; | ||
| using LaunchDarkly.Sdk.Client.Internal.Hooks.Interfaces; | ||
|
|
||
| namespace LaunchDarkly.Sdk.Client.Internal.Hooks.Series | ||
| { | ||
| using SeriesData = ImmutableDictionary<string, object>; | ||
|
|
||
| internal class IdentifyStage | ||
| { | ||
| protected enum Stage | ||
| { | ||
| BeforeIdentify, | ||
| AfterIdentify | ||
| } | ||
|
|
||
| protected readonly EvaluationStage.Order _order; | ||
| private readonly Logger _logger; | ||
|
|
||
| protected IdentifyStage(Logger logger, EvaluationStage.Order order) | ||
| { | ||
| _logger = logger; | ||
| _order = order; | ||
| } | ||
|
|
||
| protected void LogFailure(IdentifySeriesContext context, Hook h, Stage stage, Exception e) | ||
| { | ||
| _logger.Error("During identify of context \"{0}\", stage \"{1}\" of hook \"{2}\" reported error: {3}", | ||
| context.Context.Key, stage.ToString(), h.Metadata.Name, e.Message); | ||
| } | ||
| } | ||
|
|
||
| internal sealed class BeforeIdentify : IdentifyStage, IStageExecutor<IdentifySeriesContext> | ||
| { | ||
| private readonly IEnumerable<Hook> _hooks; | ||
|
|
||
| public BeforeIdentify(Logger logger, IEnumerable<Hook> hooks, EvaluationStage.Order order) : base(logger, order) | ||
| { | ||
| _hooks = (order == EvaluationStage.Order.Forward) ? hooks : hooks.Reverse(); | ||
| } | ||
|
|
||
| public IEnumerable<SeriesData> Execute(IdentifySeriesContext context, IEnumerable<SeriesData> _) | ||
| { | ||
| return _hooks.Select(hook => | ||
| { | ||
| try | ||
| { | ||
| return hook.BeforeIdentify(context, SeriesData.Empty); | ||
| } | ||
| catch (Exception e) | ||
| { | ||
| LogFailure(context, hook, Stage.BeforeIdentify, e); | ||
| return SeriesData.Empty; | ||
| } | ||
| }).ToList(); | ||
| } | ||
| } | ||
|
|
||
| internal sealed class AfterIdentify : IdentifyStage, IStageExecutor<IdentifySeriesContext, IdentifySeriesResult> | ||
| { | ||
| private readonly IEnumerable<Hook> _hooks; | ||
|
|
||
| public AfterIdentify(Logger logger, IEnumerable<Hook> hooks, EvaluationStage.Order order) : base(logger, order) | ||
| { | ||
| _hooks = (order == EvaluationStage.Order.Forward) ? hooks : hooks.Reverse(); | ||
| } | ||
|
|
||
| public IEnumerable<SeriesData> Execute(IdentifySeriesContext context, IdentifySeriesResult result, | ||
| IEnumerable<SeriesData> seriesData) | ||
| { | ||
| return _hooks.Zip((_order == EvaluationStage.Order.Reverse ? seriesData.Reverse() : seriesData), (hook, data) => | ||
| { | ||
| try | ||
| { | ||
| return hook.AfterIdentify(context, data, result); | ||
| } | ||
| catch (Exception e) | ||
| { | ||
| LogFailure(context, hook, Stage.AfterIdentify, e); | ||
| return SeriesData.Empty; | ||
| } | ||
| }).ToList(); | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.