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

Rewrite relative paths using dyn.Location of the underlying value #1273

Merged
merged 20 commits into from
Mar 18, 2024

Conversation

pietern
Copy link
Contributor

@pietern pietern commented Mar 11, 2024

Changes

This change addresses the path resolution behavior in resource definitions. Previously, all paths were resolved relative to where the resource was first defined, which could lead to confusion and errors when paths were specified in different directories. The new behavior is to resolve paths relative to where they are defined, making it more intuitive.

However, to avoid breaking existing configurations, compatibility with the old behavior is maintained.

Tests

  • Existing unit tests for path translation pass.
  • Additional test to cover both the nominal and the fallback behavior.

@codecov-commenter
Copy link

codecov-commenter commented Mar 18, 2024

Codecov Report

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

Project coverage is 52.32%. Comparing base (e22dd8a) to head (3027df6).

Files Patch % Lines
bundle/config/mutator/translate_paths_artifacts.go 70.37% 7 Missing and 1 partial ⚠️
bundle/config/mutator/translate_paths_jobs.go 95.08% 2 Missing and 1 partial ⚠️
bundle/config/mutator/translate_paths_pipelines.go 94.59% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1273      +/-   ##
==========================================
+ Coverage   52.25%   52.32%   +0.07%     
==========================================
  Files         317      318       +1     
  Lines       18004    18016      +12     
==========================================
+ Hits         9408     9427      +19     
+ Misses       7903     7894       -9     
- Partials      693      695       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@pietern pietern changed the title Rewrite relative paths using dyn.Location of the underlying value Rewrite relative paths using dyn.Location of the underlying value Mar 18, 2024
))
require.NoError(t, err)
return b
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note: this is a copy from bundle/tests/loader.go to use it from the glob test. Follow up: move the glob test to the parent package so that it can use the reference loader.

ctx := context.Background()
err := bundle.Apply(ctx, b, phases.Initialize())
require.ErrorContains(t, err, "notebook ./non-existent not found")
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These changes were needed because this change no longer has an observable side effect on the configuration if it is partially OK. If there is an error, none of the path translations are persisted in the config.

}
return err
}
return nv, nil
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 function performs the fallback. If a rewrite with first dir doesn't work, it tries a rewrite with the second dir.

