Skip to content

Commit eeaff4c

Browse files
authored
add missing label on replicator metrics and unit test (#229)
The storage type label is missing from metrics blob replicator, causing the initialization to fail on: panic: 1 unknown label(s) found during currying goroutine 1 [running]: github.com/prometheus/client_golang/prometheus.(*HistogramVec).MustCurryWith(...) external/gazelle~~go_deps~com_github_prometheus_client_golang/prometheus/histogram.go:1278 Also, add a unit test to catch this case.
1 parent a041f42 commit eeaff4c

File tree

3 files changed

+39
-13
lines changed

3 files changed

+39
-13
lines changed

pkg/blobstore/replication/BUILD.bazel

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ go_test(
4141
srcs = [
4242
"deduplicating_blob_replicator_test.go",
4343
"local_blob_replicator_test.go",
44+
"metrics_blob_replicator_test.go",
4445
"nested_blob_replicator_test.go",
4546
"queued_blob_replicator_test.go",
4647
],

pkg/blobstore/replication/metrics_blob_replicator.go

+13-13
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ var (
2727
Help: "Amount of time spent per operation on blob replicator, in seconds.",
2828
Buckets: util.DecimalExponentialBuckets(-3, 6, 2),
2929
},
30-
[]string{"operation"})
30+
[]string{"storage_type", "operation"})
3131

3232
blobReplicatorOperationsBlobSizeBytes = prometheus.NewHistogramVec(
3333
prometheus.HistogramOpts{
@@ -37,7 +37,7 @@ var (
3737
Help: "Size of blobs being replicated, in bytes.",
3838
Buckets: prometheus.ExponentialBuckets(1.0, 2.0, 33),
3939
},
40-
[]string{"operation"})
40+
[]string{"storage_type", "operation"})
4141

4242
blobReplicatorOperationsBatchSize = prometheus.NewHistogramVec(
4343
prometheus.HistogramOpts{
@@ -47,7 +47,7 @@ var (
4747
Help: "Number of blobs in batch replication requests.",
4848
Buckets: prometheus.ExponentialBuckets(1.0, 2.0, 17),
4949
},
50-
[]string{"operation"})
50+
[]string{"storage_type", "operation"})
5151
)
5252

5353
type metricsBlobReplicator struct {
@@ -78,21 +78,21 @@ func NewMetricsBlobReplicator(replicator BlobReplicator, clock clock.Clock, stor
7878
replicator: replicator,
7979
clock: clock,
8080
singleDurationSeconds: blobReplicatorOperationsDurationSeconds.MustCurryWith(map[string]string{
81-
"operation": "ReplicateSingle",
82-
"storage": storageTypeName,
81+
"storage_type": storageTypeName,
82+
"operation": "ReplicateSingle",
8383
}),
84-
singleBlobSizeBytes: blobReplicatorOperationsBlobSizeBytes.WithLabelValues("ReplicateSingle", storageTypeName),
84+
singleBlobSizeBytes: blobReplicatorOperationsBlobSizeBytes.WithLabelValues(storageTypeName, "ReplicateSingle"),
8585
compositeDurationSeconds: blobReplicatorOperationsDurationSeconds.MustCurryWith(map[string]string{
86-
"operation": "ReplicateComposite",
87-
"storage": storageTypeName,
86+
"storage_type": storageTypeName,
87+
"operation": "ReplicateComposite",
8888
}),
89-
compositeBlobSizeBytes: blobReplicatorOperationsBlobSizeBytes.WithLabelValues("ReplicateComposite", storageTypeName),
89+
compositeBlobSizeBytes: blobReplicatorOperationsBlobSizeBytes.WithLabelValues(storageTypeName, "ReplicateComposite"),
9090
multipleDurationSeconds: blobReplicatorOperationsDurationSeconds.MustCurryWith(map[string]string{
91-
"operation": "ReplicateMultiple",
92-
"storage": storageTypeName,
91+
"storage_type": storageTypeName,
92+
"operation": "ReplicateMultiple",
9393
}),
94-
multipleBlobSizeBytes: blobReplicatorOperationsBlobSizeBytes.WithLabelValues("ReplicateMultiple", storageTypeName),
95-
multipleBatchSize: blobReplicatorOperationsBatchSize.WithLabelValues("ReplicateMultiple", storageTypeName),
94+
multipleBlobSizeBytes: blobReplicatorOperationsBlobSizeBytes.WithLabelValues(storageTypeName, "ReplicateMultiple"),
95+
multipleBatchSize: blobReplicatorOperationsBatchSize.WithLabelValues(storageTypeName, "ReplicateMultiple"),
9696
}
9797
}
9898

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package replication_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/require"
7+
8+
"github.com/buildbarn/bb-storage/internal/mock"
9+
"github.com/buildbarn/bb-storage/pkg/blobstore/replication"
10+
"go.uber.org/mock/gomock"
11+
)
12+
13+
func TestNewMetricsBlobReplicator(t *testing.T) {
14+
ctrl := gomock.NewController(t)
15+
defer ctrl.Finish()
16+
17+
// Create mock using the generated mock
18+
mockReplicator := mock.NewMockBlobReplicator(ctrl)
19+
mockClock := mock.NewMockClock(ctrl)
20+
21+
// Create a new MetricsBlobReplicator
22+
storageTypeName := "cas"
23+
metricsReplicator := replication.NewMetricsBlobReplicator(mockReplicator, mockClock, storageTypeName)
24+
require.NotNil(t, metricsReplicator)
25+
}

0 commit comments

Comments
 (0)