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

New Registry Commands #1148

Merged
merged 22 commits into from
Jun 29, 2023
Merged

New Registry Commands #1148

merged 22 commits into from
Jun 29, 2023

Conversation

fritz-astronomer
Copy link
Contributor

@fritz-astronomer fritz-astronomer commented Apr 11, 2023

Description

  • astro registry dag add dbt-basic --version 1.0.4
    • add a DAG file (just the .py) directly from the registry, at the filepath defined by the registry, optionally add any providers.
  • astro registry provider add snowflake
    • add the provider to requirements.txt
  • astro registry dev init https://github.com/astronomer/my-project/
    • init a project from the registry

🧪 Functional Testing + 📸 Screenshots

List the functional testing steps to confirm this feature or fix.
Add screenshots to illustrate the validity of these changes.

registry_demo.mov

issue:

📋 Checklist

  • Rebased from the main (or release if patching) branch (before testing)
  • Ran make test before taking out of draft
  • Ran make lint before taking out of draft
  • Added/updated applicable tests
  • Tested against Astro-API (if necessary).
  • Tested against Houston-API and Astronomer (if necessary).
  • Communicated to/tagged owners of respective clients potentially impacted by these changes.
  • Updated any related documentation

@fritz-astronomer
Copy link
Contributor Author

First few commands complete. Want to add a few more quality-of-life things, and init

cmd/registry/root.go Outdated Show resolved Hide resolved
Copy link
Contributor

@iancmoritz iancmoritz left a comment

Choose a reason for hiding this comment

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

Fritz - this is fantastic. Super small changes overall but thank you!

cmd/registry/root.go Outdated Show resolved Hide resolved
cmd/registry/root.go Outdated Show resolved Hide resolved
cmd/registry/root.go Outdated Show resolved Hide resolved
cmd/registry/root.go Outdated Show resolved Hide resolved
cmd/registry/root.go Outdated Show resolved Hide resolved
return getProviderUrl.String()
}

func getProviderRoute(providerId string, providerVersion string) string {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
func getProviderRoute(providerId string, providerVersion string) string {
func getProviderRoute(providerName string, providerVersion string) string {

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 was considering apache-airflow-provider-snowflake an id and snowflake a name. And this one specifically takes the id not the name.
image

Copy link

@odaneau-astro odaneau-astro Apr 12, 2023

Choose a reason for hiding this comment

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

The airflow schema refers to apache-airflow-provider-snowflake as a "provider package name" and amazon would be the "provider name". see here: https://github.com/apache/airflow/blob/main/airflow/provider_info.schema.json

getProviderUrl := url.URL{
Scheme: "https",
Host: registryHost,
Path: fmt.Sprintf("%s/%s", registryApi, fmt.Sprintf(providerRoute, providerId, providerVersion)),
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Path: fmt.Sprintf("%s/%s", registryApi, fmt.Sprintf(providerRoute, providerId, providerVersion)),
Path: fmt.Sprintf("%s/%s", registryApi, fmt.Sprintf(providerRoute, providerName, providerVersion)),

@sunkickr sunkickr requested a review from jwitz April 21, 2023 15:25
@fritz-astronomer
Copy link
Contributor Author

Feedback notes:

  • Linting, add test coverage
  • command defs then functions
  • cmd.cloud.deployment_test, cloud.deployment_test.go
  • pkg.util.go
  • astro registry <dag|provider> <add|list>

Copy link
Contributor

@jwitz jwitz left a comment

Choose a reason for hiding this comment

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

Some minor copy review

cmd/registry/root.go Outdated Show resolved Hide resolved
cmd/registry/root.go Outdated Show resolved Hide resolved
cmd/registry/root.go Outdated Show resolved Hide resolved
cmd/registry/root.go Outdated Show resolved Hide resolved
cmd/registry/root.go Outdated Show resolved Hide resolved
cmd/registry/root.go Outdated Show resolved Hide resolved
cmd/registry/root.go Outdated Show resolved Hide resolved
cmd/registry/root.go Outdated Show resolved Hide resolved
cmd/registry/root.go Outdated Show resolved Hide resolved
cmd/registry/root.go Outdated Show resolved Hide resolved
@fritz-astronomer
Copy link
Contributor Author

fritz-astronomer commented Jun 8, 2023

Future work:

fritz-astronomer and others added 8 commits June 9, 2023 01:09
Co-authored-by: Ian Moritz <ian@alkeri.com>
Co-authored-by: Ian Moritz <ian@alkeri.com>
Co-authored-by: Jake Witz <74574233+jwitz@users.noreply.github.com>
Co-authored-by: Jake Witz <74574233+jwitz@users.noreply.github.com>
@codecov
Copy link

codecov bot commented Jun 20, 2023

Codecov Report

Patch coverage: 68.94% and project coverage change: -0.23 ⚠️

Comparison is base (9effcb1) 87.51% compared to head (8041598) 87.28%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1148      +/-   ##
==========================================
- Coverage   87.51%   87.28%   -0.23%     
==========================================
  Files         110      113       +3     
  Lines       12999    13160     +161     
==========================================
+ Hits        11376    11487     +111     
- Misses        949      986      +37     
- Partials      674      687      +13     
Impacted Files Coverage Δ
pkg/fileutil/files.go 76.92% <0.00%> (-2.45%) ⬇️
cmd/registry/dag.go 64.28% <64.28%> (ø)
cmd/registry/provider.go 72.94% <72.94%> (ø)
cmd/registry/root.go 76.92% <76.92%> (ø)
cmd/root.go 91.42% <100.00%> (+0.38%) ⬆️

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

Copy link
Contributor

@neel-astro neel-astro left a comment

Choose a reason for hiding this comment

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

left some minor comments around simplifying the logic to improve readability, LGTM otherwise

cmd/registry/dag_test.go Outdated Show resolved Hide resolved
cmd/registry/provider.go Outdated Show resolved Hide resolved
cmd/registry/provider.go Outdated Show resolved Hide resolved
pkg/util/util.go Outdated Show resolved Hide resolved
pkg/httputil/http.go Outdated Show resolved Hide resolved
cmd/registry/provider.go Outdated Show resolved Hide resolved
cmd/registry/provider.go Outdated Show resolved Hide resolved
cmd/registry/provider_test.go Outdated Show resolved Hide resolved
pkg/httputil/http.go Outdated Show resolved Hide resolved
pkg/httputil/http.go Outdated Show resolved Hide resolved
Copy link
Contributor

@neel-astro neel-astro left a comment

Choose a reason for hiding this comment

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

Great work and thanks for the contribution, this would be quite useful for users. Code LGTM, has left some final nits to squash.

cmd/registry/dag_test.go Show resolved Hide resolved
if err != nil {
log.Fatal(err)
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
defer f.Close()

nit: file close should be part of defer so that it is called from any return point in the function. Sorry I might have missed it in my earlier review

Copy link
Contributor Author

@fritz-astronomer fritz-astronomer Jun 21, 2023

Choose a reason for hiding this comment

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

The linter didn't like this because there are log.Fatal's below. I also unfortunately can't run the linter locally for some reason, so that wasn't fun to find a configuration it was happy with, beyond what you see here. Does the line in this location pass the linter for you?

Copy link
Contributor

Choose a reason for hiding this comment

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

ideally, we shouldn't have log.Fatal(), but rather have it as log.Error() and then return the error from the function, and then the caller should handle the error and act accordingly.

The linter is complaining because as of now f.Close() even if in defer won't be called if there is any log.Fatal() after that in the code execution path. It's not a big issue if we are just missing out on f.Close(), but ideally in Golang we don't exit abruptly and handle errors everywhere, which makes it simpler to maintain in the future.

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 makes sense. I'll see if I can address that

}
_, _ = fmt.Fprintf(out, "\nWrote %s to %s", providerString, filename)
}
_ = f.Close()
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
_ = f.Close()

nit: not needed once we have it as defer

cmd/registry/provider_test.go Show resolved Hide resolved
Co-authored-by: Neel Dalsania <neel.dalsania@astronomer.io>
filledDagRoute := fmt.Sprintf(dagRoute, dagID, dagVersion)
getDagURL := url.URL{
Scheme: "https",
Host: registryHost,
Copy link
Contributor

Choose a reason for hiding this comment

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

Would this work only on prod env?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

didn't take a dev registry into account yet

@kushalmalani
Copy link
Contributor

kushalmalani commented Jun 21, 2023

@fritz-astronomer Do these commands need to run in an airflow project? If yes, we need to add that check. Something we do for astro deploy

@fritz-astronomer
Copy link
Contributor Author

@kushalmalani - they don't actually need to. They just add an entry to a requirements.txt or download a file to a dags folder. I think in both instances the folder or file is created if it doesn't exist.

@sunkickr sunkickr merged commit cd1b3b4 into main Jun 29, 2023
@sunkickr sunkickr deleted the registry branch June 29, 2023 15:52
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.

7 participants