2023-03-28 18:39:22 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2022-03-07 17:47:14 +00:00
|
|
|
package proxycfg
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/mitchellh/go-testing-interface"
|
|
|
|
|
2023-03-22 18:56:18 +00:00
|
|
|
"github.com/hashicorp/consul/acl"
|
2022-03-07 17:47:14 +00:00
|
|
|
"github.com/hashicorp/consul/agent/connect"
|
|
|
|
"github.com/hashicorp/consul/agent/consul/discoverychain"
|
|
|
|
"github.com/hashicorp/consul/agent/structs"
|
2023-02-17 21:14:46 +00:00
|
|
|
"github.com/hashicorp/consul/proto/private/pbpeering"
|
2022-03-07 17:47:14 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func setupTestVariationConfigEntriesAndSnapshot(
|
|
|
|
t testing.T,
|
|
|
|
variation string,
|
2023-03-24 20:40:19 +00:00
|
|
|
enterprise bool,
|
2022-03-07 17:47:14 +00:00
|
|
|
upstreams structs.Upstreams,
|
|
|
|
additionalEntries ...structs.ConfigEntry,
|
2022-05-20 14:47:40 +00:00
|
|
|
) []UpdateEvent {
|
2022-03-07 17:47:14 +00:00
|
|
|
var (
|
|
|
|
dbUpstream = upstreams[0]
|
|
|
|
|
|
|
|
dbUID = NewUpstreamID(&dbUpstream)
|
|
|
|
)
|
|
|
|
|
2023-03-24 20:40:19 +00:00
|
|
|
dbChain := setupTestVariationDiscoveryChain(t, variation, enterprise, dbUID.EnterpriseMeta, additionalEntries...)
|
2022-03-07 17:47:14 +00:00
|
|
|
|
2022-12-21 06:26:20 +00:00
|
|
|
nodes := TestUpstreamNodes(t, "db")
|
|
|
|
if variation == "register-to-terminating-gateway" {
|
|
|
|
for _, node := range nodes {
|
|
|
|
node.Service.Kind = structs.ServiceKindTerminatingGateway
|
|
|
|
}
|
|
|
|
}
|
2022-05-20 14:47:40 +00:00
|
|
|
events := []UpdateEvent{
|
2022-03-07 17:47:14 +00:00
|
|
|
{
|
|
|
|
CorrelationID: "discovery-chain:" + dbUID.String(),
|
|
|
|
Result: &structs.DiscoveryChainResponse{
|
|
|
|
Chain: dbChain,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
CorrelationID: "upstream-target:" + dbChain.ID() + ":" + dbUID.String(),
|
|
|
|
Result: &structs.IndexedCheckServiceNodes{
|
2022-12-21 06:26:20 +00:00
|
|
|
Nodes: nodes,
|
2022-03-07 17:47:14 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2023-03-22 18:56:18 +00:00
|
|
|
dbOpts := structs.DiscoveryTargetOpts{
|
|
|
|
Service: dbUID.Name,
|
|
|
|
Namespace: dbUID.NamespaceOrDefault(),
|
|
|
|
Partition: dbUID.PartitionOrDefault(),
|
|
|
|
Datacenter: "dc1",
|
|
|
|
}
|
|
|
|
dbChainID := structs.ChainID(dbOpts)
|
|
|
|
makeChainID := func(opts structs.DiscoveryTargetOpts) string {
|
|
|
|
return structs.ChainID(structs.MergeDiscoveryTargetOpts(dbOpts, opts))
|
|
|
|
}
|
|
|
|
|
2022-03-07 17:47:14 +00:00
|
|
|
switch variation {
|
|
|
|
case "default":
|
|
|
|
case "simple-with-overrides":
|
|
|
|
case "simple":
|
|
|
|
case "external-sni":
|
|
|
|
case "failover":
|
2023-03-22 18:56:18 +00:00
|
|
|
chainID := makeChainID(structs.DiscoveryTargetOpts{Service: "fail"})
|
2022-05-20 14:47:40 +00:00
|
|
|
events = append(events, UpdateEvent{
|
2023-03-22 18:56:18 +00:00
|
|
|
CorrelationID: "upstream-target:" + chainID + ":" + dbUID.String(),
|
2022-03-07 17:47:14 +00:00
|
|
|
Result: &structs.IndexedCheckServiceNodes{
|
|
|
|
Nodes: TestUpstreamNodesAlternate(t),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
case "failover-through-remote-gateway-triggered":
|
2022-05-20 14:47:40 +00:00
|
|
|
events = append(events, UpdateEvent{
|
2023-03-22 18:56:18 +00:00
|
|
|
CorrelationID: "upstream-target:" + dbChainID + ":" + dbUID.String(),
|
2022-03-07 17:47:14 +00:00
|
|
|
Result: &structs.IndexedCheckServiceNodes{
|
|
|
|
Nodes: TestUpstreamNodesInStatus(t, "critical"),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
fallthrough
|
|
|
|
case "failover-through-remote-gateway":
|
2023-03-22 18:56:18 +00:00
|
|
|
chainID := makeChainID(structs.DiscoveryTargetOpts{Datacenter: "dc2"})
|
2022-05-20 14:47:40 +00:00
|
|
|
events = append(events, UpdateEvent{
|
2023-03-22 18:56:18 +00:00
|
|
|
CorrelationID: "upstream-target:" + chainID + ":" + dbUID.String(),
|
2022-03-07 17:47:14 +00:00
|
|
|
Result: &structs.IndexedCheckServiceNodes{
|
|
|
|
Nodes: TestUpstreamNodesDC2(t),
|
|
|
|
},
|
|
|
|
})
|
2022-05-20 14:47:40 +00:00
|
|
|
events = append(events, UpdateEvent{
|
2022-03-07 17:47:14 +00:00
|
|
|
CorrelationID: "mesh-gateway:dc2:" + dbUID.String(),
|
2022-09-01 14:46:30 +00:00
|
|
|
Result: &structs.IndexedCheckServiceNodes{
|
2022-03-07 17:47:14 +00:00
|
|
|
Nodes: TestGatewayNodesDC2(t),
|
|
|
|
},
|
|
|
|
})
|
2022-08-30 15:46:34 +00:00
|
|
|
case "failover-to-cluster-peer":
|
|
|
|
events = append(events, UpdateEvent{
|
|
|
|
CorrelationID: "peer-trust-bundle:cluster-01",
|
|
|
|
Result: &pbpeering.TrustBundleReadResponse{
|
|
|
|
Bundle: &pbpeering.PeeringTrustBundle{
|
|
|
|
PeerName: "peer1",
|
|
|
|
TrustDomain: "peer1.domain",
|
|
|
|
ExportedPartition: "peer1ap",
|
|
|
|
RootPEMs: []string{"peer1-root-1"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
2023-03-22 18:56:18 +00:00
|
|
|
uid := UpstreamID{
|
2023-03-24 20:40:19 +00:00
|
|
|
Name: "db",
|
|
|
|
Peer: "cluster-01",
|
|
|
|
}
|
|
|
|
if enterprise {
|
|
|
|
uid.EnterpriseMeta = acl.NewEnterpriseMetaWithPartition(dbUID.PartitionOrDefault(), "ns9")
|
2023-03-22 18:56:18 +00:00
|
|
|
}
|
2022-08-30 15:46:34 +00:00
|
|
|
events = append(events, UpdateEvent{
|
2023-03-22 18:56:18 +00:00
|
|
|
CorrelationID: "upstream-peer:" + uid.String(),
|
2022-08-30 15:46:34 +00:00
|
|
|
Result: &structs.IndexedCheckServiceNodes{
|
2023-03-24 20:40:19 +00:00
|
|
|
Nodes: structs.CheckServiceNodes{structs.TestCheckNodeServiceWithNameInPeer(t, "db", "dc2", "cluster-01", "10.40.1.1", false, uid.EnterpriseMeta)},
|
2022-08-30 15:46:34 +00:00
|
|
|
},
|
|
|
|
})
|
2022-09-09 17:58:28 +00:00
|
|
|
case "redirect-to-cluster-peer":
|
|
|
|
events = append(events, UpdateEvent{
|
|
|
|
CorrelationID: "peer-trust-bundle:cluster-01",
|
|
|
|
Result: &pbpeering.TrustBundleReadResponse{
|
|
|
|
Bundle: &pbpeering.PeeringTrustBundle{
|
|
|
|
PeerName: "peer1",
|
|
|
|
TrustDomain: "peer1.domain",
|
|
|
|
ExportedPartition: "peer1ap",
|
|
|
|
RootPEMs: []string{"peer1-root-1"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
2023-03-22 18:56:18 +00:00
|
|
|
uid := UpstreamID{
|
2023-03-24 20:40:19 +00:00
|
|
|
Name: "db",
|
|
|
|
Peer: "cluster-01",
|
|
|
|
}
|
|
|
|
if enterprise {
|
|
|
|
uid.EnterpriseMeta = acl.NewEnterpriseMetaWithPartition(dbUID.PartitionOrDefault(), "ns9")
|
2023-03-22 18:56:18 +00:00
|
|
|
}
|
2022-09-09 17:58:28 +00:00
|
|
|
events = append(events, UpdateEvent{
|
2023-03-22 18:56:18 +00:00
|
|
|
CorrelationID: "upstream-peer:" + uid.String(),
|
2022-09-09 17:58:28 +00:00
|
|
|
Result: &structs.IndexedCheckServiceNodes{
|
2023-03-24 20:40:19 +00:00
|
|
|
Nodes: structs.CheckServiceNodes{structs.TestCheckNodeServiceWithNameInPeer(t, "db", "dc2", "cluster-01", "10.40.1.1", false, uid.EnterpriseMeta)},
|
2022-09-09 17:58:28 +00:00
|
|
|
},
|
|
|
|
})
|
2022-03-07 17:47:14 +00:00
|
|
|
case "failover-through-double-remote-gateway-triggered":
|
2023-03-22 18:56:18 +00:00
|
|
|
chainID := makeChainID(structs.DiscoveryTargetOpts{Datacenter: "dc2"})
|
2022-05-20 14:47:40 +00:00
|
|
|
events = append(events, UpdateEvent{
|
2023-03-22 18:56:18 +00:00
|
|
|
CorrelationID: "upstream-target:" + dbChainID + ":" + dbUID.String(),
|
2022-03-07 17:47:14 +00:00
|
|
|
Result: &structs.IndexedCheckServiceNodes{
|
|
|
|
Nodes: TestUpstreamNodesInStatus(t, "critical"),
|
|
|
|
},
|
2023-03-22 18:56:18 +00:00
|
|
|
},
|
|
|
|
UpdateEvent{
|
|
|
|
CorrelationID: "upstream-target:" + chainID + ":" + dbUID.String(),
|
|
|
|
Result: &structs.IndexedCheckServiceNodes{
|
|
|
|
Nodes: TestUpstreamNodesInStatusDC2(t, "critical"),
|
|
|
|
},
|
|
|
|
})
|
2022-03-07 17:47:14 +00:00
|
|
|
fallthrough
|
|
|
|
case "failover-through-double-remote-gateway":
|
2023-03-22 18:56:18 +00:00
|
|
|
chainID := makeChainID(structs.DiscoveryTargetOpts{Datacenter: "dc3"})
|
2022-05-20 14:47:40 +00:00
|
|
|
events = append(events, UpdateEvent{
|
2023-03-22 18:56:18 +00:00
|
|
|
CorrelationID: "upstream-target:" + chainID + ":" + dbUID.String(),
|
2022-03-07 17:47:14 +00:00
|
|
|
Result: &structs.IndexedCheckServiceNodes{
|
|
|
|
Nodes: TestUpstreamNodesDC2(t),
|
|
|
|
},
|
2023-03-22 18:56:18 +00:00
|
|
|
},
|
|
|
|
UpdateEvent{
|
|
|
|
CorrelationID: "mesh-gateway:dc2:" + dbUID.String(),
|
|
|
|
Result: &structs.IndexedCheckServiceNodes{
|
|
|
|
Nodes: TestGatewayNodesDC2(t),
|
|
|
|
},
|
2022-03-07 17:47:14 +00:00
|
|
|
},
|
2023-03-22 18:56:18 +00:00
|
|
|
UpdateEvent{
|
|
|
|
CorrelationID: "mesh-gateway:dc3:" + dbUID.String(),
|
|
|
|
Result: &structs.IndexedCheckServiceNodes{
|
|
|
|
Nodes: TestGatewayNodesDC3(t),
|
|
|
|
},
|
|
|
|
})
|
2022-03-07 17:47:14 +00:00
|
|
|
case "failover-through-local-gateway-triggered":
|
2022-05-20 14:47:40 +00:00
|
|
|
events = append(events, UpdateEvent{
|
2023-03-22 18:56:18 +00:00
|
|
|
CorrelationID: "upstream-target:" + dbChainID + ":" + dbUID.String(),
|
2022-03-07 17:47:14 +00:00
|
|
|
Result: &structs.IndexedCheckServiceNodes{
|
|
|
|
Nodes: TestUpstreamNodesInStatus(t, "critical"),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
fallthrough
|
|
|
|
case "failover-through-local-gateway":
|
2023-03-22 18:56:18 +00:00
|
|
|
chainID := makeChainID(structs.DiscoveryTargetOpts{Datacenter: "dc2"})
|
2022-05-20 14:47:40 +00:00
|
|
|
events = append(events, UpdateEvent{
|
2023-03-22 18:56:18 +00:00
|
|
|
CorrelationID: "upstream-target:" + chainID + ":" + dbUID.String(),
|
2022-03-07 17:47:14 +00:00
|
|
|
Result: &structs.IndexedCheckServiceNodes{
|
|
|
|
Nodes: TestUpstreamNodesDC2(t),
|
|
|
|
},
|
2023-03-22 18:56:18 +00:00
|
|
|
},
|
|
|
|
UpdateEvent{
|
|
|
|
CorrelationID: "mesh-gateway:dc1:" + dbUID.String(),
|
|
|
|
Result: &structs.IndexedCheckServiceNodes{
|
|
|
|
Nodes: TestGatewayNodesDC1(t),
|
|
|
|
},
|
|
|
|
})
|
2022-03-07 17:47:14 +00:00
|
|
|
case "failover-through-double-local-gateway-triggered":
|
2023-03-22 18:56:18 +00:00
|
|
|
db2ChainID := makeChainID(structs.DiscoveryTargetOpts{Datacenter: "dc2"})
|
2022-05-20 14:47:40 +00:00
|
|
|
events = append(events, UpdateEvent{
|
2023-03-22 18:56:18 +00:00
|
|
|
CorrelationID: "upstream-target:" + dbChainID + ":" + dbUID.String(),
|
2022-03-07 17:47:14 +00:00
|
|
|
Result: &structs.IndexedCheckServiceNodes{
|
|
|
|
Nodes: TestUpstreamNodesInStatus(t, "critical"),
|
|
|
|
},
|
2023-03-22 18:56:18 +00:00
|
|
|
},
|
|
|
|
UpdateEvent{
|
|
|
|
CorrelationID: "upstream-target:" + db2ChainID + ":" + dbUID.String(),
|
|
|
|
Result: &structs.IndexedCheckServiceNodes{
|
|
|
|
Nodes: TestUpstreamNodesInStatusDC2(t, "critical"),
|
|
|
|
},
|
|
|
|
})
|
2022-03-07 17:47:14 +00:00
|
|
|
fallthrough
|
|
|
|
case "failover-through-double-local-gateway":
|
2023-03-22 18:56:18 +00:00
|
|
|
db3ChainID := makeChainID(structs.DiscoveryTargetOpts{Datacenter: "dc3"})
|
2022-05-20 14:47:40 +00:00
|
|
|
events = append(events, UpdateEvent{
|
2023-03-22 18:56:18 +00:00
|
|
|
CorrelationID: "upstream-target:" + db3ChainID + ":" + dbUID.String(),
|
2022-03-07 17:47:14 +00:00
|
|
|
Result: &structs.IndexedCheckServiceNodes{
|
|
|
|
Nodes: TestUpstreamNodesDC2(t),
|
|
|
|
},
|
|
|
|
})
|
2022-05-20 14:47:40 +00:00
|
|
|
events = append(events, UpdateEvent{
|
2022-03-07 17:47:14 +00:00
|
|
|
CorrelationID: "mesh-gateway:dc1:" + dbUID.String(),
|
2022-09-01 14:46:30 +00:00
|
|
|
Result: &structs.IndexedCheckServiceNodes{
|
2022-03-07 17:47:14 +00:00
|
|
|
Nodes: TestGatewayNodesDC1(t),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
case "splitter-with-resolver-redirect-multidc":
|
2023-03-22 18:56:18 +00:00
|
|
|
v1ChainID := makeChainID(structs.DiscoveryTargetOpts{ServiceSubset: "v1"})
|
|
|
|
v2ChainID := makeChainID(structs.DiscoveryTargetOpts{ServiceSubset: "v2", Datacenter: "dc2"})
|
2022-05-20 14:47:40 +00:00
|
|
|
events = append(events, UpdateEvent{
|
2023-03-22 18:56:18 +00:00
|
|
|
CorrelationID: "upstream-target:" + v1ChainID + ":" + dbUID.String(),
|
2022-03-07 17:47:14 +00:00
|
|
|
Result: &structs.IndexedCheckServiceNodes{
|
|
|
|
Nodes: TestUpstreamNodes(t, "db"),
|
|
|
|
},
|
|
|
|
})
|
2022-05-20 14:47:40 +00:00
|
|
|
events = append(events, UpdateEvent{
|
2023-03-22 18:56:18 +00:00
|
|
|
CorrelationID: "upstream-target:" + v2ChainID + ":" + dbUID.String(),
|
2022-03-07 17:47:14 +00:00
|
|
|
Result: &structs.IndexedCheckServiceNodes{
|
|
|
|
Nodes: TestUpstreamNodesDC2(t),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
case "chain-and-splitter":
|
|
|
|
case "grpc-router":
|
|
|
|
case "chain-and-router":
|
|
|
|
case "lb-resolver":
|
2022-12-21 06:26:20 +00:00
|
|
|
case "register-to-terminating-gateway":
|
2022-03-07 17:47:14 +00:00
|
|
|
default:
|
|
|
|
t.Fatalf("unexpected variation: %q", variation)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return events
|
|
|
|
}
|
|
|
|
|
|
|
|
func setupTestVariationDiscoveryChain(
|
|
|
|
t testing.T,
|
|
|
|
variation string,
|
2023-03-24 20:40:19 +00:00
|
|
|
enterprise bool,
|
2023-03-22 18:56:18 +00:00
|
|
|
entMeta acl.EnterpriseMeta,
|
2022-03-07 17:47:14 +00:00
|
|
|
additionalEntries ...structs.ConfigEntry,
|
|
|
|
) *structs.CompiledDiscoveryChain {
|
|
|
|
// Compile a chain.
|
|
|
|
var (
|
|
|
|
entries []structs.ConfigEntry
|
|
|
|
compileSetup func(req *discoverychain.CompileRequest)
|
|
|
|
)
|
|
|
|
|
|
|
|
switch variation {
|
|
|
|
case "default":
|
|
|
|
// no config entries
|
2022-12-21 06:26:20 +00:00
|
|
|
case "register-to-terminating-gateway":
|
2022-03-07 17:47:14 +00:00
|
|
|
case "simple-with-overrides":
|
|
|
|
compileSetup = func(req *discoverychain.CompileRequest) {
|
|
|
|
req.OverrideMeshGateway.Mode = structs.MeshGatewayModeLocal
|
|
|
|
req.OverrideProtocol = "grpc"
|
|
|
|
req.OverrideConnectTimeout = 66 * time.Second
|
|
|
|
}
|
|
|
|
fallthrough
|
|
|
|
case "simple":
|
|
|
|
entries = append(entries,
|
|
|
|
&structs.ServiceResolverConfigEntry{
|
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "db",
|
2023-03-22 18:56:18 +00:00
|
|
|
EnterpriseMeta: entMeta,
|
2022-03-07 17:47:14 +00:00
|
|
|
ConnectTimeout: 33 * time.Second,
|
2023-03-03 14:37:12 +00:00
|
|
|
RequestTimeout: 33 * time.Second,
|
2022-03-07 17:47:14 +00:00
|
|
|
},
|
|
|
|
)
|
|
|
|
case "external-sni":
|
|
|
|
entries = append(entries,
|
|
|
|
&structs.ServiceConfigEntry{
|
2023-03-22 18:56:18 +00:00
|
|
|
Kind: structs.ServiceDefaults,
|
|
|
|
Name: "db",
|
|
|
|
EnterpriseMeta: entMeta,
|
|
|
|
ExternalSNI: "db.some.other.service.mesh",
|
2022-03-07 17:47:14 +00:00
|
|
|
},
|
|
|
|
&structs.ServiceResolverConfigEntry{
|
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "db",
|
2023-03-22 18:56:18 +00:00
|
|
|
EnterpriseMeta: entMeta,
|
2022-03-07 17:47:14 +00:00
|
|
|
ConnectTimeout: 33 * time.Second,
|
2023-03-03 14:37:12 +00:00
|
|
|
RequestTimeout: 33 * time.Second,
|
2022-03-07 17:47:14 +00:00
|
|
|
},
|
|
|
|
)
|
|
|
|
case "failover":
|
|
|
|
entries = append(entries,
|
|
|
|
&structs.ServiceResolverConfigEntry{
|
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "db",
|
2023-03-22 18:56:18 +00:00
|
|
|
EnterpriseMeta: entMeta,
|
2022-03-07 17:47:14 +00:00
|
|
|
ConnectTimeout: 33 * time.Second,
|
2023-03-03 14:37:12 +00:00
|
|
|
RequestTimeout: 33 * time.Second,
|
2022-03-07 17:47:14 +00:00
|
|
|
Failover: map[string]structs.ServiceResolverFailover{
|
|
|
|
"*": {
|
|
|
|
Service: "fail",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)
|
|
|
|
case "failover-through-remote-gateway-triggered":
|
|
|
|
fallthrough
|
|
|
|
case "failover-through-remote-gateway":
|
|
|
|
entries = append(entries,
|
|
|
|
&structs.ServiceConfigEntry{
|
2023-03-22 18:56:18 +00:00
|
|
|
Kind: structs.ServiceDefaults,
|
|
|
|
Name: "db",
|
|
|
|
EnterpriseMeta: entMeta,
|
2022-03-07 17:47:14 +00:00
|
|
|
MeshGateway: structs.MeshGatewayConfig{
|
|
|
|
Mode: structs.MeshGatewayModeRemote,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&structs.ServiceResolverConfigEntry{
|
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "db",
|
2023-03-22 18:56:18 +00:00
|
|
|
EnterpriseMeta: entMeta,
|
2022-03-07 17:47:14 +00:00
|
|
|
ConnectTimeout: 33 * time.Second,
|
2023-03-03 14:37:12 +00:00
|
|
|
RequestTimeout: 33 * time.Second,
|
2022-03-07 17:47:14 +00:00
|
|
|
Failover: map[string]structs.ServiceResolverFailover{
|
|
|
|
"*": {
|
|
|
|
Datacenters: []string{"dc2"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)
|
2022-08-30 15:46:34 +00:00
|
|
|
case "failover-to-cluster-peer":
|
2023-03-24 20:40:19 +00:00
|
|
|
target := structs.ServiceResolverFailoverTarget{
|
|
|
|
Peer: "cluster-01",
|
|
|
|
}
|
|
|
|
|
|
|
|
if enterprise {
|
|
|
|
target.Namespace = "ns9"
|
|
|
|
}
|
|
|
|
|
2022-08-30 15:46:34 +00:00
|
|
|
entries = append(entries,
|
|
|
|
&structs.ServiceResolverConfigEntry{
|
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "db",
|
2023-03-22 18:56:18 +00:00
|
|
|
EnterpriseMeta: entMeta,
|
2022-08-30 15:46:34 +00:00
|
|
|
ConnectTimeout: 33 * time.Second,
|
2023-03-03 14:37:12 +00:00
|
|
|
RequestTimeout: 33 * time.Second,
|
2022-08-30 15:46:34 +00:00
|
|
|
Failover: map[string]structs.ServiceResolverFailover{
|
|
|
|
"*": {
|
2023-03-24 20:40:19 +00:00
|
|
|
Targets: []structs.ServiceResolverFailoverTarget{target},
|
2022-08-30 15:46:34 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)
|
2022-09-09 17:58:28 +00:00
|
|
|
case "redirect-to-cluster-peer":
|
2023-03-24 20:40:19 +00:00
|
|
|
redirect := &structs.ServiceResolverRedirect{
|
|
|
|
Peer: "cluster-01",
|
|
|
|
}
|
|
|
|
if enterprise {
|
|
|
|
redirect.Namespace = "ns9"
|
|
|
|
}
|
|
|
|
|
2022-09-09 17:58:28 +00:00
|
|
|
entries = append(entries,
|
|
|
|
&structs.ServiceResolverConfigEntry{
|
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "db",
|
2023-03-22 18:56:18 +00:00
|
|
|
EnterpriseMeta: entMeta,
|
2022-09-09 17:58:28 +00:00
|
|
|
ConnectTimeout: 33 * time.Second,
|
2023-03-03 14:37:12 +00:00
|
|
|
RequestTimeout: 33 * time.Second,
|
2023-03-24 20:40:19 +00:00
|
|
|
Redirect: redirect,
|
2022-09-09 17:58:28 +00:00
|
|
|
},
|
|
|
|
)
|
2022-03-07 17:47:14 +00:00
|
|
|
case "failover-through-double-remote-gateway-triggered":
|
|
|
|
fallthrough
|
|
|
|
case "failover-through-double-remote-gateway":
|
|
|
|
entries = append(entries,
|
|
|
|
&structs.ServiceConfigEntry{
|
2023-03-22 18:56:18 +00:00
|
|
|
Kind: structs.ServiceDefaults,
|
|
|
|
Name: "db",
|
|
|
|
EnterpriseMeta: entMeta,
|
2022-03-07 17:47:14 +00:00
|
|
|
MeshGateway: structs.MeshGatewayConfig{
|
|
|
|
Mode: structs.MeshGatewayModeRemote,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&structs.ServiceResolverConfigEntry{
|
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "db",
|
2023-03-22 18:56:18 +00:00
|
|
|
EnterpriseMeta: entMeta,
|
2022-03-07 17:47:14 +00:00
|
|
|
ConnectTimeout: 33 * time.Second,
|
2023-03-03 14:37:12 +00:00
|
|
|
RequestTimeout: 33 * time.Second,
|
2022-03-07 17:47:14 +00:00
|
|
|
Failover: map[string]structs.ServiceResolverFailover{
|
|
|
|
"*": {
|
|
|
|
Datacenters: []string{"dc2", "dc3"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)
|
|
|
|
case "failover-through-local-gateway-triggered":
|
|
|
|
fallthrough
|
|
|
|
case "failover-through-local-gateway":
|
|
|
|
entries = append(entries,
|
|
|
|
&structs.ServiceConfigEntry{
|
2023-03-22 18:56:18 +00:00
|
|
|
Kind: structs.ServiceDefaults,
|
|
|
|
Name: "db",
|
|
|
|
EnterpriseMeta: entMeta,
|
2022-03-07 17:47:14 +00:00
|
|
|
MeshGateway: structs.MeshGatewayConfig{
|
|
|
|
Mode: structs.MeshGatewayModeLocal,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&structs.ServiceResolverConfigEntry{
|
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "db",
|
2023-03-22 18:56:18 +00:00
|
|
|
EnterpriseMeta: entMeta,
|
2022-03-07 17:47:14 +00:00
|
|
|
ConnectTimeout: 33 * time.Second,
|
2023-03-03 14:37:12 +00:00
|
|
|
RequestTimeout: 33 * time.Second,
|
2022-03-07 17:47:14 +00:00
|
|
|
Failover: map[string]structs.ServiceResolverFailover{
|
|
|
|
"*": {
|
|
|
|
Datacenters: []string{"dc2"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)
|
|
|
|
case "failover-through-double-local-gateway-triggered":
|
|
|
|
fallthrough
|
|
|
|
case "failover-through-double-local-gateway":
|
|
|
|
entries = append(entries,
|
|
|
|
&structs.ServiceConfigEntry{
|
2023-03-22 18:56:18 +00:00
|
|
|
Kind: structs.ServiceDefaults,
|
|
|
|
Name: "db",
|
|
|
|
EnterpriseMeta: entMeta,
|
2022-03-07 17:47:14 +00:00
|
|
|
MeshGateway: structs.MeshGatewayConfig{
|
|
|
|
Mode: structs.MeshGatewayModeLocal,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&structs.ServiceResolverConfigEntry{
|
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "db",
|
2023-03-22 18:56:18 +00:00
|
|
|
EnterpriseMeta: entMeta,
|
2022-03-07 17:47:14 +00:00
|
|
|
ConnectTimeout: 33 * time.Second,
|
2023-03-03 14:37:12 +00:00
|
|
|
RequestTimeout: 33 * time.Second,
|
2022-03-07 17:47:14 +00:00
|
|
|
Failover: map[string]structs.ServiceResolverFailover{
|
|
|
|
"*": {
|
|
|
|
Datacenters: []string{"dc2", "dc3"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)
|
|
|
|
case "splitter-with-resolver-redirect-multidc":
|
2023-03-22 18:56:18 +00:00
|
|
|
em := acl.NewEnterpriseMetaWithPartition(entMeta.PartitionOrDefault(), acl.NamespaceOrDefault(""))
|
2022-03-07 17:47:14 +00:00
|
|
|
entries = append(entries,
|
|
|
|
&structs.ProxyConfigEntry{
|
2023-03-22 18:56:18 +00:00
|
|
|
Kind: structs.ProxyDefaults,
|
|
|
|
Name: structs.ProxyConfigGlobal,
|
|
|
|
EnterpriseMeta: em,
|
2022-03-07 17:47:14 +00:00
|
|
|
Config: map[string]interface{}{
|
|
|
|
"protocol": "http",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&structs.ServiceSplitterConfigEntry{
|
2023-03-22 18:56:18 +00:00
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "db",
|
|
|
|
EnterpriseMeta: entMeta,
|
2022-03-07 17:47:14 +00:00
|
|
|
Splits: []structs.ServiceSplit{
|
|
|
|
{Weight: 50, Service: "db-dc1"},
|
|
|
|
{Weight: 50, Service: "db-dc2"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&structs.ServiceResolverConfigEntry{
|
2023-03-22 18:56:18 +00:00
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "db-dc1",
|
|
|
|
EnterpriseMeta: entMeta,
|
2022-03-07 17:47:14 +00:00
|
|
|
Redirect: &structs.ServiceResolverRedirect{
|
|
|
|
Service: "db",
|
|
|
|
ServiceSubset: "v1",
|
|
|
|
Datacenter: "dc1",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&structs.ServiceResolverConfigEntry{
|
2023-03-22 18:56:18 +00:00
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "db-dc2",
|
|
|
|
EnterpriseMeta: entMeta,
|
2022-03-07 17:47:14 +00:00
|
|
|
Redirect: &structs.ServiceResolverRedirect{
|
|
|
|
Service: "db",
|
|
|
|
ServiceSubset: "v2",
|
|
|
|
Datacenter: "dc2",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&structs.ServiceResolverConfigEntry{
|
2023-03-22 18:56:18 +00:00
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "db",
|
|
|
|
EnterpriseMeta: entMeta,
|
2022-03-07 17:47:14 +00:00
|
|
|
Subsets: map[string]structs.ServiceResolverSubset{
|
|
|
|
"v1": {
|
|
|
|
Filter: "Service.Meta.version == v1",
|
|
|
|
},
|
|
|
|
"v2": {
|
|
|
|
Filter: "Service.Meta.version == v2",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)
|
|
|
|
case "chain-and-splitter":
|
|
|
|
entries = append(entries,
|
|
|
|
&structs.ServiceResolverConfigEntry{
|
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "db",
|
2023-03-22 18:56:18 +00:00
|
|
|
EnterpriseMeta: entMeta,
|
2022-03-07 17:47:14 +00:00
|
|
|
ConnectTimeout: 33 * time.Second,
|
2023-03-03 14:37:12 +00:00
|
|
|
RequestTimeout: 33 * time.Second,
|
2022-03-07 17:47:14 +00:00
|
|
|
},
|
|
|
|
&structs.ProxyConfigEntry{
|
2023-03-22 18:56:18 +00:00
|
|
|
Kind: structs.ProxyDefaults,
|
|
|
|
Name: structs.ProxyConfigGlobal,
|
|
|
|
EnterpriseMeta: entMeta,
|
2022-03-07 17:47:14 +00:00
|
|
|
Config: map[string]interface{}{
|
|
|
|
"protocol": "http",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&structs.ServiceSplitterConfigEntry{
|
2023-03-22 18:56:18 +00:00
|
|
|
Kind: structs.ServiceSplitter,
|
|
|
|
Name: "db",
|
|
|
|
EnterpriseMeta: entMeta,
|
2022-03-07 17:47:14 +00:00
|
|
|
Splits: []structs.ServiceSplit{
|
|
|
|
{
|
|
|
|
Weight: 95.5,
|
|
|
|
Service: "big-side",
|
|
|
|
RequestHeaders: &structs.HTTPHeaderModifiers{
|
|
|
|
Set: map[string]string{"x-split-leg": "big"},
|
|
|
|
},
|
|
|
|
ResponseHeaders: &structs.HTTPHeaderModifiers{
|
|
|
|
Set: map[string]string{"x-split-leg": "big"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Weight: 4,
|
|
|
|
Service: "goldilocks-side",
|
|
|
|
RequestHeaders: &structs.HTTPHeaderModifiers{
|
|
|
|
Set: map[string]string{"x-split-leg": "goldilocks"},
|
|
|
|
},
|
|
|
|
ResponseHeaders: &structs.HTTPHeaderModifiers{
|
|
|
|
Set: map[string]string{"x-split-leg": "goldilocks"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Weight: 0.5,
|
|
|
|
Service: "lil-bit-side",
|
|
|
|
RequestHeaders: &structs.HTTPHeaderModifiers{
|
|
|
|
Set: map[string]string{"x-split-leg": "small"},
|
|
|
|
},
|
|
|
|
ResponseHeaders: &structs.HTTPHeaderModifiers{
|
|
|
|
Set: map[string]string{"x-split-leg": "small"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)
|
|
|
|
case "grpc-router":
|
|
|
|
entries = append(entries,
|
|
|
|
&structs.ServiceResolverConfigEntry{
|
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "db",
|
2023-03-22 18:56:18 +00:00
|
|
|
EnterpriseMeta: entMeta,
|
2022-03-07 17:47:14 +00:00
|
|
|
ConnectTimeout: 33 * time.Second,
|
2023-03-03 14:37:12 +00:00
|
|
|
RequestTimeout: 33 * time.Second,
|
2022-03-07 17:47:14 +00:00
|
|
|
},
|
|
|
|
&structs.ProxyConfigEntry{
|
2023-03-22 18:56:18 +00:00
|
|
|
Kind: structs.ProxyDefaults,
|
|
|
|
Name: structs.ProxyConfigGlobal,
|
|
|
|
EnterpriseMeta: entMeta,
|
2022-03-07 17:47:14 +00:00
|
|
|
Config: map[string]interface{}{
|
|
|
|
"protocol": "grpc",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&structs.ServiceRouterConfigEntry{
|
2023-03-22 18:56:18 +00:00
|
|
|
Kind: structs.ServiceRouter,
|
|
|
|
Name: "db",
|
|
|
|
EnterpriseMeta: entMeta,
|
2022-03-07 17:47:14 +00:00
|
|
|
Routes: []structs.ServiceRoute{
|
|
|
|
{
|
|
|
|
Match: &structs.ServiceRouteMatch{
|
|
|
|
HTTP: &structs.ServiceRouteHTTPMatch{
|
|
|
|
PathExact: "/fgrpc.PingServer/Ping",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Destination: &structs.ServiceRouteDestination{
|
|
|
|
Service: "prefix",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)
|
|
|
|
case "chain-and-router":
|
|
|
|
entries = append(entries,
|
|
|
|
&structs.ServiceResolverConfigEntry{
|
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "db",
|
2023-03-22 18:56:18 +00:00
|
|
|
EnterpriseMeta: entMeta,
|
2022-03-07 17:47:14 +00:00
|
|
|
ConnectTimeout: 33 * time.Second,
|
2023-03-03 14:37:12 +00:00
|
|
|
RequestTimeout: 33 * time.Second,
|
2022-03-07 17:47:14 +00:00
|
|
|
},
|
|
|
|
&structs.ProxyConfigEntry{
|
2023-03-22 18:56:18 +00:00
|
|
|
Kind: structs.ProxyDefaults,
|
|
|
|
Name: structs.ProxyConfigGlobal,
|
|
|
|
EnterpriseMeta: entMeta,
|
2022-03-07 17:47:14 +00:00
|
|
|
Config: map[string]interface{}{
|
|
|
|
"protocol": "http",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&structs.ServiceSplitterConfigEntry{
|
2023-03-22 18:56:18 +00:00
|
|
|
Kind: structs.ServiceSplitter,
|
|
|
|
Name: "split-3-ways",
|
|
|
|
EnterpriseMeta: entMeta,
|
2022-03-07 17:47:14 +00:00
|
|
|
Splits: []structs.ServiceSplit{
|
|
|
|
{Weight: 95.5, Service: "big-side"},
|
|
|
|
{Weight: 4, Service: "goldilocks-side"},
|
|
|
|
{Weight: 0.5, Service: "lil-bit-side"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&structs.ServiceRouterConfigEntry{
|
2023-03-22 18:56:18 +00:00
|
|
|
Kind: structs.ServiceRouter,
|
|
|
|
Name: "db",
|
|
|
|
EnterpriseMeta: entMeta,
|
2022-03-07 17:47:14 +00:00
|
|
|
Routes: []structs.ServiceRoute{
|
|
|
|
{
|
|
|
|
Match: httpMatch(&structs.ServiceRouteHTTPMatch{
|
|
|
|
PathPrefix: "/prefix",
|
|
|
|
}),
|
|
|
|
Destination: toService("prefix"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Match: httpMatch(&structs.ServiceRouteHTTPMatch{
|
|
|
|
PathExact: "/exact",
|
|
|
|
}),
|
|
|
|
Destination: toService("exact"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Match: httpMatch(&structs.ServiceRouteHTTPMatch{
|
|
|
|
PathRegex: "/regex",
|
|
|
|
}),
|
|
|
|
Destination: toService("regex"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Match: httpMatchHeader(structs.ServiceRouteHTTPMatchHeader{
|
|
|
|
Name: "x-debug",
|
|
|
|
Present: true,
|
|
|
|
}),
|
|
|
|
Destination: toService("hdr-present"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Match: httpMatchHeader(structs.ServiceRouteHTTPMatchHeader{
|
|
|
|
Name: "x-debug",
|
|
|
|
Present: true,
|
|
|
|
Invert: true,
|
|
|
|
}),
|
|
|
|
Destination: toService("hdr-not-present"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Match: httpMatchHeader(structs.ServiceRouteHTTPMatchHeader{
|
|
|
|
Name: "x-debug",
|
|
|
|
Exact: "exact",
|
|
|
|
}),
|
|
|
|
Destination: toService("hdr-exact"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Match: httpMatchHeader(structs.ServiceRouteHTTPMatchHeader{
|
|
|
|
Name: "x-debug",
|
|
|
|
Prefix: "prefix",
|
|
|
|
}),
|
|
|
|
Destination: toService("hdr-prefix"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Match: httpMatchHeader(structs.ServiceRouteHTTPMatchHeader{
|
|
|
|
Name: "x-debug",
|
|
|
|
Suffix: "suffix",
|
|
|
|
}),
|
|
|
|
Destination: toService("hdr-suffix"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Match: httpMatchHeader(structs.ServiceRouteHTTPMatchHeader{
|
|
|
|
Name: "x-debug",
|
|
|
|
Regex: "regex",
|
|
|
|
}),
|
|
|
|
Destination: toService("hdr-regex"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Match: httpMatch(&structs.ServiceRouteHTTPMatch{
|
|
|
|
Methods: []string{"GET", "PUT"},
|
|
|
|
}),
|
|
|
|
Destination: toService("just-methods"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Match: httpMatch(&structs.ServiceRouteHTTPMatch{
|
|
|
|
Header: []structs.ServiceRouteHTTPMatchHeader{
|
|
|
|
{
|
|
|
|
Name: "x-debug",
|
|
|
|
Exact: "exact",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Methods: []string{"GET", "PUT"},
|
|
|
|
}),
|
|
|
|
Destination: toService("hdr-exact-with-method"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Match: httpMatchParam(structs.ServiceRouteHTTPMatchQueryParam{
|
|
|
|
Name: "secretparam1",
|
|
|
|
Exact: "exact",
|
|
|
|
}),
|
|
|
|
Destination: toService("prm-exact"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Match: httpMatchParam(structs.ServiceRouteHTTPMatchQueryParam{
|
|
|
|
Name: "secretparam2",
|
|
|
|
Regex: "regex",
|
|
|
|
}),
|
|
|
|
Destination: toService("prm-regex"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Match: httpMatchParam(structs.ServiceRouteHTTPMatchQueryParam{
|
|
|
|
Name: "secretparam3",
|
|
|
|
Present: true,
|
|
|
|
}),
|
|
|
|
Destination: toService("prm-present"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Match: nil,
|
|
|
|
Destination: toService("nil-match"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Match: &structs.ServiceRouteMatch{},
|
|
|
|
Destination: toService("empty-match-1"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Match: &structs.ServiceRouteMatch{
|
|
|
|
HTTP: &structs.ServiceRouteHTTPMatch{},
|
|
|
|
},
|
|
|
|
Destination: toService("empty-match-2"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Match: httpMatch(&structs.ServiceRouteHTTPMatch{
|
|
|
|
PathPrefix: "/prefix",
|
|
|
|
}),
|
|
|
|
Destination: &structs.ServiceRouteDestination{
|
|
|
|
Service: "prefix-rewrite-1",
|
|
|
|
PrefixRewrite: "/",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Match: httpMatch(&structs.ServiceRouteHTTPMatch{
|
|
|
|
PathPrefix: "/prefix",
|
|
|
|
}),
|
|
|
|
Destination: &structs.ServiceRouteDestination{
|
|
|
|
Service: "prefix-rewrite-2",
|
|
|
|
PrefixRewrite: "/nested/newlocation",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Match: httpMatch(&structs.ServiceRouteHTTPMatch{
|
|
|
|
PathPrefix: "/timeout",
|
|
|
|
}),
|
|
|
|
Destination: &structs.ServiceRouteDestination{
|
|
|
|
Service: "req-timeout",
|
|
|
|
RequestTimeout: 33 * time.Second,
|
|
|
|
},
|
|
|
|
},
|
2022-11-29 22:43:15 +00:00
|
|
|
{
|
|
|
|
Match: httpMatch(&structs.ServiceRouteHTTPMatch{
|
|
|
|
PathPrefix: "/idle-timeout",
|
|
|
|
}),
|
|
|
|
Destination: &structs.ServiceRouteDestination{
|
|
|
|
Service: "idle-timeout",
|
|
|
|
IdleTimeout: 33 * time.Second,
|
|
|
|
},
|
|
|
|
},
|
2022-03-07 17:47:14 +00:00
|
|
|
{
|
|
|
|
Match: httpMatch(&structs.ServiceRouteHTTPMatch{
|
|
|
|
PathPrefix: "/retry-connect",
|
|
|
|
}),
|
|
|
|
Destination: &structs.ServiceRouteDestination{
|
|
|
|
Service: "retry-connect",
|
|
|
|
NumRetries: 15,
|
|
|
|
RetryOnConnectFailure: true,
|
|
|
|
},
|
|
|
|
},
|
2022-10-05 17:06:44 +00:00
|
|
|
{
|
|
|
|
Match: httpMatch(&structs.ServiceRouteHTTPMatch{
|
|
|
|
PathPrefix: "/retry-reset",
|
|
|
|
}),
|
|
|
|
Destination: &structs.ServiceRouteDestination{
|
|
|
|
Service: "retry-reset",
|
|
|
|
NumRetries: 15,
|
|
|
|
RetryOn: []string{"reset"},
|
|
|
|
},
|
|
|
|
},
|
2022-03-07 17:47:14 +00:00
|
|
|
{
|
|
|
|
Match: httpMatch(&structs.ServiceRouteHTTPMatch{
|
|
|
|
PathPrefix: "/retry-codes",
|
|
|
|
}),
|
|
|
|
Destination: &structs.ServiceRouteDestination{
|
|
|
|
Service: "retry-codes",
|
|
|
|
NumRetries: 15,
|
|
|
|
RetryOnStatusCodes: []uint32{401, 409, 451},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Match: httpMatch(&structs.ServiceRouteHTTPMatch{
|
2022-10-05 17:06:44 +00:00
|
|
|
PathPrefix: "/retry-all",
|
2022-03-07 17:47:14 +00:00
|
|
|
}),
|
|
|
|
Destination: &structs.ServiceRouteDestination{
|
2022-10-05 17:06:44 +00:00
|
|
|
Service: "retry-all",
|
2022-03-07 17:47:14 +00:00
|
|
|
RetryOnConnectFailure: true,
|
2022-10-05 17:06:44 +00:00
|
|
|
RetryOn: []string{"5xx", "gateway-error", "reset", "connect-failure", "envoy-ratelimited", "retriable-4xx", "refused-stream", "cancelled", "deadline-exceeded", "internal", "resource-exhausted", "unavailable"},
|
2022-03-07 17:47:14 +00:00
|
|
|
RetryOnStatusCodes: []uint32{401, 409, 451},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Match: httpMatch(&structs.ServiceRouteHTTPMatch{
|
|
|
|
PathPrefix: "/split-3-ways",
|
|
|
|
}),
|
|
|
|
Destination: toService("split-3-ways"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Match: httpMatch(&structs.ServiceRouteHTTPMatch{
|
|
|
|
PathExact: "/header-manip",
|
|
|
|
}),
|
|
|
|
Destination: &structs.ServiceRouteDestination{
|
|
|
|
Service: "header-manip",
|
|
|
|
RequestHeaders: &structs.HTTPHeaderModifiers{
|
|
|
|
Add: map[string]string{
|
|
|
|
"request": "bar",
|
|
|
|
},
|
|
|
|
Set: map[string]string{
|
|
|
|
"bar": "baz",
|
|
|
|
},
|
|
|
|
Remove: []string{"qux"},
|
|
|
|
},
|
|
|
|
ResponseHeaders: &structs.HTTPHeaderModifiers{
|
|
|
|
Add: map[string]string{
|
|
|
|
"response": "bar",
|
|
|
|
},
|
|
|
|
Set: map[string]string{
|
|
|
|
"bar": "baz",
|
|
|
|
},
|
|
|
|
Remove: []string{"qux"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)
|
|
|
|
case "lb-resolver":
|
|
|
|
entries = append(entries,
|
|
|
|
&structs.ProxyConfigEntry{
|
2023-03-22 18:56:18 +00:00
|
|
|
Kind: structs.ProxyDefaults,
|
|
|
|
Name: structs.ProxyConfigGlobal,
|
|
|
|
EnterpriseMeta: entMeta,
|
2022-03-07 17:47:14 +00:00
|
|
|
Config: map[string]interface{}{
|
|
|
|
"protocol": "http",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&structs.ServiceSplitterConfigEntry{
|
2023-03-22 18:56:18 +00:00
|
|
|
Kind: structs.ServiceSplitter,
|
|
|
|
Name: "db",
|
|
|
|
EnterpriseMeta: entMeta,
|
2022-03-07 17:47:14 +00:00
|
|
|
Splits: []structs.ServiceSplit{
|
|
|
|
{Weight: 95.5, Service: "something-else"},
|
|
|
|
{Weight: 4.5, Service: "db"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&structs.ServiceResolverConfigEntry{
|
2023-03-22 18:56:18 +00:00
|
|
|
Kind: structs.ServiceResolver,
|
|
|
|
Name: "db",
|
|
|
|
EnterpriseMeta: entMeta,
|
2022-03-07 17:47:14 +00:00
|
|
|
LoadBalancer: &structs.LoadBalancer{
|
|
|
|
Policy: "ring_hash",
|
|
|
|
RingHashConfig: &structs.RingHashConfig{
|
|
|
|
MinimumRingSize: 20,
|
|
|
|
MaximumRingSize: 30,
|
|
|
|
},
|
|
|
|
HashPolicies: []structs.HashPolicy{
|
|
|
|
{
|
|
|
|
Field: "cookie",
|
|
|
|
FieldValue: "chocolate-chip",
|
|
|
|
Terminal: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Field: "cookie",
|
|
|
|
FieldValue: "chocolate-chip",
|
|
|
|
CookieConfig: &structs.CookieConfig{Session: true},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Field: "header",
|
|
|
|
FieldValue: "x-user-id",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
SourceIP: true,
|
|
|
|
Terminal: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)
|
|
|
|
default:
|
|
|
|
t.Fatalf("unexpected variation: %q", variation)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(additionalEntries) > 0 {
|
|
|
|
entries = append(entries, additionalEntries...)
|
|
|
|
}
|
|
|
|
|
2023-03-22 18:56:18 +00:00
|
|
|
return discoverychain.TestCompileConfigEntries(t, "db", entMeta.NamespaceOrDefault(), entMeta.PartitionOrDefault(), "dc1", connect.TestClusterID+".consul", compileSetup, entries...)
|
2022-03-07 17:47:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func httpMatch(http *structs.ServiceRouteHTTPMatch) *structs.ServiceRouteMatch {
|
|
|
|
return &structs.ServiceRouteMatch{HTTP: http}
|
|
|
|
}
|
|
|
|
func httpMatchHeader(headers ...structs.ServiceRouteHTTPMatchHeader) *structs.ServiceRouteMatch {
|
|
|
|
return httpMatch(&structs.ServiceRouteHTTPMatch{
|
|
|
|
Header: headers,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
func httpMatchParam(params ...structs.ServiceRouteHTTPMatchQueryParam) *structs.ServiceRouteMatch {
|
|
|
|
return httpMatch(&structs.ServiceRouteHTTPMatch{
|
|
|
|
QueryParam: params,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
func toService(svc string) *structs.ServiceRouteDestination {
|
|
|
|
return &structs.ServiceRouteDestination{Service: svc}
|
|
|
|
}
|