-
Notifications
You must be signed in to change notification settings - Fork 3
feat: add event summarizer #19
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
14 commits
Select commit
Hold shift + click to select a range
60080f4
Adding event summarizer
cwaldren-ld 922e114
Add summary counting
cwaldren-ld 7d34a34
Adding summarizer unit tests
cwaldren-ld b7ec2ee
fix summary counter JSON serialization
cwaldren-ld ba24383
Fix a bunch of lints
cwaldren-ld 67974d0
qol fixes
cwaldren-ld 9b4880c
fix lints'
cwaldren-ld c9beb2a
fix more lints
cwaldren-ld eb799f3
Improve Summarizer ergonomics
cwaldren-ld 3f90218
Update event serialization tests to use FeatureEvent constructor
cwaldren-ld c72fcd6
Add a bunch of parameterized tests
cwaldren-ld 72451cf
fix lints
cwaldren-ld ab2c1b9
refactor with test helper
cwaldren-ld df678d3
switch to std::set and std::map for summary states for consistent ord…
cwaldren-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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
--- | ||
CheckOptions: | ||
- { key: readability-identifier-length.IgnoredParameterNames, value: 'i|j|k|c|os|it' } | ||
- { key: readability-identifier-length.IgnoredVariableNames, value: 'ec' } | ||
- { key: readability-identifier-length.IgnoredLoopCounterNames, value: 'i|j|k|c|os|it' } | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
#pragma once | ||
#include <boost/container_hash/hash.hpp> | ||
#include <chrono> | ||
#include <functional> | ||
#include <set> | ||
#include <unordered_map> | ||
#include <unordered_set> | ||
#include "events/events.hpp" | ||
#include "value.hpp" | ||
|
||
namespace launchdarkly::events::detail { | ||
|
||
/** | ||
* Summarizer is responsible for accepting FeatureEventParams (the context | ||
* related to a feature evaluation) and outputting summary events (which | ||
* essentially condenses the various evaluation results into a single | ||
* structure). | ||
*/ | ||
class Summarizer { | ||
public: | ||
using Time = std::chrono::system_clock::time_point; | ||
using FlagKey = std::string; | ||
|
||
/** | ||
* Construct a Summarizer starting at the given time. | ||
* @param start Start time of the summary. | ||
*/ | ||
explicit Summarizer(Time start_time); | ||
|
||
/** | ||
* Construct a Summarizer at time zero. | ||
*/ | ||
Summarizer() = default; | ||
|
||
/** | ||
* Updates the summary with a feature event. | ||
* @param event Feature event. | ||
*/ | ||
void Update(client::FeatureEventParams const& event); | ||
|
||
/** | ||
* Marks the summary as finished at a given timestamp. | ||
* @param end_time End time of the summary. | ||
*/ | ||
Summarizer& Finish(Time end_time); | ||
|
||
/** | ||
* Returns true if the summary is empty. | ||
*/ | ||
[[nodiscard]] bool Empty() const; | ||
|
||
/** | ||
* Returns the summary's start time as given in the constructor. | ||
*/ | ||
[[nodiscard]] Time start_time() const; | ||
|
||
/** | ||
* Returns the summary's end time as specified using Finish. | ||
*/ | ||
[[nodiscard]] Time end_time() const; | ||
|
||
struct VariationSummary { | ||
public: | ||
explicit VariationSummary(Value value); | ||
void Increment(); | ||
[[nodiscard]] std::int32_t count() const; | ||
[[nodiscard]] Value const& value() const; | ||
|
||
private: | ||
std::int32_t count_; | ||
Value value_; | ||
}; | ||
|
||
struct VariationKey { | ||
std::optional<Version> version; | ||
std::optional<VariationIndex> variation; | ||
|
||
VariationKey(); | ||
VariationKey(Version version, std::optional<VariationIndex> variation); | ||
|
||
bool operator==(VariationKey const& k) const { | ||
return k.variation == variation && k.version == version; | ||
} | ||
|
||
bool operator<(VariationKey const& k) const { | ||
if (variation < k.variation) { | ||
return true; | ||
} | ||
return version < k.version; | ||
} | ||
}; | ||
|
||
struct State { | ||
Value default_; | ||
std::set<std::string> context_kinds; | ||
std::map<Summarizer::VariationKey, Summarizer::VariationSummary> | ||
counters; | ||
|
||
explicit State(Value defaultVal); | ||
}; | ||
|
||
[[nodiscard]] std::unordered_map<FlagKey, State> const& features() const; | ||
|
||
private: | ||
Time start_time_; | ||
Summarizer::Time end_time_; | ||
std::unordered_map<FlagKey, State> features_; | ||
kinyoklion marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}; | ||
|
||
} // namespace launchdarkly::events::detail |
This file was deleted.
Oops, something went wrong.
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
boost::system::error_code ec
is all over the boost docs.