Skip to content

refactor: consolidate duplicate DIFC filtered-item struct and tagsToStrings#2111

Merged
lpcox merged 2 commits intomainfrom
copilot/duplicate-code-analysis-report
Mar 18, 2026
Merged

refactor: consolidate duplicate DIFC filtered-item struct and tagsToStrings#2111
lpcox merged 2 commits intomainfrom
copilot/duplicate-code-analysis-report

Conversation

Copy link
Contributor

Copilot AI commented Mar 18, 2026

Two duplication patterns introduced in internal/server/difc_log.go required parallel edits across files when modifying DIFC filter event data shapes.

Changes

  • Struct consolidationFilteredItemLogEntry (server) and JSONLFilteredItem (logger) shared identical 11-field data definitions. Moved the shared fields into a new logger.FilteredItemLogEntry; JSONLFilteredItem now embeds it, keeping only its own Timestamp and Type fields:

    // Before: 11 fields duplicated verbatim in both structs
    type JSONLFilteredItem struct {
        Timestamp string `json:"timestamp"`
        Type      string `json:"type"`
        ServerID  string `json:"server_id"`
        // ... 9 more duplicated fields
    }
    
    // After: embed the shared struct
    type JSONLFilteredItem struct {
        Timestamp string `json:"timestamp"`
        Type      string `json:"type"`
        FilteredItemLogEntry
    }
  • Remove toJSONLFilteredItem() — field-by-field copy method replaced with a direct struct literal: &logger.JSONLFilteredItem{FilteredItemLogEntry: entry}

  • Eliminate duplicate tagsToStrings — local helper in difc_log.go was identical to difc.TagsToStrings; replaced all call sites with the canonical package function

  • Test updatesdifc_log_test.go updated to reference logger.FilteredItemLogEntry instead of the removed local type

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • example.com
    • Triggering command: /tmp/go-build3728142662/b332/launcher.test /tmp/go-build3728142662/b332/launcher.test -test.testlogfile=/tmp/go-build3728142662/b332/testlog.txt -test.paniconexit0 -test.timeout=10m0s rev-�� /unix (dns block)
  • invalid-host-that-does-not-exist-12345.com
    • Triggering command: /tmp/go-build3728142662/b317/config.test /tmp/go-build3728142662/b317/config.test -test.testlogfile=/tmp/go-build3728142662/b317/testlog.txt -test.paniconexit0 -test.timeout=10m0s rev-�� ache/go/1.25.8/x-p cf9O/V70NMeR5oSymain x_amd64/vet (dns block)
  • nonexistent.local
    • Triggering command: /tmp/go-build3728142662/b332/launcher.test /tmp/go-build3728142662/b332/launcher.test -test.testlogfile=/tmp/go-build3728142662/b332/testlog.txt -test.paniconexit0 -test.timeout=10m0s rev-�� /unix (dns block)
  • slow.example.com
    • Triggering command: /tmp/go-build3728142662/b332/launcher.test /tmp/go-build3728142662/b332/launcher.test -test.testlogfile=/tmp/go-build3728142662/b332/testlog.txt -test.paniconexit0 -test.timeout=10m0s rev-�� /unix (dns block)
  • this-host-does-not-exist-12345.com
    • Triggering command: /tmp/go-build3728142662/b341/mcp.test /tmp/go-build3728142662/b341/mcp.test -test.testlogfile=/tmp/go-build3728142662/b341/testlog.txt -test.paniconexit0 -test.timeout=10m0s rev-�� ache/go/1.25.8/x64/src/runtime/cgo1.25.8 (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI linked an issue Mar 18, 2026 that may be closed by this pull request
…trings function

- Move shared data fields into logger.FilteredItemLogEntry in jsonl_logger.go
- Have JSONLFilteredItem embed FilteredItemLogEntry (adds only Timestamp and Type)
- Remove duplicate FilteredItemLogEntry struct from server/difc_log.go
- Remove toJSONLFilteredItem() method; use direct struct literal instead
- Replace local tagsToStrings() with difc.TagsToStrings
- Update difc_log_test.go to use logger.FilteredItemLogEntry

Fixes #2085, #2086, #2087

Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Copilot AI changed the title [WIP] [duplicate-code] Fix duplicate code patterns in DIFC logging refactor: consolidate duplicate DIFC filtered-item struct and tagsToStrings Mar 18, 2026
Copilot AI requested a review from lpcox March 18, 2026 23:34
@lpcox lpcox marked this pull request as ready for review March 18, 2026 23:40
Copilot AI review requested due to automatic review settings March 18, 2026 23:40
@lpcox lpcox merged commit 0e5e4c4 into main Mar 18, 2026
15 checks passed
@lpcox lpcox deleted the copilot/duplicate-code-analysis-report branch March 18, 2026 23:41
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR reduces duplication in DIFC filtered-item logging by centralizing the shared filtered-item payload fields in the internal/logger package and reusing existing DIFC tag conversion helpers, so future schema changes require fewer parallel edits.

Changes:

  • Consolidates the shared filtered-item payload into logger.FilteredItemLogEntry and embeds it into logger.JSONLFilteredItem.
  • Simplifies DIFC JSONL emission by removing the per-field conversion helper and using a direct struct literal.
  • Replaces the duplicated tagsToStrings helper in difc_log.go with difc.TagsToStrings, and updates tests accordingly.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
internal/server/difc_log.go Switches filtered-item entry construction to logger.FilteredItemLogEntry, uses difc.TagsToStrings, and simplifies JSONL logging construction.
internal/logger/jsonl_logger.go Introduces FilteredItemLogEntry and embeds it into JSONLFilteredItem to eliminate duplicated field definitions.
internal/server/difc_log_test.go Updates tests to unmarshal/compare against logger.FilteredItemLogEntry.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[duplicate-code] Duplicate Code Analysis Report

3 participants