Skip to content
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

Merged
merged 19 commits into from
Jan 25, 2024

Conversation

rgraber
Copy link
Contributor

@rgraber rgraber commented Jan 24, 2024

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:

  • tag reviewer
  • tag reviewer

Merge checklist:

  • All reviewers approved
  • CI build is green
  • Version bumped
  • Changelog record added
  • Documentation updated (not only docstrings)
  • Commits are squashed

Post merge:

  • Create a tag
  • Check new version is pushed to PyPI after tag-triggered build is
    finished.
  • Delete working branch (if not needed anymore)

Author concerns: List any concerns about this PR - inelegant
solutions, hacks, quick-and-dirty implementations, concerns about
migrations, etc.

@rgraber rgraber marked this pull request as ready for review January 24, 2024 16:23
@rgraber rgraber requested a review from a team as a code owner January 24, 2024 16:23
@rgraber rgraber force-pushed the rsgraber/20240124-fix-source-field branch from 68cc715 to 40ba1bb Compare January 24, 2024 16:24
CHANGELOG.rst Outdated Show resolved Hide resolved
"""
Get the value that should be used for the source of an event.
"""
source = getattr(settings, "EVENT_BUS_SERVICE_NAME", None)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. I think we need setting annotations here.
  2. 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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. 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"
  1. I agree that SERVICE_VARIANT is probably not the best option.

Copy link
Contributor

@robrap robrap Jan 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

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.

Copy link
Contributor Author

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.

@ddt.data(
('settings_variant', None, 'openedx/settings_variant/web'),
(None, 'my_service', 'openedx/my_service/web'),
(None, None, 'openedx//web'),
Copy link
Contributor

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:

Suggested change
(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.

@rgraber rgraber force-pushed the rsgraber/20240124-fix-source-field branch from ee7516c to f208269 Compare January 24, 2024 18:48
@rgraber rgraber requested a review from robrap January 24, 2024 19:17
@@ -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()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIt:

  1. 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
  1. Consider something like SERVICE-NAME-UNSET in place of unidentified, to give something easy to search for and easy to resolve.

@@ -27,6 +27,19 @@ def _ensure_utc_time(_, attribute, value):
raise ValueError(f"'{attribute.name}' must have timezone.utc")


def get_source_name():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Should be get_service_name.
  2. Can we keep this internal-only and call it _get_service_name?

Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor

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?

Copy link
Contributor Author

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

@rgraber rgraber merged commit 0a7e448 into main Jan 25, 2024
6 checks passed
@rgraber rgraber deleted the rsgraber/20240124-fix-source-field branch January 25, 2024 14:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants