Skip to content

Commit

Permalink
Merge pull request #127221 from cockroachdb/blathers/backport-release…
Browse files Browse the repository at this point in the history
…-24.1-127195

release-24.1: schematelemetry: don't redact object ID or validation error in logs
  • Loading branch information
rafiss authored Jul 17, 2024
2 parents 34298cf + a6b9e53 commit 69bc012
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
1 change: 1 addition & 0 deletions pkg/sql/catalog/schematelemetry/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ go_library(
"//pkg/util/metric",
"//pkg/util/uuid",
"@com_github_cockroachdb_errors//:errors",
"@com_github_cockroachdb_redact//:redact",
],
)

Expand Down
16 changes: 14 additions & 2 deletions pkg/sql/catalog/schematelemetry/schema_telemetry_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/util/metric"
"github.com/cockroachdb/cockroach/pkg/util/uuid"
"github.com/cockroachdb/errors"
"github.com/cockroachdb/redact"
)

type Metrics struct {
Expand Down Expand Up @@ -116,7 +117,11 @@ func processInvalidObjects(
return err
}

rows, err := txn.QueryIteratorEx(ctx, "sql-telemetry-invalid-objects", txn.KV(), sessiondata.NodeUserSessionDataOverride, `SELECT id, error FROM "".crdb_internal.invalid_objects LIMIT $1`, maxRecords)
rows, err := txn.QueryIteratorEx(
ctx, "sql-telemetry-invalid-objects", txn.KV(), sessiondata.NodeUserSessionDataOverride,
`SELECT id, error_redactable FROM "".crdb_internal.invalid_objects LIMIT $1`,
maxRecords,
)
if err != nil {
return err
}
Expand Down Expand Up @@ -148,10 +153,17 @@ func processInvalidObjects(
return errors.AssertionFailedf("expected err to be string (was %T)", row[1])
}

log.Warningf(ctx, "found invalid object with ID %d: %q", descID, validationErr)
// IDs are always non-sensitive, and the validationErr is written to the
// table with redact.Sprint, so it's a RedactableString.
log.Warningf(ctx, "found invalid object with ID %d: %s",
redact.SafeInt(*descID), redact.RedactableString(*validationErr),
)
}

metrics.InvalidObjects.Update(count)
if count == 0 {
log.Infof(ctx, "schema telemetry job found no invalid objects")
}

return nil
})
Expand Down
9 changes: 8 additions & 1 deletion pkg/sql/catalog/schematelemetry/schema_telemetry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,15 @@ UPDATE system.namespace SET id = %d WHERE id = %d;

// Ensure that a log line is emitted for each invalid object, with a loose
// enforcement of the log structure.
errorRE := regexp.MustCompile(`found invalid object with ID \d+: ".+"`)
errorRE := regexp.MustCompile(`found invalid object with ID \d+: .+`)
entries, err := log.FetchEntriesFromFiles(0, math.MaxInt64, 1000, errorRE, log.SelectEditMode(false, false))
require.NoError(t, err)
require.Len(t, entries, 9)

// Verify that the log entries have redaction markers applied by checking one
// of the specific error messages.
errorRE = regexp.MustCompile(`found invalid object with ID \d+: relation ‹"nojob"›`)
entries, err = log.FetchEntriesFromFiles(0, math.MaxInt64, 1000, errorRE, log.SelectEditMode(false, true /* keepRedactable */))
require.NoError(t, err)
require.Len(t, entries, 1)
}

0 comments on commit 69bc012

Please sign in to comment.