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

Use Chariott #30

Merged
merged 23 commits into from
Jun 6, 2023
Merged

Use Chariott #30

merged 23 commits into from
Jun 6, 2023

Conversation

ashbeitz
Copy link
Contributor

@ashbeitz ashbeitz commented Jun 2, 2023

No description provided.

@github-actions
Copy link
Contributor

github-actions bot commented Jun 2, 2023

Alex Recommends Report

Alex recommends the following language changes, but Alex is a regular expression based algorithm, so take them with a grain of salt.

✨ 🚀 ✨ Nothing to Report ✨ 🚀 ✨

Copy link
Contributor

@jorchiu jorchiu left a comment

Choose a reason for hiding this comment

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

Please take a look at my comments.

.gitmodules Show resolved Hide resolved
samples/command/consumer/src/main.rs Show resolved Hide resolved
samples/command/provider/src/main.rs Outdated Show resolved Hide resolved
samples/common/src/misc.rs Outdated Show resolved Hide resolved
samples/common/src/misc.rs Outdated Show resolved Hide resolved
samples/command/consumer/src/main.rs Outdated Show resolved Hide resolved
samples/common/src/lib.rs Outdated Show resolved Hide resolved
samples/property/provider/src/main.rs Outdated Show resolved Hide resolved
Cargo.toml Show resolved Hide resolved
samples/common/src/misc.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@ladatz ladatz left a comment

Choose a reason for hiding this comment

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

Please consider my comments

samples/common/src/misc.rs Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Show resolved Hide resolved
core/invehicle-digital-twin/src/main.rs Show resolved Hide resolved
core/invehicle-digital-twin/src/main.rs Outdated Show resolved Hide resolved
samples/mixed/consumer/src/main.rs Outdated Show resolved Hide resolved
README.md Show resolved Hide resolved
core/invehicle-digital-twin/src/main.rs Outdated Show resolved Hide resolved
let fulfillment = match request
.into_inner()
.intent
.and_then(|i| i.intent)
Copy link
Contributor

Choose a reason for hiding this comment

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

this is more related to chariott than this PR, but this interface seems very strange to me. Why does request.into_inner().intent have a property also named intent? also, the use of and_then looks awkward here, though I don't know if there's a better way to do this right now.

tagging @ladatz since this is related to chariott APIs

Copy link
Contributor

@wilyle wilyle Jun 5, 2023

Choose a reason for hiding this comment

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

edit: I've read a bit more and apparently and_then is the correct idiomatic way to achieve what I wrote below rather than .map(...).flatten(), so I don't think we should use this suggestion. I still don't really like using and_then because I think it looks weird so we should still consider the other suggestion in the next comment


for a more intuitive way of doing this, we can consider this slightly more verbose approach:

let fulfillment = match request
    .into_inner()
    .intent
    .map(|i| i.intent)
    .flatten()
    .ok_or_else(...)? {...}

I think using the map function better illustrates the intent here (no pun intended), and flatten() is necessary to go from the resulting Option<Option<T>> to just Option<T>

Copy link
Contributor

Choose a reason for hiding this comment

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

Alternatively we could call ok_or_else twice in the call chain which is probably clearer:

let fulfillment = match request
    .into_inner()
    .intent
    .ok_or_else(...)?
    .intent
    .ok_or_else(...)? {...}

Copy link
Contributor

Choose a reason for hiding this comment

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

To answer why it looks so awkward, I believe its because of the use of oneof in the common proto file in chariott. The FulfillRequest looks like this in runtime.proto
image
And it references this structure in common.proto. The 'outer' intent is mapped to the message, while the 'inner' intent is mapped to the oneof kind:
image

Copy link
Contributor

@wilyle wilyle Jun 5, 2023

Choose a reason for hiding this comment

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

would it make sense to change the intent API to look like this:

message Intent {
    oneof value {
        ...
    }
}

Then the API to access it would be (ignoring Option syntax) request.intent.value

Also, do you have any comments on my suggestions for how to access the value here in the code with all of the extra syntax? The current code is derived from the chariott samples so these suggestions would propagate to there 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.

For the API, I agree that a change in the protobuf structure would be valuable to make things more readable. In terms of the suggestions, I would say that the first one looks a little more clear to me, however its not significantly more clear than what is already there (my opinion). I would say that since this is intended to be changed with chariott redesign that its okay to leave as is.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree that request -> intent -> value looks a lot better than what we have now. Of Will's suggestions above, I think I like the multiple ok_or_else option, but I need a little more investigation myself. For this Ibeji PR sepcifically, I also agree with Devin that we could leave it as-is in Ibeji for now. The following Issue (for chariott service discovery simplification) is currently being worked on, and from Ibeji's perspective, it will remove the need for this code at all: eclipse-chariott/chariott#134. This is a good discussion to keep in mind as we modify Chariott's APIs moving forward, though.

Copy link
Contributor Author

@ashbeitz ashbeitz Jun 6, 2023

Choose a reason for hiding this comment

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

Let’s not address this concern for now, as it should either go away or be addressed by Chariott's Simplify Service Discovery work and follow-on component specific refactoring.

samples/command/provider/src/main.rs Outdated Show resolved Hide resolved
samples/common/src/misc.rs Outdated Show resolved Hide resolved
samples/common/src/misc.rs Outdated Show resolved Hide resolved
.into_inner()
.fulfillment
.and_then(|fulfillment_message| fulfillment_message.fulfillment)
.and_then(|fulfillment_enum| match fulfillment_enum {
Copy link
Contributor

Choose a reason for hiding this comment

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

there is probably a similar approach here as suggested for the intent API to make this easier to understand

Copy link
Contributor Author

@ashbeitz ashbeitz Jun 6, 2023

Choose a reason for hiding this comment

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

Let’s not address this concern for now, as it should either go away or be addressed by Chariott's Simplify Service Discovery work and follow-on component specific refactoring.

samples/common/src/misc.rs Outdated Show resolved Hide resolved
samples/mixed/consumer/src/main.rs Show resolved Hide resolved

if matching_endpoint_info_option.is_none() {
return Err("Did not find an endpoint that met our requirements".to_string());
match entity_access_info.endpoint_info_list.iter()
Copy link
Contributor

Choose a reason for hiding this comment

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

instead of a match statement here you could consider using ok_or, though that would not let you include the info statement on line 103 easily if you want to have that

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We chatted about this. I want to leave the logging in, so it's fine as is.

@ashbeitz ashbeitz merged commit fe4a8aa into main Jun 6, 2023
@ashbeitz ashbeitz deleted the ashbeitz/useChariott branch June 6, 2023 18:06
mobicatk pushed a commit to Mobica/EclipseSDV_ibeji that referenced this pull request Apr 24, 2024
* Use Chariott

* Use Chariott

* Use Chariott

* Use Chariott

* Use Chariott

* Use Chariott

* Use Chariott

* Use Chariott

* Use Chariott

* Use Chariott

* Use Chariott

* Use Chariott

* Use Chariott

* Use Chariott

* Use Chariott

* Use Chariott

* Use Chariott

* Use Chariott

* Use Chariott

* Use Chariott

* Use Chariott

* Use Chariott

* Use Chariott
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.

5 participants