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

Consolidate environment variable interaction #747

Merged
merged 3 commits into from
Sep 11, 2023
Merged

Conversation

pietern
Copy link
Contributor

@pietern pietern commented Sep 7, 2023

Changes

There are a couple places throughout the code base where interaction with environment variables takes place. Moreover, more than one of these would try to read a value from more than one environment variable as fallback (for backwards compatibility). This change consolidates those accesses.

The majority of diffs in this change are mechanical (i.e. add an argument or replace a call).

This change:

  • Moves common environment variable lookups for bundles to bundles/env.
  • Adds a libs/env package that wraps os.LookupEnv and os.Getenv and allows for overrides to take place in a context.Context. By scoping overrides to a context.Context we can avoid t.Setenv in testing and unlock parallel test execution for integration tests.
  • Updates call sites to pass through a context.Context where needed.
  • For bundles, introduces DATABRICKS_BUNDLE_ROOT as new primary variable instead of BUNDLE_ROOT. This was the last environment variable that did not use the DATABRICKS_ prefix.

Tests

Unit tests pass.

There are a couple places throughout the code base where interaction with
environment variables takes place. Moreover, more than one of these would try
to read a value from more than one environment variable as fallback (for
backwards compatibility). This change consolidates those accesses.

The majority of diffs in this change are mechanical (i.e. add an argument or
replace a call).

This change:
* Moves common environment variable lookups for bundles to `bundles/env`.
* Adds a `libs/env` package that wraps `os.LookupEnv` and `os.Getenv` and
  allows for overrides to take place in a `context.Context`. By scoping
  overrides to a `context.Context` we can avoid `t.Setenv` in testing and
  unlock parallel test execution.
* Updates call sites to pass through a `context.Context` where needed.
* For bundles, introduces `DATABRICKS_BUNDLE_ROOT` as new primary variable
  instead of `BUNDLE_ROOT`. This was the last environment variable that did not
  use the `DATABRICKS_` prefix.

// format is <DATABRICKS_BUNDLE_TMP>/<target>
assert.NoError(t, err)
assert.Equal(t, filepath.Join(bundleTmpDir, "default"), cacheDir)
}

func TestBundleMustLoadSuccess(t *testing.T) {
t.Setenv(envBundleRoot, "./tests/basic")
t.Setenv(env.RootVariable, "./tests/basic")
Copy link
Contributor

Choose a reason for hiding this comment

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

shall we use envlib.Set(ctx, env.RootVariable, "./tests/basic") here instead already? Or in general what is our plan to get rid of t.Setenv?

Copy link
Contributor

Choose a reason for hiding this comment

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

We have (and will have) a couple of long running tests that should be parallelized. We don't have to parallelise all tests IMO, for example tests that don't make any/very few network calls.

For example, the sync integration tests can take minutes if run serially and thus are important to parallelise.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed, we can do this incrementally. I'd like this change to be as small and mechanical as possible.

@pietern pietern added this pull request to the merge queue Sep 11, 2023
Merged via the queue into main with commit 4ccc70a Sep 11, 2023
4 checks passed
@pietern pietern deleted the consolidate-env-lookups branch September 11, 2023 08:29
pietern added a commit that referenced this pull request Sep 11, 2023
Bundles:
 * Fix conversion of job parameters ([#744](#744)).
 * Add schema and config validation to jsonschema package ([#740](#740)).
 * Support Model Serving Endpoints in bundles ([#682](#682)).
 * Do not include empty output in job run output ([#749](#749)).
 * Fixed marking libraries from DBFS as remote ([#750](#750)).
 * Process only Python wheel tasks which have local libraries used ([#751](#751)).
 * Add enum support for bundle templates ([#668](#668)).
 * Apply Python wheel trampoline if workspace library is used ([#755](#755)).
 * List available targets when incorrect target passed ([#756](#756)).
 * Make bundle and sync fields optional ([#757](#757)).
 * Consolidate environment variable interaction ([#747](#747)).

Internal:
 * Update Go SDK to v0.19.1 ([#759](#759)).
@pietern pietern mentioned this pull request Sep 11, 2023
github-merge-queue bot pushed a commit that referenced this pull request Sep 11, 2023
Bundles:
* Fix conversion of job parameters
([#744](#744)).
* Add schema and config validation to jsonschema package
([#740](#740)).
* Support Model Serving Endpoints in bundles
([#682](#682)).
* Do not include empty output in job run output
([#749](#749)).
* Fixed marking libraries from DBFS as remote
([#750](#750)).
* Process only Python wheel tasks which have local libraries used
([#751](#751)).
* Add enum support for bundle templates
([#668](#668)).
* Apply Python wheel trampoline if workspace library is used
([#755](#755)).
* List available targets when incorrect target passed
([#756](#756)).
* Make bundle and sync fields optional
([#757](#757)).
* Consolidate environment variable interaction
([#747](#747)).

Internal:
* Update Go SDK to v0.19.1
([#759](#759)).
hectorcast-db pushed a commit that referenced this pull request Oct 13, 2023
## Changes

There are a couple places throughout the code base where interaction
with environment variables takes place. Moreover, more than one of these
would try to read a value from more than one environment variable as
fallback (for backwards compatibility). This change consolidates those
accesses.

The majority of diffs in this change are mechanical (i.e. add an
argument or replace a call).

This change:
* Moves common environment variable lookups for bundles to
`bundles/env`.
* Adds a `libs/env` package that wraps `os.LookupEnv` and `os.Getenv`
and allows for overrides to take place in a `context.Context`. By
scoping overrides to a `context.Context` we can avoid `t.Setenv` in
testing and unlock parallel test execution for integration tests.
* Updates call sites to pass through a `context.Context` where needed.
* For bundles, introduces `DATABRICKS_BUNDLE_ROOT` as new primary
variable instead of `BUNDLE_ROOT`. This was the last environment
variable that did not use the `DATABRICKS_` prefix.

## Tests

Unit tests pass.
hectorcast-db pushed a commit that referenced this pull request Oct 13, 2023
Bundles:
* Fix conversion of job parameters
([#744](#744)).
* Add schema and config validation to jsonschema package
([#740](#740)).
* Support Model Serving Endpoints in bundles
([#682](#682)).
* Do not include empty output in job run output
([#749](#749)).
* Fixed marking libraries from DBFS as remote
([#750](#750)).
* Process only Python wheel tasks which have local libraries used
([#751](#751)).
* Add enum support for bundle templates
([#668](#668)).
* Apply Python wheel trampoline if workspace library is used
([#755](#755)).
* List available targets when incorrect target passed
([#756](#756)).
* Make bundle and sync fields optional
([#757](#757)).
* Consolidate environment variable interaction
([#747](#747)).

Internal:
* Update Go SDK to v0.19.1
([#759](#759)).
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.

None yet

3 participants