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

[Console] OSI support for API and Console Library #680

Merged
merged 18 commits into from
May 29, 2024

Conversation

lewijacn
Copy link
Collaborator

@lewijacn lewijacn commented May 23, 2024

Description

This change refactors the previous OSI migration library to be a component of the new console library. Such that the following commands are now available from the console CLI:

Usage: console [OPTIONS] COMMAND [ARGS]...

Options:
  --config-file TEXT  Path to config file
  --json
  -v, --verbose       Verbosity level. Default is warn, -v is info, -vv is
                      debug.
  --help              Show this message and exit.

Commands:
  backfill  All actions related to historical/backfill data migrations
  clusters
  metrics
  replayer

Enter Backfill Options:

Usage: console backfill [OPTIONS] COMMAND [ARGS]...

  All actions related to historical/backfill data migrations

Options:
  --help  Show this message and exit.

Commands:
  create-migration  Create migration action
  start-migration   Start migration action
  stop-migration    Stop migration action

Along with this the three stubbed django APIs have now been implemented to also use this common library on the Migration console, giving the following endpoints:

curl -XPOST http://localhost:8000/orchestrator/osi-create-migration
curl -XPOST http://localhost:8000/orchestrator/osi-start-migration
curl -XPOST http://localhost:8000/orchestrator/osi-stop-migration

Issues Resolved

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

Is this a backport? If so, please add backport PR # and/or commits #

Testing

Local docker testing, unit 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.

lewijacn added 4 commits May 20, 2024 22:38
Signed-off-by: Tanner Lewis <lewijacn@amazon.com>
Signed-off-by: Tanner Lewis <lewijacn@amazon.com>
Signed-off-by: Tanner Lewis <lewijacn@amazon.com>
Signed-off-by: Tanner Lewis <lewijacn@amazon.com>
Copy link

codecov bot commented May 23, 2024

Codecov Report

Attention: Patch coverage is 74.43946% with 57 lines in your changes are missing coverage. Please review.

Project coverage is 73.60%. Comparing base (5b185fa) to head (3e83480).
Report is 3 commits behind head on e2e-tests-q2.

Files Patch % Lines
...rationConsole/lib/console_link/console_link/cli.py 0.00% 21 Missing ⚠️
.../lib/console_link/console_link/models/osi_utils.py 90.00% 15 Missing ⚠️
.../lib/console_link/console_link/models/migration.py 70.27% 11 Missing ⚠️
...b/console_link/console_link/logic/instantiation.py 0.00% 9 Missing ⚠️
...le/lib/console_link/console_link/models/cluster.py 83.33% 1 Missing ⚠️
Additional details and impacted files
@@                Coverage Diff                 @@
##             e2e-tests-q2     #680      +/-   ##
==================================================
- Coverage           75.33%   73.60%   -1.73%     
  Complexity           1416     1416              
==================================================
  Files                 150      160      +10     
  Lines                6147     6707     +560     
  Branches              561      561              
==================================================
+ Hits                 4631     4937     +306     
- Misses               1143     1397     +254     
  Partials              373      373              
Flag Coverage Δ
unittests 75.33% <ø> (ø)

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.

lewijacn added 2 commits May 23, 2024 19:59
…nsole-link

Signed-off-by: Tanner Lewis <lewijacn@amazon.com>
Signed-off-by: Tanner Lewis <lewijacn@amazon.com>
@lewijacn lewijacn marked this pull request as ready for review May 24, 2024 01:19
lewijacn added 5 commits May 24, 2024 11:22
Signed-off-by: Tanner Lewis <lewijacn@amazon.com>
…nsole-link

# Conflicts:
#	TrafficCapture/dockerSolution/src/main/docker/migrationConsole/lib/console_link/console_link/cli.py
#	TrafficCapture/dockerSolution/src/main/docker/migrationConsole/lib/console_link/console_link/logic/__init__.py
#	TrafficCapture/dockerSolution/src/main/docker/migrationConsole/lib/console_link/console_link/logic/instantiation.py
#	TrafficCapture/dockerSolution/src/main/docker/migrationConsole/lib/console_link/console_link/models/cluster.py
#	TrafficCapture/dockerSolution/src/main/docker/migrationConsole/lib/console_link/tests/requirements.txt
#	TrafficCapture/dockerSolution/src/main/docker/migrationConsole/osiMigration.py
Signed-off-by: Tanner Lewis <lewijacn@amazon.com>
Signed-off-by: Tanner Lewis <lewijacn@amazon.com>
Signed-off-by: Tanner Lewis <lewijacn@amazon.com>
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.

