-
Notifications
You must be signed in to change notification settings - Fork 18
Logline specialization #63
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
Changes from all commits
50d3b24
3b9ebc7
78c7404
4a68115
519d5ce
adefea3
096653c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,8 +26,10 @@ type Topology struct { | |
| upch chan string | ||
|
|
||
| metrics MetricsClient | ||
| invalid [LogLineNumFields]int64 // count validation errors (by field) | ||
| malformed int64 // count parse or empty records | ||
| malformed int64 // count parse or empty records | ||
|
|
||
| mu sync.RWMutex // protects invalid map | ||
| invalid map[FieldIndex]int64 // tracks validation errors (by field) | ||
|
|
||
| shard func(l Record) uint64 | ||
| chain func(l Record) | ||
|
|
@@ -59,6 +61,7 @@ func NewTopologyFromConfig(cfg *Config) (*Topology, error) { | |
| return cfg.createRecord() | ||
| }, | ||
| }, | ||
| invalid: make(map[FieldIndex]int64), | ||
| } | ||
|
|
||
| // Create the metrics client first since it's injected into components parameters. | ||
|
|
@@ -369,8 +372,11 @@ func (t *Topology) runFilterChain() { | |
| // Validate against patterns | ||
| if t.validate != nil { | ||
| // call external validation function | ||
| if ok, idx := t.validate(record); !ok { | ||
| atomic.AddInt64(&t.invalid[idx], 1) | ||
| ok, idx := t.validate(record) | ||
| if !ok { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is it as fast as the previous version?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No it's not since incrementing an atomic is faster than locking a mutex. However this is the only correct way to do it. Moreover the change is only seen when there's an invalid logline, the happy path stays the same |
||
| t.mu.Lock() | ||
| t.invalid[idx]++ | ||
| t.mu.Unlock() | ||
| continue | ||
| } | ||
| } | ||
|
|
||
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.
the user should copy the logline but also rename the object, if I'm not mistaken. If true, I'd also change the code example below using something like
MyCustomLoglineThere 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.
No it's not necessary since the user will do this in its own project so in a different package so the definitions are never going to clash