Skip to content

Commit

Permalink
blobstore: Add metrics_tag config field
Browse files Browse the repository at this point in the history
WIP; more description to come
  • Loading branch information
minor-fixes committed Nov 11, 2024
1 parent 0941111 commit a670343
Show file tree
Hide file tree
Showing 4 changed files with 437 additions and 414 deletions.
7 changes: 5 additions & 2 deletions pkg/blobstore/configuration/new_blob_access.go
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,10 @@ func (nc *simpleNestedBlobAccessCreator) NewNestedBlobAccess(configuration *pb.B
}).NewNestedBlobAccess(config.Backend, creator)
case *pb.BlobAccessConfiguration_Label:
if labelBackend, ok := nc.labels[backend.Label]; ok {
return labelBackend, nil
return BlobAccessInfo{
BlobAccess: blobstore.NewMetricsBlobAccess(labelBackend.BlobAccess, clock.SystemClock, creator.GetStorageTypeName(), "label", configuration.GetMetricsTag()),
DigestKeyFormat: labelBackend.DigestKeyFormat,
}, nil
}
return BlobAccessInfo{}, status.Errorf(codes.InvalidArgument, "Label %#v not declared", backend.Label)
}
Expand All @@ -556,7 +559,7 @@ func (nc *simpleNestedBlobAccessCreator) NewNestedBlobAccess(configuration *pb.B
return BlobAccessInfo{}, err
}
return BlobAccessInfo{
BlobAccess: blobstore.NewMetricsBlobAccess(backend.BlobAccess, clock.SystemClock, creator.GetStorageTypeName(), backendType),
BlobAccess: blobstore.NewMetricsBlobAccess(backend.BlobAccess, clock.SystemClock, creator.GetStorageTypeName(), backendType, configuration.GetMetricsTag()),
DigestKeyFormat: backend.DigestKeyFormat,
}, nil
}
Expand Down
26 changes: 13 additions & 13 deletions pkg/blobstore/metrics_blob_access.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var (
Help: "Size of blobs being inserted/retrieved, in bytes.",
Buckets: prometheus.ExponentialBuckets(1.0, 2.0, 33),
},
[]string{"storage_type", "backend_type", "operation"})
[]string{"storage_type", "backend_type", "operation", "metrics_tag"})
blobAccessOperationsFindMissingBatchSize = prometheus.NewHistogramVec(
prometheus.HistogramOpts{
Namespace: "buildbarn",
Expand All @@ -37,7 +37,7 @@ var (
Help: "Number of digests provided to FindMissing().",
Buckets: prometheus.ExponentialBuckets(1.0, 2.0, 17),
},
[]string{"storage_type", "backend_type"})
[]string{"storage_type", "backend_type", "metrics_tag"})
blobAccessOperationsDurationSeconds = prometheus.NewHistogramVec(
prometheus.HistogramOpts{
Namespace: "buildbarn",
Expand All @@ -46,7 +46,7 @@ var (
Help: "Amount of time spent per operation on blob access objects, in seconds.",
Buckets: util.DecimalExponentialBuckets(-3, 6, 2),
},
[]string{"storage_type", "backend_type", "operation", "grpc_code"})
[]string{"storage_type", "backend_type", "operation", "metrics_tag", "grpc_code"})
)

type metricsBlobAccess struct {
Expand All @@ -66,7 +66,7 @@ type metricsBlobAccess struct {

// NewMetricsBlobAccess creates an adapter for BlobAccess that adds
// basic instrumentation in the form of Prometheus metrics.
func NewMetricsBlobAccess(blobAccess BlobAccess, clock clock.Clock, storageType, backendType string) BlobAccess {
func NewMetricsBlobAccess(blobAccess BlobAccess, clock clock.Clock, storageType, backendType, metricsTag string) BlobAccess {
blobAccessOperationsPrometheusMetrics.Do(func() {
prometheus.MustRegister(blobAccessOperationsBlobSizeBytes)
prometheus.MustRegister(blobAccessOperationsFindMissingBatchSize)
Expand All @@ -77,15 +77,15 @@ func NewMetricsBlobAccess(blobAccess BlobAccess, clock clock.Clock, storageType,
blobAccess: blobAccess,
clock: clock,

getBlobSizeBytes: blobAccessOperationsBlobSizeBytes.WithLabelValues(storageType, backendType, "Get"),
getDurationSeconds: blobAccessOperationsDurationSeconds.MustCurryWith(map[string]string{"storage_type": storageType, "backend_type": backendType, "operation": "Get"}),
getFromCompositeBlobSizeBytes: blobAccessOperationsBlobSizeBytes.WithLabelValues(storageType, backendType, "GetFromComposite"),
getFromCompositeDurationSeconds: blobAccessOperationsDurationSeconds.MustCurryWith(map[string]string{"storage_type": storageType, "backend_type": backendType, "operation": "GetFromComposite"}),
putBlobSizeBytes: blobAccessOperationsBlobSizeBytes.WithLabelValues(storageType, backendType, "Put"),
putDurationSeconds: blobAccessOperationsDurationSeconds.MustCurryWith(map[string]string{"storage_type": storageType, "backend_type": backendType, "operation": "Put"}),
findMissingBatchSize: blobAccessOperationsFindMissingBatchSize.WithLabelValues(storageType, backendType),
findMissingDurationSeconds: blobAccessOperationsDurationSeconds.MustCurryWith(map[string]string{"storage_type": storageType, "backend_type": backendType, "operation": "FindMissing"}),
getCapabilitiesSeconds: blobAccessOperationsDurationSeconds.MustCurryWith(map[string]string{"storage_type": storageType, "backend_type": backendType, "operation": "GetCapabilities"}),
getBlobSizeBytes: blobAccessOperationsBlobSizeBytes.WithLabelValues(storageType, backendType, "Get", metricsTag),
getDurationSeconds: blobAccessOperationsDurationSeconds.MustCurryWith(map[string]string{"storage_type": storageType, "backend_type": backendType, "operation": "Get", "metrics_tag": metricsTag}),
getFromCompositeBlobSizeBytes: blobAccessOperationsBlobSizeBytes.WithLabelValues(storageType, backendType, "GetFromComposite", metricsTag),
getFromCompositeDurationSeconds: blobAccessOperationsDurationSeconds.MustCurryWith(map[string]string{"storage_type": storageType, "backend_type": backendType, "operation": "GetFromComposite", "metrics_tag": metricsTag}),
putBlobSizeBytes: blobAccessOperationsBlobSizeBytes.WithLabelValues(storageType, backendType, "Put", metricsTag),
putDurationSeconds: blobAccessOperationsDurationSeconds.MustCurryWith(map[string]string{"storage_type": storageType, "backend_type": backendType, "operation": "Put", "metrics_tag": metricsTag}),
findMissingBatchSize: blobAccessOperationsFindMissingBatchSize.WithLabelValues(storageType, backendType, metricsTag),
findMissingDurationSeconds: blobAccessOperationsDurationSeconds.MustCurryWith(map[string]string{"storage_type": storageType, "backend_type": backendType, "operation": "FindMissing", "metrics_tag": metricsTag}),
getCapabilitiesSeconds: blobAccessOperationsDurationSeconds.MustCurryWith(map[string]string{"storage_type": storageType, "backend_type": backendType, "operation": "GetCapabilities", "metrics_tag": metricsTag}),
}
}

Expand Down
Loading

0 comments on commit a670343

Please sign in to comment.