@@ -21,6 +21,7 @@ import (
2121 "github.com/buildbuddy-io/buildbuddy/server/util/authutil"
2222 "github.com/buildbuddy-io/buildbuddy/server/util/bytebufferpool"
2323 "github.com/buildbuddy-io/buildbuddy/server/util/cdc"
24+ "github.com/buildbuddy-io/buildbuddy/server/util/claims"
2425 "github.com/buildbuddy-io/buildbuddy/server/util/compression"
2526 "github.com/buildbuddy-io/buildbuddy/server/util/lib/set"
2627 "github.com/buildbuddy-io/buildbuddy/server/util/log"
3940 chunkUploadConcurrency = flag .Int ("cache_proxy.chunk_upload_concurrency" , 8 , "Maximum number of concurrent chunk uploads when uploading missing chunks to remote cache." )
4041)
4142
43+ func groupIDForMetrics (ctx context.Context ) string {
44+ c , err := claims .ClaimsFromContext (ctx )
45+ if err != nil {
46+ return interfaces .AuthAnonymousUser
47+ }
48+ return c .GroupID
49+ }
50+
4251type ByteStreamServerProxy struct {
4352 supportsEncryption func (context.Context ) bool
4453 authenticator interfaces.Authenticator
@@ -416,6 +425,7 @@ func (s *ByteStreamServerProxy) readRemoteWriteLocal(req *bspb.ReadRequest, stre
416425type byteStreamMetrics struct {
417426 requestType string
418427 compressor string
428+ groupID string
419429 err error
420430 bytes int64
421431 chunked bool
@@ -504,6 +514,7 @@ func (s *ByteStreamServerProxy) Write(stream bspb.ByteStream_WriteServer) error
504514 recordWriteMetrics (byteStreamMetrics {
505515 requestType : requestTypeLabel ,
506516 compressor : meteredStream .compressor ,
517+ groupID : groupIDForMetrics (ctx ),
507518 err : nil ,
508519 bytes : meteredStream .bytes ,
509520 chunked : true ,
@@ -680,12 +691,17 @@ func recordWriteMetrics(bsm byteStreamMetrics) {
680691 metrics .StatusLabel : status .MetricsLabel (bsm .err ),
681692 metrics .CompressionType : bsm .compressor ,
682693 }
694+ chunkedLabelsWithGroup := prometheus.Labels {
695+ metrics .StatusLabel : status .MetricsLabel (bsm .err ),
696+ metrics .CompressionType : bsm .compressor ,
697+ metrics .GroupID : bsm .groupID ,
698+ }
683699 metrics .ByteStreamChunkedWriteBlobBytes .With (chunkedLabels ).Add (float64 (bsm .blobBytes ))
684700 if bsm .chunksTotal > 0 {
685- metrics .ByteStreamChunkedWriteChunksTotal .With (chunkedLabels ).Add (float64 (bsm .chunksTotal ))
701+ metrics .ByteStreamChunkedWriteChunksTotal .With (chunkedLabelsWithGroup ).Add (float64 (bsm .chunksTotal ))
686702 }
687703 if bsm .chunksDeduped > 0 {
688- metrics .ByteStreamChunkedWriteChunksDeduped .With (chunkedLabels ).Add (float64 (bsm .chunksDeduped ))
704+ metrics .ByteStreamChunkedWriteChunksDeduped .With (chunkedLabelsWithGroup ).Add (float64 (bsm .chunksDeduped ))
689705 }
690706 if bsm .chunkBytesTotal > 0 {
691707 metrics .ByteStreamChunkedWriteChunkBytes .With (chunkedLabels ).Add (float64 (bsm .chunkBytesTotal ))
0 commit comments