nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: alibaba/sentinel-golang
Pull request #377 (2021-01-12 06:55:52)

feat: add NewCustomizedBaseStatNode to create the BaseStatNode with specified param
feat: add NewCustomizedBaseStatNode to create the BaseStatNode with specified param

<!--  Thanks for submitting a pull request! Here are some tips for you:
1. Please make sure you have read and understood the contributing guidelines: https://github.com/alibaba/blob/master/CONTRIBUTING.md
2. Please make sure the PR has a corresponding issue.
-->

### Describe what this PR does / why we need it

We need to create the BaseStatNode of a specific size without updating global config.

### Does this pull request fix one issue?

<!--If that, add "Fixes #xxxx" below in the next line. For example, Fixes #15. Otherwise, add "NONE" -->

### Describe how you did it


### Describe how to verify it


### Special notes for reviews


Patch:
diff --git a/core/stat/base_node.go b/core/stat/base_node.go
index b59cbda..adf358b 100644
--- a/core/stat/base_node.go
+++ b/core/stat/base_node.go
@@ -44,6 +44,23 @@ func NewBaseStatNode(sampleCount uint32, intervalInMs uint32) *BaseStatNode {
 	}
 }
 
+// NewCustomizedBaseStatNode creates the BaseStatNode with specified sampleCount
+// and intervalInMs.
+func NewCustomizedBaseStatNode(sampleCount uint32, intervalInMs uint32) (*BaseStatNode, error) {
+	la := sbase.NewBucketLeapArray(sampleCount, intervalInMs)
+	metric, err := sbase.NewSlidingWindowMetric(sampleCount, intervalInMs, la)
+	if err != nil {
+		return nil, err
+	}
+	return &BaseStatNode{
+		concurrency: 0,
+		sampleCount: sampleCount,
+		intervalMs:  intervalInMs,
+		arr:         la,
+		metric:      metric,
+	}, nil
+}
+
 func (n *BaseStatNode) MetricsOnCondition(predicate base.TimePredicate) []*base.MetricItem {
 	return n.metric.SecondMetricsOnCondition(predicate)
 }


Test patch:
diff --git a/core/stat/base_node_test.go b/core/stat/base_node_test.go
index ba7d711..a34ca86 100644
--- a/core/stat/base_node_test.go
+++ b/core/stat/base_node_test.go
@@ -4,6 +4,8 @@ import (
 	"testing"
 	"time"
 
+	"github.com/alibaba/sentinel-golang/core/base"
+
 	"github.com/stretchr/testify/assert"
 )
 
@@ -37,3 +39,13 @@ func TestBaseStatNodeGoroutineNum(t *testing.T) {
 	assert.Equal(t, int64(2), bsn.MaxConcurrency())
 	assert.Equal(t, int64(1), bsn.SecondMaxConcurrency())
 }
+
+func TestNewCustomizedBaseStatNode(t *testing.T) {
+	bsn, err := NewCustomizedBaseStatNode(8, 2000)
+	assert.Nil(t, err)
+	assert.NotNil(t, bsn)
+	bsn.AddCount(base.MetricEventPass, 1)
+	assert.Equal(t, int64(1), bsn.GetSum(base.MetricEventPass))
+	time.Sleep(time.Second * 2)
+	assert.Equal(t, int64(0), bsn.GetSum(base.MetricEventPass))
+}
Repository: alibaba/sentinel-golang
Pull request #420 (2021-07-26 09:46:00)

Add sampleCount zero checking in NewLeapArray func
first param of function ` NewLeapArray`   can  not  be  zero.  Or  it  will  cause panic  `runtime error: divide by zero`


