-
Notifications
You must be signed in to change notification settings - Fork 36
feat(event_processor): add forwarding event processor and integrate with optimizely #205
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
Changes from all commits
232f0a0
2320939
fbb5a68
c162465
633b095
8a5f531
35fcd82
d7201cb
c829fca
1d858b7
c3c9d46
a2eeb85
a045291
f70a1c9
faff070
c931956
2dea7fe
d7f69ec
8853cb3
5934764
23ab6ce
6474e98
1184568
592a306
c4a412a
2a3374c
ce44c11
00efd1b
54333d7
af497f9
d2f7126
f21c94b
3fd5788
ebe833c
ddef208
e964048
8953a43
b1388da
535e624
d4f2c66
80b0963
071460a
900d96d
8cd8547
b730bfd
752e35f
f9a2cb6
54446b9
aedccc8
e628e0f
855c73f
c92f79d
63c1b21
c18e359
56408dc
f851754
8f7be2b
1486fa4
b9d5fd9
d42d14b
6366d59
65a752b
ab192a0
06ac3f0
8e4c118
641d09a
9630139
3e40044
8998580
a89a5bf
2582fb7
41d44e6
cfb2d74
75725bd
42a90f0
751ee64
cb07348
c3d5b07
2d37cbe
f50e053
bb3f738
b5d461b
ca208a6
2c33344
46cc51d
1ab8b32
67e0424
f0dd1fd
4d4e7d1
477bbd5
e299dce
758ffc2
304ac00
cbd918a
5ef24de
1edb7c2
4c8b7f3
9d917a4
443b7aa
3b2cb4a
dcca0ec
dea337b
1d5aeca
b3883d6
655a859
4753c0b
86e4b7f
65fb6fa
01a8ea1
3baf024
7e20be7
15e0c8f
498db55
614a3d4
ee89a1f
2c67253
6e4d431
02c9e53
9ebf1a4
34e3cf5
d241a2f
dc53d39
8956cba
c6a2c18
41516f0
ac8663a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -117,11 +117,11 @@ def _validate_intantiation_props(self, prop, prop_name): | |
prop_name: Property name. | ||
|
||
Returns: | ||
False if property value is None or less than 1 or not a finite number. | ||
False if property value is None or less than or equal to 0 or not a finite number. | ||
False if property name is batch_size and value is a floating point number. | ||
True otherwise. | ||
""" | ||
if (prop_name == 'batch_size' and not isinstance(prop, int)) or prop is None or prop < 1 or \ | ||
if (prop_name == 'batch_size' and not isinstance(prop, int)) or prop is None or prop <= 0 or \ | ||
not validator.is_finite_number(prop): | ||
self.logger.info('Using default value for {}.'.format(prop_name)) | ||
return False | ||
|
@@ -159,11 +159,11 @@ def _run(self): | |
""" | ||
try: | ||
while True: | ||
if self._get_time() > self.flushing_interval_deadline: | ||
if self._get_time() >= self.flushing_interval_deadline: | ||
self._flush_queue() | ||
|
||
try: | ||
item = self.event_queue.get(True, 0.05) | ||
item = self.event_queue.get(False) | ||
|
||
except queue.Empty: | ||
time.sleep(0.05) | ||
|
@@ -283,3 +283,51 @@ def stop(self): | |
|
||
if self.is_running: | ||
self.logger.error('Timeout exceeded while attempting to close for ' + str(self.timeout_interval) + ' ms.') | ||
|
||
|
||
class ForwardingEventProcessor(BaseEventProcessor): | ||
""" | ||
ForwardingEventProcessor serves as the default EventProcessor. | ||
|
||
The ForwardingEventProcessor sends the LogEvent to EventDispatcher as soon as it is received. | ||
""" | ||
|
||
def __init__(self, event_dispatcher, logger=None, notification_center=None): | ||
""" ForwardingEventProcessor init method to configure event dispatching. | ||
|
||
Args: | ||
event_dispatcher: Provides a dispatch_event method which if given a URL and params sends a request to it. | ||
logger: Optional component which provides a log method to log messages. By default nothing would be logged. | ||
notification_center: Optional instance of notification_center.NotificationCenter. | ||
""" | ||
self.event_dispatcher = event_dispatcher | ||
self.logger = _logging.adapt_logger(logger or _logging.NoOpLogger()) | ||
self.notification_center = notification_center | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to feedback in #204 shouldn't we validate that |
||
|
||
if not validator.is_notification_center_valid(self.notification_center): | ||
self.logger.error(enums.Errors.INVALID_INPUT.format('notification_center')) | ||
self.notification_center = _notification_center.NotificationCenter() | ||
|
||
def process(self, user_event): | ||
""" Method to process the user_event by dispatching it. | ||
Args: | ||
user_event: UserEvent Instance. | ||
""" | ||
if not isinstance(user_event, UserEvent): | ||
self.logger.error('Provided event is in an invalid format.') | ||
return | ||
|
||
self.logger.debug('Received user_event: ' + str(user_event)) | ||
|
||
log_event = EventFactory.create_log_event(user_event, self.logger) | ||
|
||
if self.notification_center is not None: | ||
self.notification_center.send_notifications( | ||
enums.NotificationTypes.LOG_EVENT, | ||
log_event | ||
) | ||
|
||
try: | ||
self.event_dispatcher.dispatch_event(log_event) | ||
except Exception as e: | ||
self.logger.exception('Error dispatching event: ' + str(log_event) + ' ' + str(e)) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Copyright 2016-2018, Optimizely | ||
# Copyright 2016-2019, Optimizely | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
|
@@ -43,7 +43,7 @@ class InvalidGroupException(Exception): | |
|
||
|
||
class InvalidInputException(Exception): | ||
""" Raised when provided datafile, event dispatcher, logger or error handler is invalid. """ | ||
""" Raised when provided datafile, event dispatcher, logger, event processor or error handler is invalid. """ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit. Year in header needs to be updated. |
||
pass | ||
|
||
|
||
|
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.
You say it is optional, but it is not so in practice.