@@ -16,6 +16,7 @@ package blobrefresh
1616import (
1717 "errors"
1818 "fmt"
19+ "strings"
1920 "time"
2021
2122 "github.com/uber/kraken/core"
@@ -112,14 +113,13 @@ func (r *Refresher) Refresh(namespace string, d core.Digest, hooks ...PostHook)
112113 return err
113114 }
114115 t := time .Since (start )
115- r .stats .Tagged (map [string ]string {"namespace" : namespace }).
116- Timer ("download_remote_blob" ).Record (t )
116+ stats := r .stats .Tagged (map [string ]string {"namespace" : extractPrefix (namespace )})
117+ stats .Timer ("download_remote_blob" ).Record (t )
118+ stats .Counter ("downloads" ).Inc (1 )
117119 log .With (
118120 "namespace" , namespace ,
119121 "name" , d .Hex (),
120122 "download_time" , t ).Info ("Downloaded remote blob" )
121- r .stats .Tagged (map [string ]string {"namespace" : namespace }).
122- Counter ("downloads" ).Inc (1 )
123123 for _ , h := range hooks {
124124 h .Run (d )
125125 }
@@ -143,3 +143,14 @@ func (r *Refresher) download(client backend.Client, namespace string, d core.Dig
143143 return client .Download (namespace , name , w )
144144 }, pieceLength )
145145}
146+
147+ // extractPrefix extracts the prefix from the namespace to decrease the cardinality of metrics.
148+ func extractPrefix (namespace string ) string {
149+ if prefix , _ , ok := strings .Cut (namespace , "/" ); ok {
150+ return prefix
151+ }
152+ if prefix , _ , ok := strings .Cut (namespace , "_" ); ok {
153+ return prefix
154+ }
155+ return namespace
156+ }
0 commit comments