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"
|
2022-01-28 12:01:23 +00:00
|
|
|
"storj.io/storj/satellite/metrics"
|
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]
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2022-01-28 12:01:23 +00:00
|
|
|
counter := metrics.NewCounter()
|
|
|
|
err := satellite.Metabase.SegmentLoop.Join(ctx, counter)
|
2021-09-28 10:04:54 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-01-28 12:01:23 +00:00
|
|
|
require.EqualValues(t, 2, counter.InlineObjects)
|
|
|
|
require.EqualValues(t, 2, counter.RemoteObjects)
|
2021-07-30 16:31:20 +01:00
|
|
|
|
2022-01-28 12:01:23 +00:00
|
|
|
require.EqualValues(t, 2, counter.TotalInlineSegments)
|
|
|
|
require.EqualValues(t, 2, counter.TotalRemoteSegments)
|
2021-07-30 16:31:20 +01:00
|
|
|
// 2 inline segments * (1024 + encryption overhead)
|
2022-01-28 12:01:23 +00:00
|
|
|
require.EqualValues(t, 2080, counter.TotalInlineBytes)
|
2021-07-30 16:31:20 +01:00
|
|
|
// 2 remote segments * (8192 + encryption overhead)
|
2022-01-28 12:01:23 +00:00
|
|
|
require.EqualValues(t, 29696, counter.TotalRemoteBytes)
|
2019-10-16 19:08:33 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCounterInlineOnly(t *testing.T) {
|
|
|
|
testplanet.Run(t, testplanet.Config{
|
2022-01-28 12:01:23 +00:00
|
|
|
SatelliteCount: 1, 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]
|
|
|
|
|
|
|
|
// 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)
|
|
|
|
}
|
|
|
|
|
2022-01-28 12:01:23 +00:00
|
|
|
counter := metrics.NewCounter()
|
|
|
|
err := satellite.Metabase.SegmentLoop.Join(ctx, counter)
|
2021-09-28 10:04:54 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-01-28 12:01:23 +00:00
|
|
|
require.EqualValues(t, 2, counter.InlineObjects)
|
|
|
|
require.EqualValues(t, 0, 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]
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2022-01-28 12:01:23 +00:00
|
|
|
counter := metrics.NewCounter()
|
|
|
|
err := satellite.Metabase.SegmentLoop.Join(ctx, counter)
|
2021-09-28 10:04:54 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-01-28 12:01:23 +00:00
|
|
|
require.EqualValues(t, 0, counter.InlineObjects)
|
|
|
|
require.EqualValues(t, 2, counter.RemoteObjects)
|
2019-10-16 19:08:33 +01:00
|
|
|
})
|
|
|
|
}
|