Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pkg/stanza][fileconsumer] Remove/unexport deprecated fields #24688

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .chloggen/pkg-stanza-fileconsumer-deprecated.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# 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: breaking

# 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: Remove deprecated 'fileconsumer.FileAttributes'

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

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

21 changes: 21 additions & 0 deletions .chloggen/pkg-stanza-fileconsumer-deprecated2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# 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: breaking

# 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: Remove deprecated 'fileconsumer.EmitFunc'

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

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

21 changes: 21 additions & 0 deletions .chloggen/pkg-stanza-fileconsumer-deprecated3.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# 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: breaking

# 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: Remove deprecated `fileconsumer.Finder`

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

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

21 changes: 21 additions & 0 deletions .chloggen/pkg-stanza-fileconsumer-deprecated4.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# 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: breaking

# 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: Remove deprecated `fileconsumer.BaseSortRule` and `fileconsumer.SortRuleImpl`

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

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

21 changes: 21 additions & 0 deletions .chloggen/pkg-stanza-fileconsumer-deprecated5.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# 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: breaking

# 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: Remove deprecated 'fileconsumer.Reader'

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

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

24 changes: 0 additions & 24 deletions pkg/stanza/fileconsumer/attributes.go

This file was deleted.

2 changes: 1 addition & 1 deletion pkg/stanza/fileconsumer/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func (c Config) buildManager(logger *zap.SugaredLogger, emit emit.Callback, fact
maxBatchFiles: c.MaxConcurrentFiles / 2,
maxBatches: c.MaxBatches,
deleteAfterRead: c.DeleteAfterRead,
knownFiles: make([]*Reader, 0, 10),
knownFiles: make([]*reader, 0, 10),
seenPaths: make(map[string]struct{}, 100),
}, nil
}
Expand Down
20 changes: 10 additions & 10 deletions pkg/stanza/fileconsumer/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,10 @@ func TestUnmarshal(t *testing.T) {
Expect: func() *mockOperatorConfig {
cfg := NewConfig()
cfg.OrderingCriteria.Regex = `err\.[a-zA-Z]\.\d+\.(?P<rotation_time>\d{10})\.log`
cfg.OrderingCriteria.SortBy = []SortRuleImpl{
cfg.OrderingCriteria.SortBy = []sortRuleImpl{
{
&TimestampSortRule{
BaseSortRule: BaseSortRule{
baseSortRule: baseSortRule{
SortType: sortTypeTimestamp,
RegexKey: "rotation_time",
Ascending: true,
Expand All @@ -185,10 +185,10 @@ func TestUnmarshal(t *testing.T) {
Expect: func() *mockOperatorConfig {
cfg := NewConfig()
cfg.OrderingCriteria.Regex = `err\.(?P<file_num>[a-zA-Z])\.\d+\.\d{10}\.log`
cfg.OrderingCriteria.SortBy = []SortRuleImpl{
cfg.OrderingCriteria.SortBy = []sortRuleImpl{
{
&NumericSortRule{
BaseSortRule: BaseSortRule{
baseSortRule: baseSortRule{
SortType: sortTypeNumeric,
RegexKey: "file_num",
},
Expand Down Expand Up @@ -575,10 +575,10 @@ func TestBuild(t *testing.T) {
{
"BadOrderingCriteriaRegex",
func(f *Config) {
f.OrderingCriteria.SortBy = []SortRuleImpl{
f.OrderingCriteria.SortBy = []sortRuleImpl{
{
&NumericSortRule{
BaseSortRule: BaseSortRule{
baseSortRule: baseSortRule{
RegexKey: "value",
SortType: sortTypeNumeric,
},
Expand All @@ -593,10 +593,10 @@ func TestBuild(t *testing.T) {
"BasicOrderingCriteriaTimetsamp",
func(f *Config) {
f.OrderingCriteria.Regex = ".*"
f.OrderingCriteria.SortBy = []SortRuleImpl{
f.OrderingCriteria.SortBy = []sortRuleImpl{
{
&TimestampSortRule{
BaseSortRule: BaseSortRule{
baseSortRule: baseSortRule{
RegexKey: "value",
SortType: sortTypeTimestamp,
},
Expand All @@ -611,10 +611,10 @@ func TestBuild(t *testing.T) {
"GoodOrderingCriteriaTimestamp",
func(f *Config) {
f.OrderingCriteria.Regex = ".*"
f.OrderingCriteria.SortBy = []SortRuleImpl{
f.OrderingCriteria.SortBy = []sortRuleImpl{
{
&TimestampSortRule{
BaseSortRule: BaseSortRule{
baseSortRule: baseSortRule{
RegexKey: "value",
SortType: sortTypeTimestamp,
},
Expand Down
33 changes: 15 additions & 18 deletions pkg/stanza/fileconsumer/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,13 @@ const (
logFilePathResolved = "log.file.path_resolved"
)

// Deprecated: [v0.82.0] Use emit.Callback instead. This will be removed in a future release, tentatively v0.84.0.
type EmitFunc func(ctx context.Context, attrs *FileAttributes, token []byte)

type Manager struct {
*zap.SugaredLogger
wg sync.WaitGroup
cancel context.CancelFunc

readerFactory readerFactory
finder Finder
finder MatchingCriteria
roller roller
persister operator.Persister

Expand All @@ -43,7 +40,7 @@ type Manager struct {
maxBatchFiles int
deleteAfterRead bool

knownFiles []*Reader
knownFiles []*reader
seenPaths map[string]struct{}

currentFps []*fingerprint.Fingerprint
Expand All @@ -59,7 +56,7 @@ func (m *Manager) Start(persister operator.Persister) error {
return fmt.Errorf("read known files from database: %w", err)
}

if files, err := m.finder.FindFiles(); err != nil {
if files, err := m.finder.findFiles(); err != nil {
m.Warnw("error occurred while finding files", "error", err.Error())
} else if len(files) == 0 {
m.Warnw("no files match the configured include patterns",
Expand Down Expand Up @@ -119,7 +116,7 @@ func (m *Manager) poll(ctx context.Context) {
batchesProcessed := 0

// Get the list of paths on disk
matches, err := m.finder.FindFiles()
matches, err := m.finder.findFiles()
if err != nil {
m.Errorf("error finding files: %s", err)
}
Expand All @@ -142,7 +139,7 @@ func (m *Manager) poll(ctx context.Context) {

func (m *Manager) consume(ctx context.Context, paths []string) {
m.Debug("Consuming files")
readers := make([]*Reader, 0, len(paths))
readers := make([]*reader, 0, len(paths))
for _, path := range paths {
r := m.makeReader(path)
if r != nil {
Expand All @@ -156,9 +153,9 @@ func (m *Manager) consume(ctx context.Context, paths []string) {
m.roller.readLostFiles(ctx, readers)

var wg sync.WaitGroup
for _, reader := range readers {
for _, r := range readers {
wg.Add(1)
go func(r *Reader) {
go func(r *reader) {
defer wg.Done()
r.ReadToEnd(ctx)
// Delete a file if deleteAfterRead is enabled and we reached the end of the file
Expand All @@ -168,13 +165,13 @@ func (m *Manager) consume(ctx context.Context, paths []string) {
m.Errorf("could not delete %s", r.file.Name())
}
}
}(reader)
}(r)
}
wg.Wait()

// Save off any files that were not fully read
if m.deleteAfterRead {
unfinished := make([]*Reader, 0, len(readers))
unfinished := make([]*reader, 0, len(readers))
for _, r := range readers {
if !r.eof {
unfinished = append(unfinished, r)
Expand Down Expand Up @@ -242,7 +239,7 @@ func (m *Manager) checkDuplicates(fp *fingerprint.Fingerprint) bool {
// makeReader take a file path, then creates reader,
// discarding any that have a duplicate fingerprint to other files that have already
// been read this polling interval
func (m *Manager) makeReader(path string) *Reader {
func (m *Manager) makeReader(path string) *reader {
// Open the files first to minimize the time between listing and opening
fp, file := m.makeFingerprint(path)
if fp == nil {
Expand Down Expand Up @@ -274,7 +271,7 @@ func (m *Manager) clearCurrentFingerprints() {
// saveCurrent adds the readers from this polling interval to this list of
// known files, then increments the generation of all tracked old readers
// before clearing out readers that have existed for 3 generations.
func (m *Manager) saveCurrent(readers []*Reader) {
func (m *Manager) saveCurrent(readers []*reader) {
// Add readers from the current, completed poll interval to the list of known files
m.knownFiles = append(m.knownFiles, readers...)

Expand All @@ -290,7 +287,7 @@ func (m *Manager) saveCurrent(readers []*Reader) {
}
}

func (m *Manager) newReader(file *os.File, fp *fingerprint.Fingerprint) (*Reader, error) {
func (m *Manager) newReader(file *os.File, fp *fingerprint.Fingerprint) (*reader, error) {
// Check if the new path has the same fingerprint as an old path
if oldReader, ok := m.findFingerprintMatch(fp); ok {
return m.readerFactory.copy(oldReader, file)
Expand All @@ -300,7 +297,7 @@ func (m *Manager) newReader(file *os.File, fp *fingerprint.Fingerprint) (*Reader
return m.readerFactory.newReader(file, fp)
}

func (m *Manager) findFingerprintMatch(fp *fingerprint.Fingerprint) (*Reader, bool) {
func (m *Manager) findFingerprintMatch(fp *fingerprint.Fingerprint) (*reader, bool) {
// Iterate backwards to match newest first
for i := len(m.knownFiles) - 1; i >= 0; i-- {
oldReader := m.knownFiles[i]
Expand Down Expand Up @@ -347,7 +344,7 @@ func (m *Manager) loadLastPollFiles(ctx context.Context) error {
}

if encoded == nil {
m.knownFiles = make([]*Reader, 0, 10)
m.knownFiles = make([]*reader, 0, 10)
return nil
}

Expand All @@ -365,7 +362,7 @@ func (m *Manager) loadLastPollFiles(ctx context.Context) error {
}

// Decode each of the known files
m.knownFiles = make([]*Reader, 0, knownFileCount)
m.knownFiles = make([]*reader, 0, knownFileCount)
for i := 0; i < knownFileCount; i++ {
// Only the offset, fingerprint, and splitter
// will be used before this reader is discarded
Expand Down
2 changes: 1 addition & 1 deletion pkg/stanza/fileconsumer/file_sort.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type sortRule interface {
sort(re *regexp.Regexp, files []string) ([]string, error)
}

func (sr *SortRuleImpl) Unmarshal(component *confmap.Conf) error {
func (sr *sortRuleImpl) Unmarshal(component *confmap.Conf) error {
if !component.IsSet("sort_type") {
return fmt.Errorf("missing required field 'sort_type'")
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/stanza/fileconsumer/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -731,10 +731,10 @@ func TestMultiFileSort(t *testing.T) {
cfg := NewConfig().includeDir(tempDir)
cfg.StartAt = "beginning"
cfg.MatchingCriteria.OrderingCriteria.Regex = `.*(?P<value>\d)`
cfg.MatchingCriteria.OrderingCriteria.SortBy = []SortRuleImpl{
cfg.MatchingCriteria.OrderingCriteria.SortBy = []sortRuleImpl{
{
&NumericSortRule{
BaseSortRule: BaseSortRule{
baseSortRule: baseSortRule{
RegexKey: `value`,
},
},
Expand Down Expand Up @@ -765,10 +765,10 @@ func TestMultiFileSortTimestamp(t *testing.T) {
cfg := NewConfig().includeDir(tempDir)
cfg.StartAt = "beginning"
cfg.MatchingCriteria.OrderingCriteria.Regex = `.(?P<value>\d{10})\.log`
cfg.MatchingCriteria.OrderingCriteria.SortBy = []SortRuleImpl{
cfg.MatchingCriteria.OrderingCriteria.SortBy = []sortRuleImpl{
{
&TimestampSortRule{
BaseSortRule: BaseSortRule{
baseSortRule: baseSortRule{
RegexKey: `value`,
SortType: "timestamp",
},
Expand Down
Loading