-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Make state comparison more generic #4190
Conversation
filebeat/input/file/state.go
Outdated
|
||
// IsEqual compares the state to an other state supporing stringer based on the unique string | ||
func (s *State) IsEqual(c fmt.Stringer) bool { | ||
return s.String() == c.String() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Somehow relying on String()
functions seems dangerous to me. Perhaps you could have the same logic, but based on a string id
that is only computed once and stored in the state?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I initially had a ID()
function for comparison. I switched it to String()
because the Stringer
interface already exist. But perhaps have a local interface with ID() string
is a better choice? +1 on storing it locally and not generating it every time, as it should not change over time.
New version pushed |
For the state comparison FileStateOS was accessed directly. By having new prospector types there might be different state objects. This is a first step to remove the dependency on FileStateOS and do state comparison string based.
@@ -10,6 +10,7 @@ import ( | |||
|
|||
// State is used to communicate the reading state of a file | |||
type State struct { | |||
Id string `json:"-"` // local unique id to make comparison more efficient |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[golint] reported by reviewdog 🐶
struct field Id should be ID
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this can't be ID as it otherwise conflicts with the ID() method.
filebeat/input/file/state.go
Outdated
@@ -33,6 +34,20 @@ func NewState(fileInfo os.FileInfo, path string, t string) State { | |||
} | |||
} | |||
|
|||
// String returns a unique id for the state as a string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[golint] reported by reviewdog 🐶
comment on exported method State.ID should be of the form "ID ..."
For the state comparison FileStateOS was accessed directly. By having new prospector types there might be different state objects. This is a first step to remove the dependency on FileStateOS and do state comparison string based.
For the state comparison FileStateOS was accessed directly. By having new prospector types there might be different state objects. This is a first step to remove the dependency on FileStateOS and do state comparison string based.