Skip to content

Commit 35e324b

Browse files
committed
Add private attributes builders to event processor config
1 parent 8ee293f commit 35e324b

File tree

7 files changed

+81
-28
lines changed

7 files changed

+81
-28
lines changed

libs/common/include/config/detail/defaults.hpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,8 @@ struct Defaults<ClientSDK> {
2828
}
2929
static Events events() {
3030
return {
31-
100,
32-
std::chrono::seconds(30),
33-
"/mobile",
34-
AttributePolicy::Default,
35-
TransportSecurity::TLS,
31+
100, std::chrono::seconds(30), "/mobile",
32+
false, AttributeReference::SetType(), TransportSecurity::TLS,
3633
};
3734
}
3835
};
@@ -45,11 +42,8 @@ struct Defaults<ServerSDK> {
4542
}
4643
static Events events() {
4744
return {
48-
10000,
49-
std::chrono::seconds(5),
50-
"/bulk",
51-
AttributePolicy::Default,
52-
TransportSecurity::TLS,
45+
10000, std::chrono::seconds(5), "/bulk",
46+
false, AttributeReference::SetType(), TransportSecurity::TLS,
5347
};
5448
}
5549
};

libs/common/include/config/detail/events.hpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,10 @@
33
#include <chrono>
44
#include <cstddef>
55
#include <string>
6+
#include <unordered_map>
7+
#include "attribute_reference.hpp"
68
namespace launchdarkly::config::detail {
79

8-
enum class AttributePolicy {
9-
Default = 0,
10-
AllPrivate = 1,
11-
};
12-
1310
enum class TransportSecurity {
1411
None = 0,
1512
TLS = 1,
@@ -22,19 +19,23 @@ struct Events {
2219
Events(std::size_t capacity,
2320
std::chrono::milliseconds flush_interval,
2421
std::string path,
25-
AttributePolicy policy,
22+
bool all_attributes_private,
23+
AttributeReference::SetType private_attrs,
2624
TransportSecurity security);
2725
std::size_t capacity() const;
2826
std::chrono::milliseconds flush_interval() const;
2927
std::string const& path() const;
30-
AttributePolicy attribute_policy() const;
28+
bool all_attributes_private() const;
29+
AttributeReference::SetType const& private_attributes() const;
3130
TransportSecurity transport_security() const;
3231

3332
private:
3433
std::size_t capacity_;
3534
std::chrono::milliseconds flush_interval_;
3635
std::string path_;
37-
AttributePolicy attribute_policy_;
36+
bool all_attributes_private_;
37+
AttributeReference::SetType private_attributes_;
38+
3839
TransportSecurity transport_security_;
3940
};
4041

libs/common/include/config/detail/events_builder.hpp

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
#pragma once
22

3+
#include <tl/expected.hpp>
4+
#include "attribute_reference.hpp"
35
#include "config/detail/events.hpp"
46
#include "error.hpp"
57

6-
#include <tl/expected.hpp>
7-
88
#include <memory>
99
#include <optional>
1010
#include <string>
11+
#include <unordered_map>
1112

1213
namespace launchdarkly::config::detail {
1314

@@ -51,6 +52,39 @@ class EventsBuilder {
5152
*/
5253
EventsBuilder& flush_interval(std::chrono::milliseconds interval);
5354

55+
/**
56+
* Attribute privacy indicates whether or not attributes should be
57+
* retained by LaunchDarkly after being sent upon initialization,
58+
* and if attributes should later be sent in events.
59+
*
60+
* Attribute privacy may be specified in 3 ways:
61+
*
62+
* (1) To specify that all attributes should be considered private - not
63+
* just those designated private on a per-context basis - call this method
64+
* with true as the parameter.
65+
*
66+
* (2) To specify that a specific set of attributes should be considered
67+
* private
68+
* - in addition to those designated private on a per-context basis -
69+
* call @ref private_attributes.
70+
*
71+
* (3) To specify private attributes on a per-context basis, it is not
72+
* necessary to call either of these methods, as the default behavior is to
73+
* treat all attributes as non-private unless otherwise specified.
74+
*
75+
* @param value True for behavior of (1), false for default behavior of (2)
76+
* or (3).
77+
* @return Reference to this builder.
78+
*/
79+
EventsBuilder& all_attributes_private(bool);
80+
81+
/**
82+
* Specify an AttributePolicy for individual attributes.
83+
* @return
84+
*/
85+
EventsBuilder& private_attributes(
86+
AttributeReference::SetType private_attrs);
87+
5488
/**
5589
* Builds Events configuration, if the configuration is valid. If not,
5690
* returns an error.

libs/common/src/config/events.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ namespace launchdarkly::config::detail {
55
Events::Events(std::size_t capacity,
66
std::chrono::milliseconds flush_interval,
77
std::string path,
8-
AttributePolicy policy,
8+
bool all_attributes_private,
9+
AttributeReference::SetType private_attrs,
910
TransportSecurity transport_security)
1011
: capacity_(capacity),
1112
flush_interval_(flush_interval),
1213
path_(std::move(path)),
13-
attribute_policy_(policy),
14+
all_attributes_private_(all_attributes_private),
15+
private_attributes_(std::move(private_attrs)),
1416
transport_security_(transport_security) {}
1517

1618
std::size_t Events::capacity() const {
@@ -22,8 +24,13 @@ std::chrono::milliseconds Events::flush_interval() const {
2224
std::string const& Events::path() const {
2325
return path_;
2426
}
25-
AttributePolicy Events::attribute_policy() const {
26-
return attribute_policy_;
27+
28+
bool Events::all_attributes_private() const {
29+
return all_attributes_private_;
30+
}
31+
32+
AttributeReference::SetType const& Events::private_attributes() const {
33+
return private_attributes_;
2734
}
2835

2936
TransportSecurity Events::transport_security() const {
@@ -34,6 +41,7 @@ bool operator==(Events const& lhs, Events const& rhs) {
3441
return lhs.path() == rhs.path() &&
3542
lhs.flush_interval() == rhs.flush_interval() &&
3643
lhs.capacity() == rhs.capacity() &&
37-
lhs.attribute_policy() == rhs.attribute_policy();
44+
lhs.all_attributes_private() == rhs.all_attributes_private() &&
45+
lhs.private_attributes() == rhs.private_attributes();
3846
}
3947
} // namespace launchdarkly::config::detail

libs/common/src/config/events_builder.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,19 @@ EventsBuilder<SDK>& EventsBuilder<SDK>::flush_interval(
2020
return *this;
2121
}
2222

23+
template <typename SDK>
24+
EventsBuilder<SDK>& EventsBuilder<SDK>::all_attributes_private(bool value) {
25+
config_.all_attributes_private_ = value;
26+
return *this;
27+
}
28+
29+
template <typename SDK>
30+
EventsBuilder<SDK>& EventsBuilder<SDK>::private_attributes(
31+
AttributeReference::SetType attributes) {
32+
config_.private_attributes_ = std::move(attributes);
33+
return *this;
34+
}
35+
2336
template <typename SDK>
2437
tl::expected<Events, Error> EventsBuilder<SDK>::build() {
2538
if (config_.capacity() == 0) {

libs/common/src/events/dispatcher.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ std::optional<Dispatcher::RequestType> Dispatcher::make_request() {
112112
req.prepare_payload();
113113
return req;
114114
}
115-
// helper type for the visitor #4
115+
116+
// These helpers are for the std::visit within Dispatcher::process.
116117
template <class... Ts>
117118
struct overloaded : Ts... {
118119
using Ts::operator()...;

libs/common/tests/event_processor_test.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ TEST_F(EventProcessorTests, thing) {
1616

1717
auto config = client::EventsBuilder()
1818
.capacity(10)
19-
.flush_interval(std::chrono::seconds(1))
19+
.flush_interval(std::chrono::seconds(3))
2020
.build();
2121

2222
auto endpoints = client::HostsBuilder().build();
@@ -37,7 +37,9 @@ TEST_F(EventProcessorTests, thing) {
3737
ev.data = Value({"foo", "bar", "baz"});
3838
ev.metric_value = 30;
3939

40-
ep.async_send(ev);
40+
for (std::size_t i = 0; i < 10; i++) {
41+
ep.async_send(ev);
42+
}
4143

4244
std::this_thread::sleep_for(std::chrono::seconds(2));
4345

0 commit comments

Comments
 (0)