Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RSDK-1616] Do not attempt to sync empty sensor reading files #1716

Merged
merged 5 commits into from
Dec 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions services/datamanager/builtin/capture_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@ package builtin

import (
"context"
"go.viam.com/rdk/config"
"go.viam.com/test"
"testing"
"time"

"go.viam.com/rdk/config"
"go.viam.com/test"
)

var (
// Robot config which specifies data manager service.
enabledTabularCollectorConfigPath = "services/datamanager/data/fake_robot_with_data_manager.json"
disabledTabularCollectorConfigPath = "services/datamanager/data/fake_robot_with_disabled_collector.json"
enabledBinaryCollectorConfigPath = "services/datamanager/data/robot_with_cam_capture.json"
remoteCollectorConfigPath = "services/datamanager/data/fake_robot_with_remote_and_data_manager.json"
emptyFileBytesSize = 30 // size of leading metadata message
enabledTabularCollectorConfigPath = "services/datamanager/data/fake_robot_with_data_manager.json"
disabledTabularCollectorConfigPath = "services/datamanager/data/fake_robot_with_disabled_collector.json"
enabledBinaryCollectorConfigPath = "services/datamanager/data/robot_with_cam_capture.json"
infrequentCaptureTabularCollectorConfigPath = "services/datamanager/data/fake_robot_with_infrequent_capture.json"
remoteCollectorConfigPath = "services/datamanager/data/fake_robot_with_remote_and_data_manager.json"
emptyFileBytesSize = 30 // size of leading metadata message
)

func TestDataCaptureEnabled(t *testing.T) {
Expand Down
38 changes: 26 additions & 12 deletions services/datamanager/builtin/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,6 @@ package builtin

import (
"context"
"github.com/edaniels/golog"
"github.com/pkg/errors"
v1 "go.viam.com/api/app/datasync/v1"
"go.viam.com/rdk/config"
"go.viam.com/rdk/services/datamanager/datacapture"
"go.viam.com/rdk/services/datamanager/datasync"
"go.viam.com/test"
"go.viam.com/utils/rpc"
"io"
"math"
"os"
Expand All @@ -19,6 +11,15 @@ import (
"sync/atomic"
"testing"
"time"

"github.com/edaniels/golog"
"github.com/pkg/errors"
v1 "go.viam.com/api/app/datasync/v1"
"go.viam.com/rdk/config"
"go.viam.com/rdk/services/datamanager/datacapture"
"go.viam.com/rdk/services/datamanager/datasync"
"go.viam.com/test"
"go.viam.com/utils/rpc"
)

const (
Expand Down Expand Up @@ -144,6 +145,7 @@ func TestDataCaptureUpload(t *testing.T) {
scheduledSyncDisabled bool
serviceFailAt int
numFails int
emptyFile bool
}{
{
name: "Previously captured tabular data should be synced at start up.",
Expand Down Expand Up @@ -190,6 +192,10 @@ func TestDataCaptureUpload(t *testing.T) {
dataType: v1.DataType_DATA_TYPE_BINARY_SENSOR,
numFails: 2,
},
{
name: "Files with no sensor data should not be synced.",
emptyFile: true,
},
}

for _, tc := range tests {
Expand All @@ -207,10 +213,14 @@ func TestDataCaptureUpload(t *testing.T) {
defer dmsvc.Close(context.Background())
dmsvc.SetSyncerConstructor(getTestSyncerConstructor(rpcServer))
var cfg *config.Config
if tc.dataType == v1.DataType_DATA_TYPE_TABULAR_SENSOR {
cfg = setupConfig(t, enabledTabularCollectorConfigPath)
if tc.emptyFile {
cfg = setupConfig(t, infrequentCaptureTabularCollectorConfigPath)
} else {
cfg = setupConfig(t, enabledBinaryCollectorConfigPath)
if tc.dataType == v1.DataType_DATA_TYPE_TABULAR_SENSOR {
cfg = setupConfig(t, enabledTabularCollectorConfigPath)
} else {
cfg = setupConfig(t, enabledBinaryCollectorConfigPath)
}
}

// Set up service config with only capture enabled.
Expand All @@ -233,7 +243,11 @@ func TestDataCaptureUpload(t *testing.T) {
// Get all captured data.
capturedData, err := getCapturedData(tmpDir)
test.That(t, err, test.ShouldBeNil)
test.That(t, len(capturedData), test.ShouldBeGreaterThan, 0)
if tc.emptyFile {
test.That(t, len(capturedData), test.ShouldEqual, 0)
} else {
test.That(t, len(capturedData), test.ShouldBeGreaterThan, 0)
}

// Turn dmsvc back on with capture disabled.
newDMSvc := newTestDataManager(t)
Expand Down
43 changes: 43 additions & 0 deletions services/datamanager/data/fake_robot_with_infrequent_capture.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"network": {
"fqdn": "something-unique",
"bind_address": ":8080"
},
"components": [
{
"name": "arm1",
"type": "arm",
"model": "fake",
"service_config": [
{
"type": "data_manager",
"attributes": {
"capture_methods": [
{
"method": "EndPosition",
"capture_frequency_hz": 0.001,
"tags": [
"a",
"b"
]
}
]
}
}
]
}
],
"services": [
{
"name": "data_manager1",
"type": "data_manager",
"model": "builtin",
"attributes": {
"sync_disabled": false,
"sync_interval_mins": 0,
"capture_dir": "/tmp/capture",
"capture_disabled": false
}
}
]
}
5 changes: 5 additions & 0 deletions services/datamanager/datasync/upload_data_capture_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ func uploadDataCaptureFile(ctx context.Context, client v1.DataSyncServiceClient,
return err
}

// Do not attempt to upload a file without any sensor readings.
if len(sensorData) == 0 {
return nil
}

ur := &v1.DataCaptureUploadRequest{
Metadata: &v1.UploadMetadata{
PartId: partID,
Expand Down