Super cool. Most of my comments are about organization. Open to pushback on them, or let me know if you think there's a preferable path where we keep it as is for now and refactor in the near-ish future.

logger.info(pretty_request(request, request_data))

osi_serializer = OpenSearchIngestionCreateRequestSerializer(data=request_data)
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is super nice!

response_data = {
'Timestamp': datetime.datetime.now(datetime.timezone.utc)
'Timestamp': datetime.datetime.now(datetime.timezone.utc),
'MigrationType': MigrationType.OSI_HISTORICAL_MIGRATION
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this a thing that DMS has requested? I'm fine with it, but not sure exactly why we need it

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

They haven't and in its current context isn't super useful. I originally was going to have this function not be specific to a certain type of migration and this would have been more useful.

OSI_HISTORICAL_MIGRATION = "OSI_HISTORICAL_MIGRATION"


class Migration():
Copy link
Collaborator

Choose a reason for hiding this comment

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

can we make this Backfill or Historical? I think a Migration will be a very high level class that includes the full context of backfill, a replay, possibly validation, switchover, etc.

@@ -1,3 +1,5 @@
-e ../lib/console_link
Copy link
Collaborator

Choose a reason for hiding this comment

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

in the future, we probably don't want -e (editable install) but it's very helpful for testing in the short term. just worth adding a note that it shouldn't make it to production.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Agreed, have added a comment here as a reminder

Comment on lines +19 to +22
- AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}
- AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}
- AWS_SESSION_TOKEN=${AWS_SESSION_TOKEN}
- AWS_DEFAULT_REGION=${AWS_DEFAULT_REGION}
Copy link
Collaborator

Choose a reason for hiding this comment

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

this approach vs. mounting the ~/.aws directory -- is there a benefit? I don't think I know either approach well enough to have a preference, but standardization > not-standardization.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Curious how you typically load credentials? I think my ~/.aws is pretty much empty and I normally am only using environment variables

Comment on lines 73 to 76
try:
self.auth_details = config["authorization"]["details"]
except KeyError:
self.auth_details = None
Copy link
Collaborator

Choose a reason for hiding this comment

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

in general, I think self.auth_details = config["authorization"].get("details", None) is a little more concise and clearer. I'd do try/except in this case if we intended to do a more complicated behavior or throw an error if it were missing.

not a blocker though.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Definitely cleaner, updated

Comment on lines +13 to +17
'type': 'list',
'required': True,
'schema': {
'type': 'string',
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

this syntax means "list of strings"? 👍

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes!

if not v.validate(config):
raise ValueError("Invalid config file for OpenSearchIngestion migration", v.errors)
self.osi_props = OpenSearchIngestionMigrationProps(config=config)
self.migration_logic = OSIMigrationLogic()
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is interesting. I'm not opposed to it, but I had been picturing logic imports models, not models imports logic. I'm game to play with it for now and see what we end up with. The risk of having both directions right now is that we're going to run into circular imports at some point, but we can play with it until we hit that.

Copy link
Collaborator

Choose a reason for hiding this comment

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

One point of consideration, I guess -- are there any contexts outside of this class that will use the OSIMigrationLogic? If not, I'd tend to make them internal methods of this class.

My thought was that logic would be used to make sure that the users of the library could remain as thin as possible--so catIndices goes in the logic module because 1. it means that callers don't have to know anything about the exact endpoint or how to call it, but 2. it would be the same logic for all Clusters, regardless of type, so there's no reason to re-implement it multiple times in each class.

I don't know if that's the optimal approach, very open to discussion on it. But I'd tend to say that if the OSIMigrationLogic stuff is more "internal" it should go inside this class or into a osi_utils sort of spot.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Per discussion, have moved all implementation details out of logic and they now reside in osi_utils. Still expecting a middleware layer that will create this OpenSearchIngestionMigration from the raw input it receives

target_cluster=self.target_cluster,
print_config_only=print_config_only)

