-
Notifications
You must be signed in to change notification settings - Fork 62
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
Refactor bundle init
#2074
base: main
Are you sure you want to change the base?
Refactor bundle init
#2074
Conversation
If integration tests don't run automatically, an authorized user can run them manually by following the instructions below: Trigger: Inputs:
Checks will be approved automatically on success. |
} | ||
|
||
// Return template descriptions for command-line help | ||
func nativeTemplateHelpDescriptions() string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved totemplate.HelpDescriptions()
} | ||
|
||
// Return template options for an interactive prompt | ||
func nativeTemplateOptions() []cmdio.Tuple { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved to template.options()
return names | ||
} | ||
|
||
func getNativeTemplateByDescription(description string) string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved inline to template. SelectTemplate()
return "" | ||
} | ||
|
||
func getUrlForNativeTemplate(name string) string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replaced by template.Get()
return "" | ||
} | ||
|
||
func getFsForNativeTemplate(name string) (fs.FS, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replaced by template.Reader.FS()
method.
return parts[len(parts)-1] | ||
} | ||
|
||
func constructOutputFiler(ctx context.Context, outputDir string) (filer.Filer, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved to template.constructOutputFiler
. Also added unit tests for it in TestDefaultWriterConfigure
and TestDefaultWriterConfigureOnDBR
@@ -198,92 +38,32 @@ See https://docs.databricks.com/en/dev-tools/bundles/templates.html for more inf | |||
|
|||
cmd.PreRunE = root.MustWorkspaceClient | |||
cmd.RunE = func(cmd *cobra.Command, args []string) error { | |||
if tag != "" && branch != "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved over to template.Resolver.Resolve
. This allows us to easily write unit tests for the function.
@@ -16,7 +16,7 @@ import ( | |||
"github.com/databricks/databricks-sdk-go/service/workspace" | |||
) | |||
|
|||
type workspaceFilesExtensionsClient struct { | |||
type WorkspaceFilesExtensionsClient struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made public for assertion in TestDefaultWriterConfigureOnDBR
// configFilePath: file path containing user defined config values | ||
// templateFS: root of the template definition | ||
// outputFiler: filer to use for writing the initialized template | ||
func Materialize(ctx context.Context, configFilePath string, templateFS fs.FS, outputFiler filer.Filer) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic Moved to defaultWriter{}
struct in this library
type Writer interface { | ||
Configure(ctx context.Context, configPath, outputDir string) error | ||
Materialize(ctx context.Context, r Reader) error | ||
LogTelemetry(ctx context.Context) error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function does nothing right now. Telemetry functionality will be added in a followup PR.
Integration tests were green, and after a while, I made a few linting commits. Triggered another run of the integration tests. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not completely clear what parts are just moved and which are new, could you summarize that in PR description?
@denik Thanks! I redid the PR summary. Hopefully that makes it more legible what exactly changed. |
Summary of changes
This PR introduces three new abstractions:
Resolver
: Resolves which reader and writer to use for a template.Writer
: Writes a template project to disk. Prompts the user if necessary.Reader
: Reads a template specification from disk, built into the CLI or from GitHub.Introducing these abstractions helps decouple reading a template from writing it. When I tried adding telemetry for the
bundle init
command, I noticed that the code incmd/init.go
was getting convoluted and hard to test. A future change could have accidentally logged PII when a user initialised a custom template.Hedging against that risk is important here because we use a generic untyped
map<string, string>
representation in the backend to log telemetry for thedatabricks bundle init
. Otherwise, we risk accidentally breaking our compliance with our centralization requirements.Details
After this PR there are two classes of templates that can be initialized:
databricks
template: This could be a builtin template or a template outside the CLI like mlops-stacks, which is still owned and managed by Databricks. These templates log their telemetry arguments and template name.custom
template: These are templates created by and managed by the end user. In these templates we do not log the template name and args. Instead a generic placeholder string of "custom" is logged in our telemetry system.NOTE: The functionality of the
databricks bundle init
command remains the same after this PR. Only the internal abstractions used are changed.Tests
New unit tests. Existing golden and unit tests. Also a fair bit of manual testing.