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

agent: Use an in-process listener with cache #12762

Merged
merged 15 commits into from
Oct 16, 2021

Conversation

tvoran
Copy link
Member

@tvoran tvoran commented Oct 7, 2021

Uses a bufconn listener between consul-template and vault-agent, when caching is enabled and either templates or a listener is defined. This means no listeners need to be defined in vault-agent for just templating. Always routes consul-template through the vault-agent cache (instead of only when persistent cache is enabled).

Depends on these config changes in consul-template: hashicorp/consul-template#1520

Uses a bufconn listener between consul-template and vault-agent, when
cache and templates are in use. This means no listeners need to be
defined in vault-agent for just templating. Always routes
consul-template through the vault-agent cache (instead of only when
persistent cache is enabled).
@tvoran tvoran requested a review from a team October 7, 2021 05:28
@vercel vercel bot temporarily deployed to Preview – vault-storybook October 7, 2021 05:32 Inactive
@vercel vercel bot temporarily deployed to Preview – vault October 7, 2021 05:32 Inactive
Copy link
Contributor

@tomhjp tomhjp 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! I love that there are no config options for it - super clean UX

command/agent/config/config.go Outdated Show resolved Hide resolved
internalshared/listenerutil/bufconn.go Outdated Show resolved Hide resolved
@vercel vercel bot temporarily deployed to Preview – vault-storybook October 8, 2021 21:52 Inactive
@vercel vercel bot temporarily deployed to Preview – vault October 8, 2021 21:52 Inactive
@vercel vercel bot temporarily deployed to Preview – vault October 8, 2021 22:48 Inactive
@vercel vercel bot temporarily deployed to Preview – vault-storybook October 8, 2021 22:48 Inactive
import (
"net"

ctconfig "github.com/hashicorp/consul-template/config"
Copy link
Contributor

Choose a reason for hiding this comment

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

I wasn't sure if there was a reason to avoid including this dependency, because it's only there for the _ ctconfig.TransportDialer = (*BufConnListenerDialer)(nil) line. But I see no harm in having it personally.

Copy link
Contributor

Choose a reason for hiding this comment

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

An option would be to define a local (internal?) interface that is also satisfied by net.Dialer, especially if we also need to port this over to go-secure-stdlib/listenerutil.

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 attempted to do something like this in 8e26033. Let me know if that looks better.

Copy link
Contributor

@tomhjp tomhjp left a comment

Choose a reason for hiding this comment

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

LGTM! Nice work 🎉

go.mod Outdated Show resolved Hide resolved
@vercel vercel bot temporarily deployed to Preview – vault-storybook October 12, 2021 22:43 Inactive
@vercel vercel bot temporarily deployed to Preview – vault October 12, 2021 22:43 Inactive
// TransportDialer, to serve both ends of an in-process connection (Dial and
// Accept).
type BufConnListenerDialer struct {
listener *bufconn.Listener
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to wrap this, or can we use buffconn.Listener directly?

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 we will still need to wrap it for the Dial() function, since bufconn's Dial is

func (l *Listener) Dial() (net.Conn, error)

and net.Dialer is

func (d *Dialer) Dial(network, address string) (Conn, error)

But you're right, bufconn.Listener implements all the net.Listener interface, so we could reduce this interface to just implement TransportDialer. I'll see what that looks like.

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 made some changes to that effect in 8e26033.

if lnConfig.Type == "bufconn" {
inProcListener := listenerutil.NewBufConnListenerDialer()
config.Cache.InProcDialer = inProcListener
ln = inProcListener
Copy link
Contributor

Choose a reason for hiding this comment

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

Isln.Addr().String() empty at this point? Asking since we're populating info[infoKey] with this value further below.

Copy link
Member Author

Choose a reason for hiding this comment

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

No it comes back as bufconn at this point.

Uses a local transportDialer interface in config.Cache{}. Adds
DialContext() to BufConnListenerDialer.
@vercel vercel bot temporarily deployed to Preview – vault October 13, 2021 19:11 Inactive
@vercel vercel bot temporarily deployed to Preview – vault-storybook October 13, 2021 19:11 Inactive
command/agent.go Outdated Show resolved Hide resolved
Remove the pointer to my fork
Use a "bufconn" const, remove unused parameters.
@vercel vercel bot temporarily deployed to Preview – vault-storybook October 15, 2021 19:08 Inactive
@vercel vercel bot temporarily deployed to Preview – vault October 15, 2021 19:08 Inactive
@vercel vercel bot temporarily deployed to Preview – vault October 15, 2021 21:16 Inactive
@vercel vercel bot temporarily deployed to Preview – vault-storybook October 15, 2021 21:16 Inactive
Copy link
Contributor

@benashz benashz left a comment

Choose a reason for hiding this comment

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

Very nice!

@vercel vercel bot temporarily deployed to Preview – vault-storybook October 15, 2021 23:47 Inactive
@vercel vercel bot temporarily deployed to Preview – vault October 15, 2021 23:47 Inactive
@vercel vercel bot temporarily deployed to Preview – vault October 15, 2021 23:51 Inactive
@vercel vercel bot temporarily deployed to Preview – vault-storybook October 15, 2021 23:51 Inactive
@tvoran tvoran merged commit 99e2132 into main Oct 16, 2021
@tvoran tvoran deleted the VAULT-1776/agent-cache-in-process-listener branch October 16, 2021 00:22
@tvoran tvoran added this to the 1.9 milestone Oct 28, 2021
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.

4 participants