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

Min/Max Support #79

Merged

Conversation

erikbosch
Copy link
Contributor

@erikbosch erikbosch commented Oct 15, 2024

This PR adds the following functionality

  • When reading a VSS JSON file min/max values are read and stored as well.
  • When requesting metadata you also get min/max metadata
  • When setting a datapoint min/max check is performed (min <= value <= max)

Some tests have been performed using a custom VSS JSON file.

Copy link

codecov bot commented Oct 15, 2024

Codecov Report

Attention: Patch coverage is 81.85452% with 227 lines in your changes missing coverage. Please review.

Project coverage is 58.84%. Comparing base (a8df2f6) to head (78e1adc).
Report is 4 commits behind head on feature/databroker-api-v2.

Files with missing lines Patch % Lines
databroker/src/grpc/kuksa_val_v2/conversions.rs 23.71% 74 Missing ⚠️
databroker/src/grpc/kuksa_val_v1/val.rs 37.14% 66 Missing ⚠️
databroker/src/broker.rs 93.48% 54 Missing ⚠️
databroker/src/vss.rs 52.00% 12 Missing ⚠️
databroker/src/main.rs 0.00% 9 Missing ⚠️
databroker/src/grpc/sdv_databroker_v1/collector.rs 0.00% 6 Missing ⚠️
databroker/src/grpc/kuksa_val_v2/val.rs 98.78% 2 Missing ⚠️
databroker/src/grpc/sdv_databroker_v1/broker.rs 0.00% 2 Missing ⚠️
databroker/src/viss/v2/server.rs 0.00% 2 Missing ⚠️
Additional details and impacted files
@@                      Coverage Diff                      @@
##           feature/databroker-api-v2      #79      +/-   ##
=============================================================
+ Coverage                      55.33%   58.84%   +3.51%     
=============================================================
  Files                             33       33              
  Lines                          14677    15531     +854     
=============================================================
+ Hits                            8121     9139    +1018     
+ Misses                          6556     6392     -164     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@lukasmittag lukasmittag left a comment

Choose a reason for hiding this comment

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

should we add some tests?

databroker/src/broker.rs Outdated Show resolved Hide resolved
databroker/src/grpc/kuksa_val_v1/val.rs Show resolved Hide resolved
databroker/src/grpc/kuksa_val_v1/val.rs Show resolved Hide resolved
@erikbosch
Copy link
Contributor Author

should we add some tests?

Some tests coming soon.

@erikbosch erikbosch changed the title Min/Max first increment Min/Max Support Oct 16, 2024
@erikbosch erikbosch marked this pull request as ready for review October 16, 2024 09:23
@erikbosch
Copy link
Contributor Author

I have now added some test cases, but they do not cover all possible VSS/Databroker Datatypes. We have quite much duplication in code (and tests) due to the strong type checks in Rust, so not that easy to reuse. I think the level of tests are quite reasonable now.

Copy link
Contributor

@rafaeling rafaeling left a comment

Choose a reason for hiding this comment

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

Looks good to me, apart from some general comments like why DataValue does not implement Int8 and Uint8, are we upcasting values to int32/64 and uint32/64?
Also looks good unit test coverage for kuksa.val.v2
Thanks Erik :)

Ok(f64::from(*value) < *other_value)
}
pub fn greater_than_equal(&self, other: &DataValue) -> Result<bool, CastError> {
match self.greater_than(other) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Just saw that greater_than function:

(DataValue::Int32(value), DataValue::Int32(other_value)) => Ok(value > other_value),
does not support all possible data types in DataType

Even DataValue does not support all of them:

pub enum DataValue {

What is the reason for that? Is that on purpose?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That is better a question for @argerus. I have some theories - one is that we do not "save" that much memory by using u32 instead of u16/u8 and i32 instead of i8/i16, another is that it simplifies implementation as we do not need to handle that many combinations.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

there's no int8 in proto3

Copy link
Contributor

Choose a reason for hiding this comment

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

That is better a question for @argerus. I have some theories - one is that we do not "save" that much memory by using u32 instead of u16/u8 and i32 instead of i8/i16, another is that it simplifies implementation as we do not need to handle that many combinations.

Exactly. It reduces the combinatorial explosion in the implementation and doesn't really cost anything memory wise since they are all part of the same enum anyway. Using 32 & 64 bit integers might even be marginally more efficient cpu wise (probably doesn't matter much). And as @lukasmittag mentions, it would need to be converted anyway when using protobuf.

The VSS data type is enforced when setting a value, and is not encoded by the value enum itself. This simplifies setting a value to NotAvailable as well.

Copy link
Contributor

Choose a reason for hiding this comment

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

Got it, thanks

databroker/src/broker.rs Show resolved Hide resolved
databroker/src/grpc/kuksa_val_v2/conversions.rs Outdated Show resolved Hide resolved
databroker/src/grpc/kuksa_val_v2/val.rs Outdated Show resolved Hide resolved
databroker/src/grpc/kuksa_val_v2/conversions.rs Outdated Show resolved Hide resolved
databroker/src/grpc/kuksa_val_v2/conversions.rs Outdated Show resolved Hide resolved
databroker/src/broker.rs Outdated Show resolved Hide resolved
Move most to broker.rs
Add one checking proto results
@erikbosch erikbosch merged commit 50f2ba6 into eclipse-kuksa:feature/databroker-api-v2 Oct 24, 2024
23 checks passed
@erikbosch erikbosch deleted the erik_get_value branch October 24, 2024 09:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants