Skip to content

Commit

Permalink
Fix issue when exclude_older_than is enabled without `ordering_crit…
Browse files Browse the repository at this point in the history
…eria` configured (open-telemetry#32683)

**Description:** <Describe what has changed.>
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->

Fix issue when `exclude_older_than` is enabled without
`ordering_criteria` configured

**Link to tracking Issue:** <Issue number if applicable> open-telemetry#32681

**Testing:** <Describe what testing was performed and which tests were
added.>

**Documentation:** <Describe the documentation added.>
  • Loading branch information
newly12 authored Apr 26, 2024
1 parent 2c69cae commit b7d2395
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 8 deletions.
27 changes: 27 additions & 0 deletions .chloggen/fix-stanza-matcher.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: bug_fix

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: pkg/stanza

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: "Fix issue when `exclude_older_than` is enabled without `ordering_criteria` configured"

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [32681]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [user]
10 changes: 10 additions & 0 deletions pkg/stanza/fileconsumer/matcher/internal/filter/sort.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,16 @@ func SortTemporal(regexKey string, ascending bool, layout string, location strin
)
}

type TopNOption int

//nolint:unparam
func (t TopNOption) apply(items []*item) ([]*item, error) {
if len(items) <= int(t) {
return items, nil
}
return items[:t], nil
}

type mtimeSortOption struct{}

type mtimeItem struct {
Expand Down
11 changes: 3 additions & 8 deletions pkg/stanza/fileconsumer/matcher/matcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ func New(c Criteria) (*Matcher, error) {
if c.OrderingCriteria.TopN == 0 {
c.OrderingCriteria.TopN = defaultOrderingCriteriaTopN
}
m.topN = c.OrderingCriteria.TopN

var regex *regexp.Regexp
if orderingCriteriaNeedsRegex(c.OrderingCriteria.SortBy) {
Expand Down Expand Up @@ -138,6 +137,8 @@ func New(c Criteria) (*Matcher, error) {
}
}

m.filterOpts = append(m.filterOpts, filter.TopNOption(c.OrderingCriteria.TopN))

return m, nil
}

Expand All @@ -156,7 +157,6 @@ type Matcher struct {
include []string
exclude []string
regex *regexp.Regexp
topN int
filterOpts []filter.Option
}

Expand All @@ -178,10 +178,5 @@ func (m Matcher) MatchFiles() ([]string, error) {
if len(result) == 0 {
return result, errors.Join(err, errs)
}

if len(result) <= m.topN {
return result, errors.Join(err, errs)
}

return result[:m.topN], errors.Join(err, errs)
return result, errs
}

0 comments on commit b7d2395

Please sign in to comment.