You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@yunikorn.apache.org by GitBox <gi...@apache.org> on 2022/03/15 22:56:24 UTC

[GitHub] [incubator-yunikorn-core] craigcondit opened a new pull request #386: [YUNIKORN-1120] Allow unit specifiers in core configs

craigcondit opened a new pull request #386:
URL: https://github.com/apache/incubator-yunikorn-core/pull/386


   ### What is this PR for?
   This PR updates the scheduler core to allow unit specifiers in configuration.
   
   ### What type of PR is it?
   * [ ] - Bug Fix
   * [x] - Improvement
   * [ ] - Feature
   * [ ] - Documentation
   * [ ] - Hot Fix
   * [ ] - Refactoring
   
   ### Todos
   * [ ] - Task
   
   ### What is the Jira issue?
   https://issues.apache.org/jira/browse/YUNIKORN-1120
   
   ### How should this be tested?
   Unit tests added / updated
   
   ### Screenshots (if appropriate)
   
   ### Questions:
   * [ ] - The licenses files need update.
   * [x] - There is breaking changes for older versions.
   * [x] - It needs documentation.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@yunikorn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-yunikorn-core] craigcondit commented on a change in pull request #386: [YUNIKORN-1120] Allow unit specifiers in core configs

Posted by GitBox <gi...@apache.org>.
craigcondit commented on a change in pull request #386:
URL: https://github.com/apache/incubator-yunikorn-core/pull/386#discussion_r828158148



##########
File path: pkg/common/resources/quantity.go
##########
@@ -0,0 +1,103 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+package resources
+
+import (
+	"errors"
+	"math/big"
+	"regexp"
+	"strconv"
+)
+
+// This code handles parsing of SI units in quantities:
+// <quantity>     ::= <signedNumber><suffix>
+// <signedNumber> ::= <digits> | <sign><digits>
+// <sign>         ::= "+" | "-"
+// <digit>        ::= 0 | 1 | ... | 9
+// <digits>       ::= <digit> | <digit><digits>
+// <suffix>       ::= <binarySI> | <decimalSI>
+// <binarySI>     ::= Ki | Mi | Gi | Ti | Pi | Ei
+// <decimalSI>    ::= "" | k | K | M | G | T | P | E
+// Additionally, ParseVCore supports decimalSI of 'm' to indicate millicore.
+
+var whitespace = regexp.MustCompile(`\s+`)
+var legal = regexp.MustCompile(`^(?P<Number>[+-]?[0-9]+)(?P<Suffix>[A-Za-z]*)$`)
+
+var multipliers = map[string]int64{
+	"":   1,
+	"m":  1, // special handling if milli is in use
+	"k":  1e3,
+	"M":  1e6,
+	"G":  1e9,
+	"T":  1e12,
+	"P":  1e15,
+	"E":  1e18,
+	"Ki": 1 << 10,
+	"Mi": 1 << 20,
+	"Gi": 1 << 30,
+	"Ti": 1 << 40,
+	"Pi": 1 << 50,
+	"Ei": 1 << 60,
+}
+
+// ParseQuantity is used to parse user-provided values into int64 quantities.
+func ParseQuantity(value string) (Quantity, error) {
+	return parse(value, false)
+}
+
+// ParseVCore is similar to ParseQuantity but allows the 'm' suffix. Additionally, the base unit returned is a
+// millicore, so values without units will be converted to milliCPUs (i.e. '10' will result in 10000, and '500m' will
+// result in 500).
+func ParseVCore(value string) (Quantity, error) {
+	return parse(value, true)
+}
+
+func parse(value string, milli bool) (Quantity, error) {
+	value = whitespace.ReplaceAllLiteralString(value, "")
+
+	parts := legal.FindStringSubmatch(value)
+	if parts == nil || len(parts) != 3 {
+		return 0, errors.New("invalid quantity")
+	}

Review comment:
       Done.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@yunikorn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-yunikorn-core] craigcondit commented on a change in pull request #386: [YUNIKORN-1120] Allow unit specifiers in core configs

Posted by GitBox <gi...@apache.org>.
craigcondit commented on a change in pull request #386:
URL: https://github.com/apache/incubator-yunikorn-core/pull/386#discussion_r828157623



