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

[Uptime] [Synthetics Integration] browser - add script recorder option #115184

Conversation

dominiqueclarke
Copy link
Contributor

@dominiqueclarke dominiqueclarke commented Oct 15, 2021

Summary

Fixes elastic/uptime#371

Adds the option to import scripts generated by the Elastic Synthetics Recorder.

Screen Shot 2021-10-04 at 7 28 28 PM

Screen Shot 2021-10-04 at 7 29 20 PM

Screen Shot 2021-10-04 at 7 29 28 PM

Testing

Setting up your e2e testing environment
Overview: You will need to run a local version of kibana and package registry to test pending changes, but will use elastic-package to run a snapshot view of elasticsearch, fleet-server, and elastic-agent. Since fleet server relies on kibana, we'll also use elastic-package to start a snapshot view of kibana exclusively for bootstrapping fleet-server, but will point our local version of kibana to a separate port. So we'll be running two versions of Kibana.

  1. Stop all instances of elasticsearch or kibana
  2. Checkout this PR. In kibana.dev.yml settings, add remove kibana.index and xpack.task_manager.index to remove legacy multitenancy features. This ensures that both our instances of Kibana can share saved objects related to fleet and agent. Also, add the following keys:
xpack.encryptedSavedObjects.encryptionKey: "12345678901234567890123456789012"
xpack.fleet.registryUrl: "http://localhost:8080"
server.port: 5602
  1. Start your local kibana instance using env BUILD_TS_REFS_DISABLE=true yarn kbn bootstrap && yarn start
  2. Update elastic package. It was recently updated to add support for the elastic-agent-complete image which contains support for running synthetics agent via heartbeat. Run go get github.com/elastic/elastic-package
  3. Run elastic-package stack up -d -v --services "elasticsearch" --version 8.0.0-SNAPSHOT.
  4. Change the password to kibana_system user curl -u elastic:changeme -X POST "http://localhost:9200/_security/user/kibana_system/_password?pretty" -H 'Content-Type: application/json' -d' { "password" : "changeme" } '
  5. Allow your local kibana to start up
  6. Checkout synthetics - add new ssl and filter params for browser monitors integrations#1778. Navigate to packages/synthetics in the repo directory. Run elastic-package clean, then elastic-package build.
  7. Run elastic-package stack up --version 8.0.0-SNAPSHOT -v --services "package-registry,kibana,elastic-agent,fleet-server" in the packages/synthetics directory. This will start up elasticsearch, fleet-server, elastic-agent, package registry AND kibana. This is because fleet-server requires kibana for bootstrapping.
  8. Navigate to your local instance of kibana at http://localhost:5602

Testing happy path

  1. Navigate to the synthetics integration at fleet/integrations/synthetics-0.3.1/add-integration
  2. Add a policy name, then select the browser type from the dropdown
  3. Select the "Script recorder" tab.
  4. Upload an inline script file. This should be a synthetics script starting with step. There are a few you can use in the synthetics repo in the examples/inline directory if you have it pulled down, or you can use the script recorder to actually create a script.
  5. Save the integration and navigate to Uptime
  6. Verify that the journey was ran

Testing invalid file

  1. Navigate to the synthetics integration at fleet/integrations/synthetics-0.3.1/add-integration
  2. Add a policy name, then select the browser type from the dropdown
  3. Select the "Script recorder" tab.
  4. Upload anything besides a javascript file. Observe the error.

Testing non inline journey

  1. Navigate to the synthetics integration at fleet/integrations/synthetics-0.3.1/add-integration
  2. Add a policy name, then select the browser type from the dropdown
  3. Select the "Script recorder" tab.
  4. Upload a .js file that does not start with step and is therefore not an inline journey. Observe the error.

@dominiqueclarke dominiqueclarke added auto-backport Deprecated - use backport:version if exact versions are needed enhancement New value added to drive a business result release_note:enhancement Team:Uptime - DEPRECATED Synthetics & RUM sub-team of Application Observability v7.16.0 v8.0.0 labels Oct 15, 2021
@dominiqueclarke dominiqueclarke marked this pull request as ready for review October 15, 2021 13:36
@dominiqueclarke dominiqueclarke requested a review from a team as a code owner October 15, 2021 13:36
@elasticmachine
Copy link
Contributor

Pinging @elastic/uptime (Team:uptime)

@dominiqueclarke dominiqueclarke force-pushed the feature/366-uptime-synthetics-integration-browser-add-script-recorder-option branch from 5ed2368 to e2ccf3a Compare October 15, 2021 14:44
…ptime-synthetics-integration-browser-add-script-recorder-option
@dominiqueclarke dominiqueclarke changed the title Feature/366 uptime synthetics integration browser add script recorder option [Uptime] [Synthetics Integration] browser - add script recorder option Oct 15, 2021
@dominiqueclarke
Copy link
Contributor Author

@elasticmachine merge upstream

}
};

// @ts-expect-error update types
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 remember why I added this. I'll remove it because I don't think it's necessary. If it is, I'll add a comment.

Copy link
Contributor

Choose a reason for hiding this comment

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

You're referring to the @ts-expect-error?

@justinkambic
Copy link
Contributor

