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

acc: Implement config merge #2294

Merged
merged 7 commits into from
Feb 7, 2025
Merged

acc: Implement config merge #2294

merged 7 commits into from
Feb 7, 2025

Conversation

denik
Copy link
Contributor

@denik denik commented Feb 4, 2025

Changes

Instead of using leaf-most config, all configs from root at acceptance/test.toml to all intermediate ones to leaf config are merged into one. Maps are merged, slices are appended, other values are overridden.

I had to disable caching, because it is tricky when merging is involved - deep copy is needed. There is performance
impact but currently it is tiny, about 1%.

Also, remove empty root config.

Tests

Manually checked that inheritance of LocalOnly setting worked for these tests:

Before - integration tests showed:

PASS acceptance.TestAccept/bundle/templates/wrong-url (0.70s)
PASS acceptance.TestAccept/bundle/templates/wrong-path (0.44s)

After:

SKIP acceptance.TestAccept/bundle/templates/wrong-url (0.00s)
SKIP acceptance.TestAccept/bundle/templates/wrong-path (0.00s)
      acceptance_test.go:216: Disabled via LocalOnly setting in bundle/templates/test.toml, bundle/templates/wrong-path/test.toml (CLOUD_ENV=***)

@denik denik temporarily deployed to test-trigger-is February 4, 2025 17:21 — with GitHub Actions Inactive
@denik denik temporarily deployed to test-trigger-is February 5, 2025 14:21 — with GitHub Actions Inactive
@denik denik force-pushed the denik/test-config-merge branch from 94d2cf0 to f65b5bd Compare February 7, 2025 10:08
@denik denik temporarily deployed to test-trigger-is February 7, 2025 10:08 — with GitHub Actions Inactive
@denik denik temporarily deployed to test-trigger-is February 7, 2025 10:24 — with GitHub Actions Inactive
@denik denik temporarily deployed to test-trigger-is February 7, 2025 10:28 — with GitHub Actions Inactive
@denik denik marked this pull request as ready for review February 7, 2025 10:32
@denik denik enabled auto-merge February 7, 2025 11:11
dario.cat/mergo
Copyright (c) 2013 Dario Castañé. All rights reserved.
Copyright (c) 2012 The Go Authors. All rights reserved.
https://github.com/darccio/mergo/blob/master/LICENSE
Copy link
Contributor

Choose a reason for hiding this comment

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

Historical tidbit: we used to depend on this bundle configuration merging before the move to libs/dyn.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks. It looks solid. From the past experience, are there any issues or quirks to be aware of?

Copy link
Contributor

Choose a reason for hiding this comment

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

No, it did its job well.

if dir == "" || dir == "." {
break
}

if os.IsNotExist(err) {
dir = filepath.Dir(dir)
dir = filepath.Dir(dir)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the path guaranteed to never be absolute?

If it is, this loop will be infinite.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, in this context is always relative. If it was absolute, the logic would not work anyway as we don't want to search for configs outside of acceptance/.

Added a comment about this requirement.

// FindConfig finds the closest config file.
func FindConfig(t *testing.T, dir string) (string, bool) {
shared := false
// FindConfigs finds the closest config file.
Copy link
Contributor

Choose a reason for hiding this comment

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

Comment is out of date.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated, thanks.

continue
}

t.Fatalf("Error while reading %s: %s", path, err)
}

t.Fatal("Config not found: " + configFilename)
return "", shared
slices.Reverse(configs)
Copy link
Contributor

Choose a reason for hiding this comment

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

This can include a comment that the output will be ordered from outer to inner configuration.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Included in function description.

@pietern pietern disabled auto-merge February 7, 2025 12:32
denik added 6 commits February 7, 2025 13:37
All configs using all test.toml found from acceptance/test.toml to acceptance/<specific test>/test.toml

Maps are merged, slices are appended, other values are overriden.

I had to disable caching, because it is tricky when merging is involved - deep copy is needed. There is performance
impact but currently it is tiny:

~/work/cli/acceptance % hyperfine -w 2 'go test -count=1'  # this change:
Benchmark 1: go test -count=1
  Time (mean ± σ):      5.074 s ±  0.105 s    [User: 6.189 s, System: 9.551 s]
  Range (min … max):    4.926 s …  5.263 s    10 runs

~/work/cli/acceptance % git stash  # base
~/work/cli/acceptance % hyperfine -w 2 'go test -count=1'
Benchmark 1: go test -count=1
  Time (mean ± σ):      5.009 s ±  0.095 s    [User: 6.176 s, System: 10.617 s]
  Range (min … max):    4.803 s …  5.123 s    10 runs
@denik denik force-pushed the denik/test-config-merge branch from f3c155a to 8e16c80 Compare February 7, 2025 12:44
@denik denik force-pushed the denik/test-config-merge branch from 8e16c80 to d14d075 Compare February 7, 2025 12:45
@denik denik enabled auto-merge February 7, 2025 12:46
@denik denik temporarily deployed to test-trigger-is February 7, 2025 12:46 — with GitHub Actions Inactive
@denik denik added this pull request to the merge queue Feb 7, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Feb 7, 2025
@denik denik added this pull request to the merge queue Feb 7, 2025
@denik denik removed this pull request from the merge queue due to a manual request Feb 7, 2025
@denik denik merged commit ff4a5c2 into main Feb 7, 2025
9 checks passed
@denik denik deleted the denik/test-config-merge branch February 7, 2025 16:38
github-merge-queue bot pushed a commit that referenced this pull request Feb 7, 2025
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.

2 participants