##########
File path: pkg/common/resources/quantity.go
##########
@@ -0,0 +1,103 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+package resources
+
+import (
+	"errors"
+	"math/big"
+	"regexp"
+	"strconv"
+)
+
+// This code handles parsing of SI units in quantities:
+// <quantity>     ::= <signedNumber><suffix>
+// <signedNumber> ::= <digits> | <sign><digits>
+// <sign>         ::= "+" | "-"

Review comment:
       Removed negative support.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@yunikorn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-yunikorn-core] codecov[bot] commented on pull request #386: [YUNIKORN-1120] Allow unit specifiers in core configs

Posted by GitBox <gi...@apache.org>.
codecov[bot] commented on pull request #386:
URL: https://github.com/apache/incubator-yunikorn-core/pull/386#issuecomment-1068544431


   # [Codecov](https://codecov.io/gh/apache/incubator-yunikorn-core/pull/386?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
   > Merging [#386](https://codecov.io/gh/apache/incubator-yunikorn-core/pull/386?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (7b7f9c0) into [master](https://codecov.io/gh/apache/incubator-yunikorn-core/commit/2f7ee5bd43e7cd1f5bd86118be778982b42f8d01?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (2f7ee5b) will **increase** coverage by `0.10%`.
   > The diff coverage is `100.00%`.
   
   ```diff
   @@            Coverage Diff             @@
   ##           master     #386      +/-   ##
   ==========================================
   + Coverage   69.40%   69.51%   +0.10%     
   ==========================================
     Files          66       67       +1     
     Lines        9475     9515      +40     
   ==========================================
   + Hits         6576     6614      +38     
   - Misses       2655     2656       +1     
   - Partials      244      245       +1     
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/incubator-yunikorn-core/pull/386?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
   |---|---|---|
   | [pkg/common/resources/quantity.go](https://codecov.io/gh/apache/incubator-yunikorn-core/pull/386/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGtnL2NvbW1vbi9yZXNvdXJjZXMvcXVhbnRpdHkuZ28=) | `100.00% <100.00%> (ø)` | |
   | [pkg/common/resources/resources.go](https://codecov.io/gh/apache/incubator-yunikorn-core/pull/386/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGtnL2NvbW1vbi9yZXNvdXJjZXMvcmVzb3VyY2VzLmdv) | `98.21% <100.00%> (+0.01%)` | :arrow_up: |
   | [pkg/events/event\_publisher.go](https://codecov.io/gh/apache/incubator-yunikorn-core/pull/386/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGtnL2V2ZW50cy9ldmVudF9wdWJsaXNoZXIuZ28=) | `92.59% <0.00%> (-7.41%)` | :arrow_down: |
   
   ------
   
   [Continue to review full report at Codecov](https://codecov.io/gh/apache/incubator-yunikorn-core/pull/386?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   > `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
   > Powered by [Codecov](https://codecov.io/gh/apache/incubator-yunikorn-core/pull/386?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Last update [2f7ee5b...7b7f9c0](https://codecov.io/gh/apache/incubator-yunikorn-core/pull/386?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@yunikorn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-yunikorn-core] craigcondit commented on a change in pull request #386: [YUNIKORN-1120] Allow unit specifiers in core configs

Posted by GitBox <gi...@apache.org>.
craigcondit commented on a change in pull request #386:
URL: https://github.com/apache/incubator-yunikorn-core/pull/386#discussion_r828158024



##########
File path: pkg/common/resources/quantity.go
##########
@@ -0,0 +1,103 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+package resources
+
+import (
+	"errors"
+	"math/big"
+	"regexp"
+	"strconv"
+)
+
+// This code handles parsing of SI units in quantities:
+// <quantity>     ::= <signedNumber><suffix>
+// <signedNumber> ::= <digits> | <sign><digits>
+// <sign>         ::= "+" | "-"
+// <digit>        ::= 0 | 1 | ... | 9
+// <digits>       ::= <digit> | <digit><digits>
+// <suffix>       ::= <binarySI> | <decimalSI>
+// <binarySI>     ::= Ki | Mi | Gi | Ti | Pi | Ei
+// <decimalSI>    ::= "" | k | K | M | G | T | P | E
+// Additionally, ParseVCore supports decimalSI of 'm' to indicate millicore.
+
+var whitespace = regexp.MustCompile(`\s+`)
+var legal = regexp.MustCompile(`^(?P<Number>[+-]?[0-9]+)(?P<Suffix>[A-Za-z]*)$`)

Review comment:
       Done.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@yunikorn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-yunikorn-core] codecov[bot] edited a comment on pull request #386: [YUNIKORN-1120] Allow unit specifiers in core configs

Posted by GitBox <gi...@apache.org>.
codecov[bot] edited a comment on pull request #386:
URL: https://github.com/apache/incubator-yunikorn-core/pull/386#issuecomment-1068544431


   # [Codecov](https://codecov.io/gh/apache/incubator-yunikorn-core/pull/386?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
   > Merging [#386](https://codecov.io/gh/apache/incubator-yunikorn-core/pull/386?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (5a160f5) into [master](https://codecov.io/gh/apache/incubator-yunikorn-core/commit/2f7ee5bd43e7cd1f5bd86118be778982b42f8d01?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (2f7ee5b) will **increase** coverage by `0.09%`.
   > The diff coverage is `100.00%`.
   
   ```diff
   @@            Coverage Diff             @@
   ##           master     #386      +/-   ##
   ==========================================
   + Coverage   69.40%   69.50%   +0.09%     
   ==========================================
     Files          66       67       +1     
     Lines        9475     9515      +40     
   ==========================================
   + Hits         6576     6613      +37     
   - Misses       2655     2657       +2     
   - Partials      244      245       +1     
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/incubator-yunikorn-core/pull/386?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
   |---|---|---|
   | [pkg/common/resources/quantity.go](https://codecov.io/gh/apache/incubator-yunikorn-core/pull/386/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGtnL2NvbW1vbi9yZXNvdXJjZXMvcXVhbnRpdHkuZ28=) | `100.00% <100.00%> (ø)` | |
   | [pkg/common/resources/resources.go](https://codecov.io/gh/apache/incubator-yunikorn-core/pull/386/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGtnL2NvbW1vbi9yZXNvdXJjZXMvcmVzb3VyY2VzLmdv) | `97.67% <100.00%> (-0.52%)` | :arrow_down: |
   
   ------
   
   [Continue to review full report at Codecov](https://codecov.io/gh/apache/incubator-yunikorn-core/pull/386?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   > `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
   > Powered by [Codecov](https://codecov.io/gh/apache/incubator-yunikorn-core/pull/386?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Last update [2f7ee5b...5a160f5](https://codecov.io/gh/apache/incubator-yunikorn-core/pull/386?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@yunikorn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-yunikorn-core] craigcondit closed pull request #386: [YUNIKORN-1120] Allow unit specifiers in core configs

Posted by GitBox <gi...@apache.org>.
craigcondit closed pull request #386:
URL: https://github.com/apache/incubator-yunikorn-core/pull/386


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@yunikorn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-yunikorn-core] craigcondit closed pull request #386: [YUNIKORN-1120] Allow unit specifiers in core configs

Posted by GitBox <gi...@apache.org>.
craigcondit closed pull request #386:
URL: https://github.com/apache/incubator-yunikorn-core/pull/386


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@yunikorn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-yunikorn-core] craigcondit commented on a change in pull request #386: [YUNIKORN-1120] Allow unit specifiers in core configs

Posted by GitBox <gi...@apache.org>.
craigcondit commented on a change in pull request #386:
URL: https://github.com/apache/incubator-yunikorn-core/pull/386#discussion_r828157864



##########
File path: pkg/common/resources/quantity.go
##########
@@ -0,0 +1,103 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+package resources
+
+import (
+	"errors"
+	"math/big"
+	"regexp"
+	"strconv"
+)
+
+// This code handles parsing of SI units in quantities:
+// <quantity>     ::= <signedNumber><suffix>
+// <signedNumber> ::= <digits> | <sign><digits>
+// <sign>         ::= "+" | "-"
+// <digit>        ::= 0 | 1 | ... | 9
+// <digits>       ::= <digit> | <digit><digits>
+// <suffix>       ::= <binarySI> | <decimalSI>
+// <binarySI>     ::= Ki | Mi | Gi | Ti | Pi | Ei
+// <decimalSI>    ::= "" | k | K | M | G | T | P | E
+// Additionally, ParseVCore supports decimalSI of 'm' to indicate millicore.
+
+var whitespace = regexp.MustCompile(`\s+`)

Review comment:
       Done.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@yunikorn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-yunikorn-core] wilfred-s commented on a change in pull request #386: [YUNIKORN-1120] Allow unit specifiers in core configs

Posted by GitBox <gi...@apache.org>.
wilfred-s commented on a change in pull request #386:
URL: https://github.com/apache/incubator-yunikorn-core/pull/386#discussion_r827530584



##########
File path: pkg/common/resources/quantity.go
##########
@@ -0,0 +1,103 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+package resources
+
+import (
+	"errors"
+	"math/big"
+	"regexp"
+	"strconv"
+)
+
+// This code handles parsing of SI units in quantities:
+// <quantity>     ::= <signedNumber><suffix>
+// <signedNumber> ::= <digits> | <sign><digits>
+// <sign>         ::= "+" | "-"
+// <digit>        ::= 0 | 1 | ... | 9
+// <digits>       ::= <digit> | <digit><digits>
+// <suffix>       ::= <binarySI> | <decimalSI>
+// <binarySI>     ::= Ki | Mi | Gi | Ti | Pi | Ei
+// <decimalSI>    ::= "" | k | K | M | G | T | P | E
+// Additionally, ParseVCore supports decimalSI of 'm' to indicate millicore.
+
+var whitespace = regexp.MustCompile(`\s+`)

Review comment:
       Use a `strings.TrimSpace()` instead of a regexp. We do not want to allow "1 000 000" as a value which we do with the current setup. If we allow spaces between value and suffix we need to add it in the regexp as below.

##########
File path: pkg/common/resources/quantity.go
##########
@@ -0,0 +1,103 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+package resources
+
+import (
+	"errors"
+	"math/big"
+	"regexp"
+	"strconv"
+)
+
+// This code handles parsing of SI units in quantities:
+// <quantity>     ::= <signedNumber><suffix>
+// <signedNumber> ::= <digits> | <sign><digits>
+// <sign>         ::= "+" | "-"

Review comment:
       In the config(s) we do not allow negative values. I don't think we should allow that here.

##########
File path: pkg/common/resources/quantity.go
##########
@@ -0,0 +1,103 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+package resources
+
+import (
+	"errors"
+	"math/big"
+	"regexp"
+	"strconv"
+)
+
+// This code handles parsing of SI units in quantities:
+// <quantity>     ::= <signedNumber><suffix>
+// <signedNumber> ::= <digits> | <sign><digits>
+// <sign>         ::= "+" | "-"
+// <digit>        ::= 0 | 1 | ... | 9
+// <digits>       ::= <digit> | <digit><digits>
+// <suffix>       ::= <binarySI> | <decimalSI>
+// <binarySI>     ::= Ki | Mi | Gi | Ti | Pi | Ei
+// <decimalSI>    ::= "" | k | K | M | G | T | P | E
+// Additionally, ParseVCore supports decimalSI of 'm' to indicate millicore.
+
+var whitespace = regexp.MustCompile(`\s+`)
+var legal = regexp.MustCompile(`^(?P<Number>[+-]?[0-9]+)(?P<Suffix>[A-Za-z]*)$`)

Review comment:
       Narrow the regexp for the parts further:
   ```
   var legal = regexp.MustCompile(`^(?P<Number>[+-]?[0-9]+)\s*(?P<Suffix>[[mkKMGTPE]i?]*)$`)
   ```
   That complies better to the described suffixes. The only extra suffixes that are not filtered out are K, ki and mi

