Skip to content

Commit

Permalink
go/network: remove creation publication ID from SNI cache
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jgraettinger committed Oct 16, 2024
1 parent 00996df commit 6b4a8c8
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
10 changes: 9 additions & 1 deletion go/network/sni.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
31 changes: 31 additions & 0 deletions go/network/sni_test.go
Original file line number Diff line number Diff line change
@@ -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))
}

0 comments on commit 6b4a8c8

Please sign in to comment.