Skip to content

Commit

Permalink
feat(spanner): make randIDForProcess hexadecimal in x-goog-spanner-re…
Browse files Browse the repository at this point in the history
…quest-id (#11546)

Implements a new requirement that randIDForProcess should
be a hexadecimal value with the format specifier "%016x".

Fixes #11545
  • Loading branch information
odeke-em authored Feb 2, 2025
1 parent a8f16ef commit d7671ec
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion spanner/request_id_header.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func init() {
if err != nil {
panic(err)
}
randIDForProcess = r64.String()
randIDForProcess = fmt.Sprintf("%016x", r64.Uint64())
}

// Please bump this version whenever this implementation
Expand Down
11 changes: 11 additions & 0 deletions spanner/request_id_header_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package spanner

import (
"context"
"encoding/hex"
"encoding/json"
"fmt"
"math"
Expand Down Expand Up @@ -1925,3 +1926,13 @@ func TestRequestIDHeader_SingleUseReadOnly_ExecuteStreamingSql_UnavailableDuring
t.Fatalf("RequestID streaming segments mismatch: got - want +\n%s", diff)
}
}

func TestRequestID_randIDForProcessIsHexadecimal(t *testing.T) {
decoded, err := hex.DecodeString(randIDForProcess)
if err != nil {
t.Fatal(err)
}
if len(decoded) == 0 {
t.Fatal("Expected a non-empty decoded result")
}
}

0 comments on commit d7671ec

Please sign in to comment.