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

config: command to apply profile after init #4195

Merged
merged 11 commits into from
Jan 2, 2018
Merged

Conversation

magik6k
Copy link
Member

@magik6k magik6k commented Sep 1, 2017

TODO:

  • Revert command
  • Tests
  • Docs

@whyrusleeping
Copy link
Member

It would be nice to print out what changes are being made

@magik6k magik6k force-pushed the feat/config-patch branch 2 times, most recently from 865f4fb to 128e6ba Compare September 12, 2017 23:44
Run: func(req cmds.Request, res cmds.Response) {
args := req.Arguments()

profile, ok := config.Profiles[args[0]]
Copy link
Member

Choose a reason for hiding this comment

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

instead of binding it to args and just using the [0] on it, why not do:

profilename := req.Arguments()[0]

"/ip4/203.0.113.0/ipcidr/24",
"/ip4/240.0.0.0/ipcidr/4",
}

Copy link
Member

Choose a reason for hiding this comment

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

Not really related to this PR, but i was just thinking that we should probably add LAN addresses to the NoAnnounce field for the server config.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@magik6k magik6k force-pushed the feat/config-patch branch 3 times, most recently from a017c41 to 48f1069 Compare September 21, 2017 22:26

profile, ok := config.Profiles[req.Arguments()[0]]
if !ok {
res.SetError(fmt.Errorf("%s in not a profile", req.Arguments()[0]), cmds.ErrNormal)
Copy link
Member

Choose a reason for hiding this comment

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

s/in/is/

}

func transformConfig(configRoot string, transformer config.Transformer) error {
r, err := fsrepo.Open(configRoot)
Copy link
Member

Choose a reason for hiding this comment

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

if the daemon is running while the user runs this they might run into issues. You cant open the repo again

Copy link
Member

Choose a reason for hiding this comment

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

probably best to pass in the repo from the IpfsNode

Copy link
Member Author

Choose a reason for hiding this comment

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

That's what other commands here do. Looking at repo.Open it should be safe:

func Open(repoPath string) (repo.Repo, error) {
	fn := func() (repo.Repo, error) {
		return open(repoPath)
	}
	return onlyOne.Open(repoPath, fn)
}

Copy link
Member

Choose a reason for hiding this comment

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

oh, i see. good point.

docs/config.md Outdated
@@ -267,3 +268,17 @@ Disables the p2p-circuit relay transport.
- `EnableRelayHop`
Enables HOP relay for the node. If this is enabled, the node will act as
an intermediate (Hop Relay) node in relay circuits for connected peers.

## Profiles
Copy link
Member

Choose a reason for hiding this comment

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

Hrm... i'm not sure this belongs here. Maybe put it at the top of the document? to distinguish it from just looking like another config field

Copy link
Member Author

Choose a reason for hiding this comment

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

Moved it to the header, makes a bit more sense now

@ghost ghost assigned magik6k Oct 29, 2017
@ghost ghost added the status/in-progress In progress label Oct 29, 2017
@magik6k
Copy link
Member Author

magik6k commented Nov 1, 2017

@whyrusleeping Is there anything else to do here? Getting this in would make #4154 a bit easier for me to test.

c.Discovery.MDNS.Enabled = false
return nil
},
Unapply: func(c *Config) error {
Copy link
Member

Choose a reason for hiding this comment

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

Maybe call it Revert instead of Unapply?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@whyrusleeping
Copy link
Member

One small comment, then LGTM

Copy link
Contributor

@kevina kevina left a comment

Choose a reason for hiding this comment

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

See individual comments.

Also could use some some ore comprehensive tests.

var configProfileRevertCmd = &cmds.Command{
Helptext: cmds.HelpText{
Tagline: "Revert profile changes.",
ShortDescription: `Reverts profile-related changes to the config.
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be Reverts profile-related changes to the default config..

docs/config.md Outdated
Reduces external interference, useful for running ipfs in test environments.
Note that with these settings node won't be able to talk to the rest of the
network without manual bootstrap.

## Table of Contents
Copy link
Contributor

Choose a reason for hiding this comment

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

@whyrusleeping should we document the badgerds profile here but label it as experimental?

Copy link
Member

Choose a reason for hiding this comment

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

Its somewhat out of scope, but probably a good idea.

Copy link
Contributor

Choose a reason for hiding this comment

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

Out of scope?

I meant to add under the new Profiles section in case that wasn't clear.

Copy link
Member

Choose a reason for hiding this comment

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

@kevina ah, gotcha. Yeah, lets get that in here.

@kevina
Copy link
Contributor

kevina commented Nov 20, 2017

I also like we should create backup files automatically. We could call them: .config.preapply-PROFILE and .config.prerevert.PROFILE

@whyrusleeping others, thoughs?

@whyrusleeping
Copy link
Member

@kevina I do like the idea of making backups automatically. That will require some changes to the repo abstraction I think.

@magik6k magik6k force-pushed the feat/config-patch branch 2 times, most recently from 248e971 to 81579d6 Compare November 25, 2017 02:48
@magik6k
Copy link
Member Author

magik6k commented Nov 25, 2017

  • Rebased, updated to use new commands
  • Did what @kevina suggested in the review
  • Backups are todo, other than that that PR is mergable

License: MIT
Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
License: MIT
Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
@magik6k magik6k force-pushed the feat/config-patch branch 2 times, most recently from 917f232 to bebdd2b Compare December 15, 2017 20:43
@magik6k
Copy link
Member Author

magik6k commented Dec 15, 2017

Backups done

@kevina kevina self-requested a review December 15, 2017 21:22
repo/mock.go Outdated
@@ -28,6 +28,10 @@ func (m *Mock) SetConfig(updated *config.Config) error {
return nil
}

func (m *Mock) BackupConfig(prefix string) (string, error) {
return "config-" + prefix + "-backup", nil
Copy link
Member

Choose a reason for hiding this comment

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

maybe this can just return errTODO like the other methods? If we arent actually going to back up the config, we probably should bother to pretend with the name

Copy link
Member Author

Choose a reason for hiding this comment

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

done

Copy link
Member

@whyrusleeping whyrusleeping left a comment

Choose a reason for hiding this comment

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

The backups look pretty cleanly done, I just have one comment on the mock repo.

License: MIT
Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
docs/config.md Outdated
If you apply this profile after `ipfs init`, you will need to convert your
datastore to the new configuration. You can do this using [ipfs-ds-convert](https://github.com/ipfs/ipfs-ds-convert)

WARNING: badger datastore is experimantal. Make sure to backup your data
Copy link
Member

Choose a reason for hiding this comment

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

badger datastore is experimental

docs/config.md Outdated
- `server`

Recommended for nodes with public IPv4 address, disables host and content
discovery in local networks.
Copy link
Member

Choose a reason for hiding this comment

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

Or those running on VPSs.


Subcommands: map[string]*cmds.Command{
"apply": configProfileApplyCmd,
"revert": configProfileRevertCmd,
Copy link
Member

@Stebalien Stebalien Dec 16, 2017

Choose a reason for hiding this comment

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

Actually reverting is impossible (for us). We're not reverting, we're applying the inverse of the profile. Do we really need to provide this feature?

We could, instead, provide inverse profiles: local-discovery and flatfs-ds.

I'm worried that a user will think that profiles act like drop-ins (that's how a lot of unix daemons work) and will believe that revert will revert the apply.


Alternatively, we could just do this with layered drop-ins (but that's more complex).

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree with @Stebalien this is not really a revert so we perhaps we should name it something else, not sure what, "unapply" comes to mind.

The idea of instead providing inverse profiles is also a good idea.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think I like the idea of inverse profiles better, I'll see how that looks

"/ip4/240.0.0.0/ipcidr/4",
}

c.Addresses.NoAnnounce = append(c.Addresses.NoAnnounce, defaultServerFilters...)
Copy link
Member

Choose a reason for hiding this comment

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

We should probably try merging these instead of just appending.

return nil
},
Revert: func(c *Config) error {
c.Addresses.NoAnnounce = []string{}
Copy link
Member

Choose a reason for hiding this comment

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

If we do keep the revert command, we should only remove the ones we've added.

Copy link
Contributor

@kevina kevina left a comment

Choose a reason for hiding this comment

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

I would use more helpful names for the backup. The name config-profile-444132629 is not very descriptive. This also makes it hard to find the right config backup to undo the change.

I made suggestions for improving on this. However, I am not set on this, so I can change my review if no one else agrees with me.

If I was writing this I would also use a timestamp rather then TempFile so that if there are multiple backups it is clear what the latest one is. Another option would be to just overright the old backup, that is what most other programs would do.

c.Discovery.MDNS.Enabled = false
return nil
// Transformer is a function which takes configuration and applies some filter to it
type Transformer func(c *Config) error
Copy link
Contributor

Choose a reason for hiding this comment

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

I would make this a struct something like

type Transformer struct {
  Name string
  Apply func(c *Config) error
}

return err
}

_, err = r.BackupConfig("profile-")
Copy link
Contributor

Choose a reason for hiding this comment

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

After making config.Transformer I would make this

_, err = r.BackupConfig(transformer.Name + "-")

To provide more helpful backup names.

License: MIT
Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
@magik6k
Copy link
Member Author

magik6k commented Dec 16, 2017

Refactored revert into inverse profiles, cc @Stebalien

ipfs config profile apply '${inverse_profile}'
'

test_expect_success "config is back to previous state after ${profile} revert" '
Copy link
Contributor

Choose a reason for hiding this comment

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

This test is a bit misnamed now.

@magik6k magik6k force-pushed the feat/config-patch branch 2 times, most recently from c19cc7f to 0546f1f Compare December 16, 2017 19:54
Copy link
Contributor

@kevina kevina left a comment

Choose a reason for hiding this comment

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

Some more nitpicks on how backup are handled.

Otherwise looks good.

docs/config.md Outdated
#### Profiles
Configuration profiles allow to tweak configuration quickly. Profiles can be
applied with `--profile` flag to `ipfs init` or with `ipfs config profile apply`
command.
Copy link
Contributor

Choose a reason for hiding this comment

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

I would mention that a backup is created and what it is called.

},
}

func transformConfig(configRoot string, backupName string, transformer config.Transformer) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

I would call backupName configName.

return err
}

_, err = r.BackupConfig(backupName + "-")
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit. I would make this "pre-" + configName + "-" to make it clear that the backup before the config was applied.

License: MIT
Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
@whyrusleeping
Copy link
Member

Finally getting this one in, Thanks @magik6k !

@whyrusleeping whyrusleeping merged commit f4fd369 into master Jan 2, 2018
@whyrusleeping whyrusleeping deleted the feat/config-patch branch January 2, 2018 22:02
@ghost ghost removed the status/in-progress In progress label Jan 2, 2018
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

5 participants