-
Notifications
You must be signed in to change notification settings - Fork 18
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
Added UDPOPtionSetters: ClientNet and ClientAddr. Setters bug fixed. … #42
Open
lisitsky
wants to merge
5
commits into
gravitational:master
Choose a base branch
from
lisitsky:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
af45874
Added UDPOPtionSetters: ClientNet and ClientAddr. Setters bug fixed. …
lisitsky 3f76d21
Code cleanup:
lisitsky f790038
Remove Type field (and corresponding "type" in json output) because i…
lisitsky 67aba50
Add Target func to set UDPHook clientNet and clientAdd options at one…
lisitsky 7b5be6f
Bugfix, in specific situations logger stacktracer sees filename as ""…
lisitsky File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,3 +22,6 @@ _testmain.go | |
*.exe | ||
*.test | ||
*.prof | ||
|
||
# IDE | ||
.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,30 @@ const ( | |
// UDPOptionSetter represents functional arguments passed to ELKHook | ||
type UDPOptionSetter func(f *UDPHook) | ||
|
||
// ClientNet sets clientNet option in UDPHook | ||
// Usage: hook, err := NewUDPHook(ClientNet("tcp")) | ||
func ClientNet(clientNet string) UDPOptionSetter { | ||
return func(f *UDPHook) { | ||
f.clientNet = clientNet | ||
} | ||
} | ||
// ClientAddr sets clientAddr option in UDPHook | ||
// Usage: hook, err := NewUDPHook(ClientAddr("192.168.1.1:65000")) | ||
func ClientAddr(clientAddr string) UDPOptionSetter { | ||
return func(f *UDPHook) { | ||
f.clientAddr = clientAddr | ||
} | ||
} | ||
|
||
// Target sets clientNet and clientAddr option in UDPHook in one call | ||
// Usage: hook, err := NewUDPHook(Target("udp", "192.168.1.1:65000")) | ||
func Target(network, addr string) UDPOptionSetter { | ||
return func(f *UDPHook) { | ||
f.clientNet = network | ||
f.clientAddr = addr | ||
} | ||
} | ||
|
||
// NewUDPHook returns logrus-compatible hook that sends data to UDP socket | ||
func NewUDPHook(opts ...UDPOptionSetter) (*UDPHook, error) { | ||
f := &UDPHook{} | ||
|
@@ -57,7 +81,6 @@ type UDPHook struct { | |
|
||
type Frame struct { | ||
Time time.Time `json:"time"` | ||
Type string `json:"type"` | ||
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. Field |
||
Entry map[string]interface{} `json:"entry"` | ||
Message string `json:"message"` | ||
Level string `json:"level"` | ||
|
@@ -74,7 +97,6 @@ func (elk *UDPHook) Fire(e *log.Entry) error { | |
} | ||
data, err := json.Marshal(Frame{ | ||
Time: elk.Clock.Now().UTC(), | ||
Type: "trace", | ||
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. Field |
||
Entry: entry.Data, | ||
Message: entry.Message, | ||
Level: entry.Level.String(), | ||
|
@@ -89,7 +111,7 @@ func (elk *UDPHook) Fire(e *log.Entry) error { | |
} | ||
defer conn.Close() | ||
|
||
resolvedAddr, err := net.ResolveUDPAddr("udp", "127.0.0.1:5000") | ||
resolvedAddr, err := net.ResolveUDPAddr(elk.clientNet, elk.clientAddr) | ||
if err != nil { | ||
return Wrap(err) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
overall makes sense, one request though - instead of two functional argument parameters, let's make it one:
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.
Yes, that makes sense, simplifying calls. I can add it. But I think what if somebody needs to set only one option? Or later we need to add 3rd option? I guess setting options one-by-one forces more writing, but makes things more flexible. One can set options only he/she needs and in any order. What do you think of it?
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.
we can address those problems later, I don't think this is a big deal for now
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've added
Target
to set them at one call.