mirror of
https://github.com/prometheus/prometheus.git
synced 2025-01-27 05:32:27 -08:00
Signed-off-by: crystalstall <crystalruby@qq.com>
refactor: using slices.Contains to simplify the code Signed-off-by: crystalstall <crystalruby@qq.com>
This commit is contained in:
parent
a441ad771e
commit
616914abe2
|
@ -19,6 +19,7 @@ import (
|
|||
"fmt"
|
||||
"log/slog"
|
||||
"net"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
@ -248,12 +249,7 @@ func (d *Discovery) shouldWatchFromName(name string) bool {
|
|||
return true
|
||||
}
|
||||
|
||||
for _, sn := range d.watchedServices {
|
||||
if sn == name {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
return slices.Contains(d.watchedServices, name)
|
||||
}
|
||||
|
||||
// shouldWatchFromTags returns whether the service of the given name should be watched based on its tags.
|
||||
|
|
|
@ -221,7 +221,7 @@ type BlockMetaCompaction struct {
|
|||
}
|
||||
|
||||
func (bm *BlockMetaCompaction) SetOutOfOrder() {
|
||||
if bm.containsHint(CompactionHintFromOutOfOrder) {
|
||||
if bm.FromOutOfOrder() {
|
||||
return
|
||||
}
|
||||
bm.Hints = append(bm.Hints, CompactionHintFromOutOfOrder)
|
||||
|
@ -229,16 +229,7 @@ func (bm *BlockMetaCompaction) SetOutOfOrder() {
|
|||
}
|
||||
|
||||
func (bm *BlockMetaCompaction) FromOutOfOrder() bool {
|
||||
return bm.containsHint(CompactionHintFromOutOfOrder)
|
||||
}
|
||||
|
||||
func (bm *BlockMetaCompaction) containsHint(hint string) bool {
|
||||
for _, h := range bm.Hints {
|
||||
if h == hint {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
return slices.Contains(bm.Hints, CompactionHintFromOutOfOrder)
|
||||
}
|
||||
|
||||
const (
|
||||
|
|
|
@ -15,6 +15,7 @@ package testutil
|
|||
|
||||
import (
|
||||
"net"
|
||||
"slices"
|
||||
"sync"
|
||||
"testing"
|
||||
)
|
||||
|
@ -48,12 +49,7 @@ func RandomUnprivilegedPort(t *testing.T) int {
|
|||
}
|
||||
|
||||
func portWasUsed(port int) bool {
|
||||
for _, usedPort := range usedPorts {
|
||||
if port == usedPort {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
return slices.Contains(usedPorts, port)
|
||||
}
|
||||
|
||||
func getPort() (int, error) {
|
||||
|
|
Loading…
Reference in a new issue