MchLogToolkitGo - V3 roteia LogSubject por subject: levels via Graylog UDP, eventos de domínio em disco#18
Open
JVVeiga wants to merge 3 commits into
Open
MchLogToolkitGo - V3 roteia LogSubject por subject: levels via Graylog UDP, eventos de domínio em disco#18JVVeiga wants to merge 3 commits into
JVVeiga wants to merge 3 commits into
Conversation
V3 internally wraps every Initialize in a routerDestination that holds
a file impl (always) and an optional network impl. Level-like subjects
(test/debug/info/warn/error/fatal) — i.e., output from Logger.Info/.Warn/
.Error/... — go to the network impl when configured; everything else
(domain events) goes to file in the same V2 layout. Caller may extend
the level set via DestinationConfig.NetworkSubjects.
Configure shape reshaped: Protocol/ProtocolFile/ProtocolGraylogUDP/Addr/
Source/DisableGZIP replaced by Network *NetworkConfig{Type, Addr, Source,
DisableGZIP} + NetworkSubjects []string. Zero value keeps file-only
behavior (same as legacy ProtocolFile).
Initialize fails loud on UDP dial errors; routing is exclusive (no tee).
V3 README section rewritten around the router: explains level-vs-domain routing, exclusive dispatch, fail-loud on UDP init, NetworkSubjects extender semantics, and migration path. mchlogcore.InitializeMchLog doc comment updated to reflect that V3 always has a file impl and uses the path's last segment for service name on the network side.
There was a problem hiding this comment.
Refactor sólido: router por subject preserva persistência em disco para eventos de domínio enquanto permite levels via UDP. Cobertura de testes excelente — matriz table-driven + 3 end-to-end loopback + stress 20×20 com race detector. Breaking change bem documentado e default zero-value mantém compatibilidade bit-a-bit com V2.
- ActiveConfig now deep-copies Network ptr and NetworkSubjects slice, symmetric with Configure. Callers may mutate the result freely. - defaultLevelSubjects comment documents case-sensitivity (Logger internal always emits lowercase). - TestRouterConcurrentLogSubject doc + inline comment explain why the UDP datagram check accepts N > 0: loopback drops under bursts, exact total is validated via the domain-subject file (deterministic).
JRaphaelO
approved these changes
May 20, 2026
mateusmetzker
approved these changes
May 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Descrição
V3 hoje seleciona um destino único (file ou Graylog UDP). Quando UDP está ativo, todas as chamadas
LogSubjectvão por rede — inclusive subjects de domínio com payloads gordos que precisam de persistência (ex.:historico_posicao_taxi,log_posicao_alterada,trajeto_solicitacao,webhook_event_position). Esses payloads não cabem em UDP de forma confiável e historicamente vivem em disco.Este PR introduz um router por subject dentro do V3:
test,debug,info,warn,error,fatal) — saída deLogger.Info/.Warn/.Error/...— vão para o destino de rede quando configurado.DestinationConfig.NetworkSubjects.Mudanças por commit
0298278feat(mchlogcorev3)!: route LogSubject by subject (file + optional UDP)mchlogcorev3/config.go—Protocol/ProtocolFile/ProtocolGraylogUDP/Addr/Source/DisableGZIPremovidos. EntrouNetwork *NetworkConfig{Type, Addr, Source, DisableGZIP}+NetworkSubjects []string. Zero value = file-only (mesmo comportamento do legacyProtocolFile).mchlogcorev3/router.go(novo) —routerDestinationcom whitelist hardcoded + extender, dispatch por subject,GetFileNameFromStreamName/Closeper-subject.mchlogcorev3/mchlogv3.go—Initializesempre constrói file impl + opcional network impl, embrulha em router.graylogUDP.cfgagora éNetworkConfig(não maisDestinationConfig).mchlogcorev3/gelf.go—buildGELFMessageaceitaNetworkConfig.mchlogcorev3/router_test.go(novo) — matriz de dispatch (table-driven) + 3 cenários end-to-end loopback UDP + stress 20×20 goroutines.mchlogcore/v3_dispatch_test.go.546004cdocs(mchlogcorev3): describe subject router model in README and facadeREADME.md— seção V3 reescrita: modelo router, tabela de campos, avisos sobreNetworkSubjects.mchlogcore/mchlog.go— comentário deInitializeMchLogatualizado.Tipo de Mudança
DestinationConfigmudou. Callers que usamProtocol: ProtocolFile/ProtocolGraylogUDPnão compilam mais.LogSubject.Checklist
Como testar as alterações
Integration test opcional (precisa de Graylog real):
GRAYLOG_TEST_ADDR=localhost:12201 go test -tags=integration -v ./mchlogcorev3/...Para validar o comportamento de routing manualmente:
Configure(DestinationConfig{})(zero value) → arquivo-only, layout V2.Configure(DestinationConfig{Network: &NetworkConfig{Type: NetworkGraylogUDP, Addr: ..., Source: ...}})→LogSubject("info", ...)vai para UDP;LogSubject("meu_evento_dominio", ...)vai para<basePath>/<service>/meu_evento_dominio/meu_evento_dominio.log.NetworkSubjects: []string{"meu_evento_dominio"}→ o evento de domínio passa a ir para UDP em vez de arquivo (extender).Impactos no Deploy
mchlogcorev3e usamProtocol/Addr/Source/DisableGZIPemDestinationConfigprecisam migrar paraNetwork *NetworkConfig{...}. Migração é mecânica.<basePath>/<service>/<subject>/<subject>.logdo V2). Sem migração de dados.infra/logger/logger.gopara a nova shape antes de bumpar a dependência.Dependências
Sem mudanças em
go.mod/go.sum. Continua usandogithub.com/Graylog2/go-gelf/gelf.Issues
—
Observações Adicionais
mchlogcorev2, que mantém umsync.Mapglobal de*zerolog.Loggerpor subject. Testes que escrevem o mesmo subject emt.TempDir()diferentes podem colidir (o cache mantém FD aberto contra arquivo já unlinked). O stress test usa subject único para evitar — comentário norouter_test.goexplica. Não é novo nesta PR, é design legado do V2.NetworkSubjectsvai 100% para UDP, sem tee em disco. Use com cautela — eventos críticos que precisam persistência local devem ficar fora dessa lista.GetFileNameFromStreamName(subject)devolver um caminho de arquivo real devem usar subjects fora da whitelist (mantém comportamento atual).