Skip to content

Commit

Permalink
Flattened innoparser errs
Browse files Browse the repository at this point in the history
  • Loading branch information
naman47vyas committed May 8, 2024
1 parent e637d66 commit 2a9ff9c
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion receiver/mysqlreceiver/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ func (c *mySQLClient) getInnodbStatusStats() (map[string]int64, error) {
/*
TODO: The NewInnodbStatusParser should be able to be created with the mySQLClient.
*/

innodbParser, err := parser.NewInnodbStatusParser()
if err != nil {
err := fmt.Errorf("could not create parser for innodb stats, %s", err)
Expand Down Expand Up @@ -219,8 +220,10 @@ func (c *mySQLClient) getInnodbStatusStats() (map[string]int64, error) {
total_errs += 1
}
}

if total_errs > 0 {
err := fmt.Errorf("%d errors in parsing metrics", total_errs)
errorString := flattenErrorMap(errs)
err := fmt.Errorf(errorString)
return nil, err
}

Expand Down Expand Up @@ -574,3 +577,15 @@ func (c *mySQLClient) Close() error {
}
return nil
}

func flattenErrorMap(errs map[string][]error) string {
var errorMessages []string
for key, errors := range errs {
for _, err := range errors {
errorMessage := fmt.Sprintf("%s: %s", key, err.Error())
errorMessages = append(errorMessages, errorMessage)
}
}
result := strings.Join(errorMessages, "\n")
return result
}

0 comments on commit 2a9ff9c

Please sign in to comment.