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

Cherry-pick #18827 to 7.x: Add a GRPC listener service for Agent #18889

Merged
merged 1 commit into from
Jun 2, 2020

Conversation

blakerouse
Copy link
Contributor

Cherry-pick of PR #18827 to 7.x branch. Original message:

What does this PR do?

Adds a GRPC server implementation to the Elastic Agent. This is just the implementation, the server is not actually used by the Elastic Agent (coming in later PR).

The GRPC server maintains the currently reported status of an application (connected or not connected). Pushes config updates to the application and informs the application when to stop. A watchdog is included in the server to ensure that the application checkin every 30 seconds if not then the first missed window of time the application will be marked degraded and then after another missed window (total of 60 seconds) the application will be marked failed (currently nothing is done at this point, follow up PR will add the kill/restart logic).

Actions are also handled by the GRPC server implementation, even across connections and disconnections, including timeout of operations. A action can timeout or be cancelled depending on the application state in the GRPC server.

Usage:

type StubHandler struct{}

func (h *StubHandler) OnStatusChange(as *ApplicationState, status proto.StateObserved_Status, message string) {
	// handle status changes
}

srv, _ := server.New(logger, ":6890", &StubHandler{})
_ = srv.Start()

app := application.New(...)
as, _ := srv.Register(app)

as.UpdateConfig("new_config")

resp, err := as.PerformAction("name", map[string]interface{}{}, 30 * time.Second)  // 30 seconds to perform action

as.Stop(30 * time.Second) // 30 seconds to stop

as.Destroy()  // Remove application from server, prevent application from re-connect, and do signal stop

Why is it important?

This is need as the contract between Elastic Agent and the spawned applications has flipped where the applications now connecting back to the Agent. Support for stopping and performing actions on application was also required this PR adds those required building blocks.

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

  • Unit tests pass with data race checking go test -race github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/core/server

How to test this PR locally

go test -race github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/core/server

Related issues

* Work on the GRPC server for agent.

* Lots of testing.

* Fix data races.

* Add support for elastic license in generate_notice.py.

* Update to generate server name unique per application.

* Fix go vet on stackdriver metricset using latest protobuf.

* Fix data race issue.

* Fix tests.

(cherry picked from commit 6e91ce4)
@botelastic botelastic bot added the needs_team Indicates that the issue/PR needs a Team:* label label Jun 1, 2020
@elasticmachine
Copy link
Collaborator

Pinging @elastic/ingest-management (Team:Ingest Management)

@botelastic botelastic bot removed the needs_team Indicates that the issue/PR needs a Team:* label label Jun 1, 2020
@blakerouse blakerouse requested a review from a team June 1, 2020 20:37
@elasticmachine
Copy link
Collaborator

💔 Build Failed

Pipeline View Test View Changes Artifacts preview

Expand to view the summary

Build stats

  • Build Cause: [Pull request #18889 opened]

  • Start Time: 2020-06-01T20:37:38.823+0000

  • Duration: 70 min 10 sec

Test stats 🧪

Test Results
Failed 0
Passed 6229
Skipped 947
Total 7176

Steps errors

Expand to view the steps failures

  • Name: Report to Codecov

    • Description: curl -sSLo codecov https://codecov.io/bash for i in auditbeat filebeat heartbeat libbeat metricbeat packetbeat winlogbeat journalbeat do FILE="${i}/build/coverage/full.cov" if [ -f "${FILE}" ]; then bash codecov -f "${FILE}" fi done

    • Duration: 2 min 22 sec

    • Start Time: 2020-06-01T21:38:32.231+0000

    • log

  • Name: Mage goIntegTest

    • Description: mage goIntegTest

    • Duration: 1 min 8 sec

    • Start Time: 2020-06-01T21:01:25.016+0000

    • log

Log output

Expand to view the last 100 lines of log output

[2020-06-01T21:47:14.812Z] 	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
[2020-06-01T21:47:14.812Z] 	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[2020-06-01T21:47:14.812Z] 	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
[2020-06-01T21:47:14.812Z] 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
[2020-06-01T21:47:14.812Z] 	at java.lang.Thread.run(Thread.java:748)
[2020-06-01T21:47:14.812Z] No artifacts found that match the file pattern "**/build/TEST*.out". Configuration error?
[2020-06-01T21:47:15.278Z] + curl -sSLo codecov https://codecov.io/bash
[2020-06-01T21:47:15.850Z] + FILE=auditbeat/build/coverage/full.cov
[2020-06-01T21:47:15.850Z] + [ -f auditbeat/build/coverage/full.cov ]
[2020-06-01T21:47:15.850Z] + FILE=filebeat/build/coverage/full.cov
[2020-06-01T21:47:15.850Z] + [ -f filebeat/build/coverage/full.cov ]
[2020-06-01T21:47:15.850Z] + FILE=heartbeat/build/coverage/full.cov
[2020-06-01T21:47:15.850Z] + [ -f heartbeat/build/coverage/full.cov ]
[2020-06-01T21:47:15.850Z] + FILE=libbeat/build/coverage/full.cov
[2020-06-01T21:47:15.850Z] + [ -f libbeat/build/coverage/full.cov ]
[2020-06-01T21:47:15.850Z] + FILE=metricbeat/build/coverage/full.cov
[2020-06-01T21:47:15.850Z] + [ -f metricbeat/build/coverage/full.cov ]
[2020-06-01T21:47:15.850Z] + FILE=packetbeat/build/coverage/full.cov
[2020-06-01T21:47:15.850Z] + [ -f packetbeat/build/coverage/full.cov ]
[2020-06-01T21:47:15.850Z] + FILE=winlogbeat/build/coverage/full.cov
[2020-06-01T21:47:15.850Z] + [ -f winlogbeat/build/coverage/full.cov ]
[2020-06-01T21:47:15.850Z] + FILE=journalbeat/build/coverage/full.cov
[2020-06-01T21:47:15.850Z] + [ -f journalbeat/build/coverage/full.cov ]
[2020-06-01T21:47:19.087Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18889/src/github.com/elastic/beats
[2020-06-01T21:47:19.426Z] + find . -type f -name TEST*.xml -path */build/* -delete
[2020-06-01T21:47:19.448Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18889/src/github.com/elastic/beats/Lint
[2020-06-01T21:47:19.592Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18889/src/github.com/elastic/beats/Metricbeat-OSS-Integration-tests
[2020-06-01T21:47:19.735Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18889/src/github.com/elastic/beats/Winlogbeat-oss
[2020-06-01T21:47:19.878Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18889/src/github.com/elastic/beats/Auditbeat-crosscompile
[2020-06-01T21:47:20.020Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18889/src/github.com/elastic/beats/Elastic-Agent-x-pack
[2020-06-01T21:47:20.161Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18889/src/github.com/elastic/beats/Dockerlogbeat
[2020-06-01T21:47:20.305Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18889/src/github.com/elastic/beats/Journalbeat-oss
[2020-06-01T21:47:20.450Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18889/src/github.com/elastic/beats/Generators-Metricbeat-Linux
[2020-06-01T21:47:20.593Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18889/src/github.com/elastic/beats/Functionbeat-x-pack
[2020-06-01T21:47:20.745Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18889/src/github.com/elastic/beats/Elastic-Agent-x-pack-Windows
[2020-06-01T21:47:20.898Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18889/src/github.com/elastic/beats/Metricbeat-OSS-Unit-tests
[2020-06-01T21:47:21.054Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18889/src/github.com/elastic/beats/Metricbeat-crosscompile
[2020-06-01T21:47:21.206Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18889/src/github.com/elastic/beats/Heartbeat-oss
[2020-06-01T21:47:21.358Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18889/src/github.com/elastic/beats/Auditbeat-oss-Windows
[2020-06-01T21:47:21.502Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18889/src/github.com/elastic/beats/Auditbeat-x-pack
[2020-06-01T21:47:21.712Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18889/src/github.com/elastic/beats/Libbeat-x-pack
[2020-06-01T21:47:21.868Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18889/src/github.com/elastic/beats/Auditbeat-x-pack-Windows
[2020-06-01T21:47:22.012Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18889/src/github.com/elastic/beats/Winlogbeat-Windows-x-pack
[2020-06-01T21:47:22.155Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18889/src/github.com/elastic/beats/Filebeat-x-pack-Windows
[2020-06-01T21:47:22.304Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18889/src/github.com/elastic/beats/Packetbeat-oss
[2020-06-01T21:47:22.451Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18889/src/github.com/elastic/beats/Filebeat-Windows
[2020-06-01T21:47:22.600Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18889/src/github.com/elastic/beats/Auditbeat-oss-Linux
[2020-06-01T21:47:22.745Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18889/src/github.com/elastic/beats/Winlogbeat-Windows
[2020-06-01T21:47:22.891Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18889/src/github.com/elastic/beats/Metricbeat-Windows
[2020-06-01T21:47:23.038Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18889/src/github.com/elastic/beats/Metricbeat-x-pack-Windows
[2020-06-01T21:47:23.183Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18889/src/github.com/elastic/beats/Generators-Beat-Linux
[2020-06-01T21:47:23.330Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18889/src/github.com/elastic/beats/Filebeat-x-pack
[2020-06-01T21:47:23.479Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18889/src/github.com/elastic/beats/Functionbeat-Windows
[2020-06-01T21:47:23.629Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18889/src/github.com/elastic/beats/Heartbeat-Windows
[2020-06-01T21:47:23.775Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18889/src/github.com/elastic/beats/Metricbeat-x-pack
[2020-06-01T21:47:23.921Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18889/src/github.com/elastic/beats/Filebeat-oss
[2020-06-01T21:47:24.072Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18889/src/github.com/elastic/beats/Metricbeat-Python-integration-tests
[2020-06-01T21:47:24.218Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18889/src/github.com/elastic/beats/Libbeat-oss
[2020-06-01T21:47:24.364Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18889/src/github.com/elastic/beats/Libbeat-crosscompile
[2020-06-01T21:47:24.508Z] Running in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18889/src/github.com/elastic/beats/Libbeat-stress-tests
[2020-06-01T21:47:24.962Z] + cat
[2020-06-01T21:47:24.962Z] + /usr/local/bin/runbld ./runbld-script
[2020-06-01T21:47:24.962Z] Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF8
[2020-06-01T21:47:33.125Z] runbld>>> runbld started
[2020-06-01T21:47:33.125Z] runbld>>> 1.6.11/a66728ff8f4356963772e6e6d2069392fa06acbe
[2020-06-01T21:47:34.071Z] runbld>>> The following profiles matched the job 'Beats/beats-beats-mbp/PR-18889' in order of occurrence in the config (last value wins).
[2020-06-01T21:47:35.460Z] runbld>>> Debug logging enabled.
[2020-06-01T21:47:35.460Z] runbld>>> Storing result
[2020-06-01T21:47:35.460Z] runbld>>> Store result: created {:total 2, :successful 2, :failed 0} 1
[2020-06-01T21:47:35.460Z] runbld>>> BUILD: https://c150076387b5421f9154dfbf536e5c60.us-west1.gcp.cloud.es.io:9243/build-1587637540455/t/20200601214735-C7867871
[2020-06-01T21:47:35.460Z] runbld>>> Adding system facts.
[2020-06-01T21:47:36.406Z] runbld>>> Adding vcs info for the latest commit:  a79399da187fc74721a22c758c115d96a7430ed7
[2020-06-01T21:47:36.980Z] runbld>>> >>>>>>>>>>>> SCRIPT EXECUTION BEGIN >>>>>>>>>>>>
[2020-06-01T21:47:36.980Z] runbld>>> Adding /usr/lib/jvm/java-8-openjdk-amd64/bin to the path.
[2020-06-01T21:47:36.980Z] Processing JUnit reports with runbld...
[2020-06-01T21:47:36.980Z] + echo 'Processing JUnit reports with runbld...'
[2020-06-01T21:47:37.243Z] runbld>>> <<<<<<<<<<<< SCRIPT EXECUTION END <<<<<<<<<<<<
[2020-06-01T21:47:37.243Z] runbld>>> DURATION: 28ms
[2020-06-01T21:47:37.243Z] runbld>>> STDOUT: 40 bytes
[2020-06-01T21:47:37.243Z] runbld>>> STDERR: 49 bytes
[2020-06-01T21:47:37.243Z] runbld>>> WRAPPED PROCESS: SUCCESS (0)
[2020-06-01T21:47:37.243Z] runbld>>> Searching for build metadata in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18889/src/github.com/elastic/beats
[2020-06-01T21:47:38.632Z] runbld>>> Storing build metadata: 
[2020-06-01T21:47:38.633Z] runbld>>> Adding test report.
[2020-06-01T21:47:38.633Z] runbld>>> Searching for junit test output files with the pattern: TEST-.*\.xml$ in: /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18889/src/github.com/elastic/beats
[2020-06-01T21:47:40.022Z] runbld>>> Found 41 test output files
[2020-06-01T21:47:41.414Z] runbld>>> Test output logs contained: Errors: 0 Failures: 0 Tests: 7026 Skipped: 866
[2020-06-01T21:47:41.676Z] runbld>>> Storing result
[2020-06-01T21:47:41.676Z] runbld>>> FAILURES: 0
[2020-06-01T21:47:41.676Z] runbld>>> Store result: updated {:total 2, :successful 2, :failed 0} 2
[2020-06-01T21:47:41.676Z] runbld>>> BUILD: https://c150076387b5421f9154dfbf536e5c60.us-west1.gcp.cloud.es.io:9243/build-1587637540455/t/20200601214735-C7867871
[2020-06-01T21:47:41.676Z] runbld>>> Email notification disabled by environment variable.
[2020-06-01T21:47:41.676Z] runbld>>> Slack notification disabled by environment variable.
[2020-06-01T21:47:47.728Z] Running on Jenkins in /var/lib/jenkins/workspace/Beats_beats-beats-mbp_PR-18889
[2020-06-01T21:47:48.020Z] [INFO] getVaultSecret: Getting secrets
[2020-06-01T21:47:48.078Z] Masking supported pattern matches of $VAULT_ADDR or $VAULT_ROLE_ID or $VAULT_SECRET_ID
[2020-06-01T21:47:49.068Z] + chmod 755 generate-build-data.sh
[2020-06-01T21:47:49.068Z] + ./generate-build-data.sh https://beats-ci.elastic.co/blue/rest/organizations/jenkins/pipelines/Beats/beats-beats-mbp/PR-18889/ https://beats-ci.elastic.co/blue/rest/organizations/jenkins/pipelines/Beats/beats-beats-mbp/PR-18889/runs/1 FAILURE 4209973
[2020-06-01T21:47:49.068Z] INFO: curl https://beats-ci.elastic.co/blue/rest/organizations/jenkins/pipelines/Beats/beats-beats-mbp/PR-18889/runs/1/steps/?limit=10000 -o steps-info.json
[2020-06-01T21:47:50.412Z] INFO: curl https://beats-ci.elastic.co/blue/rest/organizations/jenkins/pipelines/Beats/beats-beats-mbp/PR-18889/runs/1/tests/?status=FAILED -o tests-errors.json

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.

backport looks good

@blakerouse blakerouse merged commit eb661f9 into elastic:7.x Jun 2, 2020
@blakerouse blakerouse deleted the backport_18827_7.x branch June 2, 2020 11:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants