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

Updates to Orchestrator API for OSI #805

Merged
merged 11 commits into from
Jul 19, 2024

Conversation

lewijacn
Copy link
Collaborator

@lewijacn lewijacn commented Jul 9, 2024

Description

This changes introduces the following additions to the Console Orchestrator API

  • Update OSI Create API model to use URI field instead of host and port and remove unnecessary migration type field
  • Add serializer to verify received data for all API actions
  • Add delete action as another OSI API action
  • Add assume role ability to all OSI actions, this allows passing in a separate role for creating/updating/deleting pipelines that is different than the default task role of the container

Issues Resolved

https://opensearch.atlassian.net/browse/MIGRATIONS-1843

Testing

Unit testing, Cloud testing

Check List

  • New functionality includes testing
    • All tests pass, including unit test, integration test and doctest
  • New functionality has been documented
  • Commits are signed per the DCO using --signoff

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

…ine pattern, add assume role for all actions

Signed-off-by: Tanner Lewis <[email protected]>
Copy link

codecov bot commented Jul 9, 2024

Codecov Report

Attention: Patch coverage is 98.42520% with 2 lines in your changes missing coverage. Please review.

Project coverage is 88.45%. Comparing base (88b2de7) to head (6dfa278).
Report is 15 commits behind head on main.

Files Patch % Lines
...console_api/console_api/apps/orchestrator/views.py 93.93% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #805      +/-   ##
==========================================
+ Coverage   88.18%   88.45%   +0.26%     
==========================================
  Files          56       67      +11     
  Lines        3478     3723     +245     
==========================================
+ Hits         3067     3293     +226     
- Misses        411      430      +19     
Flag Coverage Δ
python-test 88.39% <100.00%> (+0.20%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Signed-off-by: Tanner Lewis <[email protected]>
Signed-off-by: Tanner Lewis <[email protected]>
# Conflicts:
#	TrafficCapture/dockerSolution/src/main/docker/migrationConsole/lib/console_link/tests/test_osi_utils.py
Signed-off-by: Tanner Lewis <[email protected]>
Signed-off-by: Tanner Lewis <[email protected]>
Copy link
Collaborator

@mikaylathompson mikaylathompson left a comment

Choose a reason for hiding this comment

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

A few questions, but no major concerns

- uses: codecov/codecov-action@v4
with:
files: ./coverage.xml

Copy link
Collaborator

Choose a reason for hiding this comment

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

Note for a follow up change in the sonarqube stuff to incorporate this

Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for creating this, yes we need to add

@@ -13,6 +13,8 @@ sqlparse = "==0.5.0"
pyopenssl = "*"

[dev-packages]
coverage = "*"
moto = "*"
Copy link
Collaborator

Choose a reason for hiding this comment

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

It looks like you can install moto with just the specific dependencies you want to mock (https://docs.getmoto.org/en/latest/docs/getting_started.html#installing-moto) -- worth doing? I assume we're mocking a pretty narrow list

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Went ahead and added the specifier for sts for moto, from my testing all decorators like mock_sts have been removed in favor of using the single mock_aws

}


# Moto has not yet implemented mocking for OSI API actions, using @patch for these calls
Copy link
Collaborator

Choose a reason for hiding this comment

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

So moto is basically handling/mocking creating the boto3 client? It looks like we could add the OSI actions directly to moto (like https://docs.getmoto.org/en/latest/docs/services/patching_other_services.html or via PR to their repo), but I think this approach is fine with me for now

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Switched to using patch for moto like you mentioned to give a little more flexibility here. Thanks for suggestion

create_pipeline_from_json(osi_client=determine_osi_client(request_data=request_data, action_name=action_name),
input_json=request_data,
pipeline_template_path=PIPELINE_TEMPLATE_PATH)
except InvalidAuthParameters as i:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Minor note that at some point, it would be great to have a test that exercised this branch, but not a blocker for this PR

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Have added a test for this now 👍

Comment on lines +99 to +106
def osi_start_migration(request):
return osi_update_workflow(request=request, osi_action_func=start_pipeline, action_name='Start')


@api_view(['POST'])
@parser_classes([JSONParser])
def osi_stop_migration(request):
request_data = request.data
logger.info(pretty_request(request, request_data))
return osi_update_workflow(request=request, osi_action_func=stop_pipeline, action_name='Stop')
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there/should there be validation that the pipeline exists for these actions? What happens if it doesn't?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I imagine users will get a 500 with the error message, that the pipeline doesn't exist. But agree this is likely a common error case we should test for and be more specific for like a 404 response code. Have created a task around this here: https://opensearch.atlassian.net/browse/MIGRATIONS-1877

@@ -57,6 +58,20 @@ def __init__(self, config: Dict) -> None:
self.tags = convert_str_tags_to_dict(tags)


def get_assume_role_session(role_arn, session_name) -> boto3.Session:
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd love to see an example of what the caller sees if this fails. It seems like one of the more likely to fail pieces, given the general complication of IAM stuff.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

From my testing, users will get a 500 and see the boto3 error message along the lines of Unable to assume role: .... for x reason. Which may be clear enough for now, but potentially something we could make more obvious

Signed-off-by: Tanner Lewis <[email protected]>
Signed-off-by: Tanner Lewis <[email protected]>
@lewijacn lewijacn merged commit 600022b into opensearch-project:main Jul 19, 2024
15 checks passed
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