Skip to content

Commit 51aaf56

Browse files
committed
log queries and record metric where columns are null
1 parent 4b32880 commit 51aaf56

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

query.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ func (q *Query) Collect(ctx context.Context, conn *sql.DB, ch chan<- Metric) {
159159
}
160160

161161
// Apply lag calculations and other transformations
162-
transformedRow := q.applyTransformations(row, mf.config)
162+
transformedRow := q.applyTransformations(row, mf.config, ch)
163163

164164
mf.Collect(transformedRow, ch)
165165
metricsGenerated++
@@ -416,7 +416,7 @@ func (q *Query) columnIsNeeded(column string, metric *config.MetricConfig) bool
416416
}
417417

418418
// applyTransformations applies configured transformations like lag calculations to a row
419-
func (q *Query) applyTransformations(row map[string]any, metric *config.MetricConfig) map[string]any {
419+
func (q *Query) applyTransformations(row map[string]any, metric *config.MetricConfig, ch chan<- Metric) map[string]any {
420420
result := make(map[string]any)
421421

422422
// Check for NULL values in columns we actually care about (after row filtering)
@@ -445,6 +445,8 @@ func (q *Query) applyTransformations(row map[string]any, metric *config.MetricCo
445445
// Log NULL columns only for rows that passed filtering and columns we need
446446
if len(nullColumns) > 0 {
447447
slog.Warn("Key columns are NULL", "logContext", q.logContext, "columns", nullColumns, "table_column", tableColumn, "sql", q.config.Query)
448+
// Also register this as a scrape error
449+
ch <- NewInvalidMetric(errors.Errorf(q.logContext, "key columns are NULL: %v (table_column: %s)", nullColumns, tableColumn))
448450
}
449451

450452
// Copy original row data

0 commit comments

Comments
 (0)