Skip to content

Commit

Permalink
outliers: use a custom type for Statement.ID
Browse files Browse the repository at this point in the history
It's nicer having a type instead of those raw bytes.

Release note: None
  • Loading branch information
matthewtodd committed Jul 6, 2022
1 parent 67a8cc1 commit c393aac
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion pkg/sql/crdb_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -6205,7 +6205,7 @@ CREATE TABLE crdb_internal.node_execution_outliers (
err = errors.CombineErrors(err, addRow(
tree.NewDString(hex.EncodeToString(o.Session.ID.GetBytes())),
tree.NewDUuid(tree.DUuid{UUID: *o.Transaction.ID}),
tree.NewDString(hex.EncodeToString(o.Statement.ID)),
tree.NewDString(hex.EncodeToString(o.Statement.ID.GetBytes())),
tree.NewDBytes(tree.DBytes(sqlstatsutil.EncodeUint64ToBytes(uint64(o.Statement.FingerprintID)))),
))
})
Expand Down
1 change: 0 additions & 1 deletion pkg/sql/sqlstats/outliers/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ go_library(
"//pkg/util/metric",
"//pkg/util/quantile",
"//pkg/util/syncutil",
"//pkg/util/uint128",
"@com_github_prometheus_client_model//go",
],
)
Expand Down
3 changes: 2 additions & 1 deletion pkg/sql/sqlstats/outliers/outliers.proto
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ message Transaction {
}

message Statement {
bytes id = 1 [(gogoproto.customname) = "ID"];
bytes id = 1 [(gogoproto.customname) = "ID",
(gogoproto.customtype) = "github.com/cockroachdb/cockroach/pkg/sql/clusterunique.ID"];
uint64 fingerprint_id = 2 [(gogoproto.customname) = "FingerprintID",
(gogoproto.casttype) = "github.com/cockroachdb/cockroach/pkg/roachpb.StmtFingerprintID"];
double latency_in_seconds = 3;
Expand Down
9 changes: 6 additions & 3 deletions pkg/sql/sqlstats/outliers/outliers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ func TestOutliers(t *testing.T) {
session := &outliers.Session{ID: &sessionID}
txnID := uuid.FastMakeV4()
transaction := &outliers.Transaction{ID: &txnID}
statementID := clusterunique.IDFromBytes([]byte("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"))
statement := &outliers.Statement{
ID: []byte("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"),
ID: &statementID,
FingerprintID: roachpb.StmtFingerprintID(100),
LatencyInSeconds: 2,
}
Expand Down Expand Up @@ -82,8 +83,9 @@ func TestOutliers(t *testing.T) {
t.Run("too fast", func(t *testing.T) {
st := cluster.MakeTestingClusterSettings()
outliers.LatencyThreshold.Override(ctx, &st.SV, 1*time.Second)
statement2ID := clusterunique.IDFromBytes([]byte("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"))
statement2 := &outliers.Statement{
ID: []byte("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"),
ID: &statement2ID,
FingerprintID: roachpb.StmtFingerprintID(100),
LatencyInSeconds: 0.5,
}
Expand All @@ -106,8 +108,9 @@ func TestOutliers(t *testing.T) {
otherSession := &outliers.Session{ID: &otherSessionID}
otherTxnID := uuid.FastMakeV4()
otherTransaction := &outliers.Transaction{ID: &otherTxnID}
otherStatementID := clusterunique.IDFromBytes([]byte("dddddddddddddddddddddddddddddddd"))
otherStatement := &outliers.Statement{
ID: []byte("dddddddddddddddddddddddddddddddd"),
ID: &otherStatementID,
FingerprintID: roachpb.StmtFingerprintID(101),
LatencyInSeconds: 3,
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/sql/sqlstats/outliers/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"github.com/cockroachdb/cockroach/pkg/sql/clusterunique"
"github.com/cockroachdb/cockroach/pkg/util/cache"
"github.com/cockroachdb/cockroach/pkg/util/syncutil"
"github.com/cockroachdb/cockroach/pkg/util/uint128"
)

// maxCacheSize is the number of detected outliers we will retain in memory.
Expand Down Expand Up @@ -89,7 +88,7 @@ func (r *registry) ObserveTransaction(sessionID clusterunique.ID, transaction *T

if hasOutlier {
for _, s := range statements {
r.mu.outliers.Add(uint128.FromBytes(s.ID), &Outlier{
r.mu.outliers.Add(s.ID, &Outlier{
Session: &Session{ID: &sessionID},
Transaction: transaction,
Statement: s,
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/sqlstats/ssmemstorage/ss_mem_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func (s *Container) RecordStatement(
}

s.outliersRegistry.ObserveStatement(value.SessionID, &outliers.Statement{
ID: value.StatementID.GetBytes(),
ID: &value.StatementID,
FingerprintID: stmtFingerprintID,
LatencyInSeconds: value.ServiceLatency,
})
Expand Down

0 comments on commit c393aac

Please sign in to comment.