Skip to content

[STORY] Log Search and Filtering #665

@jsbattig

Description

@jsbattig

Part of: #663

Part of: #EPIC_NUMBER

[Conversation Reference: "Story 2: Log Search and Filtering - As an administrator, I want to search and filter logs so that I can quickly find relevant log entries"]

Story Overview

Objective: Implement search and filtering capabilities for logs across Web UI, REST API, and MCP API, enabling administrators to quickly locate specific log entries by text, log level, and correlation ID.

User Value: Administrators can efficiently narrow down logs to find specific issues, reducing troubleshooting time from scrolling through thousands of entries to targeted searches returning relevant results.

Acceptance Criteria Summary: Text search across message/correlation ID; log level filtering; multiple filter combination; consistent filtering across all interfaces.

Acceptance Criteria

AC1: Text Search in Web UI

Scenario: Administrator searches logs by text

Given logs are displayed in the Logs tab
And a search input field is visible
When I enter a search term (e.g., "authentication failed")
And I submit the search
Then only logs containing the search term are displayed
And the search matches against message content
And the search matches against correlation ID
And the search is case-insensitive

Technical Requirements:

  • Add search input field to Logs tab UI
  • Implement HTMX-based search with server-side filtering
  • Search across message and correlation_id fields
  • Case-insensitive search using LIKE operator
  • Show "No matching logs" message when search returns empty
  • Preserve search term in input after submission
  • Add clear search button

AC2: Log Level Filtering in Web UI

Scenario: Administrator filters logs by severity level

Given logs are displayed in the Logs tab
And a log level dropdown/checkboxes are visible
When I select a specific level (e.g., "ERROR")
Then only logs of that level are displayed
And I can select multiple levels (e.g., ERROR and WARNING)
Then logs matching any selected level are displayed

Technical Requirements:

  • Add log level filter UI (dropdown or checkboxes)
  • Support filtering by: DEBUG, INFO, WARNING, ERROR, CRITICAL
  • Support multi-select for multiple levels
  • Default: show all levels
  • Visual indication of active filters
  • Count of logs per level (optional enhancement)

AC3: Combined Filters

Scenario: Administrator applies multiple filters simultaneously

Given logs are displayed in the Logs tab
When I enter a search term "SSO"
And I select log level "ERROR"
Then only logs matching BOTH criteria are displayed
And removing one filter immediately updates results

Technical Requirements:

  • Combine search and level filters with AND logic
  • Update results immediately on filter change (HTMX)
  • Clear all filters button
  • URL parameters reflect current filters (shareable/bookmarkable)
  • Maintain filter state on refresh

AC4: REST API Filtering

Scenario: Administrator queries logs with filters via REST API

Given I have admin authentication credentials
When I send GET /admin/api/logs?search=SSO&level=ERROR
Then I receive logs matching both criteria
And the response includes filter metadata

Technical Requirements:

  • Add query parameters: search, level (comma-separated for multiple)
  • Implement search across message and correlation_id
  • Implement level filtering with multi-value support
  • Return filter parameters in response metadata
  • Document API parameters in OpenAPI spec

AC5: MCP API Filtering

Scenario: Administrator queries logs with filters via MCP API

Given I have admin authentication credentials
When I call admin_logs_query with search="SSO" and level=["ERROR"]
Then I receive logs matching both criteria
And response format matches REST API

Technical Requirements:

  • Add parameters to admin_logs_query: search, level (array)
  • Implement identical filtering logic as REST API
  • Ensure response format parity with REST API
  • Document MCP tool parameters

AC6: Correlation ID Search

Scenario: Administrator searches for specific correlation ID

Given a correlation ID from an error message
When I search for that exact correlation ID
Then all logs with that correlation ID are displayed
And I can see the full trace of related operations

Technical Requirements:

  • Exact match search for correlation_id
  • Highlight correlation ID matches in results
  • Show all entries sharing same correlation ID
  • Sort by timestamp to show operation sequence

Implementation Status

