Skip to content

feat(agent-filter): equal_to e not_equal_to aceitam conjunto de valores - #24

Merged
gomessguii merged 1 commit into
developfrom
feat/agent-filter-multi-value
Aug 5, 2026
Merged

feat(agent-filter): equal_to e not_equal_to aceitam conjunto de valores#24
gomessguii merged 1 commit into
developfrom
feat/agent-filter-multi-value

Conversation

@gomessguii

@gomessguii gomessguii commented Aug 5, 2026

Copy link
Copy Markdown
Member

Levantado no review da EVO-2231, no lado do front.

O problema

A lista de clausulas do GET /agents e plana (agent_filter.go) e o SQL liga AND
mais forte que OR. Entao (tipo A ou B) E (modelo X ou Y) nao tem como ser
agrupado — so cabe distribuido, uma clausula por combinacao.

Medido com a querystring real:

Selecao Clausulas Querystring
1 tipo 1 114 B
"Avancado" (4 tipos) x 3 modelos 24 4,1 KB
todos os tipos x 5 modelos 60 10,3 KB
todos os tipos x 10 modelos 120 20,8 KB

O default de large_client_header_buffers do nginx e 8 KB: acima de ~50 clausulas
o usuario toma 414.

O que muda

Um valor separado por virgula passa a ser lido como conjunto e vira IN /
NOT IN. O mesmo filtro cai para 2 clausulas em qualquer combinacao.

Só os operadores de conjunto dividem — contains continua tratando virgula como
parte do texto buscado, e ha teste para isso. created_at segue no formato de valor
unico.

Compatibilidade

Aditivo: valor sem virgula produz exatamente o SQL de antes. O front ainda nao usa
este formato de proposito — ele continua mandando a forma distribuida, que funciona
contra as duas versoes. A troca no front vira follow-up seguro depois que esta imagem
subir; antes disso, um shell novo contra um core antigo devolveria lista vazia.

Testes

go build, go vet e gofmt limpos. Os 8 casos que ja existiam seguem passando;
+4 cobrindo conjunto, NOT IN, virgula em contains e data.

Summary by Sourcery

Allow agent filters to interpret comma-separated values as sets for more compact type/model queries while preserving existing behavior for single values and dates.

New Features:

  • Support comma-separated value sets for equal_to and not_equal_to filters, generating IN/NOT IN conditions with case-insensitive matching.

Enhancements:

  • Preserve single-value semantics for created_at filters and keep commas literal for contains filters to maintain backward compatibility.

Tests:

  • Add tests covering set-based equal_to/not_equal_to filters, comma handling in contains filters, and single-value behavior for created_at date filters.

A lista de clausulas do endpoint e plana e o SQL liga AND mais forte que OR,
entao "(tipo A ou B) e (modelo X ou Y)" so cabia distribuido: uma clausula por
combinacao. Com 6 tipos e 5 modelos isso vira 60 clausulas e ~10 KB de
querystring, acima do buffer padrao de 8 KB do nginx.

Um valor separado por virgula passa a ser lido como conjunto e vira IN/NOT IN,
o que reduz o mesmo filtro a duas clausulas. So os operadores de conjunto
dividem: contains segue tratando virgula como parte do texto buscado.
@sourcery-ai

sourcery-ai Bot commented Aug 5, 2026

Copy link
Copy Markdown

Reviewer's Guide

This PR updates the agent filtering logic so that equal_to and not_equal_to operators can interpret comma-separated values as sets, generating SQL IN/NOT IN clauses instead of one clause per combination, while preserving existing behavior for single values, created_at, and contains, and adds tests to validate the new behavior.

File-Level Changes

Change Details Files
Allow equal_to/not_equal_to filters to treat comma-separated values as sets and emit IN/NOT IN SQL, preserving special cases like created_at and contains.
  • Introduced splitFilterValues to parse comma-separated filter values into trimmed string slices, used only by set-capable operators.
  • Added loweredValues helper to normalize value slices to lowercase before building IN/NOT IN conditions.
  • Extended agentFilterFragment to detect multi-value sets for non-created_at equal_to/not_equal_to filters and generate LOWER(column) IN (?) or column IS NULL OR LOWER(column) NOT IN (?) with []string args, while leaving created_at as single-value and contains unchanged.
pkg/agent/repository/agent_filter.go
Add tests to cover set handling, NOT IN, comma behavior for contains, and the created_at single-value behavior.
  • Added TestAgentFilterFragmentValueSet to assert equal_to/not_equal_to with comma-separated values produce IN/NOT IN SQL and []string arguments, using reflect.DeepEqual for verification.
  • Added TestAgentFilterFragmentContainsKeepsComma to ensure contains does not split on commas and treats them as part of the substring.
  • Added TestAgentFilterFragmentDateStaysSingle to verify created_at equal_to ignores commas and keeps the single-value DATE(...) comparison.
  • Imported reflect in agent_filter_test.go for slice comparison.
pkg/agent/repository/agent_filter_test.go

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@gomessguii
gomessguii merged commit 954c808 into develop Aug 5, 2026
5 checks passed
@gomessguii
gomessguii deleted the feat/agent-filter-multi-value branch August 5, 2026 13:27
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.

1 participant