Skip to content

Commit 2624c08

Browse files
anurag-rajawatdaemon1024
authored andcommitted
feat(envoy-plugin): Add support to get response backend latency
Signed-off-by: Anurag Singh Rajawat <anuragsinghrajawat22@gmail.com>
1 parent be05a68 commit 2624c08

9 files changed

Lines changed: 212 additions & 198 deletions

File tree

filter/envoy/envoy-wasm-filters/src/lib.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ struct Reqquest {
5555
struct Ressponse {
5656
headers: HashMap<String, String>,
5757
body: String,
58+
backend_latency_in_nanos: u64,
5859
}
5960

6061
const MAX_BODY_SIZE: usize = 1_000_000; // 1 MB
@@ -213,6 +214,16 @@ impl HttpContext for Plugin {
213214
if !body.is_empty() && body.len() <= MAX_BODY_SIZE {
214215
self.api_event.response.body = body;
215216
}
217+
218+
if let Some(value) = self.get_property(vec!["response", "backend_latency"]) {
219+
// Ensure the byte vector has at least 8 bytes for u64
220+
if value.len() >= 8 {
221+
// Convert the first 8 bytes to an u64 (nanoseconds)
222+
self.api_event.response.backend_latency_in_nanos =
223+
u64::from_ne_bytes(value[..8].try_into().unwrap_or_default());
224+
}
225+
}
226+
216227
Action::Continue
217228
}
218229
}

protobuf/golang/sentryflow.pb.go

Lines changed: 155 additions & 153 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

protobuf/golang/sentryflow_grpc.pb.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

protobuf/golang/sentryflow_metrics.pb.go

Lines changed: 14 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

protobuf/golang/sentryflow_metrics_grpc.pb.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

protobuf/python/sentryflow_metrics_pb2.py

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

protobuf/python/sentryflow_pb2.py

Lines changed: 22 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

protobuf/python/sentryflow_pb2.pyi

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ class Request(_message.Message):
129129
def __init__(self, headers: _Optional[_Mapping[str, str]] = ..., body: _Optional[str] = ...) -> None: ...
130130

131131
class Response(_message.Message):
132-
__slots__ = ("headers", "body")
132+
__slots__ = ("headers", "body", "backend_latency_in_nanos")
133133
class HeadersEntry(_message.Message):
134134
__slots__ = ("key", "value")
135135
KEY_FIELD_NUMBER: _ClassVar[int]
@@ -139,9 +139,11 @@ class Response(_message.Message):
139139
def __init__(self, key: _Optional[str] = ..., value: _Optional[str] = ...) -> None: ...
140140
HEADERS_FIELD_NUMBER: _ClassVar[int]
141141
BODY_FIELD_NUMBER: _ClassVar[int]
142+
BACKEND_LATENCY_IN_NANOS_FIELD_NUMBER: _ClassVar[int]
142143
headers: _containers.ScalarMap[str, str]
143144
body: str
144-
def __init__(self, headers: _Optional[_Mapping[str, str]] = ..., body: _Optional[str] = ...) -> None: ...
145+
backend_latency_in_nanos: int
146+
def __init__(self, headers: _Optional[_Mapping[str, str]] = ..., body: _Optional[str] = ..., backend_latency_in_nanos: _Optional[int] = ...) -> None: ...
145147

146148
class APIMetrics(_message.Message):
147149
__slots__ = ("perAPICounts",)

protobuf/sentryflow.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ message Request {
9292
message Response {
9393
map<string, string> headers = 1;
9494
string body = 2;
95+
uint64 backend_latency_in_nanos = 3;
9596
}
9697

9798
message APIMetrics {

0 commit comments

Comments
 (0)