Skip to content

Commit a3733b6

Browse files
authored
Ban system metric collector for windows OS(#312)
1 parent f9ddf58 commit a3733b6

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

api/init.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import (
66
"github.com/alibaba/sentinel-golang/core/config"
77
"github.com/alibaba/sentinel-golang/core/log/metric"
88
"github.com/alibaba/sentinel-golang/core/system"
9+
"github.com/alibaba/sentinel-golang/logging"
910
"github.com/alibaba/sentinel-golang/util"
1011
)
1112

12-
// InitDefault initializes Sentinel using the configuration from system
1313
// environment and the default value.
1414
func InitDefault() error {
1515
return initSentinel("")
@@ -50,8 +50,12 @@ func initCoreComponents() error {
5050
if err := metric.InitTask(); err != nil {
5151
return err
5252
}
53+
if !util.IsWindowsOS() {
54+
system.InitCollector(config.SystemStatCollectIntervalMs())
55+
} else {
56+
logging.Warn("[Init initCoreComponents] system metric collect is not available for system module in windows")
57+
}
5358

54-
system.InitCollector(config.SystemStatCollectIntervalMs())
5559
if config.UseCacheTime() {
5660
util.StartTimeTicker()
5761
}

core/system/slot.go

+5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package system
33
import (
44
"github.com/alibaba/sentinel-golang/core/base"
55
"github.com/alibaba/sentinel-golang/core/stat"
6+
"github.com/alibaba/sentinel-golang/util"
67
)
78

89
type AdaptiveSlot struct {
@@ -12,6 +13,10 @@ func (s *AdaptiveSlot) Check(ctx *base.EntryContext) *base.TokenResult {
1213
if ctx == nil || ctx.Resource == nil || ctx.Resource.FlowType() != base.Inbound {
1314
return nil
1415
}
16+
// system module is not available for windows OS
17+
if util.IsWindowsOS() {
18+
return nil
19+
}
1520
rules := GetRules()
1621
result := ctx.RuleCheckResult
1722
for _, rule := range rules {

util/safe.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package util
22

3-
import "unsafe"
3+
import (
4+
"runtime"
5+
"unsafe"
6+
)
47

58
// SliceHeader is a safe version of SliceHeader used within this project.
69
type SliceHeader struct {
@@ -14,3 +17,9 @@ type StringHeader struct {
1417
Data unsafe.Pointer
1518
Len int
1619
}
20+
21+
const windows = "windows"
22+
23+
func IsWindowsOS() bool {
24+
return runtime.GOOS == windows
25+
}

0 commit comments

Comments
 (0)