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

x-pack/filebeat/input/streaming: add falcon hose stream follower #40838

Merged
merged 4 commits into from
Sep 23, 2024

Conversation

efd6
Copy link
Contributor

@efd6 efd6 commented Sep 16, 2024

Proposed commit message

See title.

Checklist

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have made corresponding change to the default configuration files
  • I have added tests that prove my fix is effective or that my feature works
  • I have added an entry in CHANGELOG.next.asciidoc or CHANGELOG-developer.next.asciidoc.

Disruptive User Impact

Author's Checklist

  • [ ]

How to test this PR locally

Related issues

Use cases

Screenshots

Logs

@efd6 efd6 added enhancement Filebeat Filebeat Team:Security-Service Integrations Security Service Integrations Team labels Sep 16, 2024
@efd6 efd6 self-assigned this Sep 16, 2024
@botelastic botelastic bot added needs_team Indicates that the issue/PR needs a Team:* label and removed needs_team Indicates that the issue/PR needs a Team:* label labels Sep 16, 2024
Copy link
Contributor

mergify bot commented Sep 16, 2024

This pull request does not have a backport label.
If this is a bug or security fix, could you label this PR @efd6? 🙏.
For such, you'll need to label your PR with:

  • The upcoming major version of the Elastic Stack
  • The upcoming minor version of the Elastic Stack (if you're not pushing a breaking change)

To fixup this pull request, you need to add the backport labels for the needed
branches, such as:

  • backport-8./d is the label to automatically backport to the 8./d branch. /d is the digit

Copy link
Contributor

mergify bot commented Sep 16, 2024

backport-8.x has been added to help with the transition to the new branch 8.x.
If you don't need it please use backport-skip label and remove the backport-8.x label.

@mergify mergify bot added the backport-8.x Automated backport to the 8.x branch with mergify label Sep 16, 2024
@efd6 efd6 force-pushed the 40264-crowdstrike branch 3 times, most recently from 3fd22c6 to 473744b Compare September 16, 2024 07:01
@efd6 efd6 marked this pull request as ready for review September 16, 2024 09:08
@efd6 efd6 requested a review from a team as a code owner September 16, 2024 09:08
@elasticmachine
Copy link
Collaborator

Pinging @elastic/security-service-integrations (Team:Security-Service Integrations)

@pierrehilbert pierrehilbert added the Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team label Sep 16, 2024
@elasticmachine
Copy link
Collaborator

Pinging @elastic/elastic-agent-data-plane (Team:Elastic-Agent-Data-Plane)

@pierrehilbert pierrehilbert requested review from belimawr and rdner and removed request for mauri870 and VihasMakwana September 16, 2024 12:19
Copy link
Contributor

@belimawr belimawr left a comment

Choose a reason for hiding this comment

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

Could you also look at the lint warnings?

Comment on lines 203 to 214
if offset > 0 {
feedURL, err := url.Parse(r.FeedURL)
if err != nil {
log.Fatalf("failed to parse feed url: %v", err)
}
feedQuery, err := url.ParseQuery(feedURL.RawQuery)
if err != nil {
log.Fatalf("failed to parse feed query: %v", err)
}
feedQuery.Set("offset", strconv.Itoa(offset))
feedURL.RawQuery = feedQuery.Encode()
r.FeedURL = feedURL.String()
}
Copy link
Contributor

Choose a reason for hiding this comment

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

The calls to log.Fatalf on this block will cause Filebeat to exit instantly. An input failure should not crash the whole Filebeat instance.

If there is no way for the input to recover, returning an error, logging and stopping the input would be the best way to handle it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is accidental leftovers from the original toy.

Comment on lines +235 to +241
if err != nil {
s.metrics.errorsTotal.Inc()
if err == io.EOF {
s.log.Info("stream ended, restarting")
return state, nil
}
return state, Warning{fmt.Errorf("error decoding event: %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.

An EOF just signals the end of the stream, looking at how it's handled, I believe it should not be counted as an error for metrics.

Suggested change
if err != nil {
s.metrics.errorsTotal.Inc()
if err == io.EOF {
s.log.Info("stream ended, restarting")
return state, nil
}
return state, Warning{fmt.Errorf("error decoding event: %w", err)}
}
if err != nil {
if err == io.EOF {
s.log.Info("stream ended, restarting")
return state, nil
}
s.metrics.errorsTotal.Inc()
return state, Warning{fmt.Errorf("error decoding event: %w", err)}
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, in this case an EOF would only happen if something went wrong in keeping up with session refresh requests. So I would like to keep this as an error metric addition.

@efd6
Copy link
Contributor Author

efd6 commented Sep 16, 2024

wrt to the lint complaints, I fixed the errors that it noted that are meaningful. The two remaining are related to untouched code (the unused field) and what is an antipattern of using errors.Is always; in the case that it notes, io.EOF is never wrapped and is bound by go1compat to retain this behaviour.

@efd6 efd6 requested a review from a team as a code owner September 16, 2024 20:53
@rdner rdner removed their request for review September 17, 2024 12:57
@efd6 efd6 requested a review from belimawr September 17, 2024 20:36
Copy link
Contributor

@belimawr belimawr left a comment

Choose a reason for hiding this comment

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

LGTM, there is an error that should be wrapped, but aside from that, all good.

}
feedQuery, err := url.ParseQuery(feedURL.RawQuery)
if err != nil {
log.Fatalf("failed to parse feed query: %v", err)
return state, Warning{fmt.Errorf("failed to parse feed query: %v", err)}
Copy link
Contributor

Choose a reason for hiding this comment

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

That's a valid warning from the lint, the error should be wrapped

Suggested change
return state, Warning{fmt.Errorf("failed to parse feed query: %v", err)}
return state, Warning{fmt.Errorf("failed to parse feed query: %w", err)}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks

Copy link
Contributor

mergify bot commented Sep 18, 2024

This pull request is now in conflicts. Could you fix it? 🙏
To fixup this pull request, you can check out it locally. See documentation: https://help.github.com/articles/checking-out-pull-requests-locally/

git fetch upstream
git checkout -b 40264-crowdstrike upstream/40264-crowdstrike
git merge upstream/main
git push upstream 40264-crowdstrike

@efd6 efd6 requested a review from a team September 20, 2024 22:00
@efd6
Copy link
Contributor Author

efd6 commented Sep 20, 2024

/cc @elastic/ingest-eng-prod for codeowners change.

@efd6
Copy link
Contributor Author

efd6 commented Sep 23, 2024

/test

Copy link
Contributor

@dliappis dliappis left a comment

Choose a reason for hiding this comment

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

LGTM from the ingest-eng-prod PoV for the change in the CODEOWNERS file (the directory websocket was renamed to streaming in #40421)

@efd6 efd6 merged commit e561736 into elastic:main Sep 23, 2024
18 of 20 checks passed
mergify bot pushed a commit that referenced this pull request Sep 23, 2024
efd6 added a commit that referenced this pull request Sep 24, 2024
) (#40944)

(cherry picked from commit e561736)

Co-authored-by: Dan Kortschak <dan.kortschak@elastic.co>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-8.x Automated backport to the 8.x branch with mergify enhancement Filebeat Filebeat Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team Team:Security-Service Integrations Security Service Integrations Team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Re-work websocket input to support Crowdstrike streaming API format
6 participants