mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -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"
|
"fmt"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"net"
|
"net"
|
||||||
|
"slices"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
@ -248,12 +249,7 @@ func (d *Discovery) shouldWatchFromName(name string) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, sn := range d.watchedServices {
|
return slices.Contains(d.watchedServices, name)
|
||||||
if sn == name {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// shouldWatchFromTags returns whether the service of the given name should be watched based on its tags.
|
// 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() {
|
func (bm *BlockMetaCompaction) SetOutOfOrder() {
|
||||||
if bm.containsHint(CompactionHintFromOutOfOrder) {
|
if bm.FromOutOfOrder() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
bm.Hints = append(bm.Hints, CompactionHintFromOutOfOrder)
|
bm.Hints = append(bm.Hints, CompactionHintFromOutOfOrder)
|
||||||
|
@ -229,16 +229,7 @@ func (bm *BlockMetaCompaction) SetOutOfOrder() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bm *BlockMetaCompaction) FromOutOfOrder() bool {
|
func (bm *BlockMetaCompaction) FromOutOfOrder() bool {
|
||||||
return bm.containsHint(CompactionHintFromOutOfOrder)
|
return slices.Contains(bm.Hints, CompactionHintFromOutOfOrder)
|
||||||
}
|
|
||||||
|
|
||||||
func (bm *BlockMetaCompaction) containsHint(hint string) bool {
|
|
||||||
for _, h := range bm.Hints {
|
|
||||||
if h == hint {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
|
@ -15,6 +15,7 @@ package testutil
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net"
|
"net"
|
||||||
|
"slices"
|
||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
@ -48,12 +49,7 @@ func RandomUnprivilegedPort(t *testing.T) int {
|
||||||
}
|
}
|
||||||
|
|
||||||
func portWasUsed(port int) bool {
|
func portWasUsed(port int) bool {
|
||||||
for _, usedPort := range usedPorts {
|
return slices.Contains(usedPorts, port)
|
||||||
if port == usedPort {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func getPort() (int, error) {
|
func getPort() (int, error) {
|
||||||
|
|
Loading…
Reference in a new issue