-
Notifications
You must be signed in to change notification settings - Fork 21
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
feat: use new setting to set ce_source #305
Conversation
68cc715
to
40ba1bb
Compare
openedx_events/data.py
Outdated
""" | ||
Get the value that should be used for the source of an event. | ||
""" | ||
source = getattr(settings, "EVENT_BUS_SERVICE_NAME", None) |
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.
- I think we need setting annotations here.
- Maybe just on the PR, and maybe in the docs, you should explain:
- Why we need the new setting, and when we should use it over the SERVICE_VARIANT setting. I imagine you basically wish to deprecate use of SERVICE_VARIANT here?
- Is it ok that an "EVENT_BUS" setting will be used for all events, regardless of whether or not they are sent over the event bus? It may be ok, but maybe we should note this.
Not sure if we need a small ADR around this, or if we can just use code comments?
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.
I didn't put settings annotations here because I put them in event-bus-kafka. Not sure what the protocol is when the same setting is used in 2 different places. I can change that.
I'd indeed like to deprecate use of service variant since that only really applies to lms and cms.
I'd be fine with EVENTS_SERVICE_NAME but we do need to decide on one that we'll use both here and in EBK.
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.
I really don't think this needs an ADR
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.
- If the setting is only documented once, it should live in this library, since it serves as the interface for the other implementations. One way to make this more explicit would be if you had this library expose a variable like the following, which could be used in all the libraries:
EVENT_BUS_SERVICE_NAME = "EVENT_BUS_SERVICE_NAME"
- I agree that SERVICE_VARIANT is probably not the best option.
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.
[inform] @mariajgrimaldi @felipemontoya
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.
@mariajgrimaldi: I don't know if this will notify you twice, but I added the wrong username and had to edit it above. I'm adding this in case you never got a notification.
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.
The PR description explains why we shouldn't use SERVICE_VARIANT. I think it would actually be more confusing to talk about it more in the code comments.
openedx_events/tests/test_data.py
Outdated
@ddt.data( | ||
('settings_variant', None, 'openedx/settings_variant/web'), | ||
(None, 'my_service', 'openedx/my_service/web'), | ||
(None, None, 'openedx//web'), |
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.
I wonder if we should do something for this case? Something like the following:
(None, None, 'openedx//web'), | |
(None, None, 'openedx/unknown_service/web'), # Or `misconfigured_service`? |
The setting annotation could detail this so that people know how to interpret whatever shows up.
Co-authored-by: Robert Raposa <[email protected]>
ee7516c
to
f208269
Compare
openedx_events/data.py
Outdated
@@ -62,7 +75,8 @@ class EventsMetadata: | |||
source = attr.ib( | |||
type=str, default=None, | |||
converter=attr.converters.default_if_none( | |||
attr.Factory(lambda: "openedx/{service}/web".format(service=getattr(settings, "SERVICE_VARIANT", ""))) | |||
attr.Factory(lambda: "openedx/{service}/web".format(service=get_source_name()) if get_source_name() |
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.
NIt:
- I'd find this easier to read if on and earlier line you set:
service_name = "unidentified" or _get_service_name(). # see other PR comment for method name change
- Consider something like
SERVICE-NAME-UNSET
in place ofunidentified
, to give something easy to search for and easy to resolve.
openedx_events/data.py
Outdated
@@ -27,6 +27,19 @@ def _ensure_utc_time(_, attribute, value): | |||
raise ValueError(f"'{attribute.name}' must have timezone.utc") | |||
|
|||
|
|||
def get_source_name(): |
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.
- Should be
get_service_name
. - Can we keep this internal-only and call it
_get_service_name
?
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.
Also note that if this function were private, and just used for this one purpose, it could return SERVICE-NAME-UNSET
itself in place of None.
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.
I wanted to call it from event bus kafka
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.
It should still be changed to get_service_name
though, right?
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.
It was. I have 2 methods now
Description: Use a new EVENTS_SERVICE_NAME setting to determine the source in EventsMetadata. Defaults to the old SERVICE_VARIANT setting if not set. SERVICE_VARIANT is usually only set on lms or cms, and has other uses, so it makes sense to have a new variable that all services can use for the events.
I didn't talk about how the EVENTS_SERVICE_NAME will be used to set the client id because that is Kafka specific.
Testing instructions:
pip install -e openedx-events
set EVENTS_SERVICE_NAME in your service settings
fire an event
check that the event source is openedx/<EVENTS_SERVICE_NAME>/web
Reviewers:
Merge checklist:
Post merge:
finished.
Author concerns: List any concerns about this PR - inelegant
solutions, hacks, quick-and-dirty implementations, concerns about
migrations, etc.