@@ -55,9 +55,16 @@ impl LokiLogStore {
5555 from : & str ,
5656 to : & str ,
5757 limit : u32 ,
58+ order_direction : super :: OrderDirection ,
5859 ) -> Result < Vec < LogEntry > , LogStoreError > {
5960 let url = format ! ( "{}/loki/api/v1/query_range" , self . endpoint) ;
6061
62+ // Map order direction to Loki's direction parameter
63+ let direction = match order_direction {
64+ super :: OrderDirection :: Desc => "backward" , // Most recent first
65+ super :: OrderDirection :: Asc => "forward" , // Oldest first
66+ } ;
67+
6168 let mut request = self
6269 . client
6370 . get ( & url)
@@ -66,7 +73,7 @@ impl LokiLogStore {
6673 ( "start" , from) ,
6774 ( "end" , to) ,
6875 ( "limit" , & limit. to_string ( ) ) ,
69- ( "direction" , "backward" ) , // Most recent first
76+ ( "direction" , direction ) ,
7077 ] )
7178 . timeout ( Duration :: from_secs ( 10 ) ) ;
7279
@@ -158,7 +165,9 @@ impl LogStore for LokiLogStore {
158165 // Execute query with limit + skip to handle pagination
159166 let limit = query. first + query. skip ;
160167
161- let mut entries = self . execute_query ( & logql_query, from, to, limit) . await ?;
168+ let mut entries = self
169+ . execute_query ( & logql_query, from, to, limit, query. order_direction )
170+ . await ?;
162171
163172 // Apply skip/first pagination
164173 if query. skip > 0 {
@@ -239,6 +248,7 @@ mod tests {
239248 search : None ,
240249 first : 100 ,
241250 skip : 0 ,
251+ order_direction : crate :: components:: log_store:: OrderDirection :: Desc ,
242252 } ;
243253
244254 let logql = store. build_logql_query ( & query) ;
@@ -256,6 +266,7 @@ mod tests {
256266 search : None ,
257267 first : 100 ,
258268 skip : 0 ,
269+ order_direction : crate :: components:: log_store:: OrderDirection :: Desc ,
259270 } ;
260271
261272 let logql = store. build_logql_query ( & query) ;
@@ -273,6 +284,7 @@ mod tests {
273284 search : Some ( "transaction failed" . to_string ( ) ) ,
274285 first : 100 ,
275286 skip : 0 ,
287+ order_direction : crate :: components:: log_store:: OrderDirection :: Desc ,
276288 } ;
277289
278290 let logql = store. build_logql_query ( & query) ;
0 commit comments