Skip to content

Commit

Permalink
Ban system metric collector for windows OS(#312)
Browse files Browse the repository at this point in the history
  • Loading branch information
binbin0325 authored Oct 29, 2020
1 parent f9ddf58 commit a3733b6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
8 changes: 6 additions & 2 deletions api/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import (
"github.com/alibaba/sentinel-golang/core/config"
"github.com/alibaba/sentinel-golang/core/log/metric"
"github.com/alibaba/sentinel-golang/core/system"
"github.com/alibaba/sentinel-golang/logging"
"github.com/alibaba/sentinel-golang/util"
)

// InitDefault initializes Sentinel using the configuration from system
// environment and the default value.
func InitDefault() error {
return initSentinel("")
Expand Down Expand Up @@ -50,8 +50,12 @@ func initCoreComponents() error {
if err := metric.InitTask(); err != nil {
return err
}
if !util.IsWindowsOS() {
system.InitCollector(config.SystemStatCollectIntervalMs())
} else {
logging.Warn("[Init initCoreComponents] system metric collect is not available for system module in windows")
}

system.InitCollector(config.SystemStatCollectIntervalMs())
if config.UseCacheTime() {
util.StartTimeTicker()
}
Expand Down
5 changes: 5 additions & 0 deletions core/system/slot.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package system
import (
"github.com/alibaba/sentinel-golang/core/base"
"github.com/alibaba/sentinel-golang/core/stat"
"github.com/alibaba/sentinel-golang/util"
)

type AdaptiveSlot struct {
Expand All @@ -12,6 +13,10 @@ func (s *AdaptiveSlot) Check(ctx *base.EntryContext) *base.TokenResult {
if ctx == nil || ctx.Resource == nil || ctx.Resource.FlowType() != base.Inbound {
return nil
}
// system module is not available for windows OS
if util.IsWindowsOS() {
return nil
}
rules := GetRules()
result := ctx.RuleCheckResult
for _, rule := range rules {
Expand Down
11 changes: 10 additions & 1 deletion util/safe.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package util

import "unsafe"
import (
"runtime"
"unsafe"
)

// SliceHeader is a safe version of SliceHeader used within this project.
type SliceHeader struct {
Expand All @@ -14,3 +17,9 @@ type StringHeader struct {
Data unsafe.Pointer
Len int
}

const windows = "windows"

func IsWindowsOS() bool {
return runtime.GOOS == windows
}

0 comments on commit a3733b6

Please sign in to comment.