cmd/XDC, metrics/prometheus: fix staticcheck QF1012 (#1713)

This commit is contained in:
Daniel Liu 2025-12-07 18:33:06 +08:00 committed by GitHub
parent 8129ac77cd
commit 640d448491
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 11 additions and 11 deletions

View file

@ -167,7 +167,7 @@ func remoteConsole(ctx *cli.Context) error {
func ephemeralConsole(ctx *cli.Context) error {
var b strings.Builder
for _, file := range ctx.Args().Slice() {
b.WriteString(fmt.Sprintf("loadScript('%s');", file))
fmt.Fprintf(&b, "loadScript('%s');", file)
}
utils.Fatalf(`The "js" command is deprecated. Please use the following instead:
XDC --exec "%s" console`, b.String())

View file

@ -99,7 +99,7 @@ func (c *collector) addHistogram(name string, m metrics.HistogramSnapshot) {
pv := []float64{0.5, 0.75, 0.95, 0.99, 0.999, 0.9999}
ps := m.Percentiles(pv)
c.writeSummaryCounter(name, m.Count())
c.buff.WriteString(fmt.Sprintf(typeSummaryTpl, mutateKey(name)))
fmt.Fprintf(c.buff, typeSummaryTpl, mutateKey(name))
for i := range pv {
c.writeSummaryPercentile(name, strconv.FormatFloat(pv[i], 'f', -1, 64), ps[i])
}
@ -114,7 +114,7 @@ func (c *collector) addTimer(name string, m *metrics.TimerSnapshot) {
pv := []float64{0.5, 0.75, 0.95, 0.99, 0.999, 0.9999}
ps := m.Percentiles(pv)
c.writeSummaryCounter(name, m.Count())
c.buff.WriteString(fmt.Sprintf(typeSummaryTpl, mutateKey(name)))
fmt.Fprintf(c.buff, typeSummaryTpl, mutateKey(name))
for i := range pv {
c.writeSummaryPercentile(name, strconv.FormatFloat(pv[i], 'f', -1, 64), ps[i])
}
@ -128,7 +128,7 @@ func (c *collector) addResettingTimer(name string, m *metrics.ResettingTimerSnap
pv := []float64{0.5, 0.75, 0.95, 0.99, 0.999, 0.9999}
ps := m.Percentiles(pv)
c.writeSummaryCounter(name, m.Count())
c.buff.WriteString(fmt.Sprintf(typeSummaryTpl, mutateKey(name)))
fmt.Fprintf(c.buff, typeSummaryTpl, mutateKey(name))
for i := range pv {
c.writeSummaryPercentile(name, strconv.FormatFloat(pv[i], 'f', -1, 64), ps[i])
}
@ -137,7 +137,7 @@ func (c *collector) addResettingTimer(name string, m *metrics.ResettingTimerSnap
func (c *collector) writeGaugeInfo(name string, value metrics.GaugeInfoValue) {
name = mutateKey(name)
c.buff.WriteString(fmt.Sprintf(typeGaugeTpl, name))
fmt.Fprintf(c.buff, typeGaugeTpl, name)
c.buff.WriteString(name)
c.buff.WriteString(" ")
kvs := make([]string, 0, len(value))
@ -145,24 +145,24 @@ func (c *collector) writeGaugeInfo(name string, value metrics.GaugeInfoValue) {
kvs = append(kvs, fmt.Sprintf("%v=%q", k, v))
}
slices.Sort(kvs)
c.buff.WriteString(fmt.Sprintf("{%v} 1\n\n", strings.Join(kvs, ", ")))
fmt.Fprintf(c.buff, "{%v} 1\n\n", strings.Join(kvs, ", "))
}
func (c *collector) writeGaugeCounter(name string, value interface{}) {
name = mutateKey(name)
c.buff.WriteString(fmt.Sprintf(typeGaugeTpl, name))
c.buff.WriteString(fmt.Sprintf(keyValueTpl, name, value))
fmt.Fprintf(c.buff, typeGaugeTpl, name)
fmt.Fprintf(c.buff, keyValueTpl, name, value)
}
func (c *collector) writeSummaryCounter(name string, value interface{}) {
name = mutateKey(name + "_count")
c.buff.WriteString(fmt.Sprintf(typeCounterTpl, name))
c.buff.WriteString(fmt.Sprintf(keyValueTpl, name, value))
fmt.Fprintf(c.buff, typeCounterTpl, name)
fmt.Fprintf(c.buff, keyValueTpl, name, value)
}
func (c *collector) writeSummaryPercentile(name, p string, value interface{}) {
name = mutateKey(name)
c.buff.WriteString(fmt.Sprintf(keyQuantileTagValueTpl, name, p, value))
fmt.Fprintf(c.buff, keyQuantileTagValueTpl, name, p, value)
}
func mutateKey(key string) string {