From 6b4a8c8dbd4b2a7d48e1699e3e13204f372b1392 Mon Sep 17 00:00:00 2001 From: Johnny Graettinger Date: Tue, 15 Oct 2024 18:16:51 -0500 Subject: [PATCH] go/network: remove creation publication ID from SNI cache This prevents a deletion and re-creation of a task with the same name from then failing to resolve, because both the old and new task will share a common shardIDPrefix. --- go/network/sni.go | 10 +++++++++- go/network/sni_test.go | 31 +++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 go/network/sni_test.go diff --git a/go/network/sni.go b/go/network/sni.go index e174d8608c..8be19822c7 100644 --- a/go/network/sni.go +++ b/go/network/sni.go @@ -64,8 +64,16 @@ func parseSNI(target string) (parsedSNI, error) { func newResolvedSNI(parsed parsedSNI, shard *pc.ShardSpec) resolvedSNI { var shardIDPrefix = shard.Id.String() + + // Strip final Shard ID suffix, like `00000000-00000000`. + if ind := strings.LastIndexByte(shardIDPrefix, '/'); ind != -1 { + shardIDPrefix = shardIDPrefix[:ind] + } + // Strip embedded creation publication ID, like `0123457890abcdef`. + // If we didn't do this, a deletion and creation of a task with the + // same name would break our resolution index cache. if ind := strings.LastIndexByte(shardIDPrefix, '/'); ind != -1 { - shardIDPrefix = shardIDPrefix[:ind+1] // Including trailing '/'. + shardIDPrefix = shardIDPrefix[:ind+1] // Retain trailing '/'. } var portProtocol = shard.LabelSet.ValueOf(labels.PortProtoPrefix + parsed.port) diff --git a/go/network/sni_test.go b/go/network/sni_test.go new file mode 100644 index 0000000000..6f7913a7f7 --- /dev/null +++ b/go/network/sni_test.go @@ -0,0 +1,31 @@ +package network + +import ( + "testing" + + "github.com/estuary/flow/go/labels" + "github.com/stretchr/testify/require" + pb "go.gazette.dev/core/broker/protocol" + pc "go.gazette.dev/core/consumer/protocol" +) + +func TestResolveSNIMapping(t *testing.T) { + var ( + parsed = parsedSNI{ + hostname: "abcdefg", + port: "8080", + } + shard = &pc.ShardSpec{ + Id: "capture/AcmeCo/My/Capture/source-http-ingest/0f05593ad1800023/00000000-00000000", + LabelSet: pb.MustLabelSet( + labels.PortProtoPrefix+"8080", "leet", + labels.PortPublicPrefix+"8080", "true", + ), + } + ) + require.Equal(t, resolvedSNI{ + shardIDPrefix: "capture/AcmeCo/My/Capture/source-http-ingest/", + portProtocol: "leet", + portIsPublic: true, + }, newResolvedSNI(parsed, shard)) +}