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

Create new types for service-defaults upstream cfg #9872

Merged
merged 12 commits into from Mar 17, 2021

Conversation

freddygv
Copy link
Contributor

@freddygv freddygv commented Mar 11, 2021

This PR expands service-defaults such that most upstream configuration can be configured centrally. There is a map called upstream_configs keyed on <optional-namespace/>service-name which provides per-upstream configuration. There is also an upstream_defaults object for providing configuration that applies across all upstreams of the given service.

The fields in both of these were promoted out of the opaque config map in Upstream so that they can be validated on config write. Note that calls to ResolveServiceConfig will return them in the existing opaque map so that clients on older versions can receive the new centrally-configured fields.

Below is an example config entry:

kind = "service-defaults"
name = "web"

connect {
  # These apply to the upstream key and override the value from upstream_defaults
  upstream_configs {
    "redis" {
      passive_health_check {
        max_failures = 3
        interval = "5s"
      }
    }

    "finance/billing" {
      mesh_gateway {
        mode = "remote"
      }
    }
  }
  
  # These defaults apply across all upstreams of web
  upstream_defaults {
    connect_timeout_ms = 10000
  }
}

In general this is the merge order for something like "protocol" for an upstream listener:

  • proxy-defaults.Config["protocol"]
  • service-defaults of the upstream
  • service-defaults.upstream_defaults of the downstream
  • service-defaults.upstream_configs of the downstream for the upstream
  • Local upstream configuration (Proxy.Upstreams[i].Config["protocol"])

TODO:

  • Fixup some tests
  • Docs changes
  • Changelog

@freddygv freddygv requested a review from a team March 11, 2021 18:15
@github-actions github-actions bot added theme/api Relating to the HTTP API interface theme/cli Flags and documentation for the CLI interface theme/envoy/xds Related to Envoy support labels Mar 11, 2021
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging March 11, 2021 18:36 Inactive
@freddygv freddygv marked this pull request as ready for review March 11, 2021 18:53
api/config_entry.go Outdated Show resolved Hide resolved
api/config_entry.go Outdated Show resolved Hide resolved
api/config_entry.go Outdated Show resolved Hide resolved
api/config_entry.go Outdated Show resolved Hide resolved
api/config_entry.go Outdated Show resolved Hide resolved
api/config_entry.go Outdated Show resolved Hide resolved
Copy link
Member

@rboyer rboyer 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 if you can rearrange things so the config flattening RPC doesn't need to know about nodes that'll be a big improvement. The only other substantial concern here was about some missing api and structs json omitempty struct tags and some possible merging problems down the line.

This is done because after removing ID and NodeName from
ServiceConfigRequest we will no longer know whether a request coming in
is for a Consul client earlier than v1.10.
ResolveServiceConfig is called by service manager before the proxy
registration is in the catalog. Therefore we should pass proxy
registration flags in the request rather than trying to fetch
them from the state store (where they may not exist yet).
@vercel vercel bot temporarily deployed to Preview – consul March 15, 2021 20:34 Inactive
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging March 15, 2021 20:34 Inactive
@freddygv freddygv requested a review from rboyer March 15, 2021 20:35
@vercel vercel bot temporarily deployed to Preview – consul March 15, 2021 22:08 Inactive
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging March 15, 2021 22:08 Inactive
agent/agent.go Outdated Show resolved Hide resolved
Copy link
Member

@rboyer rboyer left a comment

Choose a reason for hiding this comment

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

LGTM

@vercel vercel bot temporarily deployed to Preview – consul-ui-staging March 15, 2021 22:38 Inactive
@vercel vercel bot temporarily deployed to Preview – consul March 15, 2021 22:38 Inactive
Copy link
Contributor

@markan markan left a comment

Choose a reason for hiding this comment

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

One minor suggestion around readability, but otherwise this looks good.

@@ -329,31 +329,21 @@ func (c *ConfigEntry) ResolveServiceConfig(args *structs.ServiceConfigRequest, r
&reply.QueryMeta,
func(ws memdb.WatchSet, state *state.Store) 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 wonder if it might make sense to split this function out and apart.
With big closures like this can be hard to reason about what is captured from the surrounding context; splitting it into a small closure that calls another function makes that explicit.
There's also quite a bit of code, and a number of separate concerns; for example figuring out the default protocol is spread around a bit.

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 is a good point. I added a TODO here that I can take care of for the beta.

@vercel vercel bot temporarily deployed to Preview – consul March 17, 2021 22:45 Inactive
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging March 17, 2021 22:45 Inactive
@freddygv freddygv merged commit c664938 into master Mar 17, 2021
@freddygv freddygv deleted the centralized-upstream-config branch March 17, 2021 22:59
@hashicorp-ci
Copy link
Contributor

🍒 If backport labels were added before merging, cherry-picking will start automatically.

To retroactively trigger a backport after merging, add backport labels and re-run https://circleci.com/gh/hashicorp/consul/339293.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme/api Relating to the HTTP API interface theme/cli Flags and documentation for the CLI interface theme/envoy/xds Related to Envoy support
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants