You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@trafficcontrol.apache.org by GitBox <gi...@apache.org> on 2022/12/09 16:07:57 UTC

[GitHub] [trafficcontrol] rimashah25 opened a new pull request, #7241: Fixed error message for assignment of non-existent parameters to a profile

rimashah25 opened a new pull request, #7241:
URL: https://github.com/apache/trafficcontrol/pull/7241

   <!--
   Thank you for contributing! Please be sure to read our contribution guidelines: https://github.com/apache/trafficcontrol/blob/master/CONTRIBUTING.md
   If this closes or relates to an existing issue, please reference it using one of the following:
   
   Closes: #ISSUE
   Related: #ISSUE
   
   If this PR fixes a security vulnerability, DO NOT submit! Instead, contact
   the Apache Traffic Control Security Team at security@trafficcontrol.apache.org and follow the
   guidelines at https://apache.org/security regarding vulnerability disclosure.
   -->
   Closes: https://github.com/apache/trafficcontrol/issues/6229
   
   <!-- **^ Add meaningful description above** --><hr/>
   
   ## Which Traffic Control components are affected by this PR?
   <!-- Please delete all components from this list that are NOT affected by this PR.
   Feel free to add the name of a tool or script that is affected but not on the list.
   -->
   - Traffic Ops
   
   ## What is the best way to verify this PR?
   <!-- Please include here ALL the steps necessary to test your PR.
   If your PR has tests (and most should), provide the steps needed to run the tests.
   If not, please provide step-by-step instructions to test the PR manually and explain why your PR does not need tests. -->
   Using curl cmd, call api: `profileparameter` with a post body as follows (eg). Note: `14, 30, 400` are non-existent parameter
   ```
   {
       "profileId": 10,
       "paramIds": [14, 13, 400, 1]
   }
   ```
   and you should see the following message
   ```
   {"alerts":
       [{
            "text":"parse error: validating: parameters with IDs [14 13 400] don't all exist",
            "level":"error"
        }]
   }
   ```
   Note, `1` didn't show up since it is an existing parameter.
   
   ## If this is a bugfix, which Traffic Control versions contained the bug?
   <!-- Delete this section if the PR is not a bugfix, or if the bug is only in the master branch.
   Examples:
   - 5.1.2
   - 5.1.3 (RC1)
    -->
   7.0.1
   
   ## PR submission checklist
   - [ ] This PR has tests <!-- If not, please delete this text and explain why this PR does not need tests. -->
   - [ ] This PR has documentation <!-- If not, please delete this text and explain why this PR does not need documentation. -->
   - [x] This PR has a CHANGELOG.md entry <!-- A fix for a bug from an ATC release, an improvement, or a new feature should have a changelog entry. -->
   - [x] This PR **DOES NOT FIX A SERIOUS SECURITY VULNERABILITY** (see [the Apache Software Foundation's security guidelines](https://apache.org/security) for details)
   
   <!--
   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.
   -->
   


-- 
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: issues-unsubscribe@trafficcontrol.apache.org

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


[GitHub] [trafficcontrol] ocket8888 commented on a diff in pull request #7241: Fixed error message for assignment of non-existent parameters to a profile

Posted by GitBox <gi...@apache.org>.
ocket8888 commented on code in PR #7241:
URL: https://github.com/apache/trafficcontrol/pull/7241#discussion_r1048802698


##########
lib/go-tc/parameters.go:
##########
@@ -277,12 +277,15 @@ func ParamExists(id int64, tx *sql.Tx) (bool, error) {
 
 // ParamsExist returns whether parameters exist for all the given ids, and any error.
 // TODO move to helper package.
-func ParamsExist(ids []int64, tx *sql.Tx) (bool, error) {
-	count := 0
-	if err := tx.QueryRow(`SELECT count(*) from parameter where id = ANY($1)`, pq.Array(ids)).Scan(&count); err != nil {
-		return false, errors.New("querying parameters existence from id: " + err.Error())
+func ParamsExist(ids []int64, tx *sql.Tx) (bool, []int64, error) {
+	var nonExistingIDs []int64
+	if err := tx.QueryRow(`SELECT ARRAY_AGG(id) FROM UNNEST($1::INT[]) AS id WHERE id NOT IN (SELECT id FROM parameter)`, pq.Array(ids)).Scan(pq.Array(&nonExistingIDs)); err != nil {
+		return false, nil, errors.New("querying parameters existence from id: " + err.Error())

Review Comment:
   constructing errors from errors should use wrapping e.g. with `fmt.Errorf``'s `%w` formatting parameter.



##########
lib/go-tc/parameters.go:
##########
@@ -277,12 +277,15 @@ func ParamExists(id int64, tx *sql.Tx) (bool, error) {
 
 // ParamsExist returns whether parameters exist for all the given ids, and any error.
 // TODO move to helper package.
-func ParamsExist(ids []int64, tx *sql.Tx) (bool, error) {
-	count := 0
-	if err := tx.QueryRow(`SELECT count(*) from parameter where id = ANY($1)`, pq.Array(ids)).Scan(&count); err != nil {
-		return false, errors.New("querying parameters existence from id: " + err.Error())
+func ParamsExist(ids []int64, tx *sql.Tx) (bool, []int64, error) {
+	var nonExistingIDs []int64
+	if err := tx.QueryRow(`SELECT ARRAY_AGG(id) FROM UNNEST($1::INT[]) AS id WHERE id NOT IN (SELECT id FROM parameter)`, pq.Array(ids)).Scan(pq.Array(&nonExistingIDs)); err != nil {
+		return false, nil, errors.New("querying parameters existence from id: " + err.Error())

Review Comment:
   Also, this error shouldn't be shown to the user, but the way this works currently it would be. You don't need to fix that here, but you can if you want.



##########
lib/go-tc/parameters.go:
##########
@@ -277,12 +277,15 @@ func ParamExists(id int64, tx *sql.Tx) (bool, error) {
 
 // ParamsExist returns whether parameters exist for all the given ids, and any error.
 // TODO move to helper package.
-func ParamsExist(ids []int64, tx *sql.Tx) (bool, error) {
-	count := 0
-	if err := tx.QueryRow(`SELECT count(*) from parameter where id = ANY($1)`, pq.Array(ids)).Scan(&count); err != nil {
-		return false, errors.New("querying parameters existence from id: " + err.Error())
+func ParamsExist(ids []int64, tx *sql.Tx) (bool, []int64, error) {

Review Comment:
   It looks like the first return value - the boolean - is only false if the error is non-nil or there are non-existing IDs being returned. Which means it doesn't serve much purpose because it can be trivially inferred from those other return values.



##########
lib/go-tc/parameters.go:
##########
@@ -210,10 +210,10 @@ func (pp *PostProfileParam) Validate(tx *sql.Tx) error {
 	}
 	if pp.ParamIDs == nil {
 		errs = append(errs, errors.New("paramIds missing"))
-	} else if ok, err := ParamsExist(*pp.ParamIDs, tx); err != nil {
+	} else if ok, nonExistingIDs, err := ParamsExist(*pp.ParamIDs, tx); err != nil {
 		errs = append(errs, errors.New(fmt.Sprintf("checking parameter IDs %v existence: "+err.Error(), *pp.ParamIDs)))
 	} else if !ok {
-		errs = append(errs, errors.New(fmt.Sprintf("parameters with IDs %v don't all exist", *pp.ParamIDs)))
+		errs = append(errs, errors.New(fmt.Sprintf("parameters with IDs %v don't all exist", nonExistingIDs)))

Review Comment:
   Please use `fmt.Errorf(args)` instead of `errors.New(fmt.Sprintf(args))`. I see it being done in other places but if you've gotta change the line anyway, this heinous practice can be fixed in at least this one place.
   
   also, the text "... don't all exist" implies that one or more of them may actually exist, but it's more accurate to report "... all don't exist" or just "... don't exist".



-- 
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: issues-unsubscribe@trafficcontrol.apache.org

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


[GitHub] [trafficcontrol] rimashah25 commented on a diff in pull request #7241: Fixed error message for assignment of non-existent parameters to a profile

Posted by GitBox <gi...@apache.org>.
rimashah25 commented on code in PR #7241:
URL: https://github.com/apache/trafficcontrol/pull/7241#discussion_r1049010402


##########
lib/go-tc/parameters.go:
##########
@@ -277,12 +277,15 @@ func ParamExists(id int64, tx *sql.Tx) (bool, error) {
 
 // ParamsExist returns whether parameters exist for all the given ids, and any error.
 // TODO move to helper package.
-func ParamsExist(ids []int64, tx *sql.Tx) (bool, error) {
-	count := 0
-	if err := tx.QueryRow(`SELECT count(*) from parameter where id = ANY($1)`, pq.Array(ids)).Scan(&count); err != nil {
-		return false, errors.New("querying parameters existence from id: " + err.Error())
+func ParamsExist(ids []int64, tx *sql.Tx) (bool, []int64, error) {
+	var nonExistingIDs []int64
+	if err := tx.QueryRow(`SELECT ARRAY_AGG(id) FROM UNNEST($1::INT[]) AS id WHERE id NOT IN (SELECT id FROM parameter)`, pq.Array(ids)).Scan(pq.Array(&nonExistingIDs)); err != nil {
+		return false, nil, errors.New("querying parameters existence from id: " + err.Error())

Review Comment:
   I understand that we shouldn't since it is a DB level. but also there is a `TODO` to rework validation in `traffic_ops/traffic_ops_golang/api/api.go`. So, I would do it as a separate PR.
   ```
   // TODO: Rework validation to be able to return system-level errors
   type ParseValidator interface {
   	Validate(tx *sql.Tx) error
   }```



-- 
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: issues-unsubscribe@trafficcontrol.apache.org

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


[GitHub] [trafficcontrol] rimashah25 commented on a diff in pull request #7241: Fixed error message for assignment of non-existent parameters to a profile

Posted by GitBox <gi...@apache.org>.
rimashah25 commented on code in PR #7241:
URL: https://github.com/apache/trafficcontrol/pull/7241#discussion_r1049010402


##########
lib/go-tc/parameters.go:
##########
@@ -277,12 +277,15 @@ func ParamExists(id int64, tx *sql.Tx) (bool, error) {
 
 // ParamsExist returns whether parameters exist for all the given ids, and any error.
 // TODO move to helper package.
-func ParamsExist(ids []int64, tx *sql.Tx) (bool, error) {
-	count := 0
-	if err := tx.QueryRow(`SELECT count(*) from parameter where id = ANY($1)`, pq.Array(ids)).Scan(&count); err != nil {
-		return false, errors.New("querying parameters existence from id: " + err.Error())
+func ParamsExist(ids []int64, tx *sql.Tx) (bool, []int64, error) {
+	var nonExistingIDs []int64
+	if err := tx.QueryRow(`SELECT ARRAY_AGG(id) FROM UNNEST($1::INT[]) AS id WHERE id NOT IN (SELECT id FROM parameter)`, pq.Array(ids)).Scan(pq.Array(&nonExistingIDs)); err != nil {
+		return false, nil, errors.New("querying parameters existence from id: " + err.Error())

Review Comment:
   I understand that we shouldn't since it is a DB level. but also there is a `TODO` to rework validation in `traffic_ops/traffic_ops_golang/api/api.go`. So, I would do it as a separate PR.
   ```// TODO: Rework validation to be able to return system-level errors
   type ParseValidator interface {
   	Validate(tx *sql.Tx) error
   }```



-- 
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: issues-unsubscribe@trafficcontrol.apache.org

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


[GitHub] [trafficcontrol] ocket8888 merged pull request #7241: Fixed error message for assignment of non-existent parameters to a profile

Posted by GitBox <gi...@apache.org>.
ocket8888 merged PR #7241:
URL: https://github.com/apache/trafficcontrol/pull/7241


-- 
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: issues-unsubscribe@trafficcontrol.apache.org

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


[GitHub] [trafficcontrol] codecov[bot] commented on pull request #7241: Fixed error message for assignment of non-existent parameters to a profile

Posted by GitBox <gi...@apache.org>.
codecov[bot] commented on PR #7241:
URL: https://github.com/apache/trafficcontrol/pull/7241#issuecomment-1344492615

   # [Codecov](https://codecov.io/gh/apache/trafficcontrol/pull/7241?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 [#7241](https://codecov.io/gh/apache/trafficcontrol/pull/7241?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (1c10713) into [master](https://codecov.io/gh/apache/trafficcontrol/commit/bf8e18f5491f6d35e7dd454825b1b1b00ce405d1?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (bf8e18f) will **decrease** coverage by `0.00%`.
   > The diff coverage is `0.00%`.
   
   ```diff
   @@             Coverage Diff              @@
   ##             master    #7241      +/-   ##
   ============================================
   - Coverage     28.37%   28.37%   -0.01%     
     Complexity       98       98              
   ============================================
     Files           617      617              
     Lines         69197    69200       +3     
     Branches         90       90              
   ============================================
   - Hits          19634    19633       -1     
   - Misses        47754    47758       +4     
     Partials       1809     1809              
   ```
   
   | Flag | Coverage Δ | |
   |---|---|---|
   | golib_unit | `53.05% <0.00%> (-0.03%)` | :arrow_down: |
   | grove_unit | `4.60% <ø> (ø)` | |
   | t3c_generate_unit | `24.96% <ø> (ø)` | |
   | traffic_monitor_unit | `20.43% <ø> (ø)` | |
   | traffic_stats_unit | `10.41% <ø> (ø)` | |
   
   Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#carryforward-flags-in-the-pull-request-comment) to find out more.
   
   | [Impacted Files](https://codecov.io/gh/apache/trafficcontrol/pull/7241?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
   |---|---|---|
   | [lib/go-tc/parameters.go](https://codecov.io/gh/apache/trafficcontrol/pull/7241/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-bGliL2dvLXRjL3BhcmFtZXRlcnMuZ28=) | `0.00% <0.00%> (ø)` | |
   | [lib/go-atscfg/serverunknown.go](https://codecov.io/gh/apache/trafficcontrol/pull/7241/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-bGliL2dvLWF0c2NmZy9zZXJ2ZXJ1bmtub3duLmdv) | `77.96% <0.00%> (-1.70%)` | :arrow_down: |
   
   :mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?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: issues-unsubscribe@trafficcontrol.apache.org

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