ausocean / cloud

GNU General Public License v3.0
1 stars 1 forks source link

oceantv: broadcast voltage checking fails and disables broadcast #360

Open trekhopton opened 5 days ago

trekhopton commented 5 days ago

For some reason the broadcast hardware machine can't get the latest voltage scalar, despite the configuration seeming to be correct.

DEFAULT 2024-11-18T03:53:17.133962Z 2024/11/18 03:53:17 (name: Wagonga Inlet, id: 3VPfcUYIkSg) publishing event: hardwareStartRequestEvent
DEFAULT 2024-11-18T03:53:17.793622Z 2024/11/18 03:53:17 (name: Wagonga Inlet, id: 3VPfcUYIkSg) (hardware sm) handling hardware start request event
DEFAULT 2024-11-18T03:53:18.455189Z 2024/11/18 03:53:18 (name: Wagonga Inlet, id: 3VPfcUYIkSg) (hardware sm) transitioning from main.hardwareOff to main.hardwareStarting
DEFAULT 2024-11-18T03:53:18.850659Z 2024/11/18 03:53:18 (name: Wagonga Inlet, id: 3VPfcUYIkSg) could not get hardware voltage: could not get current battery voltage: could not get latest scalar: rpc error: code = FailedPrecondition desc = no matching index found. recommended index is:
DEFAULT 2024-11-18T03:53:18.850687Z 2024/11/18 03:53:18 (name: Wagonga Inlet, id: 3VPfcUYIkSg) publishing event: invalidConfigurationEvent
DEFAULT 2024-11-18T03:53:18.850692Z 2024/11/18 03:53:18 (name: Wagonga Inlet, id: 3VPfcUYIkSg) got invalid configuration event, disabling broadcast: could not get hardware voltage: could not get current battery voltage: could not get latest scalar: rpc error: code = FailedPrecondition desc = no matching index found. recommended index is:
DEFAULT 2024-11-18T03:53:18.850708Z 2024/11/18 03:53:18 (name: Wagonga Inlet, id: 3VPfcUYIkSg) broadcast context notifier is nil, setting to global notifier
DEFAULT 2024-11-18T03:53:21.826437Z 2024/11/18 03:53:21 (name: Wagonga Inlet, id: 3VPfcUYIkSg) (broadcast sm) transitioning from main.directStarting to main.directIdle
DEFAULT 2024-11-18T03:53:21.826450Z 2024/11/18 03:53:21 (name: Wagonga Inlet, id: 3VPfcUYIkSg) stopping

This results in the broadcast stopping and disabling itself. We can't use this currently so I'll have to roll back to a previous version of oceantv.

scruzin commented 4 days ago

The query is evidently attempting to use an index that does not exist:

no matching index found.

What is the query?

trekhopton commented 4 days ago

The function that tries to get the voltage is in revidCameraClient.voltage, broadcast_hardware_machine ln:452.

Which ends up calling GetLatestScalar.

func GetLatestScalar(ctx context.Context, store datastore.Store, id int64) (*Scalar, error) {
    const countPeriod = 60 * time.Minute
    start := time.Now().Add(-countPeriod).Unix()
    keys, err := GetScalarKeys(ctx, store, id, []int64{start, -1})
    if err != nil {
        return nil, err
    }
    if len(keys) == 0 {
        return nil, datastore.ErrNoSuchEntity
    }
    _, ts, _ := datastore.SplitIDKey(keys[len(keys)-1].ID)
    return GetScalar(ctx, store, id, ts)
}

This filters by ID and timestamp.

Then the key is retrieved and used to try and get the scalar.

// GetScalar gets a single scalar by ID and timestamp.
func GetScalar(ctx context.Context, store datastore.Store, id int64, ts int64) (*Scalar, error) {
    key := store.IDKey(typeScalar, datastore.IDKey(id, ts, 0))
    s := new(Scalar)
    err := store.Get(ctx, key, s)
    if err != nil {
        return nil, err
    }
    return s, nil
}
trekhopton commented 4 days ago

It seems like Id and timestamp are indexed:

vidgrind_index.yaml has:

- kind: Scalar
  properties:
  - name: ID
  - name: Timestamp
scruzin commented 2 days ago

That index is correct, and I can confirm that the index also exists in production.