|
4 | 4 | import os |
5 | 5 | import threading |
6 | 6 | import time |
| 7 | +from datetime import datetime |
7 | 8 | from contextlib import asynccontextmanager |
8 | 9 | from queue import Queue |
9 | 10 | from typing import TYPE_CHECKING, Any, Dict, List, Optional |
|
17 | 18 | from eval_protocol.dataset_logger.dataset_logger import LOG_EVENT_TYPE |
18 | 19 | from eval_protocol.event_bus import event_bus |
19 | 20 | from eval_protocol.models import Status |
| 21 | +from eval_protocol.pytest.elasticsearch_setup import ElasticsearchSetup |
20 | 22 | from eval_protocol.utils.vite_server import ViteServer |
21 | 23 | from eval_protocol.log_utils.elasticsearch_client import ElasticsearchClient |
22 | 24 | from eval_protocol.types.remote_rollout_processor import ElasticsearchConfig |
@@ -351,11 +353,19 @@ async def get_logs( |
351 | 353 | raise HTTPException(status_code=503, detail="Elasticsearch is not configured for this logs server") |
352 | 354 |
|
353 | 355 | try: |
354 | | - # Search for logs by rollout_id, sorted by timestamp in descending order (newest first) |
355 | | - sort_spec = [{"@timestamp": {"order": "desc"}}] |
356 | | - search_results = self.elasticsearch_client.search_by_match( |
357 | | - "rollout_id", rollout_id, size=limit, sort=sort_spec |
358 | | - ) |
| 356 | + # Search for logs by rollout_id using a term filter (exact match), |
| 357 | + # sorted by timestamp desc with a secondary deterministic tie-breaker on _id desc |
| 358 | + sort_spec = [ |
| 359 | + {"@timestamp": {"order": "asc"}}, |
| 360 | + ] |
| 361 | + query = { |
| 362 | + "bool": { |
| 363 | + "must": [ |
| 364 | + {"term": {"rollout_id": rollout_id}}, |
| 365 | + ] |
| 366 | + } |
| 367 | + } |
| 368 | + search_results = self.elasticsearch_client.search(query, size=limit, sort=sort_spec) |
359 | 369 |
|
360 | 370 | if not search_results or "hits" not in search_results: |
361 | 371 | # Return empty response using Pydantic model |
@@ -512,10 +522,14 @@ def serve_logs(port: Optional[int] = None, elasticsearch_config: Optional[Elasti |
512 | 522 |
|
513 | 523 | args = parser.parse_args() |
514 | 524 |
|
| 525 | + elasticsearch_config = ElasticsearchSetup().setup_elasticsearch() |
| 526 | + |
515 | 527 | # Create server with command line arguments |
516 | 528 | if args.build_dir: |
517 | | - server = LogsServer(host=args.host, port=args.port, build_dir=args.build_dir) |
| 529 | + server = LogsServer( |
| 530 | + host=args.host, port=args.port, build_dir=args.build_dir, elasticsearch_config=elasticsearch_config |
| 531 | + ) |
518 | 532 | else: |
519 | | - server = LogsServer(host=args.host, port=args.port) |
| 533 | + server = LogsServer(host=args.host, port=args.port, elasticsearch_config=elasticsearch_config) |
520 | 534 |
|
521 | 535 | server.run() |
0 commit comments