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] Allow embedding consul #2487

Closed
purpleidea opened this issue Nov 9, 2016 · 15 comments
Closed

[FEAT] Allow embedding consul #2487

purpleidea opened this issue Nov 9, 2016 · 15 comments
Labels
theme/internal-cleanup Used to identify tech debt, testing improvements, code refactoring, and non-impactful optimization type/enhancement Proposed improvement or new feature
Milestone

Comments

@purpleidea
Copy link

Thanks for all your work on consul. I think it would be very advantageous to the project if it was embeddable.

consul version for both Client and Server

Client: git master
Server: git master

Operating system and Environment details

GNU/Linux

Description of the Issue (and unexpected/desired result)

Etcd now supports embedding the server itself into your code bases. I think this would be a welcome addition to consul. Documentation on the etcd equivalent here:
https://godoc.org/github.com/coreos/etcd/embed

Thanks,
James

@slackpad slackpad added type/enhancement Proposed improvement or new feature post-0.9 labels May 3, 2017
@slackpad slackpad added the theme/internal-cleanup Used to identify tech debt, testing improvements, code refactoring, and non-impactful optimization label May 25, 2017
@slackpad
Copy link
Contributor

The work in #3037 will help greatly in moving us in this direction.

@purpleidea
Copy link
Author

FYI: we embed etcd in https://github.com/purpleidea/mgmt/ currently, but it would be fairly straight forward to make consul a pluggable alternative if someone is interested in doing the work. The client-only portion is even more straight forward and could be a good first step. Ping if interested.

@magiconair
Copy link
Contributor

I'm on it.

@purpleidea
Copy link
Author

@magiconair Ping me in #mgmtconfig IRC on Freenode if you'd like to discuss more. Alternatively, open an issue on https://github.com/purpleidea/mgmt/ to discuss if you prefer this sort of medium.

@magiconair
Copy link
Contributor

I'd like to keep the discussion here where other people can see and search for it as well. Also, I'm probably not on your timezone :)

In the end it'll look like this:

c := &agent.Config{...}
a := agent.Agent{Config: c}
a.Start()
defer a.Stop()

You'll have multiple ways of generating the Config object but that won't change the way you use it.

@magiconair
Copy link
Contributor

See also the discussion on #2217

@slackpad slackpad added this to the Unplanned milestone Jan 5, 2018
@slackpad slackpad removed the post-0.9 label Jan 5, 2018
@vtolstov
Copy link

vtolstov commented Dec 3, 2018

any news ?

@vtolstov
Copy link

vtolstov commented Dec 3, 2018

so o embed consul server i need to create config and start agent?

@gaoxinge
Copy link
Contributor

gaoxinge commented Aug 19, 2019

@vtolstov Below code may work:

package test

import (
	"testing"
	"github.com/hashicorp/consul/agent"
)

func TestConsulAgent(t *testing.T) {
	agent := agent.NewTestAgent(t, t.Name(), "")
	defer agent.Shutdown()

	fmt.Println(agent.DNSAddr())
	fmt.Println(agent.HTTPAddr())
	// do things that you want with consul
}

@mkeeler
Copy link
Member

mkeeler commented Aug 19, 2019

FWIW you could embed it similarly to how the CLI command starts an agent.

https://github.com/hashicorp/consul/blob/master/command/agent/agent.go

However, I wouldn’t recommend this. The agent makes many assumptions about its life cycle like that many long running Go routines will end when the main process ends. So you cannot restart an agent in-process without leaking go routines

@vtolstov
Copy link

this is only agent thing, but i need to embed server (kv)

@mkeeler
Copy link
Member

mkeeler commented Aug 19, 2019

An agent is either a server or client depending on the configuration given. I guess it would also be possible to embed only the server. In theory you just need to call github.com/hashicorp/consul/agent/consul.NewServerLogger with valid arguments.

The same caveats apply though of leaking go routines and such.

@jsosulska jsosulska added the waiting-reply Waiting on response from Original Poster or another individual in the thread label May 4, 2020
@jsosulska
Copy link
Contributor

Hi All,

Apologies for raising an old issue, but wanted to provide some closure here.

As Consul has matured, it's become too complicated to simply embed in other codebases. There is a large effort in making this work consistently, and on a whole, the Consul team doesn't feel that embedding Consul is the right choice to support moving forward.

As @mkeeler pointed out:

The agent makes many assumptions about its life cycle like that many long running Go routines will end when the main process ends. So you cannot restart an agent in-process without leaking go routines.

Currently the only thing that is supported as a standalone package is github.com/hashicorp/consul/api.

Happy coding!

@ghost ghost removed waiting-reply Waiting on response from Original Poster or another individual in the thread labels May 13, 2020
@purpleidea
Copy link
Author

As Consul has matured, it's become too complicated to simply embed in other codebases. There is a large effort in making this work consistently, and on a whole, the Consul team doesn't feel that embedding Consul is the right choice to support moving forward.

@jsosulska That's a pretty disappointing thing to hear. While it's unfortunate this hasn't progressed further, it makes it clear hashicorp is distancing itself from "community" wishes here, and from a technical POV I think the decision not to pursue this reflects badly on the project.

I probably shouldn't say anything, but everyone is using etcd anyways, so I guess I'll just abandon my efforts to support consul.

@vtolstov
Copy link

yes, etcd is more suitable choice for raft kv. in current situation consul have no benefit for developers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme/internal-cleanup Used to identify tech debt, testing improvements, code refactoring, and non-impactful optimization type/enhancement Proposed improvement or new feature
Projects
None yet
Development

No branches or pull requests

7 participants