Progress Tracking:

  • Core implementation complete
  • Unit tests passing (X/Y tests)
  • Integration tests passing (X/Y tests)
  • E2E tests passing (X/Y tests)
  • Code review approved
  • Manual E2E testing completed by Claude Code
  • Documentation updated

Completion: 0/Y tasks complete (0%)

Technical Implementation Details

Component Structure

src/cidx_server/
  logging/
    log_aggregator.py      # Add search/filter methods
  web/
    routes.py              # Update /admin/logs with filter params
    templates/
      admin/
        logs.html          # Add search/filter UI
        _logs_table.html   # Update for filtered results
        _log_filters.html  # NEW: Filter controls partial
  api/
    admin_routes.py        # Add filter params to /admin/api/logs
  mcp/
    admin_tools.py         # Add filter params to admin_logs_query

LogAggregatorService Query Interface

def query_logs(
    self,
    page: int = 1,
    page_size: int = 50,
    search: Optional[str] = None,
    levels: Optional[List[str]] = None,
    correlation_id: Optional[str] = None,
    sort_order: str = "desc"
) -> LogQueryResult:
    """Query logs with search and filtering."""

SQL Query Construction

SELECT * FROM logs
WHERE 1=1
  AND (message LIKE '%search%' OR correlation_id LIKE '%search%')  -- if search provided
  AND level IN ('ERROR', 'WARNING')  -- if levels provided
ORDER BY timestamp DESC
LIMIT page_size OFFSET (page - 1) * page_size

REST API Query Parameters

GET /admin/api/logs?page=1&page_size=50&search=SSO&level=ERROR,WARNING&sort=desc

Response Format (With Filters)

{
  "logs": [...],
  "pagination": {...},
  "filters": {
    "search": "SSO",
    "levels": ["ERROR", "WARNING"],
    "correlation_id": null
  }
}

Testing Requirements

Unit Test Coverage

  • LogAggregatorService search returns matching logs
  • LogAggregatorService search is case-insensitive
  • LogAggregatorService level filter works for single level
  • LogAggregatorService level filter works for multiple levels
  • Combined search and level filter uses AND logic
  • Empty search returns all logs
  • No matching results returns empty array

Integration Test Coverage

  • REST API search parameter filters correctly
  • REST API level parameter filters correctly
  • REST API combined parameters work together
  • MCP API filters match REST API behavior
  • Web UI filter submission updates table

E2E Test Coverage

  • Enter search term in UI, verify filtered results
  • Select log level in UI, verify filtered results
  • Combine search and level, verify AND logic
  • Query REST API with search param
  • Query REST API with level param
  • Query MCP API with filters

Performance Requirements

Response Time Targets

  • Search query: <2 seconds for typical search terms
  • Level filter: <1 second
  • Combined filters: <2 seconds

Resource Requirements

  • Memory: No additional beyond Story 1
  • Storage: SQLite indexes support efficient filtering
  • Network: Filtered responses smaller than unfiltered

Error Handling Specifications

User-Friendly Error Messages

"No logs match your search criteria. Try adjusting your filters."
"Invalid log level specified. Valid levels: DEBUG, INFO, WARNING, ERROR, CRITICAL."
"Search term too short. Please enter at least 2 characters."

Recovery Guidance

  • No results: Suggest broadening search or removing filters
  • Invalid level: Show valid level options
  • Search timeout: Suggest more specific search term

Definition of Done

Functional Completion

  • All acceptance criteria satisfied with evidence
  • All technical requirements implemented
  • Text search works across message and correlation_id
  • Log level filtering works with multi-select
  • Filters combine with AND logic
  • All interfaces (Web UI, REST, MCP) have filter parity

Quality Validation

  • >90% test coverage achieved
  • All tests passing (unit, integration, E2E)
  • Code review approved
  • Manual testing validated with evidence
  • Performance benchmarks met

Integration Readiness

  • Story delivers working, deployable software
  • Full vertical slice implemented
  • No broken functionality
  • Documentation complete

Story Points: Medium
Priority: High (P1)
Dependencies: Story 1 (Log Viewing with Basic Display) must be complete
Success Metric: Administrators can find specific logs using search and filters in <2 seconds via any interface

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions