-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
feat(inputs.redis): Add node discovery for clusters #15209
feat(inputs.redis): Add node discovery for clusters #15209
Conversation
Thanks so much for the pull request! |
a8bbaf7
to
3f4a9f2
Compare
3f4a9f2
to
ff4bab0
Compare
314a2ff
to
efac4c7
Compare
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.
@jeremycampbell-okta thanks for your contribution! Just a few small comments...
plugins/inputs/redis/redis.go
Outdated
str, ok := val.(string) | ||
if ok { | ||
return parseClusterNodes(str) | ||
} | ||
return nil, fmt.Errorf("could not discover nodes: %w", err) |
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 would prefer
str, ok := val.(string) | |
if ok { | |
return parseClusterNodes(str) | |
} | |
return nil, fmt.Errorf("could not discover nodes: %w", err) | |
str, ok := val.(string) | |
if !ok { | |
return nil, fmt.Errorf("could not discover nodes: %w", err) | |
} | |
return parseClusterNodes(str) |
and maybe fold the parseClusterNodes
function into this 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.
I liked separating parseClusterNodes to make it more easily/directly testable. Can you say more about why you prefer to fold it in?
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.
(To add to this...I expect maintenance of this function may take some work as/if Redis cluster nodes
format changes in the future. As you can see from the tests, there are already 3 variations.)
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.
It's mostly a personal preference but splitting code into two functions, i.e. there is only one caller, where the caller side is very small usually requires the reader to jump between different places and makes following the flow more difficult. Like in this example, the discoverNodes
function reads, "do a API call and parse the result". This adds no information to the reader as you cannot see how and what is parsed.
The splitting can be reasonable IMO if a) there are many processing steps, b) a lot of branches or c) complex processing steps. None of those criteria are applicable here as the parsing is fairly "simple" in terms of code...
Download PR build artifacts for linux_amd64.tar.gz, darwin_arm64.tar.gz, and windows_amd64.zip. 📦 Click here to get additional PR build artifactsArtifact URLs |
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 @jeremycampbell-okta!
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 for jumping on this! Two Three small nits and a question about closing the clients that I'd like your thoughts on. Thanks again!
## Enabling this feature triggers the execution of a `cluster nodes` command | ||
## at each metric gathering interval. This command automatically detects | ||
## all cluster nodes and retrieves metrics from each of them. | ||
# node_discovery = true |
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 config should show the default values.
# node_discovery = true | |
# node_discovery = false |
## Enabling this feature triggers the execution of a `cluster nodes` command | ||
## at each metric gathering interval. This command automatically detects | ||
## all cluster nodes and retrieves metrics from each of them. | ||
# node_discovery = true |
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.
# node_discovery = true | |
# node_discovery = false |
val, err := client.Do("string", "cluster", "nodes") | ||
|
||
if err != nil { | ||
return nil, err | ||
} |
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.
val, err := client.Do("string", "cluster", "nodes") | |
if err != nil { | |
return nil, err | |
} | |
val, err := client.Do("string", "cluster", "nodes") | |
if err != nil { | |
return nil, err | |
} |
@@ -302,7 +347,7 @@ func (r *Redis) connect() error { | |||
// Reads stats from all configured servers accumulates stats. | |||
// Returns one of the errors encountered while gather stats (if any). | |||
func (r *Redis) Gather(acc telegraf.Accumulator) error { | |||
if !r.connected { | |||
if !r.connected || r.NodeDiscovery { |
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.
Hmm if we re-create the slice of clients during each gather, should we also be calling client.Close()
on the existing clients first inside connect()
?
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 can test this out. I haven't seen any rise in client connectivity in my deployed tests, but this would add some certainty.
Hello! I am closing this issue due to inactivity. I hope you were able to resolve your problem, if not please try posting this question in our Community Slack or Community Forums or provide additional details in this issue and reqeust that it be re-opened. Thank you! |
@jeremycampbell-okta I would very much like to see this land. I think the only thing left was closing the connection. Is this something you are still looking into? |
Summary
Enables Redis Cluster node discovery for Telegraf Redis plug-in, so all nodes get their Metrics scraped.
Checklist
Related issues
resolves #15199