Patch:
diff --git a/core/stat/base/leap_array.go b/core/stat/base/leap_array.go
index b3dab75..d8f62be 100644
--- a/core/stat/base/leap_array.go
+++ b/core/stat/base/leap_array.go
@@ -159,7 +159,7 @@ type LeapArray struct {
 }
 
 func NewLeapArray(sampleCount uint32, intervalInMs uint32, generator BucketGenerator) (*LeapArray, error) {
-	if intervalInMs%sampleCount != 0 {
+	if sampleCount == 0 || intervalInMs%sampleCount != 0 {
 		return nil, errors.Errorf("Invalid parameters, intervalInMs is %d, sampleCount is %d", intervalInMs, sampleCount)
 	}
 	if generator == nil {


Test patch:
diff --git a/core/stat/base/leap_array_test.go b/core/stat/base/leap_array_test.go
index f236799..151bf28 100644
--- a/core/stat/base/leap_array_test.go
+++ b/core/stat/base/leap_array_test.go
@@ -297,4 +297,9 @@ func TestNewLeapArray(t *testing.T) {
 		assert.Nil(t, leapArray)
 		assert.Error(t, err, "Invalid parameters, intervalInMs is 10000, sampleCount is 30")
 	})
+	t.Run("TestNewLeapArray_Invalid_Parameters_sampleCount0", func(t *testing.T) {
+		leapArray, err := NewLeapArray(0, IntervalInMs, nil)
+		assert.Nil(t, leapArray)
+		assert.Error(t, err, "Invalid parameters, intervalInMs is 10000, sampleCount is 0")
+	})
 }
Repository: alibaba/sentinel-golang
Pull request #464 (2022-03-30 11:04:20)

feat: add degrade metric
<!--  Thanks for submitting a pull request! Here are some tips for you:
1. Please make sure you have read and understood the contributing guidelines: https://github.com/alibaba/blob/master/CONTRIBUTING.md
2. Please make sure the PR has a corresponding issue.
-->

### Describe what this PR does / why we need it


### Does this pull request fix one issue?

<!--If that, add "Fixes #xxxx" below in the next line. For example, Fixes #15. Otherwise, add "NONE" -->

### Describe how you did it


### Describe how to verify it


### Special notes for reviews


Patch:
diff --git a/core/base/metric_item.go b/core/base/metric_item.go
index f23180b..b00e83f 100644
--- a/core/base/metric_item.go
+++ b/core/base/metric_item.go
@@ -38,6 +38,7 @@ type MetricItem struct {
 	AvgRt                uint64
 	OccupiedPassQps      uint64
 	TimeoutCounter       uint64
+	DegradeCounter       uint64
 	Concurrency          uint32
 	SecondMaxConcurrency uint32
 }
diff --git a/core/base/stat.go b/core/base/stat.go
index 7278bd1..19ae069 100644
--- a/core/base/stat.go
+++ b/core/base/stat.go
@@ -39,6 +39,8 @@ const (
 	MetricEventMonitorBlock
 	// timeout counter
 	MetricEventTimeout
+	// degrade counter
+	MetricEventDegrade
 	// hack for the number of event
 	MetricEventTotal
 )
diff --git a/core/stat/base/sliding_window_metric.go b/core/stat/base/sliding_window_metric.go
index 76d58be..9efd653 100644
--- a/core/stat/base/sliding_window_metric.go
+++ b/core/stat/base/sliding_window_metric.go
@@ -217,6 +217,7 @@ func (m *SlidingWindowMetric) metricItemFromBuckets(ts uint64, ws []*BucketWrap)
 		item.CompleteQps += uint64(mb.Get(base.MetricEventComplete))
 		item.MonitorBlockQps += uint64(mb.Get(base.MetricEventMonitorBlock))
 		item.TimeoutCounter += uint64(mb.Get(base.MetricEventTimeout))
+		item.DegradeCounter += uint64(mb.Get(base.MetricEventDegrade))
 		allRt += mb.Get(base.MetricEventRt)
 	}
 	if item.CompleteQps > 0 {
@@ -245,6 +246,7 @@ func (m *SlidingWindowMetric) metricItemFromBucket(w *BucketWrap) *base.MetricIt
 		MonitorBlockQps: uint64(mb.Get(base.MetricEventMonitorBlock)),
 		ErrorQps:        uint64(mb.Get(base.MetricEventError)),
 		TimeoutCounter:  uint64(mb.Get(base.MetricEventTimeout)),
+		DegradeCounter:  uint64(mb.Get(base.MetricEventDegrade)),
 		CompleteQps:     uint64(completeQps),
 		Timestamp:       w.BucketStart,
 	}


Test patch:
diff --git a/core/stat/base/metric_bucket_test.go b/core/stat/base/metric_bucket_test.go
index e1b55c8..5783161 100644
--- a/core/stat/base/metric_bucket_test.go
+++ b/core/stat/base/metric_bucket_test.go
@@ -27,7 +27,7 @@ func Test_metricBucket_MemSize(t *testing.T) {
 	mb := NewMetricBucket()
 	t.Log("mb:", mb)
 	size := unsafe.Sizeof(*mb)
-	if size != 72 {
+	if size != 80 {
 		t.Error("unexpect memory size of MetricBucket")
 	}
 }