One thing that is strangely happening for me when using the integration is the appearance of supported TLS protocols for a ZIP URL, when I'm trying to configure a monitor with the Script Recorder option.

image

Copy link
Contributor

@justinkambic justinkambic left a comment

Choose a reason for hiding this comment

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

Had a few comments but overall looks great. Let's get this merged ASAP.

const [showScript, setShowScript] = useState(false);
const { isEditable } = usePolicyConfigContext();

const handleUpload = useCallback(
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not call the hook at the parent level?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

By parent level, you mean in the SourceFields component where ScriptRecorderFields is rendered?

I suppose the reason I have it here is separation of concerns/domain. Uploading is only relevant to the ScriptRecorderFields, not the rest of the options in SourceFields, like zip url or inline.

Does that answer your question? I'm uncertain if I understood fully.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure that's fine, just wanted to make sure we had a reason for not simply wrapping the callback where it's declared vs. after it's been passed as a prop. Looking at the callback we declare to pass here, I don't see any problem with leaving it as it is.

<EuiFlyout
ownFocus
onClose={() => setShowScript(false)}
aria-labelledby="syntheticsBrowerScriptBlockHeader"
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

);
}

const MOCK_FILE_NAME = i18n.translate(
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const MOCK_FILE_NAME = i18n.translate(
const PLACEHOLDER_FILE_NAME = i18n.translate(

For clarity's sake can we rename this to avoid overloading the term MOCK?


export function Uploader({ onUpload }: Props) {
const fileReader = useRef<null | FileReader>(null);
const [error, setError] = useState<string | null>('');
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const [error, setError] = useState<string | null>('');
const [error, setError] = useState<string | null>(null);

Any reason why not?

const parsedContent = `${content}`;

if (content?.trim().slice(0, 4) !== 'step') {
throw new Error('inline scripts must begin with the keyword "step"');
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
throw new Error('inline scripts must begin with the keyword "step"');
throw new Error('Inline scripts must begin with the keyword "step"');

const parsedContent = `${content}`;

if (content?.trim().slice(0, 4) !== 'step') {
throw new Error('inline scripts must begin with the keyword "step"');
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we're only handling this error I think we don't need to throw it in the first place. Would be faster to use a conditional block, if I'm understanding this ok.

}
};

// @ts-expect-error update types
Copy link
Contributor

Choose a reason for hiding this comment

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

You're referring to the @ts-expect-error?

};

return (
<>
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
<>

Remove.

Copy link
Contributor

@justinkambic justinkambic left a comment

Choose a reason for hiding this comment

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

Checked that the TLS protocol issue was fixed, and feedback implementation seems fine.

LGTM WFG.

@dominiqueclarke
Copy link
Contributor Author

@elasticmachine merge upstream

@drewpost
Copy link

All looks good to me. Ship it.

…cript-recorder-option' of https://github.com/dominiqueclarke/kibana into feature/366-uptime-synthetics-integration-browser-add-script-recorder-option
@dominiqueclarke
Copy link
Contributor Author

@elasticmachine merge upstream

@dominiqueclarke
Copy link
Contributor Author

@elasticmachine merge upstream

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
uptime 666 669 +3

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
uptime 573.2KB 578.5KB +5.2KB

History

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

@dominiqueclarke dominiqueclarke merged commit 7800367 into elastic:master Oct 20, 2021
@dominiqueclarke dominiqueclarke deleted the feature/366-uptime-synthetics-integration-browser-add-script-recorder-option branch October 20, 2021 04:13
kibanamachine added a commit to kibanamachine/kibana that referenced this pull request Oct 20, 2021
elastic#115184)

* Add script recorder tab for browser based monitors

* implement policy edit flow for script recorder

* add tests and translations

* adjust types

* update metadata key and add test

* merge master

* adjust usePolicy and source_field

* revert merge master

* adjust types

* use reusable hook

* update zip url tls default fields

* rename content constant

* adjust error handling and remove ts-ignore

* adjust error default value

* remove unnecessary fragment

* adjust types

* update tech preview content

Co-authored-by: Kibana Machine <[email protected]>
@kibanamachine
Copy link
Contributor

💚 Backport successful

Status Branch Result
7.x

This backport PR will be merged automatically after passing CI.

kibanamachine added a commit that referenced this pull request Oct 20, 2021
#115184) (#115698)

* Add script recorder tab for browser based monitors

* implement policy edit flow for script recorder

* add tests and translations

* adjust types

* update metadata key and add test

* merge master

* adjust usePolicy and source_field

* revert merge master

* adjust types

* use reusable hook

* update zip url tls default fields

* rename content constant

* adjust error handling and remove ts-ignore

* adjust error default value

* remove unnecessary fragment

* adjust types

* update tech preview content

Co-authored-by: Kibana Machine <[email protected]>

Co-authored-by: Dominique Clarke <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-backport Deprecated - use backport:version if exact versions are needed enhancement New value added to drive a business result release_note:enhancement Team:Uptime - DEPRECATED Synthetics & RUM sub-team of Application Observability v7.16.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Synthetics integration] Add option to add script from the Elastic Synthetics Recorder
5 participants