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

feat: add support for directory and handle piped files #80

Merged
merged 4 commits into from
Oct 14, 2020
Merged

feat: add support for directory and handle piped files #80

merged 4 commits into from
Oct 14, 2020

Conversation

vigneshshanmugam
Copy link
Member

@vigneshshanmugam vigneshshanmugam commented Oct 6, 2020

  • fix Add support for specifying directory to the runner #64
  • Add first class support for handling files and directories. Also handles duplicates between files.
  • Supports --pattern flag to allow filtering based on specific files inside the directory. Only applicable when directory is passed.
  • Allows heartbeat to invoke inline suites via --inline flag as we want a way to distinguish proper node code vs source code being passed as string.
  • handle piped content both that are files as well as actual source.

Different ways you can run synthetics now

// read files from STDIN
> ls ./examples/suites/*.js | npx @elastic/synthetics

// Invoke inline journeys from stdin (same as heartbeat)
> cat examples/inline/short.js | npx @elastic/synthetics --inline

// pass directory of suites
> npx @elastic/synthetics examples/suites example/suites/journey1.js --pattern '.ts$' 

// pass array of test suites
> npx @elastic/synthetics examples/suites/journey1.js examples/suites/journey2.js

src/cli.ts Outdated
}
});
requireSuites(suites);
} else if (program.inline) {
Copy link
Member Author

Choose a reason for hiding this comment

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

@andrewvc I introduced a new flag inline as we want a distinction between the content that is coming as source code (string) vs the actual source which is a proper JS. stdin felt different as we can pipe any content which is handled differently when done like this

> ls /examples/*.js | npx @elastic/synthetics

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm thinking we should change the naming. The --inline flag comes from heartbeat where the source was "inline" with the YAML. I think it's confusing outside of that context. I think a better term is single, since it's a single journey.

Copy link
Member Author

Choose a reason for hiding this comment

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

We need distinction between single journey files vs JS string code coming from the heartbeat. The --inline flag here only deals with the later. We have first class support for files without passing any flags. Are you proposing to change this flag from --inline to --single ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, just a rename. Thoughts on naming? CC @jahtalab @paulb-elastic @justinkambic

Copy link
Member Author

Choose a reason for hiding this comment

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

I prefer inline over single, as single can both denote single file or single journey from heartbeat. But not opposed with single either.

@apmmachine
Copy link

apmmachine commented Oct 6, 2020

💔 Build Failed

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview

Expand to view the summary

Build stats

  • Build Cause: [Pull request #80 updated]

  • Start Time: 2020-10-13T11:51:48.690+0000

  • Duration: 11 min 18 sec

Test stats 🧪

Test Results
Failed 0
Passed 33
Skipped 0
Total 33

Steps errors 2

Expand to view the steps failures

  • Name: Build Docker image

    • Description:

    • Duration: 0 min 1 sec

    • Start Time: 2020-10-13T12:03:02.479+0000

    • log

  • Name: Build Docker image

    • Description:

    • Duration: 0 min 1 sec

    • Start Time: 2020-10-13T12:03:04.488+0000

    • log

Log output

Expand to view the last 100 lines of log output

[2020-10-13T12:02:57.220Z] npm notice 1.0kB   dist/parse_args.js.map              
[2020-10-13T12:02:57.220Z] npm notice 722B    dist/plugins/performance.d.ts.map   
[2020-10-13T12:02:57.220Z] npm notice 1.0kB   dist/plugins/performance.js.map     
[2020-10-13T12:02:57.220Z] npm notice 835B    dist/plugins/plugin-manager.d.ts.map
[2020-10-13T12:02:57.220Z] npm notice 1.4kB   dist/plugins/plugin-manager.js.map  
[2020-10-13T12:02:57.220Z] npm notice 2.8kB   dist/core/runner.d.ts.map           
[2020-10-13T12:02:57.220Z] npm notice 5.4kB   dist/core/runner.js.map             
[2020-10-13T12:02:57.220Z] npm notice 303B    dist/dsl/step.d.ts.map              
[2020-10-13T12:02:57.220Z] npm notice 295B    dist/dsl/step.js.map                
[2020-10-13T12:02:57.220Z] npm notice 462B    dist/plugins/tracing.d.ts.map       
[2020-10-13T12:02:57.220Z] npm notice 1.9kB   dist/plugins/tracing.js.map         
[2020-10-13T12:02:57.220Z] npm notice 435B    README.md                           
[2020-10-13T12:02:57.220Z] npm notice 458B    dist/reporters/base.d.ts            
[2020-10-13T12:02:57.220Z] npm notice 2.9kB   src/reporters/base.ts               
[2020-10-13T12:02:57.220Z] npm notice 64B     dist/cli.d.ts                       
[2020-10-13T12:02:57.220Z] npm notice 2.7kB   src/cli.ts                          
[2020-10-13T12:02:57.220Z] npm notice 523B    dist/common_types.d.ts              
[2020-10-13T12:02:57.220Z] npm notice 436B    src/common_types.ts                 
[2020-10-13T12:02:57.220Z] npm notice 869B    dist/core/gatherer.d.ts             
[2020-10-13T12:02:57.220Z] npm notice 1.5kB   src/core/gatherer.ts                
[2020-10-13T12:02:57.220Z] npm notice 697B    dist/helpers.d.ts                   
[2020-10-13T12:02:57.220Z] npm notice 1.2kB   src/helpers.ts                      
[2020-10-13T12:02:57.220Z] npm notice 380B    dist/core/index.d.ts                
[2020-10-13T12:02:57.220Z] npm notice 86B     dist/dsl/index.d.ts                 
[2020-10-13T12:02:57.220Z] npm notice 184B    dist/index.d.ts                     
[2020-10-13T12:02:57.220Z] npm notice 154B    dist/plugins/index.d.ts             
[2020-10-13T12:02:57.220Z] npm notice 207B    dist/reporters/index.d.ts           
[2020-10-13T12:02:57.220Z] npm notice 541B    src/core/index.ts                   
[2020-10-13T12:02:57.220Z] npm notice 51B     src/dsl/index.ts                    
[2020-10-13T12:02:57.220Z] npm notice 1.4kB   src/index.ts                        
[2020-10-13T12:02:57.220Z] npm notice 119B    src/plugins/index.ts                
[2020-10-13T12:02:57.220Z] npm notice 148B    src/reporters/index.ts              
[2020-10-13T12:02:57.220Z] npm notice 664B    dist/dsl/journey.d.ts               
[2020-10-13T12:02:57.220Z] npm notice 761B    src/dsl/journey.ts                  
[2020-10-13T12:02:57.220Z] npm notice 491B    dist/reporters/json.d.ts            
[2020-10-13T12:02:57.220Z] npm notice 3.6kB   src/reporters/json.ts               
[2020-10-13T12:02:57.220Z] npm notice 134B    dist/core/logger.d.ts               
[2020-10-13T12:02:57.220Z] npm notice 609B    src/core/logger.ts                  
[2020-10-13T12:02:57.220Z] npm notice 650B    dist/plugins/network.d.ts           
[2020-10-13T12:02:57.220Z] npm notice 2.2kB   src/plugins/network.ts              
[2020-10-13T12:02:57.220Z] npm notice 107B    dist/parse_args.d.ts                
[2020-10-13T12:02:57.221Z] npm notice 1.5kB   src/parse_args.ts                   
[2020-10-13T12:02:57.221Z] npm notice 690B    dist/plugins/performance.d.ts       
[2020-10-13T12:02:57.221Z] npm notice 1.3kB   src/plugins/performance.ts          
[2020-10-13T12:02:57.221Z] npm notice 813B    dist/plugins/plugin-manager.d.ts    
[2020-10-13T12:02:57.221Z] npm notice 1.7kB   src/plugins/plugin-manager.ts       
[2020-10-13T12:02:57.221Z] npm notice 2.8kB   dist/core/runner.d.ts               
[2020-10-13T12:02:57.221Z] npm notice 7.2kB   src/core/runner.ts                  
[2020-10-13T12:02:57.221Z] npm notice 246B    dist/dsl/step.d.ts                  
[2020-10-13T12:02:57.221Z] npm notice 271B    src/dsl/step.ts                     
[2020-10-13T12:02:57.221Z] npm notice 577B    dist/plugins/tracing.d.ts           
[2020-10-13T12:02:57.221Z] npm notice 2.0kB   src/plugins/tracing.ts              
[2020-10-13T12:02:57.221Z] npm notice 178.4kB dist/tsconfig.tsbuildinfo           
[2020-10-13T12:02:57.221Z] npm notice === Tarball Details === 
[2020-10-13T12:02:57.221Z] npm notice name:          @elastic/synthetics                     
[2020-10-13T12:02:57.221Z] npm notice version:       0.0.1                                   
[2020-10-13T12:02:57.221Z] npm notice filename:      elastic-synthetics-0.0.1.tgz            
[2020-10-13T12:02:57.221Z] npm notice package size:  46.8 kB                                 
[2020-10-13T12:02:57.221Z] npm notice unpacked size: 297.8 kB                                
[2020-10-13T12:02:57.221Z] npm notice shasum:        58460fb8450856f86b335fab25293391fbe66379
[2020-10-13T12:02:57.221Z] npm notice integrity:     sha512-SuEMy//M/4JZn[...]RKiWgietTYS1g==
[2020-10-13T12:02:57.221Z] npm notice total files:   103                                     
[2020-10-13T12:02:57.221Z] npm notice 
[2020-10-13T12:02:57.221Z] elastic-synthetics-0.0.1.tgz
[2020-10-13T12:02:58.551Z] $ docker rm -f f60bc7cffe49a0980f22e9c873ebaca59218fbbf9dae7a7f5ffebfce264ed729
[2020-10-13T12:02:58.678Z] $ docker stop --time=1 1e94e795164a927e886cba394749ecd03112e1facdf8ddb17bbbb87668135bd7
[2020-10-13T12:03:00.060Z] $ docker rm -f 1e94e795164a927e886cba394749ecd03112e1facdf8ddb17bbbb87668135bd7
[2020-10-13T12:03:01.259Z] Running in /var/lib/jenkins/workspace/ent-rum_elastic-synthetics_PR-80/src/github.com/elastic/synthetics
[2020-10-13T12:03:01.282Z] [INFO] getVaultSecret: Getting secrets
[2020-10-13T12:03:01.473Z] Masking supported pattern matches of $VAULT_ADDR or $VAULT_ROLE_ID or $VAULT_SECRET_ID
[2020-10-13T12:03:02.158Z] + set +x
[2020-10-13T12:03:02.421Z] Login Succeeded
[2020-10-13T12:03:02.767Z] + date +%Y-%m-%d_%H:%M
[2020-10-13T12:03:02.767Z] + docker build -t docker.elastic.co/observability-ci/synthetics:c2176966bea50fc971850b51371b9bc8aba286ce -t docker.elastic.co/observability-ci/synthetics:PR-80-8.0.0-synthetics --build-arg STACK_VERSION=8.0.0-synthetics --label BRANCH_NAME=PR-80 --label GIT_SHA=c2176966bea50fc971850b51371b9bc8aba286ce --label TIMESTAMP=2020-10-13_12:03 .
[2020-10-13T12:03:02.768Z] Sending build context to Docker daemon   2.31MB

[2020-10-13T12:03:02.768Z] Step 1/15 : ARG STACK_VERSION=7.10.0-synthetics
[2020-10-13T12:03:02.768Z] Step 2/15 : FROM docker.elastic.co/observability-ci/heartbeat:${STACK_VERSION}
[2020-10-13T12:03:02.911Z] Running in /var/lib/jenkins/workspace/ent-rum_elastic-synthetics_PR-80/src/github.com/elastic/synthetics
[2020-10-13T12:03:02.928Z] [INFO] getVaultSecret: Getting secrets
[2020-10-13T12:03:03.114Z] Masking supported pattern matches of $VAULT_ADDR or $VAULT_ROLE_ID or $VAULT_SECRET_ID
[2020-10-13T12:03:03.340Z] manifest for docker.elastic.co/observability-ci/heartbeat:8.0.0-synthetics not found: manifest unknown: manifest unknown
[2020-10-13T12:03:03.826Z] + set +x
[2020-10-13T12:03:04.406Z] Login Succeeded
[2020-10-13T12:03:04.543Z] Stage "experimental" skipped due to earlier failure(s)
[2020-10-13T12:03:04.627Z] Failed in branch Matrix - STACK_VERSION = '8.0.0-synthetics'
[2020-10-13T12:03:04.783Z] + date +%Y-%m-%d_%H:%M
[2020-10-13T12:03:04.783Z] + docker build -t docker.elastic.co/observability-ci/synthetics:c2176966bea50fc971850b51371b9bc8aba286ce -t docker.elastic.co/observability-ci/synthetics:PR-80-7.10.0-synthetics --build-arg STACK_VERSION=7.10.0-synthetics --label BRANCH_NAME=PR-80 --label GIT_SHA=c2176966bea50fc971850b51371b9bc8aba286ce --label TIMESTAMP=2020-10-13_12:03 .
[2020-10-13T12:03:04.783Z] Sending build context to Docker daemon   2.31MB

[2020-10-13T12:03:04.783Z] Step 1/15 : ARG STACK_VERSION=7.10.0-synthetics
[2020-10-13T12:03:04.783Z] Step 2/15 : FROM docker.elastic.co/observability-ci/heartbeat:${STACK_VERSION}
[2020-10-13T12:03:05.046Z] manifest for docker.elastic.co/observability-ci/heartbeat:7.10.0-synthetics not found: manifest unknown: manifest unknown
[2020-10-13T12:03:06.005Z] Stage "experimental" skipped due to earlier failure(s)
[2020-10-13T12:03:06.084Z] Failed in branch Matrix - STACK_VERSION = '7.10.0-synthetics'
[2020-10-13T12:03:06.333Z] Running on Jenkins in /var/lib/jenkins/workspace/ent-rum_elastic-synthetics_PR-80
[2020-10-13T12:03:06.366Z] [INFO] getVaultSecret: Getting secrets
[2020-10-13T12:03:06.569Z] Masking supported pattern matches of $VAULT_ADDR or $VAULT_ROLE_ID or $VAULT_SECRET_ID
[2020-10-13T12:03:07.202Z] + chmod 755 generate-build-data.sh
[2020-10-13T12:03:07.202Z] + ./generate-build-data.sh https://apm-ci.elastic.co/blue/rest/organizations/jenkins/pipelines/apm-agent-rum/elastic-synthetics/PR-80/ https://apm-ci.elastic.co/blue/rest/organizations/jenkins/pipelines/apm-agent-rum/elastic-synthetics/PR-80/runs/4 FAILURE 678253
[2020-10-13T12:03:07.753Z] INFO: curl https://apm-ci.elastic.co/blue/rest/organizations/jenkins/pipelines/apm-agent-rum/elastic-synthetics/PR-80/runs/4/steps/?limit=10000 -o steps-info.json
[2020-10-13T12:03:08.003Z] INFO: curl https://apm-ci.elastic.co/blue/rest/organizations/jenkins/pipelines/apm-agent-rum/elastic-synthetics/PR-80/runs/4/tests/?status=FAILED -o tests-errors.json

@vigneshshanmugam
Copy link
Member Author

Test failures are unrelated to the PR.

src/cli.ts Outdated Show resolved Hide resolved
@vigneshshanmugam
Copy link
Member Author

@andrewvc The PR is ready for review

Copy link
Contributor

@andrewvc andrewvc left a comment

Choose a reason for hiding this comment

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

Generally looking good, raised some questions on some points. Also, can convert the elastic-docs and sample apps to use this format?

I think we'll learn more about this pattern, particularly about hooking in to start the ruby web server. I'm thinking it may make sense, given these changes to add {before|after|around}{Suite|Step} hooks to accomplish these sorts of things, similar to how jest does it. We can look at jest and similar as inspiration.

Also, can we include one typescript example, with a shell script included showing how to run those with the special CLI flag?

src/cli.ts Outdated
}
});
requireSuites(suites);
} else if (program.inline) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm thinking we should change the naming. The --inline flag comes from heartbeat where the source was "inline" with the YAML. I think it's confusing outside of that context. I think a better term is single, since it's a single journey.

src/cli.ts Outdated Show resolved Hide resolved
src/cli.ts Outdated Show resolved Hide resolved
@vigneshshanmugam
Copy link
Member Author

vigneshshanmugam commented Oct 13, 2020

Also, can convert the elastic-docs and sample apps to use this format?

Will do once we add support for this #84. Makes it easier

We can look at jest and similar as inspiration.

Totally agree, But we can get around that for now by moving them before steps as a interim solution and add the hooks later on. WDYT?

Also, can we include one typescript example, with a shell script included showing how to run those with the special CLI flag?

Guess examples have to wait until the support for -r flag to be landed.

Copy link
Contributor

@hmdhk hmdhk left a comment

Choose a reason for hiding this comment

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

@vigneshshanmugam , As we discussed on the tech sync, we should add support for path wildcards such as the *.journey.js (it can be more complex than this) to the command line arguments (and possibly remove the --pattern option). This would be simpler compared to using command line pipes.

I'm happy to create an issue for this enhancement if you think it doesn't fit into this PR.

@vigneshshanmugam
Copy link
Member Author

@jahtalab I thought about it and tested, glob patterns parsing and matching is harder and more slower than pattern matching (We can use library). We have to pay super huge time at startup cost which i personally don't think superior considering most patterns can be done using simple pattern matching. Please create an issue, we can discuss and get others opinion as well before introducing it.

@hmdhk
Copy link
Contributor

hmdhk commented Oct 13, 2020

Thanks @vigneshshanmugam for testing it. Do you mind posting the benchmark results here for reference? this would make it easier to discuss later.

@vigneshshanmugam
Copy link
Member Author

vigneshshanmugam commented Oct 13, 2020

@jahtalab Sure, I will post the numbers on the new issue with startup cost for regex and glob patterns. Have diverged a bit currently and it would need evaluation for the filtering tag/names on journey logic as well if we need to support glob patterns.

@vigneshshanmugam
Copy link
Member Author

@andrewvc I opened #87 where I already updated few examples to reflect how it would look like in practise on handling various formats.

@andrewvc
Copy link
Contributor

I'm OK with us using regexps instead of globs. In fact, jest does this exact thing. In fact, maybe we should do that in #26 as well. While globs are more standard in UNIX tooling, they are somewhat awkward in JS.

I doubt the perf difference is meaningful here, but skipping the dependency is probably worth it.

I'm OK keeping inline for now, we can change that in another PR if need be.

@andrewvc
Copy link
Contributor

Just to clarify, if we go with the regexp I think that resolves the outstanding questions enough for me, but we need to really think about the suite use case. If we're supporting directories of files let's move our examples over to that and add supporting features like before/after. I'm fine breaking up the work here across PRs because of our experimental / unreleased status, but in the future we'll need to make those changes in a more atomic fashion IMHO.

@vigneshshanmugam
Copy link
Member Author

vigneshshanmugam commented Oct 14, 2020

@andrewvc Agreed with your points on moving the examples and supporting hooks. I have already started porting our examples in the PR #87 and didn't do in this one specifically it felt the change is already introducing too many flags, also provided an example of how a JS only version would work and did not want to do a massive PR. That said, will address all of the comments in that PR which has the required -r flag that would make porting of our TS examples easier.

Merging this PR as it is and would move the examples in the follow up PR #87

@vigneshshanmugam vigneshshanmugam merged commit b48ff27 into elastic:master Oct 14, 2020
@vigneshshanmugam vigneshshanmugam deleted the directory branch October 14, 2020 06:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for specifying directory to the runner
4 participants