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

Databroker API V2 #33

Closed
Show file tree
Hide file tree
Changes from 15 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
2 changes: 2 additions & 0 deletions databroker-proto/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
"proto/sdv/databroker/v1/collector.proto",
"proto/kuksa/val/v1/val.proto",
"proto/kuksa/val/v1/types.proto",
"proto/kuksa/val/v2/types.proto",
"proto/kuksa/val/v2/val.proto",
],
&["proto"],
)?;
Expand Down
262 changes: 262 additions & 0 deletions proto/kuksa/val/v2/types.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,262 @@
/********************************************************************************
* Copyright (c) 2022 Contributors to the Eclipse Foundation
rafaeling marked this conversation as resolved.
Show resolved Hide resolved
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License 2.0 which is available at
* http://www.apache.org/licenses/LICENSE-2.0
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/

syntax = "proto3";

package kuksa.val.v2;
import "google/protobuf/timestamp.proto";

option go_package = "kuksa/val/v2";

message Datapoint {
rafaeling marked this conversation as resolved.
Show resolved Hide resolved
google.protobuf.Timestamp timestamp = 1;

oneof value_state {
ValueFailure failure = 2;
Value value = 3;
}
Comment on lines +24 to +27
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@argerus @rafaeling
Why I like the "oneof":
Assuming the ValueFailure represents the reason why a "real" value is missing (maybe we should rename it to "MissingReason"?), the oneof has some advantages over two separate fields (e.g. value and value_state):

  • If having a separate status with the additional state "OK" - meaning a valid value is present -, this could potentially be in mis-sync with the value field:
    • What, if status is "OK", but no value is present?
    • Or vice versa, status is not "OK", but a value is present?
  • On server side it's not possible to set both in parallel (prevented by the generated code - at least in C++)
  • It gives a small optimization during transmission via grpc: There either the value or the "MissingReason" is transferred.
    I don't see many disadvantages:
  • Code-wise (imho) it is easier, because I can better trust, that those invalid combinations of value and value_state described above cannot occur.
    Just checking if a value is there and otherwise ignoring the reason why it's missing is as easy as just having a value field or having an additional value_state field. At least in C++:
kuksa::val::v2::Datapoint datapoint;
if (datapoint.has_value()) {
    auto value =datapoint.value();
} else {
    // handle missing value, e.g.:
    throw MissingValueException();
}

This C++ code would be the same - regardless if we have:
(1)

message Datapoint {
    google.protobuf.Timestamp timestamp = 1;
    Value value = 2;
}

or (2)

message Datapoint {
    google.protobuf.Timestamp timestamp = 1;
    Value value = 2;
    ValueState state = 3;
}

or (3)

message Datapoint {
    google.protobuf.Timestamp timestamp = 1;
    oneof value_state {
        Value value = 2;
        MissingReason reason = 3;
    }
}

Besides that, I think transporting additional information about a present value (like some quality information (like "outdated" or other things we discussed today), doesn't belong into an information field describing reasons why a value is missing. Those informations aren't related.

}

message Value {
oneof typed_value {
string string = 11;
bool bool = 12;
sint32 int32 = 13;
sint64 int64 = 14;
uint32 uint32 = 15;
uint64 uint64 = 16;
float float = 17;
double double = 18;
StringArray string_array = 21;
BoolArray bool_array = 22;
Int32Array int32_array = 23;
Int64Array int64_array = 24;
Uint32Array uint32_array = 25;
Uint64Array uint64_array = 26;
FloatArray float_array = 27;
DoubleArray double_array = 28;
}
}

message SignalID {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we call the message signal? For me it was hard to follow during the usage of the SingalID message that this actually either an id or the path.

Copy link
Contributor

@BjoernAtBosch BjoernAtBosch Aug 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The term "signal" would be more than just the identifier of it. Therefore, I like the name "SignalId": "Id" is short for "identifier" which not necessarily has to be a number. It could be anything capable of serving as a unique id - therefore also a string.

oneof signal {
int32 id = 1;
string path = 2;
}
}

message Error {
ErrorCode code = 1;
string message = 2;
}

enum ErrorCode {
OK = 0;
INVALID_ARGUMENT = 1;
NOT_FOUND = 2;
PERMISSION_DENIED = 3;
}

message Metadata {
// Data type
// The VSS data type of the entry (i.e. the value, min, max etc).
//
// NOTE: protobuf doesn't have int8, int16, uint8 or uint16 which means
// that these values must be serialized as int32 and uint32 respectively.
DataType data_type = 11; // [field: FIELD_METADATA_DATA_TYPE]

// Entry type
EntryType entry_type = 12; // [field: FIELD_METADATA_ENTRY_TYPE]

// Description
// Describes the meaning and content of the entry.
optional string description = 13; // [field: FIELD_METADATA_DESCRIPTION]

// Comment [optional]
// A comment can be used to provide additional informal information
// on a entry.
optional string comment = 14; // [field: FIELD_METADATA_COMMENT]

// Deprecation [optional]
// Whether this entry is deprecated. Can contain recommendations of what
// to use instead.
optional string deprecation = 15; // [field: FIELD_METADATA_DEPRECATION]

// Unit [optional]
// The unit of measurement
optional string unit = 16; // [field: FIELD_METADATA_UNIT]

// Value restrictions [optional]
// Restrict which values are allowed.
// Only restrictions matching the DataType {datatype} above are valid.
ValueRestriction value_restriction = 17; // [field: FIELD_METADATA_VALUE_RESTRICTION]
}

// Value restriction
//
// One ValueRestriction{type} for each type, since
// they don't make sense unless the types match
//
message ValueRestriction {
oneof type {
ValueRestrictionString string = 21;
// For signed VSS integers
ValueRestrictionInt signed = 22;
// For unsigned VSS integers
ValueRestrictionUint unsigned = 23;
// For floating point VSS values (float and double)
ValueRestrictionFloat floating_point = 24;
}
}

message ValueRestrictionInt {
optional sint64 min = 1;
optional sint64 max = 2;
repeated sint64 allowed_values = 3;
}

message ValueRestrictionUint {
optional uint64 min = 1;
optional uint64 max = 2;
repeated uint64 allowed_values = 3;
}

message ValueRestrictionFloat {
optional double min = 1;
optional double max = 2;

// allowed for doubles/floats not recommended
repeated double allowed_values = 3;
}

// min, max doesn't make much sense for a string
message ValueRestrictionString {
repeated string allowed_values = 3;
}

enum ValueFailure {
// Unspecified value failure, reserved for gRPC backwards compatibility
// (see https://protobuf.dev/programming-guides/dos-donts/#unspecified-enum)
UNSPECIFIED = 0;
// The signal is known and provided, but doesn't have a valid value
INVALID_VALUE = 1;
// The signal is known, but no value is provided currently
NOT_PROVIDED = 2;
// The referred signal is unknown on the system
UNKNOWN_SIGNAL = 3;
// The client does not have the necessary access rights to the signal
ACCESS_DENIED = 4;
// Unexpected internal error
INTERNAL_ERROR = 5;
Comment on lines +158 to +163
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, those can be removed now

Suggested change
// The referred signal is unknown on the system
UNKNOWN_SIGNAL = 3;
// The client does not have the necessary access rights to the signal
ACCESS_DENIED = 4;
// Unexpected internal error
INTERNAL_ERROR = 5;

}

// VSS Data type of a signal
//
// Protobuf doesn't support int8, int16, uint8 or uint16.
// These are mapped to int32 and uint32 respectively.
//
enum DataType {
DATA_TYPE_UNSPECIFIED = 0;
DATA_TYPE_STRING = 1;
DATA_TYPE_BOOLEAN = 2;
DATA_TYPE_INT8 = 3;
DATA_TYPE_INT16 = 4;
DATA_TYPE_INT32 = 5;
DATA_TYPE_INT64 = 6;
DATA_TYPE_UINT8 = 7;
DATA_TYPE_UINT16 = 8;
DATA_TYPE_UINT32 = 9;
DATA_TYPE_UINT64 = 10;
DATA_TYPE_FLOAT = 11;
DATA_TYPE_DOUBLE = 12;
DATA_TYPE_TIMESTAMP = 13;
rafaeling marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
DATA_TYPE_TIMESTAMP = 13;

DATA_TYPE_STRING_ARRAY = 20;
DATA_TYPE_BOOLEAN_ARRAY = 21;
DATA_TYPE_INT8_ARRAY = 22;
DATA_TYPE_INT16_ARRAY = 23;
DATA_TYPE_INT32_ARRAY = 24;
DATA_TYPE_INT64_ARRAY = 25;
DATA_TYPE_UINT8_ARRAY = 26;
DATA_TYPE_UINT16_ARRAY = 27;
DATA_TYPE_UINT32_ARRAY = 28;
DATA_TYPE_UINT64_ARRAY = 29;
DATA_TYPE_FLOAT_ARRAY = 30;
DATA_TYPE_DOUBLE_ARRAY = 31;
DATA_TYPE_TIMESTAMP_ARRAY = 32;
rafaeling marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
DATA_TYPE_TIMESTAMP_ARRAY = 32;

}

// Entry type
enum EntryType {
ENTRY_TYPE_UNSPECIFIED = 0;
ENTRY_TYPE_ATTRIBUTE = 1;
ENTRY_TYPE_SENSOR = 2;
ENTRY_TYPE_ACTUATOR = 3;
}

// A `Field` corresponds to a specific field of a `DataEntry`.
//
// It can be used to:
// * populate only specific fields of a `DataEntry` response.
// * specify which fields of a `DataEntry` should be set as
// part of a `Set` request.
// * subscribe to only specific fields of a data entry.
// * convey which fields of an updated `DataEntry` have changed.
enum Field {
FIELD_UNSPECIFIED = 0; // "*" i.e. everything
FIELD_PATH = 1; // path
FIELD_VALUE = 2; // value
FIELD_ACTUATOR_TARGET = 3; // actuator_target
FIELD_METADATA = 10; // metadata.*
FIELD_METADATA_DATA_TYPE = 11; // metadata.data_type
FIELD_METADATA_DESCRIPTION = 12; // metadata.description
FIELD_METADATA_ENTRY_TYPE = 13; // metadata.entry_type
FIELD_METADATA_COMMENT = 14; // metadata.comment
FIELD_METADATA_DEPRECATION = 15; // metadata.deprecation
FIELD_METADATA_UNIT = 16; // metadata.unit
FIELD_METADATA_VALUE_RESTRICTION = 17; // metadata.value_restriction.*
FIELD_METADATA_ACTUATOR = 20; // metadata.actuator.*
FIELD_METADATA_SENSOR = 30; // metadata.sensor.*
FIELD_METADATA_ATTRIBUTE = 40; // metadata.attribute.*
}

rafaeling marked this conversation as resolved.
Show resolved Hide resolved
rafaeling marked this conversation as resolved.
Show resolved Hide resolved
message StringArray {
repeated string values = 1;
}

message BoolArray {
repeated bool values = 1;
}

message Int32Array {
repeated sint32 values = 1;
}

message Int64Array {
repeated sint64 values = 1;
}

message Uint32Array {
repeated uint32 values = 1;
}

message Uint64Array {
repeated uint64 values = 1;
}

message FloatArray {
repeated float values = 1;
}

message DoubleArray {
repeated double values = 1;
}
Loading
Loading