Skip to content

Commit 7d9c18f

Browse files
authored
Switch to new log checksum format (#8415)
Switch to outputting the new checksum format. Part of #8414
1 parent 6983f21 commit 7d9c18f

File tree

3 files changed

+12
-14
lines changed

3 files changed

+12
-14
lines changed

log/log.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,20 +160,18 @@ type stdoutWriter struct {
160160
isatty bool
161161
}
162162

163-
// NewLineChecksum computes a CRC32 over the log line, which can be checked by
163+
// LogLineChecksum computes a CRC32 over the log line, which can be checked by
164164
// log-validator to ensure no unexpected log corruption has occurred.
165-
// It is currently only accepted for Validation, and will be switched in for
166-
// LogLineChecksum in an upcoming release.
167-
func NewLineChecksum(line string) string {
165+
func LogLineChecksum(line string) string {
168166
crc := crc32.ChecksumIEEE([]byte(line))
169167
buf := make([]byte, crc32.Size)
170168
// Error is unreachable because we provide a supported type and buffer size
171169
_, _ = binary.Encode(buf, binary.LittleEndian, crc)
172170
return base64.RawURLEncoding.EncodeToString(buf)
173171
}
174172

175-
// LogLineChecksum is the current checksum algorithm, emitted in every log line.
176-
func LogLineChecksum(line string) string {
173+
// OldLineChecksum was previously used, and is still accepted for validation.
174+
func OldLineChecksum(line string) string {
177175
crc := crc32.ChecksumIEEE([]byte(line))
178176
// Using the hash.Hash32 doesn't make this any easier
179177
// as it also returns a uint32 rather than []byte

log/log_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ func TestStdoutLogger(t *testing.T) {
102102
logger.Warning("Warning log")
103103
logger.Info("Info log")
104104

105-
test.AssertEquals(t, stdout.String(), "1970-01-01 prefix 6 log.test pcbo7wk Info log\n")
106-
test.AssertEquals(t, stderr.String(), "1970-01-01 prefix 3 log.test 46_ghQg [AUDIT] Error Audit\n1970-01-01 prefix 4 log.test 97r2xAw Warning log\n")
105+
test.AssertEquals(t, stdout.String(), "1970-01-01 prefix 6 log.test JSP6nQ Info log\n")
106+
test.AssertEquals(t, stderr.String(), "1970-01-01 prefix 3 log.test 4xe4gA [AUDIT] Error Audit\n1970-01-01 prefix 4 log.test d52dyA Warning log\n")
107107
}
108108

109109
func TestSyslogMethods(t *testing.T) {
@@ -352,14 +352,14 @@ func TestLogLineChecksum(t *testing.T) {
352352
expected string
353353
}{
354354
{
355-
name: "NewLineChecksum with Hello, World!",
356-
function: NewLineChecksum,
355+
name: "LogLineChecksum with Hello, World!",
356+
function: LogLineChecksum,
357357
input: "Hello, World!",
358358
expected: "0MNK7A",
359359
},
360360
{
361-
name: "LogLineChecksum with Info log",
362-
function: LogLineChecksum,
361+
name: "OldLineChecksum with Info log",
362+
function: OldLineChecksum,
363363
input: "Info log",
364364
expected: "pcbo7wk",
365365
},

log/validator/validator.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,9 @@ func lineValid(text string) error {
208208
// TODO(#8414): Accept both the old and new checksum format, distinguished by length
209209
var computedChecksum string
210210
if len(checksum) == 6 {
211-
computedChecksum = log.NewLineChecksum(line)
212-
} else {
213211
computedChecksum = log.LogLineChecksum(line)
212+
} else {
213+
computedChecksum = log.OldLineChecksum(line)
214214
}
215215
if checksum != computedChecksum {
216216
return fmt.Errorf("%s invalid checksum (expected %q, got %q)", errorPrefix, computedChecksum, checksum)

0 commit comments

Comments
 (0)