Skip to content

Make HTTP/gRPC callout IDs unique per WasmVM instance. #186

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

Merged
merged 2 commits into from
Aug 12, 2021
Merged
Changes from all 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
34 changes: 34 additions & 0 deletions include/proxy-wasm/wasm.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,35 @@ class WasmBase : public std::enable_shared_from_this<WasmBase> {
uint32_t nextGaugeMetricId() { return next_gauge_metric_id_ += kMetricIdIncrement; }
uint32_t nextHistogramMetricId() { return next_histogram_metric_id_ += kMetricIdIncrement; }

enum class CalloutType : uint32_t {
HttpCall = 0,
GrpcCall = 1,
GrpcStream = 2,
};
static const uint32_t kCalloutTypeMask = 0x3; // Enough to cover the 3 types.
static const uint32_t kCalloutIncrement = 0x4; // Enough to cover the 3 types.
bool isHttpCallId(uint32_t callout_id) {
return (callout_id & kCalloutTypeMask) == static_cast<uint32_t>(CalloutType::HttpCall);
}
bool isGrpcCallId(uint32_t callout_id) {
return (callout_id & kCalloutTypeMask) == static_cast<uint32_t>(CalloutType::GrpcCall);
}
bool isGrpcStreamId(uint32_t callout_id) {
return (callout_id & kCalloutTypeMask) == static_cast<uint32_t>(CalloutType::GrpcStream);
}
uint32_t nextHttpCallId() {
// TODO(PiotrSikora): re-add rollover protection (requires at least 1 billion callouts).
return next_http_call_id_ += kCalloutIncrement;
}
uint32_t nextGrpcCallId() {
// TODO(PiotrSikora): re-add rollover protection (requires at least 1 billion callouts).
return next_grpc_call_id_ += kCalloutIncrement;
}
uint32_t nextGrpcStreamId() {
// TODO(PiotrSikora): re-add rollover protection (requires at least 1 billion callouts).
return next_grpc_stream_id_ += kCalloutIncrement;
}

protected:
friend class ContextBase;
class ShutdownHandle;
Expand Down Expand Up @@ -279,6 +308,11 @@ class WasmBase : public std::enable_shared_from_this<WasmBase> {
uint32_t next_gauge_metric_id_ = static_cast<uint32_t>(MetricType::Gauge);
uint32_t next_histogram_metric_id_ = static_cast<uint32_t>(MetricType::Histogram);

// HTTP/gRPC callouts.
uint32_t next_http_call_id_ = static_cast<uint32_t>(CalloutType::HttpCall);
uint32_t next_grpc_call_id_ = static_cast<uint32_t>(CalloutType::GrpcCall);
uint32_t next_grpc_stream_id_ = static_cast<uint32_t>(CalloutType::GrpcStream);

// Actions to be done after the call into the VM returns.
std::deque<std::function<void()>> after_vm_call_actions_;

Expand Down