Skip to content

Commit

Permalink
connect: ensure proxy-defaults protocol is used for upstreams (#7938)
Browse files Browse the repository at this point in the history
  • Loading branch information
rboyer authored May 21, 2020
1 parent 0a8a311 commit 1b5023c
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 6 deletions.
7 changes: 1 addition & 6 deletions agent/consul/config_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,14 +360,9 @@ func (c *ConfigEntry) ResolveServiceConfig(args *structs.ServiceConfigRequest, r
}
}

// No upstream found; skip.
if upstreamConf == nil {
continue
}

// Fallback to proxyConf global protocol.
protocol := proxyConfGlobalProtocol
if upstreamConf.Protocol != "" {
if upstreamConf != nil && upstreamConf.Protocol != "" {
protocol = upstreamConf.Protocol
}

Expand Down
47 changes: 47 additions & 0 deletions agent/consul/config_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1019,6 +1019,9 @@ func TestConfigEntry_ResolveServiceConfig_UpstreamProxyDefaultsProtocol(t *testi
"other": map[string]interface{}{
"protocol": "http",
},
"dne": map[string]interface{}{
"protocol": "http",
},
"alreadyprotocol": map[string]interface{}{
"protocol": "grpc",
},
Expand All @@ -1029,6 +1032,50 @@ func TestConfigEntry_ResolveServiceConfig_UpstreamProxyDefaultsProtocol(t *testi
require.Equal(expected, out)
}

func TestConfigEntry_ResolveServiceConfig_ProxyDefaultsProtocol_UsedForAllUpstreams(t *testing.T) {
t.Parallel()

require := require.New(t)

dir1, s1 := testServer(t)
defer os.RemoveAll(dir1)
defer s1.Shutdown()
codec := rpcClient(t, s1)
defer codec.Close()

// Create a dummy proxy/service config in the state store to look up.
state := s1.fsm.State()
require.NoError(state.EnsureConfigEntry(1, &structs.ProxyConfigEntry{
Kind: structs.ProxyDefaults,
Name: structs.ProxyConfigGlobal,
Config: map[string]interface{}{
"protocol": "http",
},
}, nil))

args := structs.ServiceConfigRequest{
Name: "foo",
Datacenter: s1.config.Datacenter,
Upstreams: []string{"bar"},
}
var out structs.ServiceConfigResponse
require.NoError(msgpackrpc.CallWithCodec(codec, "ConfigEntry.ResolveServiceConfig", &args, &out))

expected := structs.ServiceConfigResponse{
ProxyConfig: map[string]interface{}{
"protocol": "http",
},
UpstreamConfigs: map[string]map[string]interface{}{
"bar": map[string]interface{}{
"protocol": "http",
},
},
// Don't know what this is deterministically
QueryMeta: out.QueryMeta,
}
require.Equal(expected, out)
}

func TestConfigEntry_ResolveServiceConfigNoConfig(t *testing.T) {
t.Parallel()

Expand Down

0 comments on commit 1b5023c

Please sign in to comment.