fix: полный продакшен-фикс dashboard/peer/hysteria по fix35
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
"hy2xs-admin/dao"
|
||||
"hy2xs-admin/model/entity"
|
||||
"hy2xs-admin/model/vo"
|
||||
@@ -11,6 +15,19 @@ import (
|
||||
|
||||
const hysteriaVersionCacheTTL = 15 * time.Minute
|
||||
|
||||
var ansiRe = regexp.MustCompile(`\x1b\[[0-9;]*[A-Za-z]`)
|
||||
var hysteriaVersionRe = regexp.MustCompile(`(?i)v?\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?`)
|
||||
|
||||
func normalizeHysteriaVersion(raw string) string {
|
||||
cleaned := strings.TrimSpace(raw)
|
||||
cleaned = ansiRe.ReplaceAllString(cleaned, "")
|
||||
match := hysteriaVersionRe.FindString(cleaned)
|
||||
if match == "" {
|
||||
return "-"
|
||||
}
|
||||
return strings.TrimSpace(match)
|
||||
}
|
||||
|
||||
type metricsSnapshot struct {
|
||||
CollectedAt int64
|
||||
System vo.DashboardSystemVo
|
||||
@@ -48,12 +65,16 @@ func getCachedHysteriaVersion(now time.Time) string {
|
||||
}
|
||||
return "-"
|
||||
}
|
||||
normalized := normalizeHysteriaVersion(content)
|
||||
if normalized == "-" {
|
||||
logrus.Debugf("hysteria version parse failed, raw output: %q", strings.TrimSpace(content))
|
||||
}
|
||||
|
||||
metricsStore.Lock()
|
||||
metricsStore.version = content
|
||||
metricsStore.version = normalized
|
||||
metricsStore.versionAt = now
|
||||
metricsStore.Unlock()
|
||||
return content
|
||||
return normalized
|
||||
}
|
||||
|
||||
func CollectMetricsSnapshot() {
|
||||
|
||||
Reference in New Issue
Block a user