def create_from_json(self, config_json: Dict, pipeline_template_path: str) -> None:
Copy link
Collaborator

Choose a reason for hiding this comment

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

minor, probably an internal only class (because it's not part of the base class interface), so can be _create_from_json

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 removed this function for now

- `authorization`: optional, if it is provided, type is required.
- `type`: required, the only currently implemented option is "basic", but "sigv4" should be available soon
- `authorization`: required, the auth method to use, if no auth the no_auth type must be specified.
- `type`: required, the only currently implemented options are "no_auth" and "basic", but "sigv4" should be available soon
Copy link
Collaborator

Choose a reason for hiding this comment

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

mind updating this to "basic_auth"? (in the example yaml above as well)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated these spots now

lewijacn added 4 commits May 24, 2024 17:26
Signed-off-by: Tanner Lewis <lewijacn@amazon.com>
Signed-off-by: Tanner Lewis <lewijacn@amazon.com>
…nsole-link

# Conflicts:
#	TrafficCapture/dockerSolution/src/main/docker/migrationConsole/lib/console_link/tests/requirements.txt
Copy link
Collaborator Author

@lewijacn lewijacn left a comment

Choose a reason for hiding this comment

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

Addressing some minor items now, but some design decisions here need further updates that I will address in this PR later

response_data = {
'Timestamp': datetime.datetime.now(datetime.timezone.utc)
'Timestamp': datetime.datetime.now(datetime.timezone.utc),
'MigrationType': MigrationType.OSI_HISTORICAL_MIGRATION
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

They haven't and in its current context isn't super useful. I originally was going to have this function not be specific to a certain type of migration and this would have been more useful.

@@ -1,3 +1,5 @@
-e ../lib/console_link
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Agreed, have added a comment here as a reminder

Comment on lines +19 to +22
- AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}
- AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}
- AWS_SESSION_TOKEN=${AWS_SESSION_TOKEN}
- AWS_DEFAULT_REGION=${AWS_DEFAULT_REGION}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Curious how you typically load credentials? I think my ~/.aws is pretty much empty and I normally am only using environment variables

- `authorization`: optional, if it is provided, type is required.
- `type`: required, the only currently implemented option is "basic", but "sigv4" should be available soon
- `authorization`: required, the auth method to use, if no auth the no_auth type must be specified.
- `type`: required, the only currently implemented options are "no_auth" and "basic", but "sigv4" should be available soon
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated these spots now

# ##################### OSI ###################

@cli.command(name="osi-create-migration")
@click.option('--pipeline-template-file', default='/root/osiPipelineTemplate.yaml', help='Path to config file')
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

By default we will use the pipeline template file in the starting directory of the migration console, but allowing this option is nice for more involved cases

Comment on lines 18 to 25
'authorization': {
'type': 'dict',
'required': True,
'schema': {
'type': {
'type': 'string',
'required': True,
'allowed': [e.name.lower() for e in AuthMethod]
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Let me at least update so there is consistent quote usage

Comment on lines 69 to 72
try:
self.auth_type = AuthMethod[config["authorization"]["type"].upper()]
except KeyError:
self.auth_type = None
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You're right, updated

Comment on lines 73 to 76
try:
self.auth_details = config["authorization"]["details"]
except KeyError:
self.auth_details = None
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Definitely cleaner, updated

Comment on lines +13 to +17
'type': 'list',
'required': True,
'schema': {
'type': 'string',
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes!

Signed-off-by: Tanner Lewis <lewijacn@amazon.com>
Signed-off-by: Tanner Lewis <lewijacn@amazon.com>
@mikaylathompson mikaylathompson self-requested a review May 28, 2024 22:47
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.

🚢

Copy link
Member

@peternied peternied left a comment

Choose a reason for hiding this comment

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

I think there might be some linger comment threads, not sure if you'd want to follow up on them or not. but I think it would be great to merge this change onto the feature branch.

Signed-off-by: Tanner Lewis <lewijacn@amazon.com>
@lewijacn lewijacn merged commit 9f167bd into opensearch-project:e2e-tests-q2 May 29, 2024
5 of 8 checks passed
@lewijacn lewijacn deleted the osi-to-console-link branch October 10, 2024 17:49
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.

3 participants