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: add odp rest api manager #398

Merged
merged 9 commits into from
Aug 12, 2022
Merged

Conversation

Mat001
Copy link
Contributor

@Mat001 Mat001 commented Aug 8, 2022

Summary

  • Added rest api code for odp. Sending events to ODP platform.
  • added class OdpEvent
  • added a helper function for creating and mocking a fake server response
  • added unit tests
  • fixed typo in enums
  • minor fixes to odp graphql manager tests
  • See acceptance criteria in the ticket below.

Test plan

  • unit tests
  • FSC tests

Issues

tests/helpers_for_tests.py Outdated Show resolved Hide resolved
Copy link
Contributor

@andrewleap-optimizely andrewleap-optimizely left a comment

Choose a reason for hiding this comment

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

Looks good so far! I like that you reused the mock response, that's a good idea. Just a couple changes

optimizely/odp/odp_event.py Show resolved Hide resolved
optimizely/odp/zaius_rest_api_manager.py Outdated Show resolved Hide resolved
tests/helpers_for_tests.py Outdated Show resolved Hide resolved
optimizely/odp/zaius_rest_api_manager.py Outdated Show resolved Hide resolved
optimizely/odp/zaius_rest_api_manager.py Outdated Show resolved Hide resolved
Copy link
Contributor

@jaeopt jaeopt left a comment

Choose a reason for hiding this comment

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

Looks good. A couple of small changes suggested.

optimizely/odp/zaius_rest_api_manager.py Outdated Show resolved Hide resolved
tests/test_odp_zaius_rest_api_manager.py Outdated Show resolved Hide resolved
@Mat001
Copy link
Contributor Author

Mat001 commented Aug 10, 2022

@jaeopt @andrewleap-optimizely I hope exception for invalid URL is handled ok. Request.Exception's class InvalidURL is not comprehensive at all. For example it doesn't catch https://api.zaius..com or XXhttps://api.zaius.com. For cases like these two I had to add other exceptions. If better idea how to guard against an invalid url lmk

I'm not super clear how swift does it, it seems it checks for exactly that url string?
guard let url = URL(string: "\(apiHost)/v3/events") else {
let canRetry = false
completionHandler(.odpEventFailed("Invalid url", canRetry))
return
}

@andrewleap-optimizely
Copy link
Contributor

I'm not super clear how swift does it, it seems it checks for exactly that url string? guard let url = URL(string: "\(apiHost)/v3/events") else { let canRetry = false completionHandler(.odpEventFailed("Invalid url", canRetry)) return }

We can accomplish something similar using urllib.parse.urlparse

@jaeopt
Copy link
Contributor

jaeopt commented Aug 10, 2022

@jaeopt @andrewleap-optimizely I hope exception for invalid URL is handled ok. Request.Exception's class InvalidURL is not comprehensive at all. For example it doesn't catch https://api.zaius..com or XXhttps://api.zaius.com. For cases like these two I had to add other exceptions. If better idea how to guard against an invalid url lmk

I'm not super clear how swift does it, it seems it checks for exactly that url string? guard let url = URL(string: "\(apiHost)/v3/events") else { let canRetry = false completionHandler(.odpEventFailed("Invalid url", canRetry)) return }

@Mat001 I understand that RequestException will catch these all.
I don't think we need this fine level of error handling, since this is not expected to happen (apiHost we control).
Can be cleaned up if needed. Swift checks url only for lang level requirement for optional filtering.

@Mat001
Copy link
Contributor Author

Mat001 commented Aug 11, 2022

@jaeopt @andrewleap-optimizely ok. I refactored. I got rid of the specific URL parsing exceptions and made it such that generic RequestEception catches invalid URL errors (may not include urlparse errors), but it guard against quite a few. And since we control the URL I wouldn't worry about this one, if that's ok

Copy link
Contributor

@jaeopt jaeopt left a comment

Choose a reason for hiding this comment

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

LGTM with a clarification

self.logger.error(Errors.ODP_EVENT_FAILED.format('invalid URL'))
can_retry = False
# retry on network errors
should_retry = True
except RequestException as err:
Copy link
Contributor

Choose a reason for hiding this comment

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

I think so, but can you confirm that this catches all other exceptions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

@andrewleap-optimizely andrewleap-optimizely left a comment

Choose a reason for hiding this comment

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

lgtm

@Mat001 Mat001 merged commit 998dbc7 into master Aug 12, 2022
@Mat001 Mat001 deleted the mpirnovar/odp_rest_api_manager branch August 12, 2022 16:00
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.

None yet

3 participants