Skip to content

Commit 7a4f1f7

Browse files
fix(observability): correct emitted metrics (vectordotdev#17562)
Ref vectordotdev#17465 There were a couple of outstanding issues from the above PR. 1. The redis sink was counting the network bytes before actually creating the bytes, so the count was always zero. 2. The Vector sink was not counting the `JsonSize` of the event. The comment saying this was not being used was incorrect. Signed-off-by: Stephen Wakely <[email protected]>
1 parent bcc5b6c commit 7a4f1f7

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/sinks/redis.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -290,10 +290,11 @@ fn encode_event(
290290
transformer.transform(&mut event);
291291

292292
let mut bytes = BytesMut::new();
293-
let byte_size = bytes.len();
294293

295294
// Errors are handled by `Encoder`.
296295
encoder.encode(event, &mut bytes).ok()?;
296+
297+
let byte_size = bytes.len();
297298
let value = bytes.freeze();
298299

299300
let event = EncodedEvent::new(RedisKvEntry { key, value }, byte_size, event_byte_size);

src/sinks/vector/sink.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use tower::Service;
77
use vector_common::json_size::JsonSize;
88
use vector_core::{
99
stream::{BatcherSettings, DriverResponse},
10-
ByteSizeOf,
10+
ByteSizeOf, EstimatedJsonEncodedSizeOf,
1111
};
1212

1313
use super::service::VectorRequest;
@@ -20,6 +20,7 @@ use crate::{
2020
/// Data for a single event.
2121
struct EventData {
2222
byte_size: usize,
23+
json_byte_size: JsonSize,
2324
finalizers: EventFinalizers,
2425
wrapper: EventWrapper,
2526
}
@@ -30,6 +31,7 @@ struct EventCollection {
3031
pub finalizers: EventFinalizers,
3132
pub events: Vec<EventWrapper>,
3233
pub events_byte_size: usize,
34+
pub events_json_byte_size: JsonSize,
3335
}
3436

3537
pub struct VectorSink<S> {
@@ -48,6 +50,7 @@ where
4850
input
4951
.map(|mut event| EventData {
5052
byte_size: event.size_of(),
53+
json_byte_size: event.estimated_json_encoded_size_of(),
5154
finalizers: event.take_finalizers(),
5255
wrapper: EventWrapper::from(event),
5356
})
@@ -57,13 +60,14 @@ where
5760
event_collection.finalizers.merge(item.finalizers);
5861
event_collection.events.push(item.wrapper);
5962
event_collection.events_byte_size += item.byte_size;
63+
event_collection.events_json_byte_size += item.json_byte_size;
6064
},
6165
))
6266
.map(|event_collection| {
6367
let builder = RequestMetadataBuilder::new(
6468
event_collection.events.len(),
6569
event_collection.events_byte_size,
66-
JsonSize::new(event_collection.events_byte_size), // this is fine as it isn't being used
70+
event_collection.events_json_byte_size,
6771
);
6872

6973
let encoded_events = proto_vector::PushEventsRequest {

0 commit comments

Comments
 (0)