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

[Heartbeat] Refactor config system #23467

Merged
merged 45 commits into from
Feb 17, 2021
Merged

Conversation

andrewvc
Copy link
Contributor

@andrewvc andrewvc commented Jan 12, 2021

This PR:

  • Refactors the config for synthetics suites to act as regular monitors under heartbeat.monitors rather than have the new top-level synthetic.suites syntax we've been using so far.
  • Changes the behavior of local suites to copy their data into the container rather than run directly off the shared docker volume
  • Adds a first-class notion of aliasing to monitor types, so that synthetics/http monitors show up as http, and not as a distinct type (applies to all monitor types)
  • Simplifies the types associated with monitor plugins into a new plugin.Plugin{} struct, rather than passing around multiple values everywhere.
  • See https://github.com/elastic/beats/pull/23467/files#diff-7f1e5387c4757cca1e98483a5678e377a28ca5f9d77b267a4121a14249c96b82R7 for an example of the new config syntax

More on the change to copying local tests into the container

The rationale here is that doing so resolves any file permissions issues that may be present due to the suite directory being shared to the container as read only OR due to incompatible UIDs between the docker container and the host.

Fixes elastic/synthetics#156
Fixes #23823

As a note, no tests are added here due to the complexity of testing this small amount of I/O functionality, however, any issues should be caught by our E2E tests in https://github.com/elastic/synthetics/tree/master/__tests__/e2e . I've opened an issue to improve this situation here: #23346

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

Related issues

Takes over from #23347
Fixes elastic/synthetics#156
Fixes elastic/uptime#271

Use cases

Screenshots

Logs

The rationale here is that doing so resolves any file permissions issues
that may be present due to the suite directory being shared to the
container as read only OR due to incompatible UIDs between the docker
container and the host.

Fixes elastic/synthetics#156
@andrewvc andrewvc added enhancement Heartbeat Team:obs-ds-hosted-services Label for the Observability Hosted Services team v7.12.0 labels Jan 12, 2021
@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 Jan 12, 2021
@andrewvc andrewvc requested a review from drewr January 13, 2021 22:11
@@ -220,15 +234,7 @@ func makeAddSummary(monitorType string) jobs.JobWrapper {
if state.remaining == 0 {
up := state.up
down := state.down
if monitorType == "browser" {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now handled directly in the browser type


// setupOnlineDir is run in environments with internet access and attempts to make sure the node env
// is setup correctly.
func setupOnlineDir(dir string) (err error) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't have tests for this because this requires an internet connection and NPM to be functioning. Our E2E tests in synthetics will ultimately catch issues here. See #23346

@andrewvc andrewvc self-assigned this Feb 2, 2021
@andrewvc andrewvc marked this pull request as ready for review February 2, 2021 22:25
@andrewvc andrewvc requested a review from a team as a code owner February 2, 2021 22:25
@elasticmachine
Copy link
Collaborator

Pinging @elastic/uptime (Team:Uptime)

@andrewvc andrewvc changed the title Refactor config system [Heartbeat] Refactor config system Feb 2, 2021
Copy link
Contributor

@blakerouse blakerouse left a comment

Choose a reason for hiding this comment

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

Wow that was big! Overall this looks good.

I made a few comments, but no blockers. Also seems like your imports are random. I know we have discussed that before (about how annoying go fmt doesnt fix it), but it just make the code look dirty.

@@ -131,22 +124,30 @@ func (bt *Heartbeat) Run(b *beat.Beat) error {
}

// RunStaticMonitors runs the `heartbeat.monitors` portion of the yaml config if present.
func (bt *Heartbeat) RunStaticMonitors(b *beat.Beat) error {
func (bt *Heartbeat) RunStaticMonitors(b *beat.Beat) (stop func(), err error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this can be change to RunMonitors, seems that there is only one type of monitor at this level of the code.

@@ -89,29 +90,30 @@ func (jf *jobFactory) checkConfig() error {
return nil
}

func (jf *jobFactory) makeJobs() (j []jobs.Job, endpoints int, err error) {
func (jf *jobFactory) makePlugin() (plugin2 plugin.Plugin, err error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why the names returned parameters? Seems that the code always defines the return in the statement of the function.

}

j = append(j, wrappers.WithURLField(u, job))
}

return j, len(jf.config.Hosts), nil
return plugin.Plugin{Jobs: j, Close: nil, Endpoints: len(jf.config.Hosts)}, nil
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of having the caller know if Close is set, it would be better to always set it (to an empty function).

Or add a Close() function directly on the plugin that does the checking and calling of the actual function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do in a follow-up!

heartbeat/monitors/mocks_test.go Outdated Show resolved Hide resolved
"github.com/elastic/beats/v7/libbeat/common"
"github.com/elastic/beats/v7/libbeat/logp"
"github.com/elastic/beats/v7/x-pack/heartbeat/monitors/browser/synthexec"
)

func init() {
monitors.RegisterActive("browser", create)
monitors.RegisterActive("synthetic/browser", create)
plugin.Register("browser", create, "synthetic", "synthetics/synthetic")
Copy link
Contributor

Choose a reason for hiding this comment

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

Why the rename form synthetics/browser to just synthetics/synthetic? That just seems like weird naming.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the future we'd like to have a synthetics/api, and we use the browser language across the board from UI to backend

@andrewvc andrewvc merged commit fb25ded into elastic:master Feb 17, 2021
@andrewvc andrewvc deleted the remote-journeys branch February 17, 2021 14:25
andrewvc added a commit to andrewvc/beats that referenced this pull request Feb 17, 2021
* Refactors the config for synthetics suites to act as regular monitors under `heartbeat.monitors` rather than have the new top-level `synthetic.suites` syntax we've been using so far.
* Changes the behavior of local suites to copy their data into the container rather than run directly off the shared docker volume
* Adds a first-class notion of aliasing to monitor types, so that `synthetics/http` monitors show up as `http`, and not as a distinct type (applies to all monitor types)
* Simplifies the types associated with monitor plugins into a new `plugin.Plugin{}` struct, rather than passing around multiple values everywhere.
* See https://github.com/elastic/beats/pull/23467/files#diff-7f1e5387c4757cca1e98483a5678e377a28ca5f9d77b267a4121a14249c96b82R7 for an example of the new config syntax

#### More on the change to copying local tests into the container

The rationale here is that doing so resolves any file permissions issues that may be present due to the suite directory being shared to the container as read only OR due to incompatible UIDs between the docker container and the host.

Fixes elastic/synthetics#156
Fixes elastic#23823

As a note, no tests are added here due to the complexity of testing this small amount of I/O functionality, however, any issues should be caught by our E2E tests in https://github.com/elastic/synthetics/tree/master/__tests__/e2e . I've opened an issue to improve this situation here: elastic#23346

(cherry picked from commit fb25ded)
v1v added a commit to v1v/beats that referenced this pull request Feb 17, 2021
…dows-7

* upstream/master: (332 commits)
  Use ECS v1.8.0 (elastic#24086)
  Add support for postgresql csv logs (elastic#23334)
  [Heartbeat] Refactor config system (elastic#23467)
  [CI] install docker-compose with retry (elastic#24069)
  Add nodes to filebeat-kubernetes.yaml ClusterRole - fixes elastic#24051 (elastic#24052)
  updating manifest files for filebeat threatintel module (elastic#24074)
  Add Zeek Signatures (elastic#23772)
  Update Beats to ECS 1.8.0 (elastic#23465)
  Support running Docker logging plugin on ARM64 (elastic#24034)
  Fix ec2 metricset fields.yml and add integration test (elastic#23726)
  Only build targz and zip versions of Beats if PACKAGES is set in agent (elastic#24060)
  [Filebeat] Add field definitions for known Netflow/IPFIX vendor fields (elastic#23773)
  [Elastic Agent] Enroll with Fleet Server (elastic#23865)
  [Filebeat] Convert logstash logEvent.action objects to strings (elastic#23944)
  [Ingest Management] Fix reloading of log level for services (elastic#24055)
  Add Agent standalone k8s manifest (elastic#23679)
  [Metricbeat][Kubernetes] Extend state_node with more conditions (elastic#23905)
  [CI] googleStorageUploadExt step (elastic#24048)
  Check fields are documented for aws metricsets (elastic#23887)
  Update go-concert to 0.1.0 (elastic#23770)
  ...
andrewvc added a commit that referenced this pull request Feb 17, 2021
* Refactors the config for synthetics suites to act as regular monitors under `heartbeat.monitors` rather than have the new top-level `synthetic.suites` syntax we've been using so far.
* Changes the behavior of local suites to copy their data into the container rather than run directly off the shared docker volume
* Adds a first-class notion of aliasing to monitor types, so that `synthetics/http` monitors show up as `http`, and not as a distinct type (applies to all monitor types)
* Simplifies the types associated with monitor plugins into a new `plugin.Plugin{}` struct, rather than passing around multiple values everywhere.
* See https://github.com/elastic/beats/pull/23467/files#diff-7f1e5387c4757cca1e98483a5678e377a28ca5f9d77b267a4121a14249c96b82R7 for an example of the new config syntax

#### More on the change to copying local tests into the container

The rationale here is that doing so resolves any file permissions issues that may be present due to the suite directory being shared to the container as read only OR due to incompatible UIDs between the docker container and the host.

Fixes elastic/synthetics#156
Fixes #23823

As a note, no tests are added here due to the complexity of testing this small amount of I/O functionality, however, any issues should be caught by our E2E tests in https://github.com/elastic/synthetics/tree/master/__tests__/e2e . I've opened an issue to improve this situation here: #23346

(cherry picked from commit fb25ded)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Heartbeat Team:obs-ds-hosted-services Label for the Observability Hosted Services team v7.12.0
Projects
None yet
3 participants