2323 Subsystem : "remote_asset" ,
2424 Name : "http_fetcher_blob_size_bytes" ,
2525 Help : "Size of blobs fetched using the http fetcher, in bytes" ,
26- Buckets : util .DecimalExponentialBuckets (- 3 , 6 , 2 ),
26+ Buckets : util .DecimalExponentialBuckets (1 , 6 , 2 ),
2727 },
28- []string {"name" , "operation" })
28+ []string {"name" , "operation" , "resource_type" })
2929 blobAccessOperationsDurationSeconds = prometheus .NewHistogramVec (
3030 prometheus.HistogramOpts {
3131 Namespace : "buildbarn" ,
@@ -34,14 +34,14 @@ var (
3434 Help : "Amount of time spent per operation on fetching remote assets, in seconds." ,
3535 Buckets : util .DecimalExponentialBuckets (- 3 , 6 , 2 ),
3636 },
37- []string {"name" , "operation" , "status" })
37+ []string {"name" , "operation" , "status" , "resource_type" })
3838)
3939
4040type metricsFetcher struct {
4141 fetcher Fetcher
4242 clock clock.Clock
4343
44- fetchBlobBlobSizeBytes prometheus.Observer
44+ fetchBlobBlobSizeBytes prometheus.ObserverVec
4545 fetchBlobDurationSeconds prometheus.ObserverVec
4646 fetchDirectoryDurationSeconds prometheus.ObserverVec
4747}
@@ -57,36 +57,62 @@ func NewMetricsFetcher(fetcher Fetcher, clock clock.Clock, name string) Fetcher
5757 fetcher : fetcher ,
5858 clock : clock ,
5959
60- fetchBlobBlobSizeBytes : httpFetcherOperationsBlobSizeBytes .WithLabelValues ( name , "Fetch Blob" ),
60+ fetchBlobBlobSizeBytes : httpFetcherOperationsBlobSizeBytes .MustCurryWith ( map [ string ] string { " name" : name , "operation" : " Fetch Blob"} ),
6161 fetchBlobDurationSeconds : blobAccessOperationsDurationSeconds .MustCurryWith (map [string ]string {"name" : name , "operation" : "FetchBlob" }),
6262 fetchDirectoryDurationSeconds : blobAccessOperationsDurationSeconds .MustCurryWith (map [string ]string {"name" : name , "operation" : "FetchDirectory" }),
6363 }
6464}
6565
66- func (mf * metricsFetcher ) updateDurationSeconds (vec prometheus.ObserverVec , code codes.Code , timeStart time.Time ) {
67- vec .WithLabelValues (code .String ()).Observe (mf .clock .Now ().Sub (timeStart ).Seconds ())
66+ func (mf * metricsFetcher ) updateDurationSeconds (vec prometheus.ObserverVec , code codes.Code , timeStart time.Time , qualifiers []* remoteasset.Qualifier ) {
67+ if len (qualifiers ) == 0 {
68+ vec .WithLabelValues (code .String (), "N/A" ).Observe (mf .clock .Now ().Sub (timeStart ).Seconds ())
69+ } else {
70+ resourceType := "N/A"
71+ for _ , qualifier := range qualifiers {
72+ if qualifier .Name == "resource_type" {
73+ resourceType = qualifier .Value
74+ break
75+ }
76+ }
77+ vec .WithLabelValues (code .String (), resourceType ).Observe (mf .clock .Now ().Sub (timeStart ).Seconds ())
78+ }
79+ }
80+
81+ func (mf * metricsFetcher ) updateBlobSizeBytes (vec prometheus.ObserverVec , blobSize float64 , qualifiers []* remoteasset.Qualifier ) {
82+ if len (qualifiers ) == 0 {
83+ vec .WithLabelValues ("N/A" ).Observe (blobSize )
84+ } else {
85+ resourceType := "N/A"
86+ for _ , qualifier := range qualifiers {
87+ if qualifier .Name == "resource_type" {
88+ resourceType = qualifier .Value
89+ break
90+ }
91+ }
92+ vec .WithLabelValues (resourceType ).Observe (blobSize )
93+ }
6894}
6995
7096func (mf * metricsFetcher ) FetchBlob (ctx context.Context , req * remoteasset.FetchBlobRequest ) (* remoteasset.FetchBlobResponse , error ) {
7197 timeStart := mf .clock .Now ()
7298 resp , err := mf .fetcher .FetchBlob (ctx , req )
7399 if err != nil {
74- mf .updateDurationSeconds (mf .fetchBlobDurationSeconds , status .Code (err ), timeStart )
100+ mf .updateDurationSeconds (mf .fetchBlobDurationSeconds , status .Code (err ), timeStart , req . Qualifiers )
75101 return nil , err
76102 }
77- mf .updateDurationSeconds (mf .fetchBlobDurationSeconds , codes .Code (resp .Status .Code ), timeStart )
78- mf .fetchBlobBlobSizeBytes . Observe ( float64 (resp .BlobDigest .SizeBytes ))
103+ mf .updateDurationSeconds (mf .fetchBlobDurationSeconds , codes .Code (resp .Status .Code ), timeStart , req . Qualifiers )
104+ mf .updateBlobSizeBytes ( mf . fetchBlobBlobSizeBytes , float64 (resp .BlobDigest .SizeBytes ), req . Qualifiers )
79105 return resp , err
80106}
81107
82108func (mf * metricsFetcher ) FetchDirectory (ctx context.Context , req * remoteasset.FetchDirectoryRequest ) (* remoteasset.FetchDirectoryResponse , error ) {
83109 timeStart := mf .clock .Now ()
84110 resp , err := mf .fetcher .FetchDirectory (ctx , req )
85111 if err != nil {
86- mf .updateDurationSeconds (mf .fetchDirectoryDurationSeconds , status .Code (err ), timeStart )
112+ mf .updateDurationSeconds (mf .fetchDirectoryDurationSeconds , status .Code (err ), timeStart , req . Qualifiers )
87113 return nil , err
88114 }
89- mf .updateDurationSeconds (mf .fetchDirectoryDurationSeconds , codes .Code (resp .Status .Code ), timeStart )
115+ mf .updateDurationSeconds (mf .fetchDirectoryDurationSeconds , codes .Code (resp .Status .Code ), timeStart , req . Qualifiers )
90116 return resp , err
91117}
92118
0 commit comments