Skip to content

Commit

Permalink
Repeatable error messages for metric documentation checks (#28034) (#…
Browse files Browse the repository at this point in the history
…28190)

* Sort all keys before checking them for documentation to make sure missing documentation error messages are produced in a predictable and repeatable order.

This is really helpful when someone is trying to fix multiple issues and wants to make sure a specific issue is fixed before moving one to the next one. Otherwise, the errors are thrown in a random order and every time a new message is presented to the developer making it very confusing if the previous one had been resolved or not.

(cherry picked from commit a07837e)

Co-authored-by: Oleksiy Kovyrin <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
mergify[bot] and kovyrin authored Oct 1, 2021
1 parent 2d7641f commit f6b7c7d
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion metricbeat/mb/testing/testdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,15 @@ func checkDocumented(data []common.MapStr, omitFields []string) error {
}

func documentedFieldCheck(foundKeys common.MapStr, knownKeys map[string]interface{}, omitFields []string) error {
for foundKey := range foundKeys {
// Sort all found keys to guarantee consistent validation messages
sortedFoundKeys := make([]string, 0, len(foundKeys))
for k := range foundKeys {
sortedFoundKeys = append(sortedFoundKeys, k)
}
sort.Strings(sortedFoundKeys)

for k := range sortedFoundKeys {
foundKey := sortedFoundKeys[k]
if _, ok := knownKeys[foundKey]; !ok {
for _, omitField := range omitFields {
if omitDocumentedField(foundKey, omitField) {
Expand Down

0 comments on commit f6b7c7d

Please sign in to comment.