2019-04-02 15:55:58 +01:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package inspector_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
2019-06-05 15:23:10 +01:00
|
|
|
"context"
|
2019-04-02 15:55:58 +01:00
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
2019-12-27 11:48:47 +00:00
|
|
|
"storj.io/common/memory"
|
|
|
|
"storj.io/common/pb"
|
|
|
|
"storj.io/common/storj"
|
|
|
|
"storj.io/common/testcontext"
|
|
|
|
"storj.io/common/testrand"
|
2019-11-14 19:46:15 +00:00
|
|
|
"storj.io/storj/private/testplanet"
|
2019-04-02 15:55:58 +01:00
|
|
|
"storj.io/storj/storage"
|
2020-01-08 13:40:19 +00:00
|
|
|
"storj.io/uplink/eestream"
|
2019-04-02 15:55:58 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestInspectorStats(t *testing.T) {
|
2019-04-22 10:07:50 +01:00
|
|
|
testplanet.Run(t, testplanet.Config{
|
|
|
|
SatelliteCount: 1, StorageNodeCount: 6, UplinkCount: 1,
|
|
|
|
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
|
|
|
|
uplink := planet.Uplinks[0]
|
2019-06-26 11:38:51 +01:00
|
|
|
testData := testrand.Bytes(1 * memory.MiB)
|
2019-04-22 10:07:50 +01:00
|
|
|
|
|
|
|
bucket := "testbucket"
|
|
|
|
|
2019-06-26 11:38:51 +01:00
|
|
|
err := uplink.Upload(ctx, planet.Satellites[0], bucket, "test/path", testData)
|
2019-04-22 10:07:50 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
healthEndpoint := planet.Satellites[0].Inspector.Endpoint
|
|
|
|
|
|
|
|
// Get path of random segment we just uploaded and check the health
|
2019-06-05 15:23:10 +01:00
|
|
|
_ = planet.Satellites[0].Metainfo.Database.Iterate(ctx, storage.IterateOptions{Recurse: true},
|
|
|
|
func(ctx context.Context, it storage.Iterator) error {
|
2019-04-22 10:07:50 +01:00
|
|
|
var item storage.ListItem
|
2019-06-05 15:23:10 +01:00
|
|
|
for it.Next(ctx, &item) {
|
2019-04-22 10:07:50 +01:00
|
|
|
if bytes.Contains(item.Key, []byte(fmt.Sprintf("%s/", bucket))) {
|
|
|
|
break
|
|
|
|
}
|
2019-04-02 15:55:58 +01:00
|
|
|
}
|
|
|
|
|
2019-04-22 10:07:50 +01:00
|
|
|
fullPath := storj.SplitPath(item.Key.String())
|
|
|
|
require.Falsef(t, len(fullPath) < 4, "Could not retrieve a full path from pointerdb")
|
2019-04-02 15:55:58 +01:00
|
|
|
|
2019-04-22 10:07:50 +01:00
|
|
|
projectID := fullPath[0]
|
|
|
|
bucket := fullPath[2]
|
|
|
|
encryptedPath := strings.Join(fullPath[3:], "/")
|
2019-04-02 15:55:58 +01:00
|
|
|
|
2019-04-22 10:07:50 +01:00
|
|
|
{ // Test Segment Health Request
|
|
|
|
req := &pb.SegmentHealthRequest{
|
|
|
|
ProjectId: []byte(projectID),
|
|
|
|
EncryptedPath: []byte(encryptedPath),
|
|
|
|
Bucket: []byte(bucket),
|
|
|
|
SegmentIndex: -1,
|
|
|
|
}
|
2019-04-02 15:55:58 +01:00
|
|
|
|
2019-04-22 10:07:50 +01:00
|
|
|
resp, err := healthEndpoint.SegmentHealth(ctx, req)
|
|
|
|
require.NoError(t, err)
|
2019-04-04 18:11:19 +01:00
|
|
|
|
2019-04-22 10:07:50 +01:00
|
|
|
redundancy, err := eestream.NewRedundancyStrategyFromProto(resp.GetRedundancy())
|
|
|
|
require.NoError(t, err)
|
2019-04-02 15:55:58 +01:00
|
|
|
|
2019-04-22 10:07:50 +01:00
|
|
|
require.Equal(t, 4, redundancy.TotalCount())
|
|
|
|
require.True(t, bytes.Equal([]byte("l"), resp.GetHealth().GetSegment()))
|
2019-04-02 15:55:58 +01:00
|
|
|
}
|
|
|
|
|
2019-04-22 10:07:50 +01:00
|
|
|
{ // Test Object Health Request
|
|
|
|
objectHealthReq := &pb.ObjectHealthRequest{
|
|
|
|
ProjectId: []byte(projectID),
|
|
|
|
EncryptedPath: []byte(encryptedPath),
|
|
|
|
Bucket: []byte(bucket),
|
|
|
|
StartAfterSegment: 0,
|
|
|
|
EndBeforeSegment: 0,
|
|
|
|
Limit: 0,
|
|
|
|
}
|
|
|
|
resp, err := healthEndpoint.ObjectHealth(ctx, objectHealthReq)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
segments := resp.GetSegments()
|
|
|
|
require.Len(t, segments, 1)
|
|
|
|
|
|
|
|
redundancy, err := eestream.NewRedundancyStrategyFromProto(resp.GetRedundancy())
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
require.Equal(t, 4, redundancy.TotalCount())
|
|
|
|
require.True(t, bytes.Equal([]byte("l"), segments[0].GetSegment()))
|
|
|
|
}
|
2019-04-02 15:55:58 +01:00
|
|
|
|
2019-04-22 10:07:50 +01:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
)
|
|
|
|
})
|
2019-04-02 15:55:58 +01:00
|
|
|
}
|