##########
File path: pkg/common/resources/quantity.go
##########
@@ -0,0 +1,103 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+package resources
+
+import (
+	"errors"
+	"math/big"
+	"regexp"
+	"strconv"
+)
+
+// This code handles parsing of SI units in quantities:
+// <quantity>     ::= <signedNumber><suffix>
+// <signedNumber> ::= <digits> | <sign><digits>
+// <sign>         ::= "+" | "-"
+// <digit>        ::= 0 | 1 | ... | 9
+// <digits>       ::= <digit> | <digit><digits>
+// <suffix>       ::= <binarySI> | <decimalSI>
+// <binarySI>     ::= Ki | Mi | Gi | Ti | Pi | Ei
+// <decimalSI>    ::= "" | k | K | M | G | T | P | E
+// Additionally, ParseVCore supports decimalSI of 'm' to indicate millicore.
+
+var whitespace = regexp.MustCompile(`\s+`)
+var legal = regexp.MustCompile(`^(?P<Number>[+-]?[0-9]+)(?P<Suffix>[A-Za-z]*)$`)
+
+var multipliers = map[string]int64{
+	"":   1,
+	"m":  1, // special handling if milli is in use
+	"k":  1e3,
+	"M":  1e6,
+	"G":  1e9,
+	"T":  1e12,
+	"P":  1e15,
+	"E":  1e18,
+	"Ki": 1 << 10,
+	"Mi": 1 << 20,
+	"Gi": 1 << 30,
+	"Ti": 1 << 40,
+	"Pi": 1 << 50,
+	"Ei": 1 << 60,
+}
+
+// ParseQuantity is used to parse user-provided values into int64 quantities.
+func ParseQuantity(value string) (Quantity, error) {
+	return parse(value, false)
+}
+
+// ParseVCore is similar to ParseQuantity but allows the 'm' suffix. Additionally, the base unit returned is a
+// millicore, so values without units will be converted to milliCPUs (i.e. '10' will result in 10000, and '500m' will
+// result in 500).
+func ParseVCore(value string) (Quantity, error) {
+	return parse(value, true)
+}
+
+func parse(value string, milli bool) (Quantity, error) {
+	value = whitespace.ReplaceAllLiteralString(value, "")
+
+	parts := legal.FindStringSubmatch(value)
+	if parts == nil || len(parts) != 3 {
+		return 0, errors.New("invalid quantity")
+	}

Review comment:
       FindStringSubmatch returns nil if it does not match. In all other cases it returns a fixed slice of 3 parts.
   Simplify to `len(parts) == 0`




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@yunikorn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-yunikorn-core] codecov[bot] edited a comment on pull request #386: [YUNIKORN-1120] Allow unit specifiers in core configs

Posted by GitBox <gi...@apache.org>.
codecov[bot] edited a comment on pull request #386:
URL: https://github.com/apache/incubator-yunikorn-core/pull/386#issuecomment-1068544431


   # [Codecov](https://codecov.io/gh/apache/incubator-yunikorn-core/pull/386?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
   > Merging [#386](https://codecov.io/gh/apache/incubator-yunikorn-core/pull/386?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (5a160f5) into [master](https://codecov.io/gh/apache/incubator-yunikorn-core/commit/2f7ee5bd43e7cd1f5bd86118be778982b42f8d01?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (2f7ee5b) will **increase** coverage by `0.09%`.
   > The diff coverage is `100.00%`.
   
   ```diff
   @@            Coverage Diff             @@
   ##           master     #386      +/-   ##
   ==========================================
   + Coverage   69.40%   69.50%   +0.09%     
   ==========================================
     Files          66       67       +1     
     Lines        9475     9515      +40     
   ==========================================
   + Hits         6576     6613      +37     
   - Misses       2655     2657       +2     
   - Partials      244      245       +1     
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/incubator-yunikorn-core/pull/386?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
   |---|---|---|
   | [pkg/common/resources/quantity.go](https://codecov.io/gh/apache/incubator-yunikorn-core/pull/386/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGtnL2NvbW1vbi9yZXNvdXJjZXMvcXVhbnRpdHkuZ28=) | `100.00% <100.00%> (ø)` | |
   | [pkg/common/resources/resources.go](https://codecov.io/gh/apache/incubator-yunikorn-core/pull/386/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGtnL2NvbW1vbi9yZXNvdXJjZXMvcmVzb3VyY2VzLmdv) | `97.67% <100.00%> (-0.52%)` | :arrow_down: |
   
   ------
   
   [Continue to review full report at Codecov](https://codecov.io/gh/apache/incubator-yunikorn-core/pull/386?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   > `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
   > Powered by [Codecov](https://codecov.io/gh/apache/incubator-yunikorn-core/pull/386?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Last update [2f7ee5b...5a160f5](https://codecov.io/gh/apache/incubator-yunikorn-core/pull/386?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@yunikorn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org