From f4b7e7bf5b1a875db95a42781937c2a690062dd3 Mon Sep 17 00:00:00 2001 From: Lucas Di Pentima Date: Tue, 12 Mar 2019 15:19:36 -0300 Subject: [PATCH] 13937: Removes the 'any' operation type for a better way of testing driver labels Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima --- services/keepstore/azure_blob_volume_test.go | 4 ++++ services/keepstore/s3_volume_test.go | 4 ++++ services/keepstore/stats_ticker.go | 1 - services/keepstore/unix_volume_test.go | 4 ++++ services/keepstore/volume_generic_test.go | 20 +++++++++++--------- services/keepstore/volume_test.go | 3 +++ 6 files changed, 26 insertions(+), 10 deletions(-) diff --git a/services/keepstore/azure_blob_volume_test.go b/services/keepstore/azure_blob_volume_test.go index 522544ebf6..cfad7577c5 100644 --- a/services/keepstore/azure_blob_volume_test.go +++ b/services/keepstore/azure_blob_volume_test.go @@ -746,6 +746,10 @@ func (v *TestableAzureBlobVolume) Teardown() { v.azStub.Close() } +func (v *TestableAzureBlobVolume) ReadWriteOperationLabelValues() (r, w string) { + return "get", "create" +} + func (v *TestableAzureBlobVolume) DeviceID() string { // Dummy device id for testing purposes return "azure://azure_blob_volume_test" diff --git a/services/keepstore/s3_volume_test.go b/services/keepstore/s3_volume_test.go index 6fd6b653ee..6377420ff4 100644 --- a/services/keepstore/s3_volume_test.go +++ b/services/keepstore/s3_volume_test.go @@ -493,3 +493,7 @@ func (v *TestableS3Volume) TouchWithDate(locator string, lastPut time.Time) { func (v *TestableS3Volume) Teardown() { v.server.Quit() } + +func (v *TestableS3Volume) ReadWriteOperationLabelValues() (r, w string) { + return "get", "put" +} diff --git a/services/keepstore/stats_ticker.go b/services/keepstore/stats_ticker.go index 29daeb6ddd..342b9e3205 100644 --- a/services/keepstore/stats_ticker.go +++ b/services/keepstore/stats_ticker.go @@ -74,7 +74,6 @@ func (s *statsTicker) TickOps(operations ...string) { return } for _, opType := range operations { - s.opsCounters.With(prometheus.Labels{"operation": "any"}).Inc() s.opsCounters.With(prometheus.Labels{"operation": opType}).Inc() } } diff --git a/services/keepstore/unix_volume_test.go b/services/keepstore/unix_volume_test.go index 8b2bc2d545..872f408cf8 100644 --- a/services/keepstore/unix_volume_test.go +++ b/services/keepstore/unix_volume_test.go @@ -74,6 +74,10 @@ func (v *TestableUnixVolume) Teardown() { } } +func (v *TestableUnixVolume) ReadWriteOperationLabelValues() (r, w string) { + return "open", "create" +} + // serialize = false; readonly = false func TestUnixVolumeWithGenericTests(t *testing.T) { DoGenericVolumeTests(t, func(t TB) TestableVolume { diff --git a/services/keepstore/volume_generic_test.go b/services/keepstore/volume_generic_test.go index c118c20d6a..d5a413693f 100644 --- a/services/keepstore/volume_generic_test.go +++ b/services/keepstore/volume_generic_test.go @@ -573,20 +573,23 @@ func testMetrics(t TB, factory TestableVolumeFactory) { return } - var c, anyOpCounter float64 - anyOpCounter = getValueFrom(opsC, prometheus.Labels{"operation": "any"}) + var c, writeOpCounter, readOpCounter float64 + + readOpType, writeOpType := v.ReadWriteOperationLabelValues() + writeOpCounter = getValueFrom(opsC, prometheus.Labels{"operation": writeOpType}) + readOpCounter = getValueFrom(opsC, prometheus.Labels{"operation": readOpType}) + // Test Put if volume is writable if v.Writable() { err = v.Put(context.Background(), TestHash, TestBlock) if err != nil { t.Errorf("Got err putting block %q: %q, expected nil", TestBlock, err) } - // Check that the operations counter increased - c = getValueFrom(opsC, prometheus.Labels{"operation": "any"}) - if c <= anyOpCounter { + // Check that the write operations counter increased + c = getValueFrom(opsC, prometheus.Labels{"operation": writeOpType}) + if c <= writeOpCounter { t.Error("Operation(s) not counted on Put") } - anyOpCounter = c // Check that bytes counter is > 0 if getValueFrom(ioC, prometheus.Labels{"direction": "out"}) == 0 { t.Error("ioBytes{direction=out} counter shouldn't be zero") @@ -602,11 +605,10 @@ func testMetrics(t TB, factory TestableVolumeFactory) { } // Check that the operations counter increased - c = getValueFrom(opsC, prometheus.Labels{"operation": "any"}) - if c <= anyOpCounter { + c = getValueFrom(opsC, prometheus.Labels{"operation": readOpType}) + if c <= readOpCounter { t.Error("Operation(s) not counted on Get") } - anyOpCounter = c // Check that the bytes "in" counter is > 0 if getValueFrom(ioC, prometheus.Labels{"direction": "in"}) == 0 { t.Error("ioBytes{direction=in} counter shouldn't be zero") diff --git a/services/keepstore/volume_test.go b/services/keepstore/volume_test.go index 0451ee1e9f..0b8af330fb 100644 --- a/services/keepstore/volume_test.go +++ b/services/keepstore/volume_test.go @@ -27,6 +27,9 @@ type TestableVolume interface { // bypassing all constraints like readonly and serialize. PutRaw(locator string, data []byte) + // Returns the strings that a driver uses to record read/write operations. + ReadWriteOperationLabelValues() (r, w string) + // Specify the value Mtime() should return, until the next // call to Touch, TouchWithDate, or Put. TouchWithDate(locator string, lastPut time.Time) -- 2.39.5