@@ -22,13 +22,15 @@ use serde::{Deserialize, Serialize};
2222
2323#[ derive( Debug ) ]
2424pub struct StatsCounter {
25+ events_ingested : AtomicU64 ,
2526 ingestion_size : AtomicU64 ,
2627 storage_size : AtomicU64 ,
2728}
2829
2930impl Default for StatsCounter {
3031 fn default ( ) -> Self {
3132 Self {
33+ events_ingested : AtomicU64 :: new ( 0 ) ,
3234 ingestion_size : AtomicU64 :: new ( 0 ) ,
3335 storage_size : AtomicU64 :: new ( 0 ) ,
3436 }
@@ -43,13 +45,18 @@ impl PartialEq for StatsCounter {
4345}
4446
4547impl StatsCounter {
46- pub fn new ( ingestion_size : u64 , storage_size : u64 ) -> Self {
48+ pub fn new ( ingestion_size : u64 , storage_size : u64 , event_ingested : u64 ) -> Self {
4749 Self {
48- ingestion_size : AtomicU64 :: new ( ingestion_size) ,
49- storage_size : AtomicU64 :: new ( storage_size) ,
50+ ingestion_size : ingestion_size. into ( ) ,
51+ storage_size : storage_size. into ( ) ,
52+ events_ingested : event_ingested. into ( ) ,
5053 }
5154 }
5255
56+ pub fn events_ingested ( & self ) -> u64 {
57+ self . events_ingested . load ( Ordering :: Relaxed )
58+ }
59+
5360 pub fn ingestion_size ( & self ) -> u64 {
5461 self . ingestion_size . load ( Ordering :: Relaxed )
5562 }
@@ -65,18 +72,24 @@ impl StatsCounter {
6572 pub fn add_storage_size ( & self , size : u64 ) {
6673 self . storage_size . fetch_add ( size, Ordering :: AcqRel ) ;
6774 }
75+
76+ pub fn increase_event_by_one ( & self ) {
77+ self . events_ingested . fetch_add ( 1 , Ordering :: Relaxed ) ;
78+ }
6879}
6980
7081/// Helper struct type created by copying stats values from metadata
7182#[ derive( Debug , Default , Serialize , Deserialize , Clone , Copy , PartialEq , Eq ) ]
7283pub struct Stats {
84+ pub events : u64 ,
7385 pub ingestion : u64 ,
7486 pub storage : u64 ,
7587}
7688
7789impl From < & StatsCounter > for Stats {
7890 fn from ( stats : & StatsCounter ) -> Self {
7991 Self {
92+ events : stats. events_ingested ( ) ,
8093 ingestion : stats. ingestion_size ( ) ,
8194 storage : stats. storage_size ( ) ,
8295 }
@@ -85,6 +98,6 @@ impl From<&StatsCounter> for Stats {
8598
8699impl From < Stats > for StatsCounter {
87100 fn from ( stats : Stats ) -> Self {
88- StatsCounter :: new ( stats. ingestion , stats. storage )
101+ StatsCounter :: new ( stats. ingestion , stats. storage , stats . events )
89102 }
90103}
0 commit comments