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

Add spanner emulator env var detection #574

Merged
merged 2 commits into from
May 3, 2022

Conversation

samkim
Copy link
Member

@samkim samkim commented Apr 29, 2022

Detect prefixed spanner emulator env var config and set the actual env var.

@github-actions github-actions bot added the area/datastore Affects the storage system label Apr 29, 2022
@@ -84,3 +88,15 @@ func (smd SpannerMigrationDriver) Close() error {
}

var _ migrate.Driver = SpannerMigrationDriver{}

func detectEmulatorSetting() (string, bool) {
for _, env := range os.Environ() {
Copy link
Contributor

Choose a reason for hiding this comment

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

viper knows the env prefix we use - we pass it around as programName and configure viper with it:

cobrautil.SyncViperPreRunE(programName),

I'm not overly familiar with viper but it seems like there should be a way to directly ask for this value instead of manually flipping through the environment variables.

Does something like viper.Get("SPANNER_EMULATOR_HOST") work? Maybe @jzelinskie has some suggestions?

@samkim samkim force-pushed the spanner-emulator-config branch 3 times, most recently from 4f2cb84 to 5297edd Compare May 3, 2022 06:55
@github-actions github-actions bot added the area/dependencies Affects dependencies label May 3, 2022
@samkim samkim force-pushed the spanner-emulator-config branch from 5297edd to da16644 Compare May 3, 2022 07:02
@samkim samkim requested a review from ecordell May 3, 2022 07:30
@samkim samkim marked this pull request as ready for review May 3, 2022 07:30
@samkim samkim requested a review from a team May 3, 2022 07:30
@@ -58,6 +59,11 @@ func NewSpannerDatastore(database string, opts ...Option) (datastore.Datastore,
return nil, fmt.Errorf(errUnableToInstantiate, err)
}

setting, found := detectEmulatorSetting()
Copy link
Contributor

Choose a reason for hiding this comment

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

couldn't this be another Option on the spanner datastore (so that we don't have to read env vars here), and then re-use the implementation from the migrate command for the serve command?

@github-actions github-actions bot added the area/CLI Affects the command line label May 3, 2022
@samkim samkim force-pushed the spanner-emulator-config branch from f6726be to 95ce218 Compare May 3, 2022 20:49
@github-actions github-actions bot removed the area/dependencies Affects dependencies label May 3, 2022
ecordell
ecordell previously approved these changes May 3, 2022
Copy link
Contributor

@ecordell ecordell left a comment

Choose a reason for hiding this comment

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

LGTM

even though this adds a new flag that's only used for tests, I like that it's more discoverable than undocumented env vars

@samkim samkim force-pushed the spanner-emulator-config branch from f531819 to c92578f Compare May 3, 2022 22:17
@samkim samkim enabled auto-merge May 3, 2022 22:17
@samkim samkim merged commit b33fe79 into authzed:main May 3, 2022
@github-actions github-actions bot locked and limited conversation to collaborators May 3, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area/CLI Affects the command line area/datastore Affects the storage system
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants