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: add support for pushed monitor source #31428

Merged
merged 8 commits into from
May 16, 2022

Conversation

vigneshshanmugam
Copy link
Member

@vigneshshanmugam vigneshshanmugam commented Apr 27, 2022

heartbeat.monitors:
  - type: browser
    id: my-monitor
    name: My Monitor
    source:
      pushed:
        content: // base 64 encoded content linking to the bundled source
    schedule: "@every 1m"
  • This content would then be base64 decoded and unzipped in to the directory structure that was used to upload the monitors from the Synthetics command. HB basically does the reverse of what Synthetics CLI has done for uploading the monitors.

TODO

  • Docs on the pushed monitor source, however we can do that separately once synthetics is ready

@botelastic botelastic bot added the needs_team Indicates that the issue/PR needs a Team:* label label Apr 27, 2022
@vigneshshanmugam vigneshshanmugam added the Team:obs-ds-hosted-services Label for the Observability Hosted Services team label Apr 27, 2022
@botelastic botelastic bot removed the needs_team Indicates that the issue/PR needs a Team:* label label Apr 27, 2022
@vigneshshanmugam vigneshshanmugam changed the title Heartbeat: add support for pushed monitors Heartbeat: add support for pushed monitor source Apr 27, 2022
@elasticmachine
Copy link
Collaborator

elasticmachine commented Apr 27, 2022

💚 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 preview

Expand to view the summary

Build stats

  • Start Time: 2022-05-12T22:46:42.060+0000

  • Duration: 39 min 1 sec

Test stats 🧪

Test Results
Failed 0
Passed 135
Skipped 0
Total 135

💚 Flaky test report

Tests succeeded.

🤖 GitHub comments

To re-run your PR in the CI, just comment with:

  • /test : Re-trigger the build.

  • /package : Generate the packages and run the E2E tests.

  • /beats-tester : Run the installation tests with beats-tester.

  • run elasticsearch-ci/docs : Re-trigger the docs validation. (use unformatted text in the comment!)

@vigneshshanmugam vigneshshanmugam marked this pull request as ready for review May 10, 2022 00:17
@vigneshshanmugam vigneshshanmugam requested a review from a team as a code owner May 10, 2022 00:17
@elasticmachine
Copy link
Collaborator

Pinging @elastic/uptime (Team:Uptime)

Copy link
Contributor

@lucasfcosta lucasfcosta left a comment

Choose a reason for hiding this comment

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

Overall it LGTM but I would prefer to deal with the zipslip thing before merging this one in. Excellent work, I really like the tests (nice setup/teardown with the subtests too).

I have also E2E tested this PR by:

  1. Creating the following journey:
    import { journey, step, monitor } from "@elastic/synthetics";
    journey("latency", ({ page }) => {
      monitor.use({});
      step("load homepage", async () => {
        await page.goto("https://google.com");
      });
      step("wait for test", async () => {
        await page.waitForTimeout(2e3);
      });
    });
  2. I used this PR to bundle it into a zip
  3. Got the base64 encoded content
    base64 ~/bla.zip | pbcopy
    
  4. Created this monitor in Heartbeat pointing to my local Kibana
    - type: browser
      id: my-monitor
      name: My Monitor
      schedule: '@every 1m'
      source:
        pushed:
          content: UEsDBBQACAAIAGVllFQAAAAAAAAAAAAAAAAdAAAAc3ludGgtZXhhbXBsZS90ZXN0LmpvdXJuZXkuanOFz8FKxDAQgOF7n2LIKQtrA3rbRfHkA4g+wBCnbZamEzJTtJS+u0ldF28eAsPA/yVxDlCE9OTehbK4cfYonWdRdK+UWIJyDiROlkmHO/rCmEZySqLthec80dJepAkxcVZY4bo7giilI0SeKgAbdJkjmGcaUTT4H47KJObcXCNrRlSa/GKOYFdI2BNsB3h8grWBX6qdhey6Hc5lVe8oEeMHDBypBiXFYnuwtxAAPzHo7rU9K1szqCY5Odcz9yO1nqPZwb/s3nTl7fWv/7F1euH8FiLxrPaeHm5ePd9QSwcIGFh8rdsAAABmAQAAUEsBAi0DFAAIAAgAZWWUVBhYfK3bAAAAZgEAAB0AAAAAAAAAAAAgAKSBAAAAAHN5bnRoLWV4YW1wbGUvdGVzdC5qb3VybmV5LmpzUEsFBgAAAAABAAEASwAAACYBAAAAAA==
  5. Checked Kibana and saw results there 🎉

PS: Ideally one must either use a new locally built version of the agent or not use monitor.use to avoid the monitor failing.

x-pack/heartbeat/monitors/browser/source/zipurl.go Outdated Show resolved Hide resolved
return err
}

tf, err := ioutil.TempFile("/tmp", "elastic-synthetics-zip-")
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't we also defer the close of this file? Although we're already removing it the docs don't mention Remove closes the open handle.

PS: I found it interesting to learn how these are made to be globally unique

Copy link
Member Author

@vigneshshanmugam vigneshshanmugam May 12, 2022

Choose a reason for hiding this comment

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

Its explicity handled after the monitor run to completion, we control the close using p.Close() on any error and remove these unzipped directories.

x-pack/heartbeat/monitors/browser/source/zipurl.go Outdated Show resolved Hide resolved
Copy link
Contributor

@lucasfcosta lucasfcosta left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for the zipslip update!

@vigneshshanmugam vigneshshanmugam merged commit 2696fb2 into elastic:main May 16, 2022
@vigneshshanmugam vigneshshanmugam deleted the pushed-source branch May 16, 2022 15:38
chrisberkhout pushed a commit that referenced this pull request Jun 1, 2023
* Heartbeat: add support for pushed monitors

* link to global synthetics pkg

* add tests and link global path

* fix lint issues

* fix tests

* add changelog

* use install instead of link

* handle zipslip vul
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Team:obs-ds-hosted-services Label for the Observability Hosted Services team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Heartbeat] Introduce new source for pushed monitors
3 participants