nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: opencontainers/runc
Pull request #4151 (2023-12-20 03:31:04)

fix scheduler validate
https://man7.org/linux/man-pages/man2/sched_setattr.2.html
<img width="657" alt="image" src="https://github.com/opencontainers/runc/assets/15009201/53a5abfb-4971-47ce-9ea6-0e9bd156ba24">


lifubang: Good catch, when the policy is not `SCHED_OTHER` nor `SCHED_BATCH`, the `nice` value will be ignored by the kernel.
So we should not validate the `nice` value in this conditation.
Could you please add a test case for this? Both unit tests or integrate tests are ok.

Patch:
diff --git a/libcontainer/configs/validate/validator.go b/libcontainer/configs/validate/validator.go
index 4708e1b7..ed63e950 100644
--- a/libcontainer/configs/validate/validator.go
+++ b/libcontainer/configs/validate/validator.go
@@ -383,8 +383,10 @@ func scheduler(config *configs.Config) error {
 	if s.Policy == "" {
 		return errors.New("scheduler policy is required")
 	}
-	if s.Nice < -20 || s.Nice > 19 {
-		return fmt.Errorf("invalid scheduler.nice: %d", s.Nice)
+	if s.Policy == specs.SchedOther || s.Policy == specs.SchedBatch {
+		if s.Nice < -20 || s.Nice > 19 {
+			return fmt.Errorf("invalid scheduler.nice: %d when scheduler.policy is %s", s.Nice, string(s.Policy))
+		}
 	}
 	if s.Priority != 0 && (s.Policy != specs.SchedFIFO && s.Policy != specs.SchedRR) {
 		return errors.New("scheduler.priority can only be specified for SchedFIFO or SchedRR policy")


Test patch:
diff --git a/libcontainer/configs/validate/validator_test.go b/libcontainer/configs/validate/validator_test.go
index 5c12e08a..85b5e5ee 100644
--- a/libcontainer/configs/validate/validator_test.go
+++ b/libcontainer/configs/validate/validator_test.go
@@ -814,6 +814,9 @@ func TestValidateScheduler(t *testing.T) {
 		{isErr: false, policy: "SCHED_DEADLINE", runtime: 200},
 		{isErr: false, policy: "SCHED_DEADLINE", deadline: 300},
 		{isErr: false, policy: "SCHED_DEADLINE", period: 400},
+		{isErr: true, policy: "SCHED_OTHER", niceValue: 20},
+		{isErr: true, policy: "SCHED_OTHER", niceValue: -21},
+		{isErr: false, policy: "SCHED_FIFO", priority: 100, niceValue: 100},
 	}
 
 	for _, tc := range testCases {
Repository: prometheus/snmp_exporter
Pull request #527 (2020-06-08 10:54:13)

Allow lookup chaining for uints
I don't see how `gosnmp.ToBigInt` could return anything else than ints so I think it's safe to do it without any additional checks. Also added testcase that failed before but do not fail any more.


Patch:
diff --git a/collector.go b/collector.go
index 0377a3f..838f564 100644
--- a/collector.go
+++ b/collector.go
@@ -702,9 +702,7 @@ func indexesToLabels(indexOids []int, metric *config.Metric, oidToPdu map[string
 		}
 		if pdu, ok := oidToPdu[oid]; ok {
 			labels[lookup.Labelname] = pduValueAsString(&pdu, lookup.Type)
-			if _, ok := pdu.Value.(int); ok {
-				labelOids[lookup.Labelname] = []int{pdu.Value.(int)}
-			}
+			labelOids[lookup.Labelname] = []int{int(gosnmp.ToBigInt(pdu.Value).Int64())}
 		} else {
 			labels[lookup.Labelname] = ""
 		}


Test patch:
diff --git a/collector_test.go b/collector_test.go
index 4e992e8..d4b1c4b 100644
--- a/collector_test.go
+++ b/collector_test.go
@@ -972,6 +972,22 @@ func TestIndexesToLabels(t *testing.T) {
 			},
 			result: map[string]string{"a": "1", "chainable_id": "42", "targetlabel": "targetvalue"},
 		},
+		{
+			oid: []int{1, 1, 1, 1},
+			metric: config.Metric{
+				Indexes: []*config.Index{{Labelname: "a", Type: "gauge"}},
+				Lookups: []*config.Lookup{
+					{Labels: []string{"a"}, Labelname: "chainable_id", Oid: "1.1.1.2"},
+					{Labels: []string{"chainable_id"}, Labelname: "targetlabel", Oid: "2.2.2"},
+				},
+			},
+			oidToPdu: map[string]gosnmp.SnmpPDU{
+				"1.1.1.1.1": gosnmp.SnmpPDU{Value: "source_obj0"},
+				"1.1.1.2.1": gosnmp.SnmpPDU{Value: uint(42)},
+				"2.2.2.42":  gosnmp.SnmpPDU{Value: "targetvalue"},
+			},
+			result: map[string]string{"a": "1", "chainable_id": "42", "targetlabel": "targetvalue"},
+		},
 	}
 	for _, c := range cases {
 		got := indexesToLabels(c.oid, &c.metric, c.oidToPdu)