-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce error reporting in schema (#3790)
Currently in schema errors are only reported through logging which makes testing difficult. This PR introduces the collection of errors during applying the schema. Now Apply returns a list of errors. Currently these are ignored to keep the same implementation as before. Over time this should be adjusted to handle errors correctly. Logging in the schema should be remove and moved up to the Metricsets itself. This change should also simplify testing of different versions in unit tests, as `schema.Apply` will return errors. Currently this check is done in the system tests checking the log itself which is not very efficient. ApplyNoError was introduced as a temporary workaround for the processors implementation. This is part of #3807
- Loading branch information
Showing
28 changed files
with
191 additions
and
43 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,5 +30,3 @@ var schema = s.Schema{ | |
"size": c.Int("size"), | ||
}, c.DictOptional), | ||
} | ||
|
||
var eventMapping = schema.Apply |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -129,5 +129,3 @@ var wiredTigerSchema = s.Schema{ | |
"syncs": c.Int("log sync operations"), | ||
}), | ||
} | ||
|
||
var eventMapping = schema.Apply |
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
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 |
---|---|---|
|
@@ -32,5 +32,3 @@ var schema = s.Schema{ | |
"state": c.Str("state"), | ||
"query": c.Str("query"), | ||
} | ||
|
||
var eventMapping = schema.Apply |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package schema | ||
|
||
import "fmt" | ||
|
||
const ( | ||
RequiredType ErrorType = iota | ||
OptionalType ErrorType = iota | ||
) | ||
|
||
type ErrorType int | ||
|
||
type Error struct { | ||
key string | ||
message string | ||
errorType ErrorType | ||
} | ||
|
||
func NewError(key string, message string) *Error { | ||
return &Error{ | ||
key: key, | ||
message: message, | ||
errorType: RequiredType, | ||
} | ||
} | ||
|
||
func (err *Error) SetType(errorType ErrorType) { | ||
err.errorType = errorType | ||
} | ||
|
||
func (err *Error) IsType(errorType ErrorType) bool { | ||
return err.errorType == errorType | ||
} | ||
|
||
func (err *Error) Error() string { | ||
return fmt.Sprintf("Missing field: %s, Error: %s", err.key, err.message) | ||
} |
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,20 @@ | ||
package schema | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestIsError(t *testing.T) { | ||
err := NewError("test", "Hello World") | ||
assert.Error(t, err) | ||
} | ||
|
||
func TestType(t *testing.T) { | ||
err := NewError("test", "Hello World") | ||
assert.True(t, err.IsType(RequiredType)) | ||
|
||
err.SetType(OptionalType) | ||
assert.True(t, err.IsType(OptionalType)) | ||
} |
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,45 @@ | ||
package schema | ||
|
||
type Errors []Error | ||
|
||
func NewErrors() *Errors { | ||
return &Errors{} | ||
} | ||
|
||
func (errs *Errors) AddError(err *Error) { | ||
*errs = append(*errs, *err) | ||
} | ||
|
||
func (errs *Errors) AddErrors(errors *Errors) { | ||
if errors == nil { | ||
return | ||
} | ||
*errs = append(*errs, *errors...) | ||
} | ||
|
||
func (errs *Errors) HasRequiredErrors() bool { | ||
for _, err := range *errs { | ||
if err.IsType(RequiredType) { | ||
return true | ||
} | ||
} | ||
return false | ||
} | ||
|
||
func (errs *Errors) Error() string { | ||
error := "Required fields are missing: " | ||
for _, err := range *errs { | ||
if err.IsType(RequiredType) { | ||
error = error + "," + err.key | ||
} | ||
} | ||
return error | ||
} | ||
|
||
func (errs *Errors) ErrorDebug() string { | ||
error := "Fields are missing: " | ||
for _, err := range *errs { | ||
error = error + "," + err.key | ||
} | ||
return error | ||
} |
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,15 @@ | ||
package schema | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestErrors(t *testing.T) { | ||
errs := NewErrors() | ||
err := NewError("test", "Hello World") | ||
errs.AddError(err) | ||
|
||
assert.True(t, errs.HasRequiredErrors()) | ||
} |
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.