diff --git a/internal/repotesting/repotesting.go b/internal/repotesting/repotesting.go index 29d4c37c3..3edd5e7f9 100644 --- a/internal/repotesting/repotesting.go +++ b/internal/repotesting/repotesting.go @@ -10,6 +10,7 @@ import ( "github.com/stretchr/testify/require" "github.com/kopia/kopia/internal/blobtesting" + "github.com/kopia/kopia/internal/metrics" "github.com/kopia/kopia/internal/testlogging" "github.com/kopia/kopia/internal/testutil" "github.com/kopia/kopia/repo" @@ -41,6 +42,13 @@ type Options struct { OpenOptions func(*repo.Options) } +// RepositoryMetrics returns metrics.Registry associated with a repository. +func (e *Environment) RepositoryMetrics() *metrics.Registry { + return e.Repository.(interface { + Metrics() *metrics.Registry + }).Metrics() +} + // RootStorage returns the base storage map that implements the base in-memory // map at the base of all storage wrappers on top. func (e *Environment) RootStorage() blob.Storage { diff --git a/repo/repository.go b/repo/repository.go index e4a71f2c0..7883f35fe 100644 --- a/repo/repository.go +++ b/repo/repository.go @@ -39,7 +39,6 @@ type Repository interface { UpdateDescription(d string) Refresh(ctx context.Context) error Close(ctx context.Context) error - Metrics() *metrics.Registry } // RepositoryWriter provides methods to write to a repository. diff --git a/repo/repository_test.go b/repo/repository_test.go index baa9802d5..8fcdb751a 100644 --- a/repo/repository_test.go +++ b/repo/repository_test.go @@ -770,7 +770,8 @@ func (s *formatSpecificTestSuite) TestChangePassword(t *testing.T) { func TestMetrics_CompressibleData(t *testing.T) { ctx, env := repotesting.NewEnvironment(t, repotesting.FormatNotImportant) _ = ctx - ms := env.Repository.Metrics().Snapshot(false) + + ms := env.RepositoryMetrics().Snapshot(false) require.EqualValues(t, 0, ensureMapEntry(t, ms.Counters, "content_write_bytes")) @@ -780,7 +781,7 @@ func TestMetrics_CompressibleData(t *testing.T) { oid object.ID ) - for ensureMapEntry(t, env.Repository.Metrics().Snapshot(false).Counters, "content_write_duration_nanos") < 5e6 { + for ensureMapEntry(t, env.RepositoryMetrics().Snapshot(false).Counters, "content_write_duration_nanos") < 5e6 { w := env.RepositoryWriter.NewObjectWriter(ctx, object.WriterOptions{ Compressor: "gzip", }) @@ -794,7 +795,7 @@ func TestMetrics_CompressibleData(t *testing.T) { count++ } - ms = env.Repository.Metrics().Snapshot(false) + ms = env.RepositoryMetrics().Snapshot(false) require.EqualValues(t, count*len(inputData), ensureMapEntry(t, ms.Counters, "content_write_bytes")) require.EqualValues(t, count*len(inputData), ensureMapEntry(t, ms.Counters, "content_hashed_bytes")) require.EqualValues(t, len(inputData), ensureMapEntry(t, ms.Counters, "content_compression_attempted_bytes")) @@ -818,7 +819,7 @@ func TestMetrics_CompressibleData(t *testing.T) { require.NoError(t, err) require.Equal(t, inputData, data) - ms = env.Repository.Metrics().Snapshot(false) + ms = env.RepositoryMetrics().Snapshot(false) require.EqualValues(t, len(inputData), ensureMapEntry(t, ms.Counters, "content_read_bytes")) require.EqualValues(t, compressedByteCount, ensureMapEntry(t, ms.Counters, "content_decompressed_bytes")) require.EqualValues(t, compressedByteCount+encryptionOverhead, ensureMapEntry(t, ms.Counters, "content_decrypted_bytes")) @@ -836,7 +837,7 @@ func ensureMapEntry[T any](t *testing.T, m map[string]T, key string) T { func TestAllRegistryMetricsAreMapped(t *testing.T) { _, env := repotesting.NewEnvironment(t, repotesting.FormatNotImportant) - snap := env.Repository.Metrics().Snapshot(false) + snap := env.RepositoryMetrics().Snapshot(false) for s := range snap.Counters { require.Contains(t, metricid.Counters.NameToIndex, s)