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

algocfg: Add relay profile, algocfg profile cmd #5069

Merged
merged 7 commits into from
Feb 27, 2023

Conversation

Eric-Warehime
Copy link
Contributor

Summary

Adds a new config from which algocfg and set defaults separately from the Local defaults.

Some things that are troublesome w/ the way we use tags for config values.

  • Some code duplication required because we're using reflection a lot
  • Versioning on relay configs conflicts with Local defaults--this should be fine since non-specified values will be updated to the most recent config version.

The new commands:

> algocfg profile list
relay default
> algocfg profile set relay -d ~/.algorand/
> cat ~/.algorand/config.json
{
	"Version": 0,
	"Archival": true,
	"NetAddress": "4160",
	"EnableLedgerService": true
}

@codecov
Copy link

codecov bot commented Jan 27, 2023

Codecov Report

Merging #5069 (72de1f2) into master (2c0a8db) will decrease coverage by 0.05%.
The diff coverage is 10.00%.

@@            Coverage Diff             @@
##           master    #5069      +/-   ##
==========================================
- Coverage   53.44%   53.39%   -0.05%     
==========================================
  Files         431      432       +1     
  Lines       54369    54409      +40     
==========================================
- Hits        29057    29052       -5     
- Misses      23053    23099      +46     
+ Partials     2259     2258       -1     
Impacted Files Coverage Δ
cmd/algocfg/profileCommand.go 10.00% <10.00%> (ø)
network/wsPeer.go 65.97% <0.00%> (-1.84%) ⬇️
catchup/peerSelector.go 98.95% <0.00%> (-1.05%) ⬇️
catchup/service.go 68.94% <0.00%> (-0.95%) ⬇️
network/wsNetwork.go 64.98% <0.00%> (-0.19%) ⬇️
ledger/tracker.go 75.10% <0.00%> (ø)
ledger/acctonline.go 79.16% <0.00%> (+0.52%) ⬆️
agreement/proposalManager.go 98.03% <0.00%> (+1.96%) ⬆️
agreement/cryptoVerifier.go 69.71% <0.00%> (+2.11%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

if err != nil {
reportErrorf("%v", err)
}
file := filepath.Join(dataDir, config.ConfigFilename)
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add a A config.json file already exists for this data directory. Would you like to overwrite it? (Y/n) prompt in case there is already a 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.

I wish it had a "-y"/"--yes" or "-f"/"--force" option to skip the prompt, or "-w" to overwrite. New to the problem I'm not strongly opinionated on which one feels right. Maybe "-f".
ALSO, I wish it was an update not an overwrite. A "default" to reset things makes sense as one option, but "relay" could just set the 4 fields it wants to set on top of an existing config.json

Copy link
Contributor

Choose a reason for hiding this comment

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

--yes looks required to use in shell scripts

@Eric-Warehime Eric-Warehime marked this pull request as ready for review February 2, 2023 17:23
cmd/algocfg/profileCommand.go Outdated Show resolved Hide resolved
if err != nil {
reportErrorf("%v", err)
}
file := filepath.Join(dataDir, config.ConfigFilename)
Copy link
Contributor

Choose a reason for hiding this comment

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

--yes looks required to use in shell scripts

return
}
}
err = codecs.SaveNonDefaultValuesToFile(file, cfg, config.GetDefaultLocal(), nil, true)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: improvement idea: implement SaveNonDefaultValuesToWriter that works with not a file but a stream (and SaveNonDefaultValuesToFile just calls it) so that list profiles could also print non-default values in this profile.
Or allow outputting to stdout instead of config.json

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a good idea, let me add that in a separate PR.

if _, err := os.Stat(file); err == nil {
fmt.Printf("A config.json file already exists for this data directory. Would you like to overwrite it? (Y/n)")
reader := bufio.NewReader(os.Stdin)
resp, err := reader.ReadString('\n')
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe ReadRune


func getConfigForArg(configType string) (config.Local, error) {
cfg := config.GetDefaultLocal()
switch configType {
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe store the config generator function along with the array of profile names as opposed to this switch statement that will get appended to

Co-authored-by: Will Winder <wwinder.unh@gmail.com>
@Eric-Warehime
Copy link
Contributor Author

Updated behavior

> cat ~/.algorand/config.json
{
	"Archival": true,
	"NetAddress": "4160",
	"EnableLedgerService": true,
	"EnableBlockService": true
}
> algocfg profile set default -d ~/.algorand --yes
> cat ~/.algorand/config.json
{
}

@Eric-Warehime Eric-Warehime requested review from winder, algorandskiy and bbroder-algo and removed request for algolucky February 10, 2023 20:55
Copy link
Contributor

@algorandskiy algorandskiy left a comment

Choose a reason for hiding this comment

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

no stdout support but lgtm

@winder winder merged commit a525804 into algorand:master Feb 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants