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

[Synthetics] stream results back for project monitors #138069

Conversation

dominiqueclarke
Copy link
Contributor

@dominiqueclarke dominiqueclarke commented Aug 4, 2022

Summary

After elastic/uptime#475, the project monitors api became much slower, often resulting in timeouts on the synthetic-agent side for even a small number of monitors, sometimes as low as 5. This PR accounts for that by streaming updates back to the synthetics agent. The final update in the stream remains the same, and consists of a full summary of the created, updated, deleted, and failed monitors.

EDIT: Added by @justinkambic:

Testing this PR

It is possible to test the push command from Synthetics with only a Kibana/ES cluster. It's also possible to test this E2E, with some additional configuration.

Testing push only

You can configure Kibana to do this in a few minutes.

  1. Start up Kibana against a clean ES cluster
  2. Navigate to Uptime
  3. Enable Monitor Management

image

4. Click `Private Locations`, and follow the flow to make an Agent Policy

image

image

5. Navigate back to Monitor Management, follow the flow to add a Private Location

image

image

6. Create an [API key](https://www.elastic.co/guide/en/kibana/master/api-keys.html) for your admin user in Kibana. 7. Checkout the [synthetics branch that supports push streaming](https://github.com/elastic/synthetics/pull/576). 8. `npm run build && npm link`. Then, make a new directory for the project you will push. `mkdir {PROJECT_NAME}`. For the sake of clarity, make this project folder the same as the private location name you specified. 9. Use the build Synthetics CLI to create your project. `node dist/cli init {PROJECT_PATH}`. Follow the prompts to configure your project. You should see your private location on the list of choices in the CLI, select that one. 10. Enter your project dir and run `npm link @elastic/synthetics`. 11. After Synthetics builds your project, run `push` to see if your project's monitors get loaded to your Kibana instance. Example: `env SYNTHETICS_API_KEY={API_KEY} npm run push`. You should see output like the example below:
> preparing all monitors
> creating all monitors
> addition and completion of single task: monitor created successfully
> adding and removing multiple tasks: monitor created successfully
> example-monitor: monitor created successfully
✓ Pushed

Testing this patch e2e

To do this, you will largely need to replicate the previous testing example, but with some additional configuration.

Firstly, set up the elastic-package utility.

  1. Run elastic-package stack up -d -v --version 8.5.0-SNAPSHOT to spin up a deployment on 8.5 that we can use for testing purposes.
  2. Modify your local Kibana to run on port 5602 with server.port: 5602. elastic-package also uses https by default now, so you'll need to modify your host config to account for this if you were using http previously. Example: elasticsearch.hosts: https://localhost:9200.
  3. Before we can run Kibana, we need to update the kibana_system password for it.
curl -X POST https://localhost:9200/_security/user/kibana_system/_password\?pretty -u elastic:changeme -H 'Content-Type: application/json' -d '{"password": "changeme" }' --insecure
  1. Start Kibana and log in, create a Private Location with the Elastic Agent policy.

image

4. Define an API key for your user. 5. Follow the instructions in the previous steps to push monitors. 6. Navigate to Uptime, you should be able to observer your monitors running:

image

Additional testing

  • Try configuring project monitors for private locations in different spaces to ensure it's working.
  • You can also create error states in Kibana's server by modifying the PR code.

@dominiqueclarke dominiqueclarke changed the title [DRAFT] [Synthetics] stream results back for project monitors to account for long running private location tasks [DRAFT] [Synthetics] stream results back for project monitors Aug 4, 2022
}
);
};
const routeHandler: RequestHandler<any, any, any> = async (context, request, response) => {
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'd like to get these types correct.

const routeDefinition = {
path: `/${removeLeadingSlash(path)}`,
validate: {
body: schema.any(),
Copy link
Contributor Author

@dominiqueclarke dominiqueclarke Aug 4, 2022

Choose a reason for hiding this comment

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

I suppose I need to remove this for get

failedMonitors: pushMonitorFormatter.failedMonitors,
failedStaleMonitors: pushMonitorFormatter.failedStaleMonitors,
});
subject?.complete();
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 suppose I need a try catch around everything, to ensure that complete is always called in the event of errors and prevent the connection from hanging.

Copy link
Member

Choose a reason for hiding this comment

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

Think in the case of error, you would need .error from the observer. Thats how Observer pattern works IIRC.

@dominiqueclarke dominiqueclarke force-pushed the fix/synthetics-private-locations-project-stream branch from b81c4e9 to c1d6913 Compare August 4, 2022 02:57
@elastic elastic deleted a comment from kibana-ci Aug 4, 2022
@dominiqueclarke dominiqueclarke force-pushed the fix/synthetics-private-locations-project-stream branch from 8fc2377 to 8d60180 Compare August 4, 2022 20:51
@justinkambic justinkambic force-pushed the fix/synthetics-private-locations-project-stream branch from 44da1ee to 76f229a Compare August 10, 2022 21:39
@justinkambic justinkambic marked this pull request as ready for review August 10, 2022 23:07
@justinkambic justinkambic requested review from a team as code owners August 10, 2022 23:07
Copy link
Contributor

@vadimkibana vadimkibana left a comment

Choose a reason for hiding this comment

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

bfetch code changes LGTM.

@botelastic botelastic bot added Feature:ExpressionLanguage Interpreter expression language (aka canvas pipeline) Team:Uptime - DEPRECATED Synthetics & RUM sub-team of Application Observability labels Aug 11, 2022
@elasticmachine
Copy link
Contributor

Pinging @elastic/uptime (Team:uptime)

@justinkambic justinkambic changed the title [DRAFT] [Synthetics] stream results back for project monitors [Synthetics] stream results back for project monitors Aug 11, 2022
@justinkambic justinkambic added release_note:skip Skip the PR/issue when compiling release notes v8.4.0 v8.5.0 bug Fixes for quality problems that affect the customer experience labels Aug 11, 2022
@justinkambic justinkambic self-assigned this Aug 11, 2022
@awahab07
Copy link
Contributor

@elasticmachine merge upstream

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
bfetch 69 71 +2
Unknown metric groups

API count

id before after diff
bfetch 78 80 +2

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

cc @justinkambic

Copy link
Contributor

@awahab07 awahab07 left a comment

Choose a reason for hiding this comment

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

LGTM

End to end tested the PR following the instructions but using a cloud 8.5 snapshot and everything works.

});
} catch (error) {
subject?.error(error);
} finally {
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 thought I added this? I guess I didn't push my last commit. :(

Copy link
Contributor

Choose a reason for hiding this comment

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

No worries, we got it in there 😄

Copy link
Contributor Author

@dominiqueclarke dominiqueclarke left a comment

Choose a reason for hiding this comment

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

LGTM! 🚢

@justinkambic justinkambic merged commit 4990478 into elastic:main Aug 15, 2022
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Aug 15, 2022
* stream results back for private locations

* update types

* consolidate apis

* adjust tests

* Fix API tests.

* Define types more clearly.

* Reintroduce default method.

* Add error handling to observable.

Co-authored-by: Justin Kambic <jk@elastic.co>
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
(cherry picked from commit 4990478)
@kibanamachine
Copy link
Contributor

💚 All backports created successfully

Status Branch Result
8.4

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

kibanamachine added a commit to kibanamachine/kibana that referenced this pull request Aug 15, 2022
elastic#138848)

* stream results back for private locations

* update types

* consolidate apis

* adjust tests

* Fix API tests.

* Define types more clearly.

* Reintroduce default method.

* Add error handling to observable.

Co-authored-by: Justin Kambic <jk@elastic.co>
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
(cherry picked from commit 4990478)

Co-authored-by: Dominique Clarke <dominique.clarke@elastic.co>
@dominiqueclarke dominiqueclarke deleted the fix/synthetics-private-locations-project-stream branch August 16, 2022 16:11
Mpdreamz pushed a commit to Mpdreamz/kibana that referenced this pull request Sep 6, 2022
* stream results back for private locations

* update types

* consolidate apis

* adjust tests

* Fix API tests.

* Define types more clearly.

* Reintroduce default method.

* Add error handling to observable.

Co-authored-by: Justin Kambic <jk@elastic.co>
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Fixes for quality problems that affect the customer experience Feature:ExpressionLanguage Interpreter expression language (aka canvas pipeline) release_note:skip Skip the PR/issue when compiling release notes Team:Uptime - DEPRECATED Synthetics & RUM sub-team of Application Observability v8.4.0 v8.5.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants