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

[RFC] First-class catalog and schema setting #1979

Open
wants to merge 30 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
6a7d31f
Add proof of concept for catalog/schema presets
lennartkats-db Oct 20, 2024
7fb646a
WIP
lennartkats-db Oct 22, 2024
480d308
Merge remote-tracking branch 'databricks/main' into presets-catalog-s…
lennartkats-db Nov 2, 2024
c1f5b3c
Use a helper notebook to set catalog/schema
lennartkats-db Nov 2, 2024
3ca2e67
Merge remote-tracking branch 'databricks/main' into presets-catalog-s…
lennartkats-db Dec 1, 2024
487884b
WIP
lennartkats-db Dec 2, 2024
963f5e6
Add translate_paths.GetLocalPath
lennartkats-db Dec 6, 2024
2addd0c
Extend catalog/schema preset support
lennartkats-db Dec 6, 2024
2ab497d
Tweak templates
lennartkats-db Dec 8, 2024
b6fcc1d
Cleanup
lennartkats-db Dec 9, 2024
d4977c6
WIP test
lennartkats-db Dec 10, 2024
a08b59d
Add comments
lennartkats-db Dec 10, 2024
7d1f8ad
Add TODO
lennartkats-db Dec 11, 2024
6b5948c
Add serving end point support
lennartkats-db Dec 14, 2024
35bed3f
Add experimental test
lennartkats-db Dec 14, 2024
3e1e169
Add reflection/dyn-based tests
lennartkats-db Dec 16, 2024
70f54dc
Add missing fields
lennartkats-db Dec 16, 2024
6d63b31
Refine test
lennartkats-db Dec 19, 2024
feb23dd
Move catalog/schema preset logic to a separate module
lennartkats-db Dec 19, 2024
65f10d1
Cleanup
lennartkats-db Dec 20, 2024
e0b6fad
Add a recommendation for pipeline catalogs
lennartkats-db Dec 20, 2024
8eb96cc
Cleanup
lennartkats-db Dec 20, 2024
86cf7e0
Restore Target logic
lennartkats-db Dec 20, 2024
8c2eaab
Merge remote-tracking branch 'origin/main' into presets-catalog-schem…
lennartkats-db Dec 20, 2024
be08585
presets-catalog-schema-as-params # Your branch is ahead of 'origin/pr…
lennartkats-db Dec 20, 2024
fbd4760
Fix test
lennartkats-db Dec 20, 2024
f3923da
Cleanup
lennartkats-db Dec 20, 2024
6d5cb1d
Add volumes and clean room notebooks
lennartkats-db Dec 20, 2024
0acb222
Fix silly lint error
lennartkats-db Dec 20, 2024
204d3b0
Cleanup
lennartkats-db Dec 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 22 additions & 21 deletions bundle/config/mutator/apply_presets.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ type applyPresets struct{}

// Apply all presets, e.g. the prefix presets that
// adds a prefix to all names of all resources.
//
// Note that the catalog/schema presets are applied in ApplyPresetsCatalogSchema.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

apply_presets is becoming a bit too large. For the new addition, I moved everything to a separate file. Lots of boring but easy to read/test code there.

As a followup we should look into a further refactoring: either factoring the logic by preset feature or by resource. For some of the overarching tests it's certainly been better to do it by feature, but we could end up with some combination for the tests.

func ApplyPresets() *applyPresets {
return &applyPresets{}
}
Expand Down Expand Up @@ -84,6 +86,7 @@ func (m *applyPresets) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnos
}

// Pipelines presets: Prefix, PipelinesDevelopment
// Not supported: Tags (not in API as of 2024-12)
for key, p := range r.Pipelines {
if p.PipelineSpec == nil {
diags = diags.Extend(diag.Errorf("pipeline %s is not defined", key))
Expand All @@ -96,7 +99,6 @@ func (m *applyPresets) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnos
if t.TriggerPauseStatus == config.Paused {
p.Continuous = false
}
// As of 2024-06, pipelines don't yet support tags
}

// Models presets: Prefix, Tags
Expand Down Expand Up @@ -146,52 +148,50 @@ func (m *applyPresets) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnos
}

