Skip to content

refactor: split LogAnalysis interface to separate read-only and mutation concerns #29575

Closed

Description

@github-actions

Problem

The LogAnalysis interface in pkg/cli/log_aggregation.go:16-27 includes mutation methods (SetAllowedDomains, SetBlockedDomains, AddMetrics):

type LogAnalysis interface {
    GetAllowedDomains() []string
    GetBlockedDomains() []string
    SetAllowedDomains(domains []string)   // mutation
    SetBlockedDomains(domains []string)   // mutation
    AddMetrics(other LogAnalysis)          // mutation
}

Mixing read-only accessor methods with mutation methods in a single interface violates the Interface Segregation Principle and makes the type harder to mock, test, and reason about.

Impact

  • Severity: Low (maintainability)
  • Affected file: pkg/cli/log_aggregation.go
  • Risk: Consumers that only need to read domain data must implement mutating methods, creating unnecessary coupling and making unit tests more complex.

Recommendation

Split LogAnalysis into two focused interfaces — a read-only LogAnalysisReader and a writable LogAnalysisWriter (or MutableLogAnalysis):

Before:

type LogAnalysis interface {
    GetAllowedDomains() []string
    GetBlockedDomains() []string
    SetAllowedDomains(domains []string)
    SetBlockedDomains(domains []string)
    AddMetrics(other LogAnalysis)
}

After:

type LogAnalysis interface {
    GetAllowedDomains() []string
    GetBlockedDomains() []string
}

type MutableLogAnalysis interface {
    LogAnalysis
    SetAllowedDomains(domains []string)
    SetBlockedDomains(domains []string)
    AddMetrics(other LogAnalysis)
}

Update aggregateLogFiles and other internal callers to accept MutableLogAnalysis where mutation is needed, and LogAnalysis where only reading is required.

Validation

  • All direct usages of LogAnalysis compile with the new narrower interface
  • aggregateLogFiles updated to use MutableLogAnalysis
  • Existing tests pass
  • Spot-check that no external callers are broken

Estimated Effort

Medium (2-4 hours, mostly mechanical refactor)


Identified by Sergo — Run ID: §25221981612

Generated by Sergo - Serena Go Expert · ● 817.9K · ◷

  • expires on May 8, 2026, 4:24 PM UTC

Activity

  1. github-actions commented on May 1, 2026

    @github-actions
    ContributorAuthor

    🍪 Issue Monster selected this for Copilot

    I've identified this issue as a good candidate for automated resolution and requested assignment to the Copilot coding agent.

    If assignment succeeds, the Copilot coding agent will analyze the issue and create a pull request with the fix.

    Om nom nom! 🍪

    🍪 Om nom nom by Issue Monster · ● 16.5K · ◷

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

cookieIssue Monster Loves Cookies!sergo

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions