Skip to content

Commit

Permalink
Port and AllocatedPortMapping msgpack omitempty (#23980)
Browse files Browse the repository at this point in the history
to optimize log entries with empty fields, which TestPlanNormalize checks
  • Loading branch information
gulducat authored Sep 17, 2024
1 parent b7f1800 commit 603a747
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 118 deletions.
2 changes: 1 addition & 1 deletion nomad/plan_normalization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,5 @@ func TestPlanNormalize(t *testing.T) {

optimizedLogSize := buf.Len()
ratio := float64(optimizedLogSize) / float64(unoptimizedLogSize)
must.Less(t, 0.66, ratio)
must.Less(t, 0.6, ratio)
}
4 changes: 2 additions & 2 deletions nomad/structs/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -2809,10 +2809,10 @@ func portDiffs(old, new []Port, dynamic bool, contextual bool) []*ObjectDiff {
oldPorts := makeSet(old)
newPorts := makeSet(new)

var filter []string
filter := []string{"_struct"}
name := "Static Port"
if dynamic {
filter = []string{"Value"}
filter = []string{"_struct", "Value"}
name = "Dynamic Port"
}

Expand Down
46 changes: 8 additions & 38 deletions nomad/structs/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6843,9 +6843,7 @@ func TestTaskDiff(t *testing.T) {
"a": 1,
"b": 2,
},
"boom": &Port{
Label: "boom_port",
},
"boom": []string{"boom_port"},
},
},
New: &Task{
Expand All @@ -6857,9 +6855,7 @@ func TestTaskDiff(t *testing.T) {
"a": 1,
"b": 2,
},
"boom": &Port{
Label: "boom_port",
},
"boom": []string{"boom_port"},
},
},
Expected: &TaskDiff{
Expand All @@ -6877,9 +6873,7 @@ func TestTaskDiff(t *testing.T) {
"a": 1,
"b": 2,
},
"boom": &Port{
Label: "boom_port",
},
"boom": []string{"boom_port"},
},
},
New: &Task{
Expand All @@ -6891,9 +6885,7 @@ func TestTaskDiff(t *testing.T) {
"b": 3,
"c": 4,
},
"boom": &Port{
Label: "boom_port2",
},
"boom": []string{"boom_port2"},
},
},
Expected: &TaskDiff{
Expand Down Expand Up @@ -6935,7 +6927,7 @@ func TestTaskDiff(t *testing.T) {
},
{
Type: DiffTypeEdited,
Name: "boom.Label",
Name: "boom[0]",
Old: "boom_port",
New: "boom_port2",
},
Expand All @@ -6962,9 +6954,7 @@ func TestTaskDiff(t *testing.T) {
"a": 1,
"b": 2,
},
"boom": &Port{
Label: "boom_port",
},
"boom": []string{"boom_port"},
},
},
New: &Task{
Expand All @@ -6976,9 +6966,7 @@ func TestTaskDiff(t *testing.T) {
"a": 1,
"b": 2,
},
"boom": &Port{
Label: "boom_port",
},
"boom": []string{"boom_port"},
},
},
Expected: &TaskDiff{
Expand Down Expand Up @@ -7026,28 +7014,10 @@ func TestTaskDiff(t *testing.T) {
},
{
Type: DiffTypeNone,
Name: "boom.HostNetwork",
Old: "",
New: "",
},
{
Type: DiffTypeNone,
Name: "boom.Label",
Name: "boom[0]",
Old: "boom_port",
New: "boom_port",
},
{
Type: DiffTypeNone,
Name: "boom.To",
Old: "0",
New: "0",
},
{
Type: DiffTypeNone,
Name: "boom.Value",
Old: "0",
New: "0",
},
{
Type: DiffTypeEdited,
Name: "foo",
Expand Down
8 changes: 4 additions & 4 deletions nomad/structs/funcs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func TestAllocsFit(t *testing.T) {
{
Mode: "host",
IP: "10.0.0.1",
ReservedPorts: []Port{{"main", 8000, 0, ""}},
ReservedPorts: []Port{{Label: "main", Value: 8000}},
},
},
Ports: AllocatedPorts{
Expand Down Expand Up @@ -268,7 +268,7 @@ func TestAllocsFit_TerminalAlloc(t *testing.T) {
Device: "eth0",
IP: "10.0.0.1",
MBits: 50,
ReservedPorts: []Port{{"main", 8000, 80, ""}},
ReservedPorts: []Port{{Label: "main", Value: 8000, To: 80}},
},
},
},
Expand Down Expand Up @@ -322,7 +322,7 @@ func TestAllocsFit_ClientTerminalAlloc(t *testing.T) {
Device: "eth0",
IP: "10.0.0.1",
MBits: 50,
ReservedPorts: []Port{{"main", 8000, 80, ""}},
ReservedPorts: []Port{{Label: "main", Value: 8000, To: 80}},
},
},
},
Expand Down Expand Up @@ -373,7 +373,7 @@ func TestAllocsFit_ServerTerminalAlloc(t *testing.T) {
Device: "eth0",
IP: "10.0.0.1",
MBits: 50,
ReservedPorts: []Port{{"main", 8000, 80, ""}},
ReservedPorts: []Port{{Label: "main", Value: 8000, To: 80}},
},
},
},
Expand Down
Loading

0 comments on commit 603a747

Please sign in to comment.