-
Notifications
You must be signed in to change notification settings - Fork 36
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
Allow pushing single paths only [+ fix flaky tests] #526
Conversation
09a409b
to
b8403d4
Compare
@@ -42,6 +42,9 @@ describe('Generator', () => { | |||
}); | |||
}); | |||
it('generate synthetics project - NPM', async () => { | |||
// In a few development environments, this test may take | |||
// a few millisseconds more than the default 15000ms timeout | |||
jest.setTimeout(30000); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Weird why this timeouts even after pw download is skipped. Its already this way -
}, 30000); |
Maybe add retries for this particular test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great catch on the NODE_ENV stuff.
src/cli.ts
Outdated
.description( | ||
'Push journeys to create montors within Kibana monitor management UI' | ||
'Push journeys in the current directory to create montors within the Kibana monitor management UI' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo: monitors
'Push journeys to create montors within Kibana monitor management UI' | ||
'Push journeys in the current directory to create montors within the Kibana monitor management UI' | ||
) | ||
.option( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why we need these options here? Subcommands should be able to access these pattern, tags, match
without any problem IIRC.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you don't add these options here they don't appear in the --help
info for the command.
See below, for example, what happens if I remove pattern
and tags
, for example:
➜ node ./dist/cli.js push --help
Usage: npx @elastic/synthetics push [options]
Push journeys in the current directory to create monitors within the Kibana monitor management UI
Options:
--match <name> push only journeys with a name or tag that matches the glob
--schedule <time-in-minutes> schedule in minutes for the pushed monitors. Setting `10`, for example, configures monitors which don't have an interval defined to run every 10
minutes.
--locations <locations...> default list of locations from which your monitors will run. (choices: "japan", "india", "singapore", "australia_east", "united_kingdom", "germany",
"canada_east", "brazil", "us_east", "us_west")
--project <project-id> id that will be used for logically grouping monitors
--url <url> kibana URL to upload the monitors
--auth <auth> API key used for Kibana authentication(https://www.elastic.co/guide/en/kibana/master/api-keys.html).
--space <space> the target Kibana spaces for the pushed monitors — spaces help you organise pushed monitors. (default: "default")
--delete automatically delete the stale monitors.
-h, --help display help for command
Now, if I keep pattern
and tags
in, they appear in push
again:
➜ node ./dist/cli.js push --help
npm run build
Usage: npx @elastic/synthetics push [options]
Push journeys in the current directory to create monitors within the Kibana monitor management UI
Options:
--pattern <pattern> RegExp file patterns to push inside current directory
--tags <name...> push only journeys with a tag that matches the glob
--match <name> push only journeys with a name or tag that matches the glob
--schedule <time-in-minutes> schedule in minutes for the pushed monitors. Setting `10`, for example, configures monitors which don't have an interval defined to run every 10
minutes.
--locations <locations...> default list of locations from which your monitors will run. (choices: "japan", "india", "singapore", "australia_east", "united_kingdom", "germany",
"canada_east", "brazil", "us_east", "us_west")
--project <project-id> id that will be used for logically grouping monitors
--url <url> kibana URL to upload the monitors
--auth <auth> API key used for Kibana authentication(https://www.elastic.co/guide/en/kibana/master/api-keys.html).
--space <space> the target Kibana spaces for the pushed monitors — spaces help you organise pushed monitors. (default: "default")
--delete automatically delete the stale monitors.
-h, --help display help for command
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@andrewvc Just looked through the changes you added, thanks for those! They LGTM.
@vigneshshanmugam also fixed the typo and responded to your comment about the option
s.
I'll go ahead and merge this one once I get an approval from one of you if that's okay.
Please feel free to just give this a 👍 when you think we can merge it.
I'm ++ on merging this ASAP! |
Summary
This PR solves #523 by allowing users to only upload the current path of monitors.
Because now users could only point to a single target file, I made sure to implement the
--match
and--tags
flags so that users could filter journeys. Otherwise, the ergonomics of the command could become inconvenient.Implementation Details
The implementation of the changes described above was quite simple: I basically pass the path to the CWD when we require the journeys so that we can still reuse the same code we had before to load them.
Then, I went on and used the same matching function to make sure we'd only bundle monitors matching the tags or names specified.
How to test this PR
init
cd
into the new project's folder (IMPORTANT!)Please also try to use
--match
and--tags
to filter different journeys that you upload.Flaky tests
The flaky tests were a funny one.
The reason they were flaky is that one of the tests would sometime take longer to return the output, and, therefore, by the time it returned it, there was more than one event in it.
As you can see above, one of these events is opening a blank page.
So what was happening was: sometimes there would be enough time to open a blank page and return that in the output, and sometimes there wouldn't be, in which case we'd get a single line:
Now,
JSON.parse
could parse a single line, but not multiple ones. Therefore, we'd see an error.Then, because cleanup (the assignment to
NODE_ENV
and its restoration) was being done within the test, it was skipped when the test failed, thus causing other tests to fail.I fixed that by parsing the output line-by-line and picking the correct event + moving cleanup to the top of the file on a hook.