Skip to content

Commit

Permalink
Improve error handling and debug logs (#91)
Browse files Browse the repository at this point in the history
* chore: improve error handling and debug logs
  • Loading branch information
marcsanmi authored Jul 22, 2022
1 parent 735df73 commit f1643b0
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,14 @@ func PopulateInstanceMetrics(instanceEntity *integration.Entity, connection *con
populateWaitTimeMetrics(instanceEntity, connection)

if len(arguments.CustomMetricsQuery) > 0 {
log.Debug("Arguments custom metrics query: %s", arguments.CustomMetricsQuery)
populateCustomMetrics(instanceEntity, connection, customQuery{Query: arguments.CustomMetricsQuery})
} else if len(arguments.CustomMetricsConfig) > 0 {
queries, err := parseCustomQueries(arguments)
if err != nil {
log.Error("Failed to parse custom queries: %s", err)
}
log.Debug("Parsed custom queries: %+v", queries)
var wg sync.WaitGroup
for _, query := range queries {
wg.Add(1)
Expand Down Expand Up @@ -143,12 +145,18 @@ func populateCustomMetrics(instanceEntity *integration.Entity, connection *conne
prefix = "USE " + query.Database + "; "
}

log.Debug("Running custom query: %+v", query)

rows, err := connection.Queryx(prefix + query.Query)
if err != nil {
log.Error("Could not execute custom query: %s", err)
return
}

if !rows.NextResultSet() {
log.Warn("No result set found for custom query: %+v", query)
}

defer func() {
_ = rows.Close()
}()
Expand Down Expand Up @@ -255,6 +263,10 @@ func populateCustomMetrics(instanceEntity *integration.Entity, connection *conne
}
}
}

if err := rows.Err(); err != nil {
log.Error("Error iterating rows: %s", err)
}
}

// PopulateDatabaseMetrics collects per-database metrics
Expand Down

0 comments on commit f1643b0

Please sign in to comment.