Retain all diagnostic groups without capacity caps
This commit is contained in:
@@ -7,26 +7,16 @@ import (
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/contracts"
|
||||
)
|
||||
|
||||
const (
|
||||
MaxWarningGroups = 128
|
||||
MaxNonWarningGroups = 256
|
||||
)
|
||||
|
||||
// Aggregator merges origin-enriched diagnostics in caller-supplied canonical
|
||||
// order. Its zero value is ready for use.
|
||||
type Aggregator struct {
|
||||
groups []contracts.DiagnosticGroup
|
||||
indices map[groupKey]int
|
||||
warningGroups int
|
||||
nonWarningGroups int
|
||||
warningOccurrences int
|
||||
nonWarningOccurrences int
|
||||
unrepresentedOccurrences int
|
||||
groups []contracts.DiagnosticGroup
|
||||
indices map[groupKey]int
|
||||
warningOccurrences int
|
||||
nonWarningOccurrences int
|
||||
}
|
||||
|
||||
// Add validates and incorporates one final diagnostic group. Actionable
|
||||
// warnings cannot overflow; later non-warning groups are represented by exact
|
||||
// unrepresented-occurrence metadata once their fixed bound is reached.
|
||||
// Add validates and incorporates one final diagnostic group.
|
||||
func (aggregator *Aggregator) Add(group contracts.DiagnosticGroup) error {
|
||||
if err := group.Validate(); err != nil {
|
||||
return fmt.Errorf("diagnostic group: %w", err)
|
||||
@@ -45,25 +35,9 @@ func (aggregator *Aggregator) Add(group contracts.DiagnosticGroup) error {
|
||||
aggregator.addOccurrenceTotal(group.Disposition, group.OccurrenceCount)
|
||||
return nil
|
||||
}
|
||||
if group.Disposition == contracts.DiagnosticDispositionWarning {
|
||||
if aggregator.warningGroups >= MaxWarningGroups {
|
||||
return errors.New("diagnostic warning groups exceed maximum count")
|
||||
}
|
||||
} else if aggregator.nonWarningGroups >= MaxNonWarningGroups {
|
||||
if err := aggregator.checkOccurrenceTotal(group.Disposition, group.OccurrenceCount); err != nil {
|
||||
return err
|
||||
}
|
||||
aggregator.addOccurrenceTotal(group.Disposition, group.OccurrenceCount)
|
||||
return aggregator.addUnrepresented(group.OccurrenceCount)
|
||||
}
|
||||
if err := aggregator.checkOccurrenceTotal(group.Disposition, group.OccurrenceCount); err != nil {
|
||||
return err
|
||||
}
|
||||
if group.Disposition == contracts.DiagnosticDispositionWarning {
|
||||
aggregator.warningGroups++
|
||||
} else {
|
||||
aggregator.nonWarningGroups++
|
||||
}
|
||||
aggregator.addOccurrenceTotal(group.Disposition, group.OccurrenceCount)
|
||||
aggregator.indices[key] = len(aggregator.groups)
|
||||
aggregator.groups = append(aggregator.groups, contracts.CloneDiagnosticCollection(contracts.DiagnosticCollection{Groups: []contracts.DiagnosticGroup{group}}).Groups[0])
|
||||
@@ -96,9 +70,7 @@ func (aggregator *Aggregator) Collection() contracts.DiagnosticCollection {
|
||||
return contracts.DiagnosticCollection{}
|
||||
}
|
||||
return contracts.CloneDiagnosticCollection(contracts.DiagnosticCollection{
|
||||
Groups: aggregator.groups,
|
||||
Truncated: aggregator.unrepresentedOccurrences > 0,
|
||||
UnrepresentedOccurrenceCount: aggregator.unrepresentedOccurrences,
|
||||
Groups: aggregator.groups,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -118,14 +90,6 @@ func (aggregator *Aggregator) merge(index int, incoming contracts.DiagnosticGrou
|
||||
return nil
|
||||
}
|
||||
|
||||
func (aggregator *Aggregator) addUnrepresented(count int) error {
|
||||
if count > maximumInt()-aggregator.unrepresentedOccurrences {
|
||||
return errors.New("diagnostic unrepresented occurrence count overflow")
|
||||
}
|
||||
aggregator.unrepresentedOccurrences += count
|
||||
return nil
|
||||
}
|
||||
|
||||
func containsGroupSample(samples []contracts.DiagnosticSample, candidate contracts.DiagnosticSample) bool {
|
||||
for _, sample := range samples {
|
||||
if sample.Scope != candidate.Scope || sample.Message != candidate.Message || sample.ChunkID != candidate.ChunkID {
|
||||
|
||||
Reference in New Issue
Block a user