mirror of
https://github.com/siderolabs/discovery-service.git
synced 2025-03-14 09:55:08 +00:00
Rework the gRPC logger by using hand-rolled simple version, rework version parsing to remove regexp matching. The baseline (via benchmark): ``` BenchmarkViaClientSimulator-32 2934 387398 ns/op 101921 B/op 832 allocs/op ``` The baseline + removed logging middleware: ``` BenchmarkViaClientSimulator-32 3543 331166 ns/op 73581 B/op 543 allocs/op ``` Reworked logging middleware: ``` BenchmarkViaClientSimulator-32 3394 334066 ns/op 77985 B/op 568 allocs/op ``` Plus reworked version parsing: ``` BenchmarkViaClientSimulator-32 3510 325714 ns/op 66215 B/op 561 allocs/op ``` So overall, baseline to this PR: * allocs 101921 -> 66215 B/op * alloc ops 832 -> 561 allocs/op Signed-off-by: Andrey Smirnov <andrey.smirnov@siderolabs.com>
37 lines
617 B
Go
37 lines
617 B
Go
// Copyright (c) 2024 Sidero Labs, Inc.
|
|
//
|
|
// Use of this software is governed by the Business Source License
|
|
// included in the LICENSE file.
|
|
|
|
package server
|
|
|
|
import (
|
|
"strings"
|
|
)
|
|
|
|
const unknownVersion = "unknown"
|
|
|
|
func parseVersion(v string) string {
|
|
ver, suffix, _ := strings.Cut(v, "-")
|
|
|
|
if ver == "" || ver[0] != 'v' {
|
|
return unknownVersion
|
|
}
|
|
|
|
p1 := strings.IndexByte(ver, '.')
|
|
if p1 == -1 || p1 > 3 {
|
|
return unknownVersion
|
|
}
|
|
|
|
p2 := strings.IndexByte(ver[p1+1:], '.')
|
|
if p2 == -1 || p2 > 3 {
|
|
return unknownVersion
|
|
}
|
|
|
|
if suffix != "" {
|
|
return ver[:p1+p2+1] + "-pre"
|
|
}
|
|
|
|
return ver[:p1+p2+1]
|
|
}
|