Skip to content

Commit

Permalink
Add build test and remove layout overwrite
Browse files Browse the repository at this point in the history
  • Loading branch information
Miguel Rodriguez committed Jul 10, 2023
1 parent 456849a commit 73bbaae
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 2 deletions.
20 changes: 20 additions & 0 deletions .chloggen/fix-file-sort-layout-overwrite.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Use this changelog template to create an entry for release notes.
# If your change doesn't affect end users, such as a test fix or a tooling change,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.

# 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: filelogreceiver

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Fix file sort timestamp layout being overwritten

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

# (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:
3 changes: 1 addition & 2 deletions pkg/stanza/fileconsumer/file_sort.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,10 @@ func (f *TimestampSortRule) validate() error {
f.Location = "UTC"
}

layout, err := strptime.ToNative(f.Layout)
_, err := strptime.ToNative(f.Layout)
if err != nil {
return errors.Wrap(err, "parse strptime layout")
}
f.Layout = layout

return nil
}
Expand Down
36 changes: 36 additions & 0 deletions pkg/stanza/fileconsumer/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,42 @@ func TestMultiFileSort(t *testing.T) {
expectNoTokens(t, emitCalls)
}

func TestMultiFileSortTimestamp(t *testing.T) {
t.Parallel()

tempDir := t.TempDir()
cfg := NewConfig().includeDir(tempDir)
cfg.StartAt = "beginning"
cfg.MatchingCriteria.OrderingCriteria.Regex = `.*(?P<value>\d).log`
cfg.MatchingCriteria.OrderingCriteria.SortBy = []SortRuleImpl{
{
&TimestampSortRule{
BaseSortRule: BaseSortRule{
RegexKey: `value`,
SortType: "timestamp",
},
Layout: "%Y%m%d%H",
},
},
}

operator, emitCalls := buildTestManager(t, cfg)

temp1 := openTempWithPattern(t, tempDir, ".*2023020602.log")
temp2 := openTempWithPattern(t, tempDir, ".*2023020603.log")

writeString(t, temp1, "testlog1\n")
writeString(t, temp2, "testlog2\n")

require.NoError(t, operator.Start(testutil.NewMockPersister("test")))
defer func() {
require.NoError(t, operator.Stop())
}()

waitForTokens(t, emitCalls, [][]byte{[]byte("testlog2")})
expectNoTokens(t, emitCalls)
}

func TestMultiFileParallel_PreloadedFiles(t *testing.T) {
t.Parallel()

Expand Down

0 comments on commit 73bbaae

Please sign in to comment.