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

feat(config): include additional config files #84

Conversation

0xRichardH
Copy link
Contributor

@0xRichardH 0xRichardH commented Mar 17, 2024

Background

  • I will add the sesh config file to my GitHub repository dotfiles, but I don't want to commit some sensitive information to the public GitHub repository. For example:
    • I have the following sesh startup_scripts config, but I don't want to add the sensitive info (company name) ~/code/my_compay to my Github repository
      [[startup_scripts]]
      session_path = "~/code/my_compay/third_session"
      script_path = "~/.config/sesh/scripts/third_script"
  • The solution is to allow the sesh config to include additional config files, and then I could exclude the additional config files from the git commit history.

Usage

  • The custom sesh config
# ~/.config/sesh/sesh.toml

default_startup_script = "default"

[[startup_scripts]]
session_path = "~/dev/first_session"
script_path = "~/.config/sesh/scripts/first_script"

[[startup_scripts]]
session_path = "~/dev/second_session"
script_path = "~/.config/sesh/scripts/second_script"

[[extended_configs]]
path = "~/.config/sesh/local/sesh.toml"
  • The following config is an additional config that will be included in the custom sesh config
# ~/.config/sesh/local/sesh.toml
[[startup_scripts]]
session_path = "~/dev/third_session"
script_path = "~/.config/sesh/scripts/third_script"

Test Cases

  • All of the test cases are passed.
image

```toml
default_startup_script = "default"

[[startup_scripts]]
session_path = "~/dev/first_session"
script_path = "~/.config/sesh/scripts/first_script"

[[startup_scripts]]
session_path = "~/dev/second_session"
script_path = "~/.config/sesh/scripts/second_script"

[[included_paths]]
path = "~/.config/sesh/sesh.local.toml"
```
Copy link
Owner

@joshmedeski joshmedeski left a comment

Choose a reason for hiding this comment

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

I think this is an interesting idea and worth merging, I left some minor feedback on naming and performance.

config/config.go Outdated Show resolved Hide resolved
config/config.go Outdated Show resolved Hide resolved
config/config.go Outdated
if len(config.IncludedPaths) > 0 {
for _, includePath := range config.IncludedPaths {
includeConfig := Config{}
if err := parseConfigFromFile(includePath.Path, &includeConfig); err != nil {
Copy link
Owner

Choose a reason for hiding this comment

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

Please add a benchmark test and figure if there's a significant drop in performance if someone uses this feature a lot. I'd like to warn people in the README if heavy use of this feature causes performance problems.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It makes sense. I will write some benchmark tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

go test -bench=. ./config/config_test.go -benchtime=10s -benchmem
goos: darwin
goarch: arm64
BenchmarkParseConfigFile/ParseConfigFile_1-8              514300             23670 ns/op            5176 B/op         52 allocs/op
BenchmarkParseConfigFile/ParseConfigFile_10-8              98485            122762 ns/op           27536 B/op        256 allocs/op
BenchmarkParseConfigFile/ParseConfigFile_100-8             10000           1171631 ns/op          249921 B/op       2242 allocs/op
BenchmarkParseConfigFile/ParseConfigFile_1000-8              910          12548132 ns/op         2515669 B/op      22050 allocs/op
BenchmarkParseConfigFile/ParseConfigFile_10000-8              73         164291629 ns/op        25620936 B/op     220066 allocs/op
PASS
ok      command-line-arguments  83.454s

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it affects the performance if there are a thousand separate extended config files. But I think the user only needs one extended_config in most cases. So I don't think there will be any performance issues.

@0xRichardH 0xRichardH force-pushed the feat/config__include_additional_config_files branch from ee541e7 to ce71a5f Compare March 19, 2024 14:27
@joshmedeski joshmedeski mentioned this pull request Mar 21, 2024
@0xRichardH
Copy link
Contributor Author

Hi @joshmedeski Do you know why the bench tests keep failing? Do you think it is a GitHub action resource issue?

@joshmedeski
Copy link
Owner

It might be timing out due to the long test.

Now that you've tested where the dropoff point is, let's remove the bigger performance tests so the testing can be sped up.

Maybe we just need to test that two works.

@0xRichardH 0xRichardH force-pushed the feat/config__include_additional_config_files branch from c139a48 to a3a68f4 Compare March 25, 2024 14:48
@0xRichardH
Copy link
Contributor Author

0xRichardH commented Mar 25, 2024

I cannot figure out why the beach tests still fail on CI. The bench tests will fail even if I set the test input to 0 (which means not loading the extended/additional configs). So I disabled running bench tests for ParseConfigFile for now.

image

@joshmedeski
Copy link
Owner

It appears to be working now. Thanks for creating the tests, I mostly just wanted some awareness for where this feature drops off in performance, and we now have that answer.

I'll look over the code again and do some manual testing then I can merge and ship it, thanks!

Copy link
Owner

@joshmedeski joshmedeski left a comment

Choose a reason for hiding this comment

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

Looks good to me 👍

@joshmedeski joshmedeski merged commit bcc0a76 into joshmedeski:main Mar 26, 2024
4 checks passed
@joshmedeski
Copy link
Owner

I've got some more work to do this week, so I probably will do a release on Friday. Nice work!

@joshmedeski
Copy link
Owner

@0xRichardH did you play around with the built-in import feature from toml?

import = ["~/code/my_compay/sesh.toml"]

It didn't work on my first try, but this seems more simple and more inline with how toml works rather than us trying to create a brand new pattern.

We could even convert what we did to an array instead of grouping by [[extended_configs]].

What do you think? I want this to be as simple as possible before documenting and shipping it.

@0xRichardH
Copy link
Contributor Author

toml-lang/toml#397

@0xRichardH did you play around with the built-in import feature from toml?

import = ["~/code/my_compay/sesh.toml"]

It didn't work on my first try, but this seems more simple and more inline with how toml works rather than us trying to create a brand new pattern.

We could even convert what we did to an array instead of grouping by [[extended_configs]].

What do you think? I want this to be as simple as possible before documenting and shipping it.

The toml itself doesn't support import feature toml-lang/toml#397 . but it will be more elegant to use import to replace extended_configs. I will create a new PR to make a change.

import = ["~/code/my_compay/sesh.toml"]

@0xRichardH 0xRichardH deleted the feat/config__include_additional_config_files branch March 27, 2024 01:37
@joshmedeski
Copy link
Owner

Thanks! I'll look it over.

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