-
Notifications
You must be signed in to change notification settings - Fork 69
Add support for Redis unix sockets #64
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
7c29668
Add support for Redis unix sockets
brennentsmith ab535a7
Make `path` and `host` mutually exclusive
brennentsmith d3b9b4e
Add documentation updates
brennentsmith e2742b0
Revert logic to override rather than throw error if both path and hos…
brennentsmith 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -23,12 +23,19 @@ module LogStash module Inputs class Redis < LogStash::Inputs::Threadable | |
|
||
default :codec, "json" | ||
|
||
# The hostname of your Redis server. | ||
config :host, :validate => :string, :default => "127.0.0.1" | ||
# The hostname of your Redis server | ||
# This defaults to 127.0.0.1 if not specified. | ||
# This and :path are mutually exclusive. Will raise an ArgumentError if both are specified. | ||
config :host, :validate => :string | ||
|
||
# The port to connect on. | ||
config :port, :validate => :number, :default => 6379 | ||
|
||
# The unix socket path to connect on. Will override host and port if defined. | ||
# There is no unix socket path by default. | ||
# This and :host are mutually exclusive. Will raise an ArgumentError if both are specified. | ||
config :path, :validate => :string | ||
|
||
# The Redis database number. | ||
config :db, :validate => :number, :default => 0 | ||
|
||
|
@@ -68,7 +75,15 @@ def new_redis_instance | |
end | ||
|
||
def register | ||
@redis_url = "redis://#{@password}@#{@host}:#{@port}/#{@db}" | ||
if [email protected]? && [email protected]? | ||
raise ArgumentError.new( | ||
"Host and Path cannot be specified simultaneously. These options are exclusive." | ||
) | ||
elsif @host.nil? && @path.nil? | ||
@host = "127.0.0.1" | ||
end | ||
|
||
@redis_url = @path.nil? ? "redis://#{@password}@#{@host}:#{@port}/#{@db}" : "#{@password}@#{@path}/#{@db}" | ||
|
||
@redis_builder ||= method(:internal_redis_builder) | ||
|
||
|
@@ -114,13 +129,24 @@ def is_list_type? | |
|
||
# private | ||
def redis_params | ||
{ | ||
:host => @host, | ||
:port => @port, | ||
if @path.nil? | ||
connectionParams = { | ||
:host => @host, | ||
:port => @port | ||
} | ||
else | ||
connectionParams = { | ||
:path => @path | ||
} | ||
end | ||
|
||
baseParams = { | ||
:timeout => @timeout, | ||
:db => @db, | ||
:password => @password.nil? ? nil : @password.value | ||
} | ||
|
||
return connectionParams.merge(baseParams) | ||
end | ||
|
||
# private | ||
|
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.
I think we can keep this default here, and simple have the
:path
option overwrite host/port like described in line 34There 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.
If
:path
is set we can just log a warn saying that path is set, so we're ignoring host/portUh oh!
There was an error while loading. Please reload this page.
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.
Thanks @jsvd for the feedback. Ironically, that was actually the original logic of how this PR was constructed (see commit: 7c29668) Looks like I forgot to remove the comment on L34 in the subsequent commits 😆 .
@jordansissel - thoughts? I can see merits for both logic paths:
Frankly, I'm fine with either logic path - just let me know which pattern matches Logstash plugins best and I'll update the PR.