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

ref(admin): add migration groups list endpoint #3231

Merged
merged 2 commits into from
Oct 13, 2022

Conversation

dbanda
Copy link
Contributor

@dbanda dbanda commented Oct 6, 2022

More context in #3227

Add an endpoint migrations/{group}/list to show the migration for a group. Returns error 400 : invalid group if the group is not found

e.g

curl http: //localhost:1219/migrations/replays/list 

[{
      "blocking": false,
      "migration_id": "0001_replays",
      "status": "completed"
}, .... {
      "blocking": false,
      "migration_id": "0006_add_is_archived_column",
      "status": "completed"
}]

@dbanda dbanda marked this pull request as ready for review October 6, 2022 21:59
@dbanda dbanda requested a review from a team as a code owner October 6, 2022 21:59
@codecov-commenter
Copy link

codecov-commenter commented Oct 6, 2022

Codecov Report

Base: 92.30% // Head: 92.30% // Increases project coverage by +0.00% 🎉

Coverage data is based on head (319ba83) compared to base (a77edea).
Patch coverage: 96.77% of modified lines in pull request are covered.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #3231   +/-   ##
=======================================
  Coverage   92.30%   92.30%           
=======================================
  Files         697      697           
  Lines       31630    31660   +30     
=======================================
+ Hits        29195    29224   +29     
- Misses       2435     2436    +1     
Impacted Files Coverage Δ
snuba/admin/views.py 76.84% <90.00%> (+0.55%) ⬆️
tests/admin/clickhouse_migrations/test_api.py 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Member

@evanh evanh 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 you should also restrict this endpoint using the setting that Meredith added in #3227.

To that end, I think actually the best practice here would be to add a middleware that checks the group being referenced is allowed, and add it to every endpoint you create.

Comment on lines 48 to 49
def sort_by_migration_id(migration: Any) -> Any:
return migration["migration_id"]
Copy link
Member

Choose a reason for hiding this comment

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

How come sorting by migration ID? Although by convention we use incrementing numbers for migration IDs, this is just a convention and the ordering is defined explicitly by the migration group.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was just to compare the lists in the assert.

@@ -73,6 +75,27 @@ def health() -> Response:
return Response("OK", 200)


@application.route("/migrations/<group>/list")
Copy link
Member

@lynnagara lynnagara Oct 7, 2022

Choose a reason for hiding this comment

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

Just a thought but would it be easier to return the list of all migrations by group? (basically equivalent to what the snuba migrations list command outputs)? There's really hardly any data, and the UI could easily filter them. The groups and ordering of those groups would also be present there so you wouldn't need to fire so many API calls making the frontend code a lot less complex to write.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that would be easier, but the plan is to have some access control so users can only list the allowed groups.

Copy link
Member

@MeredithAnya MeredithAnya left a comment

Choose a reason for hiding this comment

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

LGTM but I did add a separate testing file for clickhouse_migrations just so the test_api doesn't get to long if you wanted to add to https://github.com/getsentry/snuba/pull/3227/files

@@ -73,6 +75,27 @@ def health() -> Response:
return Response("OK", 200)


@application.route("/migrations/<group>/list")
def migrations_groups(group: str) -> Response:
Copy link
Member

Choose a reason for hiding this comment

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

Is this supposed to be run on a per host basis? Like the system queries one where you select the host on which you want to run the command?

Copy link
Member

Choose a reason for hiding this comment

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

This should connect to the migrations cluster for which there is only one node as far as I know

@dbanda dbanda force-pushed the dbanda/SNS-1743-list-migrations branch from 577a257 to 319ba83 Compare October 13, 2022 00:22
@dbanda dbanda enabled auto-merge (squash) October 13, 2022 00:39
@dbanda dbanda merged commit 6a0dc69 into master Oct 13, 2022
@dbanda dbanda deleted the dbanda/SNS-1743-list-migrations branch October 13, 2022 00:42
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.

6 participants