Skip to content

Commit

Permalink
[chore] Remove usage of pointers for state in metadata (open-telemetr…
Browse files Browse the repository at this point in the history
…y#37784)

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

<!-- Issue number (e.g. open-telemetry#1234) or full URL to issue, if applicable. -->
#### Link to tracking issue
Fixes

<!--Describe what testing was performed and which tests were added.-->
#### Testing

<!--Describe the documentation added.-->
#### Documentation

<!--Please delete paragraphs that you did not use before submitting.-->

Signed-off-by: Bogdan Drutu <[email protected]>
  • Loading branch information
bogdandrutu authored and khushijain21 committed Feb 14, 2025
1 parent 0e1651c commit 9f68359
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 19 deletions.
27 changes: 27 additions & 0 deletions .chloggen/not-sure-understand.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: 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 `flush.WithPeriod`.

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

# (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: [api]
13 changes: 4 additions & 9 deletions pkg/stanza/fileconsumer/internal/reader/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,15 @@ func (f *Factory) NewReader(file *os.File, fp *fingerprint.Fingerprint) (*Reader
m := &Metadata{
Fingerprint: fp,
FileAttributes: attributes,
TokenLenState: &tokenlen.State{},
}
if f.FlushTimeout > 0 {
m.FlushState = &flush.State{LastDataChange: time.Now()}
TokenLenState: tokenlen.State{},
FlushState: flush.State{
LastDataChange: time.Now(),
},
}
return f.NewReaderFromMetadata(file, m)
}

func (f *Factory) NewReaderFromMetadata(file *os.File, m *Metadata) (r *Reader, err error) {
// Ensure TokenLenState is initialized
if m.TokenLenState == nil {
m.TokenLenState = &tokenlen.State{}
}

r = &Reader{
Metadata: m,
set: f.TelemetrySettings,
Expand Down
4 changes: 2 additions & 2 deletions pkg/stanza/fileconsumer/internal/reader/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ type Metadata struct {
RecordNum int64
FileAttributes map[string]any
HeaderFinalized bool
FlushState *flush.State
TokenLenState *tokenlen.State
FlushState flush.State
TokenLenState tokenlen.State
}

// Reader manages a single file
Expand Down
6 changes: 0 additions & 6 deletions pkg/stanza/flush/flush.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,3 @@ func (s *State) Func(splitFunc bufio.SplitFunc, period time.Duration) bufio.Spli
return 0, nil, nil
}
}

// Deprecated: [v0.88.0] Use WithFunc instead.
func WithPeriod(splitFunc bufio.SplitFunc, period time.Duration) bufio.SplitFunc {
s := &State{LastDataChange: internaltime.Now()}
return s.Func(splitFunc, period)
}
2 changes: 0 additions & 2 deletions pkg/stanza/flush/flush_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ func TestNewlineSplitFunc(t *testing.T) {
}

for _, tc := range testCases {
t.Run(tc.name+"/WithPeriod", splittest.New(WithPeriod(tc.baseFunc, tc.flushPeriod), tc.input, tc.steps...))

previousState := &State{LastDataChange: time.Now()}
t.Run(tc.name+"/Func", splittest.New(previousState.Func(tc.baseFunc, tc.flushPeriod), tc.input, tc.steps...))
}
Expand Down

0 comments on commit 9f68359

Please sign in to comment.