-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: expose prerequisite relations in AllFlags API (#463)
Updates the `AllFlags()` API to gather and expose prerequisite information for flags. The prereqs are available via `State::Prerequisites()`, and are more importantly serialized in the JSON representation of the bootstrap payload. The implementation strategy was to create a custom `IEventProcessor` specifically for `AllFlags` usage. Previously, `AllFlags` invoked the evaluator with a no-op `EventScope`, which made event creation a no-op within the eval algorithm. This change now passes in a `PrereqEventRecorder` which tracks the top-level prerequisites of each flag.
- Loading branch information
1 parent
922d479
commit 56de5f5
Showing
14 changed files
with
377 additions
and
21 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
|
@@ -8,7 +8,6 @@ | |
|
||
#include <chrono> | ||
#include <cstdint> | ||
#include <variant> | ||
|
||
namespace launchdarkly::events { | ||
|
||
|
This file contains 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 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 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 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 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 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 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 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
30 changes: 30 additions & 0 deletions
30
libs/server-sdk/src/prereq_event_recorder/prereq_event_recorder.cpp
This file contains 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,30 @@ | ||
#include "prereq_event_recorder.hpp" | ||
|
||
namespace launchdarkly::server_side { | ||
|
||
PrereqEventRecorder::PrereqEventRecorder(std::string flag_key) | ||
: flag_key_(std::move(flag_key)) {} | ||
|
||
void PrereqEventRecorder::SendAsync(events::InputEvent const event) { | ||
if (auto const* feat = std::get_if<events::FeatureEventParams>(&event)) { | ||
if (auto const prereq_of = feat->prereq_of) { | ||
if (*prereq_of == flag_key_) { | ||
prereqs_.push_back(feat->key); | ||
} | ||
} | ||
} | ||
} | ||
|
||
void PrereqEventRecorder::FlushAsync() {} | ||
|
||
void PrereqEventRecorder::ShutdownAsync() {} | ||
|
||
std::vector<std::string> const& PrereqEventRecorder::Prerequisites() const { | ||
return prereqs_; | ||
} | ||
|
||
std::vector<std::string>&& PrereqEventRecorder::TakePrerequisites() && { | ||
return std::move(prereqs_); | ||
} | ||
|
||
} // namespace launchdarkly::server_side |
43 changes: 43 additions & 0 deletions
43
libs/server-sdk/src/prereq_event_recorder/prereq_event_recorder.hpp
This file contains 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,43 @@ | ||
#pragma once | ||
|
||
#include <launchdarkly/events/event_processor_interface.hpp> | ||
|
||
#include <string> | ||
#include <vector> | ||
|
||
namespace launchdarkly::server_side { | ||
|
||
/** | ||
* This class is meant only to record direct prerequisites of a flag. That is, | ||
* although it will be passed events for all prerequisites seen during an | ||
* evaluation via SendAsync, it will only store those that are a direct | ||
* prerequisite of the parent flag passed in the constructor. | ||
* | ||
* As a future improvement, it would be possible to unify the EventScope | ||
* mechanism currently used by the Evaluator to send events with a class | ||
* similar to this one, or to refactor the Evaluator to include prerequisite | ||
* information in the returned EvaluationDetail (or a new Result class, which | ||
* would be a composite of the EvaluationDetail and a vector of prerequisites.) | ||
*/ | ||
class PrereqEventRecorder final : public events::IEventProcessor { | ||
public: | ||
explicit PrereqEventRecorder(std::string flag_key); | ||
|
||
void SendAsync(events::InputEvent event) override; | ||
|
||
/* No-op */ | ||
void FlushAsync() override; | ||
|
||
/* No-op */ | ||
void ShutdownAsync() override; | ||
|
||
std::vector<std::string> const& Prerequisites() const; | ||
|
||
std::vector<std::string>&& TakePrerequisites() &&; | ||
|
||
private: | ||
std::string const flag_key_; | ||
std::vector<std::string> prereqs_; | ||
}; | ||
|
||
} // namespace launchdarkly::server_side |
Oops, something went wrong.