// Model serving endpoint presets: Prefix
// Not supported: Tags (not in API as of 2024-12)
for key, e := range r.ModelServingEndpoints {
if e.CreateServingEndpoint == nil {
diags = diags.Extend(diag.Errorf("model serving endpoint %s is not defined", key))
continue
}
e.Name = normalizePrefix(prefix) + e.Name

// As of 2024-06, model serving endpoints don't yet support tags
}

// Registered models presets: Prefix
// Not supported: Tags (not in API as of 2024-12)
for key, m := range r.RegisteredModels {
if m.CreateRegisteredModelRequest == nil {
diags = diags.Extend(diag.Errorf("registered model %s is not defined", key))
continue
}
m.Name = normalizePrefix(prefix) + m.Name

// As of 2024-06, registered models don't yet support tags
}

// Quality monitors presets: Schedule
if t.TriggerPauseStatus == config.Paused {
for key, q := range r.QualityMonitors {
if q.CreateMonitor == nil {
diags = diags.Extend(diag.Errorf("quality monitor %s is not defined", key))
continue
}
// Remove all schedules from monitors, since they don't support pausing/unpausing.
// Quality monitors might support the "pause" property in the future, so at the
// CLI level we do respect that property if it is set to "unpaused."
// Not supported: Tags (not in API as of 2024-12)
for key, q := range r.QualityMonitors {
if q.CreateMonitor == nil {
diags = diags.Extend(diag.Errorf("quality monitor %s is not defined", key))
continue
}
// Remove all schedules from monitors, since they don't support pausing/unpausing.
// Quality monitors might support the "pause" property in the future, so at the
// CLI level we do respect that property if it is set to "unpaused."
if t.TriggerPauseStatus == config.Paused {
if q.Schedule != nil && q.Schedule.PauseStatus != catalog.MonitorCronSchedulePauseStatusUnpaused {
q.Schedule = nil
}
}
}

// Schemas: Prefix
// Not supported: Tags (only supported in Databricks UI / SQL API as of 2024-12)
for key, s := range r.Schemas {
if s.CreateSchema == nil {
diags = diags.Extend(diag.Errorf("schema %s is not defined", key))
continue
}
s.Name = normalizePrefix(prefix) + s.Name
// HTTP API for schemas doesn't yet support tags. It's only supported in
// the Databricks UI and via the SQL API.
}

// Clusters: Prefix, Tags
Expand All @@ -205,10 +205,10 @@ func (m *applyPresets) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnos
c.CustomTags = make(map[string]string)
}
for _, tag := range tags {
normalisedKey := b.Tagging.NormalizeKey(tag.Key)
normalisedValue := b.Tagging.NormalizeValue(tag.Value)
if _, ok := c.CustomTags[normalisedKey]; !ok {
c.CustomTags[normalisedKey] = normalisedValue
normalizedKey := b.Tagging.NormalizeKey(tag.Key)
normalizedValue := b.Tagging.NormalizeValue(tag.Value)
if _, ok := c.CustomTags[normalizedKey]; !ok {
c.CustomTags[normalizedKey] = normalizedValue
}
}
}
Expand Down Expand Up @@ -246,6 +246,7 @@ func (m *applyPresets) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnos
return diags
}

// validatePauseStatus checks the user-provided pause status is valid.
func validatePauseStatus(b *bundle.Bundle) diag.Diagnostics {
p := b.Config.Presets.TriggerPauseStatus
if p == "" || p == config.Paused || p == config.Unpaused {
Expand All @@ -259,7 +260,7 @@ func validatePauseStatus(b *bundle.Bundle) diag.Diagnostics {
}

// toTagArray converts a map of tags to an array of tags.
// We sort tags so ensure stable ordering.
// We sort tags to ensure stable ordering.
func toTagArray(tags map[string]string) []Tag {
var tagArray []Tag
if tags == nil {
Expand Down
Loading
Loading