Skip to content

Commit

Permalink
Fix typo for CorrelatedInvocationsID
Browse files Browse the repository at this point in the history
This cl make correction to the identifier's CorrelatedInvocationsID field name to make it match the proto. It was CorrelatedInvocationID before.

We need to have CorrelatedInvocationsID in the ToProto method to deduplicate builds that have the same invocation id.
  • Loading branch information
ywmei-brt1 committed Jul 25, 2024
1 parent baabf15 commit b7d4e5b
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 97 deletions.
44 changes: 22 additions & 22 deletions go/pkg/contextmd/contextmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,28 +182,28 @@ func capToLimit(m *Metadata, limit int) *Metadata {
if excess <= 0 {
return m
}
truncateStrings(limit, &m.ActionID, &m.InvocationID, &m.CorrelatedInvocationsID, &m.ToolName, &m.ToolVersion)
return m
}

// truncateStrings remove one char from the longest str at a time until the
// total length of all the strings is less than limit value.
func truncateStrings(limit int, inputs ...*string) {
total := 0
for _, s := range inputs {
total += len(*s)
}
if total <= limit {
return
}
for total > limit {
mIdx := 0
for i, s := range inputs {
if len(*s) > len(*inputs[mIdx]) {
mIdx = i
}
// We ignore the tool name, because in practice this is a
// very short constant which makes no sense to truncate.
diff := len(m.ActionID) - len(m.InvocationID)
if diff > 0 {
if diff > excess {
m.ActionID = m.ActionID[:len(m.ActionID)-excess]
} else {
m.ActionID = m.ActionID[:len(m.ActionID)-diff]
rem := (excess - diff + 1) / 2
m.ActionID = m.ActionID[:len(m.ActionID)-rem]
m.InvocationID = m.InvocationID[:len(m.InvocationID)-rem]
}
} else {
diff = -diff
if diff > excess {
m.InvocationID = m.InvocationID[:len(m.InvocationID)-excess]
} else {
m.InvocationID = m.InvocationID[:len(m.InvocationID)-diff]
rem := (excess - diff + 1) / 2
m.InvocationID = m.InvocationID[:len(m.InvocationID)-rem]
m.ActionID = m.ActionID[:len(m.ActionID)-rem]
}
*inputs[mIdx] = (*inputs[mIdx])[:len(*inputs[mIdx])-1]
total -= 1
}
return m
}
122 changes: 47 additions & 75 deletions go/pkg/contextmd/contextmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,116 +14,88 @@ func TestCapToLimit(t *testing.T) {
tests := []testCase{
{
name: "under limit",
limit: 32,
limit: 24,
input: &Metadata{
ToolName: "toolName",
ActionID: "actionID",
InvocationID: "invocID*",
CorrelatedInvocationsID: "12345678",
ToolName: "toolName",
ActionID: "actionID",
InvocationID: "invocID*",
},
want: &Metadata{
ToolName: "toolName",
ActionID: "actionID",
InvocationID: "invocID*",
CorrelatedInvocationsID: "12345678",
ToolName: "toolName",
ActionID: "actionID",
InvocationID: "invocID*",
},
},
{
name: "actionID over limit",
limit: 32,
limit: 24,
input: &Metadata{
ToolName: "toolName",
ActionID: "actionID-12345678",
InvocationID: "invocID*",
CorrelatedInvocationsID: "12345678",
ToolName: "toolName",
ActionID: "actionID-12345678",
InvocationID: "invocID*",
},
want: &Metadata{
ToolName: "toolName",
ActionID: "actionID",
InvocationID: "invocID*",
CorrelatedInvocationsID: "12345678",
ToolName: "toolName",
ActionID: "actionID",
InvocationID: "invocID*",
},
},
{
name: "invocationID over limit",
limit: 37,
limit: 29,
input: &Metadata{
ToolName: "toolName",
ToolVersion: "1.2.3",
ActionID: "actionID",
InvocationID: "invocID*-12345678",
CorrelatedInvocationsID: "12345678",
ToolName: "toolName",
ToolVersion: "1.2.3",
ActionID: "actionID",
InvocationID: "invocID*-12345678",
},
want: &Metadata{
ToolName: "toolName",
ToolVersion: "1.2.3",
ActionID: "actionID",
InvocationID: "invocID*",
CorrelatedInvocationsID: "12345678",
ToolName: "toolName",
ToolVersion: "1.2.3",
ActionID: "actionID",
InvocationID: "invocID*",
},
},
{
name: "ActionID and InvocationID both equally over limit",
limit: 32,
name: "both equally over limit",
limit: 24,
input: &Metadata{
ToolName: "toolName",
ActionID: "actionID-12345678",
InvocationID: "invocID*-12345678",
CorrelatedInvocationsID: "12345678",
ToolName: "toolName",
ActionID: "actionID-12345678",
InvocationID: "invocID*-12345678",
},
want: &Metadata{
ToolName: "toolName",
ActionID: "actionID",
InvocationID: "invocID*",
CorrelatedInvocationsID: "12345678",
ToolName: "toolName",
ActionID: "actionID",
InvocationID: "invocID*",
},
},
{
name: "ActionID and InvocationID both over limit but actionID is bigger",
limit: 32,
name: "both over limit but actionID is bigger",
limit: 24,
input: &Metadata{
ToolName: "toolName",
ActionID: "actionID-123456789012345678",
InvocationID: "invocID*-12345678",
CorrelatedInvocationsID: "12345678",
ToolName: "toolName",
ActionID: "actionID-123456789012345678",
InvocationID: "invocID*-12345678",
},
want: &Metadata{
ToolName: "toolName",
ActionID: "actionID",
InvocationID: "invocID*",
CorrelatedInvocationsID: "12345678",
ToolName: "toolName",
ActionID: "actionID",
InvocationID: "invocID*",
},
},
{
name: "CorrelatedInvocationsID and InvocationID both over limit but CorrelatedInvocationsID is bigger",
limit: 32,
name: "both over limit but invocationID is bigger",
limit: 24,
input: &Metadata{
ToolName: "toolName",
ActionID: "actionID",
InvocationID: "invocID*-12345678",
CorrelatedInvocationsID: "1234567890987654321",
ToolName: "toolName",
ActionID: "actionID-12345678",
InvocationID: "invocID*-123456789012345678",
},
want: &Metadata{
ToolName: "toolName",
ActionID: "actionID",
InvocationID: "invocID*",
CorrelatedInvocationsID: "12345678",
},
},
{
name: "ActionID and InvocationID both over limit but invocationID is bigger",
limit: 32,
input: &Metadata{
ToolName: "toolName",
ActionID: "actionID-12345678",
InvocationID: "invocID*-123456789012345678",
CorrelatedInvocationsID: "12345678",
},
want: &Metadata{
ToolName: "toolName",
ActionID: "actionID",
InvocationID: "invocID*",
CorrelatedInvocationsID: "12345678",
ToolName: "toolName",
ActionID: "actionID",
InvocationID: "invocID*",
},
},
}
Expand Down

0 comments on commit b7d4e5b

Please sign in to comment.