base := dyn.NewPattern(
dyn.Key("artifacts"),
dyn.AnyKey(),
)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note: because artifacts use the translateNoOp translation (which doesn't check if a path exists), the fallback never kicks in. This is why I didn't include fallback for artifact blocks.

We could implement this as long as we check if the directory for the artifact exists, which on its own could cause issues (not sure about the guarantees, though I expect the directory has to exist).

@pietern pietern marked this pull request as ready for review March 18, 2024 12:32
@pietern pietern requested a review from andrewnester March 18, 2024 12:32
@pietern
Copy link
Contributor Author

pietern commented Mar 18, 2024

Integration tests pass.

@pietern pietern added this pull request to the merge queue Mar 18, 2024
Merged via the queue into main with commit 7c4b349 Mar 18, 2024
4 checks passed
@pietern pietern deleted the dyn-translate-paths branch March 18, 2024 16:31
github-merge-queue bot pushed a commit that referenced this pull request Mar 19, 2024
## Changes

While working on #1273, I found that calls to `Append` on a
`dyn.Pattern` were mutating the original slice. This is expected because
appending to a slice will mutate in place if the capacity of the
original slice is large enough. This change updates the `Append` call on
the `dyn.Path` as well to return a newly allocated slice to avoid
inadvertently mutating the originals.

We have existing call sites in the `dyn` package that mutate a
`dyn.Path` (e.g. walk or visit) and these are modified to continue to do
this with a direct call to `append`. Callbacks that use the `dyn.Path`
argument outside of the callback need to make a copy to ensure it isn't
mutated (this is no different from existing semantics).

The `Join` function wasn't used and is removed as part of this change.

## Tests

Unit tests.
pietern added a commit that referenced this pull request Mar 25, 2024
CLI:
 * Propagate correct `User-Agent` for CLI during OAuth flow ([#1264](#1264)).
 * Add usage string when command fails with incorrect arguments ([#1276](#1276)).

Bundles:
 * Include `dyn.Path` as argument to the visit callback function ([#1260](#1260)).
 * Inline logic to set a value in `dyn.SetByPath` ([#1261](#1261)).
 * Add assertions for the `dyn.Path` argument to the visit callback ([#1265](#1265)).
 * Add `dyn.MapByPattern` to map a function to values with matching paths ([#1266](#1266)).
 * Filter current user from resource permissions ([#1262](#1262)).
 * Retain location annotation when expanding globs for pipeline libraries ([#1274](#1274)).
 * Added deployment state for bundles ([#1267](#1267)).
 * Do CheckRunningResource only after terraform.Write ([#1292](#1292)).
 * Rewrite relative paths using `dyn.Location` of the underlying value ([#1273](#1273)).
 * Push deployment state right after files upload ([#1293](#1293)).
 * Make `Append` function to `dyn.Path` return independent slice ([#1295](#1295)).
 * Move bundle tests into bundle/tests ([#1299](#1299)).
 * Upgrade Terraform provider to 1.38.0 ([#1308](#1308)).

Internal:
 * Add integration test for mlops-stacks initialization ([#1155](#1155)).
 * Update actions/setup-python to v5 ([#1290](#1290)).
 * Update codecov/codecov-action to v4 ([#1291](#1291)).

API Changes:
 * Changed `databricks catalogs list` command.
 * Changed `databricks online-tables create` command.
 * Changed `databricks lakeview publish` command.
 * Added `databricks lakeview create` command.
 * Added `databricks lakeview get` command.
 * Added `databricks lakeview get-published` command.
 * Added `databricks lakeview trash` command.
 * Added `databricks lakeview update` command.
 * Moved settings related commands to `databricks settings` and `databricks account settings`.

OpenAPI commit 93763b0d7ae908520c229c786fff28b8fd623261 (2024-03-20)

Dependency updates:
 * Bump golang.org/x/oauth2 from 0.17.0 to 0.18.0 ([#1270](#1270)).
 * Bump golang.org/x/mod from 0.15.0 to 0.16.0 ([#1271](#1271)).
 * Update Go SDK to v0.35.0 ([#1300](#1300)).
 * Update Go SDK to v0.36.0 ([#1304](#1304)).
@pietern pietern mentioned this pull request Mar 25, 2024
github-merge-queue bot pushed a commit that referenced this pull request Mar 25, 2024
CLI:
* Propagate correct `User-Agent` for CLI during OAuth flow
([#1264](#1264)).
* Add usage string when command fails with incorrect arguments
([#1276](#1276)).

Bundles:
* Include `dyn.Path` as argument to the visit callback function
([#1260](#1260)).
* Inline logic to set a value in `dyn.SetByPath`
([#1261](#1261)).
* Add assertions for the `dyn.Path` argument to the visit callback
([#1265](#1265)).
* Add `dyn.MapByPattern` to map a function to values with matching paths
([#1266](#1266)).
* Filter current user from resource permissions
([#1262](#1262)).
* Retain location annotation when expanding globs for pipeline libraries
([#1274](#1274)).
* Added deployment state for bundles
([#1267](#1267)).
* Do CheckRunningResource only after terraform.Write
([#1292](#1292)).
* Rewrite relative paths using `dyn.Location` of the underlying value
([#1273](#1273)).
* Push deployment state right after files upload
([#1293](#1293)).
* Make `Append` function to `dyn.Path` return independent slice
([#1295](#1295)).
* Move bundle tests into bundle/tests
([#1299](#1299)).
* Upgrade Terraform provider to 1.38.0
([#1308](#1308)).

Internal:
* Add integration test for mlops-stacks initialization
([#1155](#1155)).
* Update actions/setup-python to v5
([#1290](#1290)).
* Update codecov/codecov-action to v4
([#1291](#1291)).

API Changes:
 * Changed `databricks catalogs list` command.
 * Changed `databricks online-tables create` command.
 * Changed `databricks lakeview publish` command.
 * Added `databricks lakeview create` command.
 * Added `databricks lakeview get` command.
 * Added `databricks lakeview get-published` command.
 * Added `databricks lakeview trash` command.
 * Added `databricks lakeview update` command.
* Moved settings related commands to `databricks settings` and
`databricks account settings`.

OpenAPI commit 93763b0d7ae908520c229c786fff28b8fd623261 (2024-03-20)

Dependency updates:
* Bump golang.org/x/oauth2 from 0.17.0 to 0.18.0
([#1270](#1270)).
* Bump golang.org/x/mod from 0.15.0 to 0.16.0
([#1271](#1271)).
* Update Go SDK to v0.35.0
([#1300](#1300)).
* Update Go SDK to v0.36.0
([#1304](#1304)).
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