Skip to content
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

Conversation

jeremycampbell-okta
Copy link

Summary

Enables Redis Cluster node discovery for Telegraf Redis plug-in, so all nodes get their Metrics scraped.

Checklist

  • No AI generated code was used in this PR

Related issues

resolves #15199

@telegraf-tiger
Copy link
Contributor

Thanks so much for the pull request!
🤝 ✒️ Just a reminder that the CLA has not yet been signed, and we'll need it before merging. Please sign the CLA when you get a chance, then post a comment here saying !signed-cla

@jeremycampbell-okta jeremycampbell-okta changed the title Redis plug-in node discovery feat: Redis plug-in node discovery Apr 22, 2024
@telegraf-tiger telegraf-tiger bot added the feat Improvement on an existing feature such as adding a new setting/mode to an existing plugin label Apr 22, 2024
@jeremycampbell-okta jeremycampbell-okta marked this pull request as ready for review April 23, 2024 01:27
@srebhan srebhan changed the title feat: Redis plug-in node discovery feat(inputs.redis): Add node discovery for clusters Apr 23, 2024
@telegraf-tiger telegraf-tiger bot added area/redis plugin/input 1. Request for new input plugins 2. Issues/PRs that are related to input plugins labels Apr 23, 2024
Copy link
Contributor

@srebhan srebhan left a 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 Show resolved Hide resolved
plugins/inputs/redis/redis.go Outdated Show resolved Hide resolved
Comment on lines 405 to 409
str, ok := val.(string)
if ok {
return parseClusterNodes(str)
}
return nil, fmt.Errorf("could not discover nodes: %w", err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer

Suggested change
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...

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?

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.)

Copy link
Contributor

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...

plugins/inputs/redis/redis.go Outdated Show resolved Hide resolved
@srebhan srebhan self-assigned this Apr 23, 2024
@telegraf-tiger
Copy link
Contributor

Copy link
Contributor

@srebhan srebhan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@srebhan srebhan added the ready for final review This pull request has been reviewed and/or tested by multiple users and is ready for a final review. label Apr 24, 2024
@srebhan srebhan assigned powersj and DStrand1 and unassigned srebhan Apr 24, 2024
Copy link
Contributor

@powersj powersj left a 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
Copy link
Contributor

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.

Suggested change
# 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# node_discovery = true
# node_discovery = false

Comment on lines +393 to +397
val, err := client.Do("string", "cluster", "nodes")

if err != nil {
return nil, err
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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 {
Copy link
Contributor

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()?

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.

@powersj powersj added the waiting for response waiting for response from contributor label Apr 30, 2024
@telegraf-tiger
Copy link
Contributor

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!

@telegraf-tiger telegraf-tiger bot closed this May 14, 2024
@powersj
Copy link
Contributor

powersj commented May 15, 2024

@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?

@telegraf-tiger telegraf-tiger bot removed the waiting for response waiting for response from contributor label May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/redis feat Improvement on an existing feature such as adding a new setting/mode to an existing plugin plugin/input 1. Request for new input plugins 2. Issues/PRs that are related to input plugins ready for final review This pull request has been reviewed and/or tested by multiple users and is ready for a final review.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Redis Cluster Node Discovery
4 participants