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

fix(inputs.ipset): Parse lines with timeout #14262

Merged
merged 2 commits into from
Nov 10, 2023

Conversation

powersj
Copy link
Contributor

@powersj powersj commented Nov 8, 2023

Parsing raw CLI output, and lines with a timeout shift the values over by two. This checks for timeout, and if it exists adds it as a field as well.

fixes: #14259

Parsing raw CLI output, and lines with a timeout shift the values over
by two. This checks for timeout, and if it exists adds it as a field as
well.

fixes: influxdata#14259
@powersj powersj marked this pull request as draft November 8, 2023 15:51
@telegraf-tiger telegraf-tiger bot added fix pr to fix corresponding bug plugin/input 1. Request for new input plugins 2. Issues/PRs that are related to input plugins labels Nov 8, 2023
@attie
Copy link

attie commented Nov 8, 2023

This looks good, but is still potentially quite fragile if things change / other situations arise in the future. (I've not tested it yet)

I'd suggest iterating over the elements in data, for example (with a pinch of salt, I'm not proficient in Go):

for i, txt := range data {
  if txt == "timeout" {
    val, err := strconv.ParseUint(data[i+1], 10, 64)
    if err != nil {
      acc.AddError(err)
    }
    fields["timeout"] = val

  } else if txt == "packets" {
    val, err := strconv.ParseUint(data[i+1], 10, 64)
    if err != nil {
      acc.AddError(err)
    }
    fields["packets_total"] = val

  } else if txt == "bytes" {
    val, err := strconv.ParseUint(data[i+1], 10, 64)
    if err != nil {
      acc.AddError(err)
    }
    fields["bytes_total"] = val

  }
}

... skipping the first few (3x) fields would probably be okay, and skipping consumed values would help too. It's certainly more processing, but I would hope it's not considered excessive given the improved robustness.

Thoughts?

@powersj
Copy link
Contributor Author

powersj commented Nov 8, 2023

is still potentially quite fragile if things change / other situations arise in the future

I completely agree, which is why I made my comment in the bug about the unfortunate situation of parsing CLI output.

would probably be okay

Agreed again. I am hesitant to change any logic when the plugin is as old as it is and we have surprisingly not received any issues prior to this but can make the change.

@attie
Copy link

attie commented Nov 8, 2023

Looks good to me, thank you!

I hope to test this out tomorrow, and I'll give my thumbs up when confirmed... though I trust your testing.

@powersj powersj marked this pull request as ready for review November 9, 2023 15:57
@powersj powersj 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 Nov 9, 2023
Copy link
Member

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

Looks good to me. Thanks @powersj!

@srebhan srebhan merged commit 7d79111 into influxdata:master Nov 10, 2023
@github-actions github-actions bot added this to the v1.28.4 milestone Nov 10, 2023
@attie
Copy link

attie commented Nov 13, 2023

"tomorrow" ... works great, many thanks!

powersj added a commit that referenced this pull request Nov 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix pr to fix corresponding bug 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.

ipset plugin does not handle unexpected fields correctly
4 participants