mirror of
https://github.com/kopia/kopia.git
synced 2026-10-24 15:18:48 -04:00
fix(repository): remove metrics.Registry from repo.Repository (#2944)
This commit is contained in:
1 parent
5d8e1134c1
commit
cbc204a2c7
3 files changed
+14
-6
No files matched your search
@@ -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 {
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in new issue
Block a user