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

Add support for Logstash as a valid Agent destination #24305

Merged
merged 8 commits into from
Jun 23, 2021

Conversation

ph
Copy link
Contributor

@ph ph commented Mar 2, 2021

This PR fixes an issue to use an logstash output as a monitoring
destination, this correctly uses the type defined in the output to
generate the appropriate output configuration for the monitoring
processes.

Fixes: 22051

What does this PR do?

Why is it important?

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.

Author's Checklist

  • [ ]

How to test this PR locally

Start logstash with this configuration:

input {
  beats {
    port => 5555
  }
}
output {
  stdout {
    codec => rubydebug
  }
}

Related issues

Use cases

Screenshots

Logs

@ph ph requested a review from michalpristas March 2, 2021 22:29
@botelastic botelastic bot added the needs_team Indicates that the issue/PR needs a Team:* label label Mar 2, 2021
@ph ph added the Team:Elastic-Agent Label for the Agent team label Mar 2, 2021
@botelastic botelastic bot removed the needs_team Indicates that the issue/PR needs a Team:* label label Mar 2, 2021
@ph ph added in progress Pull request is currently in progress. needs_team Indicates that the issue/PR needs a Team:* label labels Mar 2, 2021
@botelastic botelastic bot removed the needs_team Indicates that the issue/PR needs a Team:* label label Mar 2, 2021
@botelastic
Copy link

botelastic bot commented Mar 2, 2021

This pull request doesn't have a Team:<team> label.

@elasticmachine
Copy link
Collaborator

elasticmachine commented Mar 2, 2021

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview

Expand to view the summary

Build stats

  • Build Cause: Pull request #24305 updated

  • Start Time: 2021-06-18T20:44:31.792+0000

  • Duration: 79 min 46 sec

  • Commit: 8d82e08

Test stats 🧪

Test Results
Failed 0
Passed 6964
Skipped 16
Total 6980

Trends 🧪

Image of Build Times

Image of Tests

💚 Flaky test report

Tests succeeded.

Expand to view the summary

Test stats 🧪

Test Results
Failed 0
Passed 6964
Skipped 16
Total 6980

@ph
Copy link
Contributor Author

ph commented Mar 4, 2021

@jsvd @roaksoax Hello, I've fixed the problem with Elastic Agent when Logstash was selected as the default destination, this allow logstash to receive both normal data stream document and monitoring document.

I am looking at the e2e testing for this new output is this something we could contribute together?

FYI @mostlyjason @acchen97

@roaksoax
Copy link
Contributor

roaksoax commented Mar 9, 2021

@andsel can you please take over this?

@andsel
Copy link

andsel commented Mar 11, 2021

Hi @ph great to know about this, I think I could get a copy of this branch, build and test it locally, to check that the connection between Elastic Agent and Logstash is fine.

@ph
Copy link
Contributor Author

ph commented Mar 11, 2021

/package

@ph ph force-pushed the elastic-agent/add-support-for-logstash branch from 16a9288 to 553ff45 Compare March 11, 2021 14:11
@ph
Copy link
Contributor Author

ph commented Mar 11, 2021

/package

@ph
Copy link
Contributor Author

ph commented Mar 11, 2021

@andsel I just rebased this branch on top of master, will you take a look at elastic/e2e-testing#364 to automate it? I remember that Logstash had an integration test in the Beats plugin itself so we need to figure out what we do with this change.

@andsel
Copy link

andsel commented Mar 11, 2021

In Logstash we integration tests that runs Filebeat and Elasticsearch, I think we could add one to have Elastic Agent pushing to Logstash and to Elasticsearch. Did you mean that?

@ph
Copy link
Contributor Author

ph commented Mar 17, 2021

In Logstash we integration tests that runs Filebeat and Elasticsearch, I think we could add one to have Elastic Agent pushing to Logstash and to Elasticsearch. Did you mean that?

Yes this is exactly what I mean.

@ph ph marked this pull request as ready for review March 17, 2021 14:25
@elasticmachine
Copy link
Collaborator

Pinging @elastic/agent (Team:Agent)

@ph
Copy link
Contributor Author

ph commented Mar 17, 2021

@michalpristas this is ready for review.

} else {
typeValue = elasticsearchKey

}
Copy link

Choose a reason for hiding this comment

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

nit; It seems we have this pattern in more than one place. How about introducing a transpiler.LookupString(ast, key) (contents string, ok bool)?

if found {
v, ok := t.Value().(*transpiler.StrVal)
if !ok {
return programsToRun, nil
Copy link

Choose a reason for hiding this comment

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

Shouldn't this be an error? It looks we hit this line if someone did not follow the config format schema. If so we should rather fail instead of continuing with some 'internal' state that is difficult to understand for the user.

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 indeed should error, I've tried refactoring in this PR but it became a mess, I will create a followup issue so we can consider this as techdebt and refactor it.

@@ -171,6 +171,85 @@ GROUPLOOP:
}
}

func TestMonitoringToLogstashInjection(t *testing.T) {
Copy link

Choose a reason for hiding this comment

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

A test with an invalid configuration might be nice to have.

@mergify
Copy link
Contributor

mergify bot commented Apr 7, 2021

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 elastic-agent/add-support-for-logstash upstream/elastic-agent/add-support-for-logstash
git merge upstream/master
git push upstream elastic-agent/add-support-for-logstash

@michalpristas
Copy link
Contributor

brought it even with top before review

Copy link
Contributor

@michalpristas michalpristas left a comment

Choose a reason for hiding this comment

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

tested with local logstash and i can see logs/metrics getting in

Copy link
Contributor

@michalpristas michalpristas left a comment

Choose a reason for hiding this comment

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

please revisit getMonitoringSteps

@ph
Copy link
Contributor Author

ph commented Jun 9, 2021

@michalpristas for getMonitoringSteps can you give me more details I am not familiar with that area of the code?

@michalpristas
Copy link
Contributor

michalpristas commented Jun 9, 2021

in get monitoring steps there's part of the code which extracts elasticsearch output. it is hardcoded to extract elasticsearch output. this extracted output is then passed to generate method which composes configuration for monitoring beats. the output extracted in first step is used and passed forward

func (o *Operator) getMonitoringSteps(step configrequest.Step) []configrequest.Step {

also in the same file we use hardcoded elasticsearch type on 2 other places

This PR fixes an issue to use an logstash output as a monitoring
destination, this correctly uses the type defined in the output to
generate the appropriate output configuration for the monitoring
processes.
@ph ph force-pushed the elastic-agent/add-support-for-logstash branch from b6f385c to ecc6140 Compare June 17, 2021 20:03
@ph
Copy link
Contributor Author

ph commented Jun 17, 2021

/package

michalpristas
michalpristas previously approved these changes Jun 18, 2021
Copy link
Contributor

@michalpristas michalpristas left a comment

Choose a reason for hiding this comment

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

please fix tests, go vet ./... tells you what's wrong.
other than that code looks good

@ph ph dismissed michalpristas’s stale review June 18, 2021 15:17

I think something is off, when I was doing testing.

@ph
Copy link
Contributor Author

ph commented Jun 18, 2021

OK, I've made a change locally to getMonitoringSteps and currently writing unit tests for it.
@urso For the integration tests, I don't think this can be easily done in this repository. I am taking a look at the e2e repository how I can add a new service to the running one.

@ph
Copy link
Contributor Author

ph commented Jun 18, 2021

@michalpristas Can you do another review please using a real logstash instance. I've put a working configuration in the description above. I want more tests to make sure we don't have a regression.

Copy link
Contributor

@michalpristas michalpristas left a comment

Choose a reason for hiding this comment

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

tested with ES and LS outputs, everything seems to be working fine

@ph ph added review backport-v7.14.0 Automated backport with mergify and removed in progress Pull request is currently in progress. labels Jun 23, 2021
@ph ph merged commit 9de1352 into elastic:master Jun 23, 2021
@ph
Copy link
Contributor Author

ph commented Jun 23, 2021

Merging this and creating followup issues.

mergify bot pushed a commit that referenced this pull request Jun 23, 2021
* Add support for Logstash as a valid Agent destination

This PR fixes an issue to use an logstash output as a monitoring
destination, this correctly uses the type defined in the output to
generate the appropriate output configuration for the monitoring
processes.

(cherry picked from commit 9de1352)
ph added a commit that referenced this pull request Jun 28, 2021
* Add support for Logstash as a valid Agent destination

This PR fixes an issue to use an logstash output as a monitoring
destination, this correctly uses the type defined in the output to
generate the appropriate output configuration for the monitoring
processes.

(cherry picked from commit 9de1352)

Co-authored-by: Pier-Hugues Pellerin <phpellerin@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-v7.14.0 Automated backport with mergify review Team:Elastic-Agent Label for the Agent team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants