2019-10-16 19:08:33 +01:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package metrics_test
|
|
|
|
|
|
|
|
import (
|
2020-06-12 07:35:26 +01:00
|
|
|
"strconv"
|
2019-10-16 19:08:33 +01:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
2019-12-27 11:48:47 +00:00
|
|
|
"storj.io/common/memory"
|
|
|
|
"storj.io/common/testcontext"
|
|
|
|
"storj.io/common/testrand"
|
2019-11-14 19:46:15 +00:00
|
|
|
"storj.io/storj/private/testplanet"
|
2019-10-16 19:08:33 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestCounterInlineAndRemote(t *testing.T) {
|
|
|
|
testplanet.Run(t, testplanet.Config{
|
2021-02-18 15:26:27 +00:00
|
|
|
SatelliteCount: 1, StorageNodeCount: 4, UplinkCount: 1,
|
2019-10-16 19:08:33 +01:00
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
|
|
|
satellite := planet.Satellites[0]
|
|
|
|
ul := planet.Uplinks[0]
|
|
|
|
metricsChore := satellite.Metrics.Chore
|
|
|
|
metricsChore.Loop.Pause()
|
|
|
|
|
|
|
|
segmentSize := 8 * memory.KiB
|
|
|
|
|
|
|
|
// upload 2 inline files
|
|
|
|
for i := 0; i < 2; i++ {
|
|
|
|
testData := testrand.Bytes(segmentSize / 8)
|
2020-06-12 07:35:26 +01:00
|
|
|
path := "/some/inline/path/" + strconv.Itoa(i)
|
2019-10-16 19:08:33 +01:00
|
|
|
err := ul.Upload(ctx, satellite, "bucket", path, testData)
|
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// upload 2 remote files with 1 segment
|
|
|
|
for i := 0; i < 2; i++ {
|
|
|
|
testData := testrand.Bytes(segmentSize)
|
2020-06-12 07:35:26 +01:00
|
|
|
path := "/some/remote/path/" + strconv.Itoa(i)
|
2020-01-21 10:38:41 +00:00
|
|
|
err := ul.Upload(ctx, satellite, "testbucket", path, testData)
|
2019-10-16 19:08:33 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
metricsChore.Loop.TriggerWait()
|
2021-07-01 15:48:07 +01:00
|
|
|
require.EqualValues(t, 2, metricsChore.Counter.InlineObjects)
|
|
|
|
require.EqualValues(t, 2, metricsChore.Counter.RemoteObjects)
|
2021-07-30 16:31:20 +01:00
|
|
|
|
|
|
|
require.EqualValues(t, 2, metricsChore.Counter.TotalInlineSegments)
|
|
|
|
require.EqualValues(t, 2, metricsChore.Counter.TotalRemoteSegments)
|
|
|
|
// 2 inline segments * (1024 + encryption overhead)
|
|
|
|
require.EqualValues(t, 2080, metricsChore.Counter.TotalInlineBytes)
|
|
|
|
// 2 remote segments * (8192 + encryption overhead)
|
|
|
|
require.EqualValues(t, 29696, metricsChore.Counter.TotalRemoteBytes)
|
2019-10-16 19:08:33 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCounterInlineOnly(t *testing.T) {
|
|
|
|
testplanet.Run(t, testplanet.Config{
|
2021-02-18 15:26:27 +00:00
|
|
|
SatelliteCount: 1, StorageNodeCount: 4, UplinkCount: 1,
|
2019-10-16 19:08:33 +01:00
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
|
|
|
satellite := planet.Satellites[0]
|
|
|
|
ul := planet.Uplinks[0]
|
|
|
|
metricsChore := satellite.Metrics.Chore
|
|
|
|
metricsChore.Loop.Pause()
|
|
|
|
|
|
|
|
// upload 2 inline files
|
|
|
|
for i := 0; i < 2; i++ {
|
|
|
|
testData := testrand.Bytes(memory.KiB)
|
2020-06-12 07:35:26 +01:00
|
|
|
path := "/some/inline/path/" + strconv.Itoa(i)
|
2019-10-16 19:08:33 +01:00
|
|
|
err := ul.Upload(ctx, satellite, "bucket", path, testData)
|
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
metricsChore.Loop.TriggerWait()
|
2021-07-01 15:48:07 +01:00
|
|
|
require.EqualValues(t, 2, metricsChore.Counter.InlineObjects)
|
|
|
|
require.EqualValues(t, 0, metricsChore.Counter.RemoteObjects)
|
2019-10-16 19:08:33 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCounterRemoteOnly(t *testing.T) {
|
|
|
|
testplanet.Run(t, testplanet.Config{
|
2021-02-18 15:26:27 +00:00
|
|
|
SatelliteCount: 1, StorageNodeCount: 4, UplinkCount: 1,
|
2020-01-21 10:38:41 +00:00
|
|
|
Reconfigure: testplanet.Reconfigure{
|
2021-04-07 15:20:05 +01:00
|
|
|
Satellite: testplanet.MaxSegmentSize(150 * memory.KiB),
|
2020-01-21 10:38:41 +00:00
|
|
|
},
|
2019-10-16 19:08:33 +01:00
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
|
|
|
satellite := planet.Satellites[0]
|
|
|
|
ul := planet.Uplinks[0]
|
|
|
|
metricsChore := satellite.Metrics.Chore
|
|
|
|
metricsChore.Loop.Pause()
|
|
|
|
|
2021-02-18 15:26:27 +00:00
|
|
|
// upload 2 remote files with multiple segments
|
2019-10-16 19:08:33 +01:00
|
|
|
for i := 0; i < 2; i++ {
|
2021-04-07 15:20:05 +01:00
|
|
|
testData := testrand.Bytes(300 * memory.KiB)
|
2020-06-12 07:35:26 +01:00
|
|
|
path := "/some/remote/path/" + strconv.Itoa(i)
|
2020-01-21 10:38:41 +00:00
|
|
|
err := ul.Upload(ctx, satellite, "testbucket", path, testData)
|
2019-10-16 19:08:33 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
metricsChore.Loop.TriggerWait()
|
2021-07-01 15:48:07 +01:00
|
|
|
require.EqualValues(t, 0, metricsChore.Counter.InlineObjects)
|
|
|
|
require.EqualValues(t, 2, metricsChore.Counter.RemoteObjects)
|
2019-10-16 19:08:33 +01:00
|
|
|
})
|
|
|
|
}
|