Skip to content

Commit

Permalink
fix: add flag to ignore results with missing values
Browse files Browse the repository at this point in the history
  • Loading branch information
burningalchemist committed Dec 29, 2023
1 parent adb6364 commit 1e476d0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions cmd/sql_exporter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ var (
func init() {
prometheus.MustRegister(version.NewCollector("sql_exporter"))
flag.BoolVar(&cfg.EnablePing, "config.enable-ping", true, "Enable ping for targets")
flag.BoolVar(&cfg.IgnoreMissingVals, "config.ignore-missing-values", false, "[EXPERIMENTAL] Ignore results with missing values for the requested columns")
flag.StringVar(&cfg.DsnOverride, "config.data-source-name", "", "Data source name to override the value in the configuration file with")
flag.StringVar(&cfg.TargetLabel, "config.target-label", "target", "Target label name")
}
Expand Down
7 changes: 4 additions & 3 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ const EnvDsnOverride = "SQLEXPORTER_TARGET_DSN"
const MaxInt32 int = 1<<31 - 1

var (
EnablePing bool
DsnOverride string
TargetLabel string
EnablePing bool
IgnoreMissingVals bool
DsnOverride string
TargetLabel string
)

// Load attempts to parse the given config file and return a Config object.
Expand Down
4 changes: 4 additions & 0 deletions query.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ func (q *Query) Collect(ctx context.Context, conn *sql.DB, ch chan<- Metric) {

dest, err := q.scanDest(rows)
if err != nil {
if config.IgnoreMissingVals {
klog.V(3).Info(err)
return
}
ch <- NewInvalidMetric(err)
return
}
Expand Down

0 comments on commit 1e476d0

Please sign in to comment.