-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[release/0.3] Permit duplicate param logging (#591)
Backport of #550 * Rely on database to detect duplicate parameter logging where the value has changed and prevent them * Fail the entire batch when an invalid duplicate parameter is detected * Return HTTP 400 instead of 500 in case of duplication Co-authored-by: Geoffrey Wilson <[email protected]>
- Loading branch information
1 parent
a5f3adc
commit b4287c6
Showing
8 changed files
with
370 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package repositories | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/G-Research/fasttrackml/pkg/api/mlflow/dao/models" | ||
) | ||
|
||
// makeSqlPlaceholders collects a string of "(?,?,?), (?,?,?)" and so on, | ||
// for use as sql parameters | ||
func makeSqlPlaceholders(numberInEachSet, numberOfSets int) string { | ||
set := fmt.Sprintf("(%s)", strings.Repeat("?,", numberInEachSet-1)+"?") | ||
return strings.Repeat(set+",", numberOfSets-1) + set | ||
} | ||
|
||
// makeParamConflictPlaceholdersAndValues provides sql placeholders and concatenates | ||
// Key, Value, RunID from each input Param for use in sql values replacement | ||
func makeParamConflictPlaceholdersAndValues(params []models.Param) (string, []interface{}) { | ||
// make place holders of 3 fields for each param | ||
placeholders := makeSqlPlaceholders(3, len(params)) | ||
// values array is params * 3 in length since using 3 fields from each | ||
valuesArray := make([]interface{}, len(params)*3) | ||
index := 0 | ||
for _, param := range params { | ||
valuesArray[index] = param.Key | ||
valuesArray[index+1] = param.Value | ||
valuesArray[index+2] = param.RunID | ||
index = index + 3 | ||
} | ||
return placeholders, valuesArray | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package repositories | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/G-Research/fasttrackml/pkg/api/mlflow/dao/models" | ||
) | ||
|
||
func Test_makeSqlPlaceholders(t *testing.T) { | ||
tests := []struct { | ||
numberInEachSet int | ||
numberOfSets int | ||
expectedResult string | ||
}{ | ||
{numberInEachSet: 1, numberOfSets: 1, expectedResult: "(?)"}, | ||
{numberInEachSet: 2, numberOfSets: 1, expectedResult: "(?,?)"}, | ||
{numberInEachSet: 1, numberOfSets: 2, expectedResult: "(?),(?)"}, | ||
{numberInEachSet: 2, numberOfSets: 2, expectedResult: "(?,?),(?,?)"}, | ||
} | ||
|
||
for _, tt := range tests { | ||
result := makeSqlPlaceholders(tt.numberInEachSet, tt.numberOfSets) | ||
assert.Equal(t, tt.expectedResult, result) | ||
} | ||
} | ||
|
||
func Test_makeParamConflictPlaceholdersAndValues(t *testing.T) { | ||
tests := []struct { | ||
params []models.Param | ||
expectedPlaceholders string | ||
expectedValues []interface{} | ||
}{ | ||
{ | ||
params: []models.Param{{Key: "key1", Value: "value1", RunID: "run1"}}, | ||
expectedPlaceholders: "(?,?,?)", | ||
expectedValues: []interface{}{"key1", "value1", "run1"}, | ||
}, | ||
{ | ||
params: []models.Param{ | ||
{Key: "key1", Value: "value1", RunID: "run1"}, | ||
{Key: "key2", Value: "value2", RunID: "run2"}, | ||
}, | ||
expectedPlaceholders: "(?,?,?),(?,?,?)", | ||
expectedValues: []interface{}{"key1", "value1", "run1", "key2", "value2", "run2"}, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
placeholders, values := makeParamConflictPlaceholdersAndValues(tt.params) | ||
assert.Equal(t, tt.expectedPlaceholders, placeholders) | ||
assert.Equal(t, tt.expectedValues, values) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.