-
Notifications
You must be signed in to change notification settings - Fork 65
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
Fetch RuntimeInformation of SERVICE
queries
#1798
base: master
Are you sure you want to change the base?
Conversation
@joka921 This is a first working poc, i will take car of test coverage and outdated comments in the next iteration. |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1798 +/- ##
==========================================
- Coverage 90.18% 89.87% -0.31%
==========================================
Files 400 403 +3
Lines 38440 38661 +221
Branches 4306 4330 +24
==========================================
+ Hits 34666 34746 +80
- Misses 2479 2616 +137
- Partials 1295 1299 +4 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An initial look at everything but the tests,
I think currently this breaks cancellation, because I don't know whether the websocket connections will always close gracefully.
src/engine/Operation.cpp
Outdated
|
||
// _____________________________________________________________________________ | ||
cppcoro::generator<std::shared_ptr<RuntimeInformation>> | ||
Operation::getRuntimeInfoChildren() { | ||
for (auto child : getChildren()) { | ||
AD_CONTRACT_CHECK(child); | ||
co_yield child->getRootOperation()->getRuntimeInfoPointer(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are currently porting back to C++17
, so we shouldn't use generators
in new code anymore.
Why not simply use std::vector<RuntimeInformation*>
or maybe even better absl::InlinedVector<RuntimeInformation*>
as we almost never have more than 2 children.
src/engine/Operation.cpp
Outdated
AD_CONTRACT_CHECK(child); | ||
_runtimeInfo->children_.push_back( | ||
child->getRootOperation()->getRuntimeInfoPointer()); | ||
for (auto child : getRuntimeInfoChildren()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use references when you don't need or use the copies of the child
(multiple occurences).
src/engine/Operation.h
Outdated
// Get access to the children's RuntimeInfo. Required for the `Service`, as | ||
// it's children can't be accessed using `getChildren()` above. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not required for the service
but overridden by the Service
.
src/engine/RuntimeInformation.cpp
Outdated
if (str == "fully materialized") { | ||
return fullyMaterialized; | ||
} else if (str == "lazily materialized") { | ||
return lazilyMaterialized; | ||
} else if (str == "in progress") { | ||
return inProgress; | ||
} else if (str == "not started") { | ||
return notStarted; | ||
} else if (str == "optimized out") { | ||
return optimizedOut; | ||
} else if (str == "failed") { | ||
return failed; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you set up a static HashMap
for this lookup, mostly for readability`.
src/engine/RuntimeInformation.cpp
Outdated
auto cacheStatusFromString = [](std::string_view str) { | ||
using ad_utility::CacheStatus; | ||
if (str == "cached_not_pinned") { | ||
return CacheStatus::cachedNotPinned; | ||
} else if (str == "cached_pinned") { | ||
return CacheStatus::cachedPinned; | ||
} else if (str == "computed") { | ||
return CacheStatus::computed; | ||
} else if (str == "not_in_cache_not_computed") { | ||
return CacheStatus::notInCacheAndNotComputed; | ||
} else { | ||
throw std::runtime_error( | ||
"Unknown string value was encountered in `fromString(CacheStatus)`"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe also a separate function + also use a lookup data structure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And also note with the respective enums in a big comment, that these functions also have to be changed...
src/util/http/HttpClient.h
Outdated
// Upgrade the client to a websocket connection and return a generator of | ||
// messages received from the server. | ||
static cppcoro::generator<std::string> readWebSocketStream( | ||
std::unique_ptr<HttpClientImpl> client, std::string_view host, | ||
std::string_view target); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are trying to get away from generator
s,
Please have a look at the InputRangeTypeErased
etc. classes at the end of Iterators.h
, and ask me if you have trouble.
And as stated above, you should have a possibility to cancel the websocket stream if the outer operation is cancelled.
src/util/http/HttpClient.cpp
Outdated
@@ -62,6 +62,14 @@ HttpClientImpl<StreamType>::HttpClientImpl(std::string_view host, | |||
// ____________________________________________________________________________ | |||
template <typename StreamType> | |||
HttpClientImpl<StreamType>::~HttpClientImpl() { | |||
// If the stream was upgraded to a websocket connection, try to close it. | |||
if (ws_) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is something that you probably have to expose also manually (in a threadsafe way, but ask me for details if necessayr).
src/util/http/HttpClient.cpp
Outdated
@@ -102,6 +112,10 @@ HttpOrHttpsResponse HttpClientImpl<StreamType>::sendRequest( | |||
request.set(http::field::accept, acceptHeader); | |||
request.set(http::field::content_type, contentTypeHeader); | |||
request.set(http::field::content_length, std::to_string(requestBody.size())); | |||
for (const auto& h : customHeaders) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for (const auto& h : customHeaders) { | |
for (const auto& [key, value] : customHeaders) { | |
... |
src/util/http/HttpClient.cpp
Outdated
client->ws_->read(buffer); | ||
co_yield beast::buffers_to_string(buffer.data()); | ||
buffer.consume(buffer.size()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See here for something I found about cancellation
This should document, that even normal exits will throw an exception, so that calling code has to handle everything.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or you use an explicit strand
that you run in this thread etc, but I'll have to llok into that again.
src/util/http/HttpClient.cpp
Outdated
// ____________________________________________________________________________ | ||
cppcoro::generator<std::string> readHttpOrHttpsWebsocketStream( | ||
const ad_utility::httpUtils::Url& url, std::string_view target) { | ||
auto listen = [&]<typename Client>() -> cppcoro::generator<std::string> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have a look at the util/typeIdentity.h header, there i have a trick that makes the templated lambdas easier to call.
Signed-off-by: Johannes Kalmbach <[email protected]>
Conformance check passed ✅No test result changes. |
|
Adds the retrieval of runtime information for the service query using a WebSocket client.