question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cast phase config strings to numbers in order to support ENV vars

See original GitHub issue

The Issue

When using ENV-based config for phases, for example:

config:
  phases:
    - duration: "{{ $processEnvironment.DURATION }}"
      arrivalRate: "{{ $processEnvironment.ARRIVAL_RATE }}"
      rampTo: "{{ $processEnvironment.RAMP_TO }}" # The troublemaker

The scenario does not run as expected (finishes early). In my anecdotal setup the rampTo bit is what introduces the issue.

Why does this happen?

The process environment variables which become the spec entry values are strings, and the various mathematical operations on these here: https://github.com/artilleryio/artillery/blob/74baeac42a7bfb9ad9378ce7b9a01f4535eb1490/core/lib/phases.js#L85-L92

And here: https://github.com/artilleryio/artillery/blob/74baeac42a7bfb9ad9378ce7b9a01f4535eb1490/core/lib/phases.js#L118

Are likely the culprit.

The Solution

PR introduces a conversion of defined phase config entries (based on a keys whitelist) expected to have numerical values.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
idpbondcommented, May 12, 2021

Hi @xyngfei

Sorry for not double-checking, but it looks like the env-casting feature #978 + #1025 was not yet merged into a tagged release.

I’ll have to defer to @hassy as I’m not sure how the folks at artillery do master -> x.y.z release merging

However, if you must use this feature and can’t wait for a tagged version, you can do the following:

# Install artillery@master from github directly
npm i -D git://github.com/artilleryio/artillery#master
# demo.yml
config:
  target: "https://example.com"
  # --- Commenting out the plugin ---
  # plugins:
  #   expect: {}
  phases:
    - name: "ramp up"
      duration: "{{ $processEnvironment.art_sustain_duration }}"
      rampTo: "{{ $processEnvironment.art_rampto }}"
      arrivalRate: "{{ $processEnvironment.art_arrivalRate }}"
scenarios:
  - name: "test demo site"
    flow:
      - post:
          url: "/api"
          capture:
            - json: "$.success"
              as: success
            - json: "$.errors"
              as: errors
          expect:
            - statusCode: 404
art_arrivalRate=1 art_rampto=20 art_sustain_duration=30 ./node_modules/.bin/artillery run --output report.json demo.yml

Which, for me, produced a successful (in that it finished) test:

************************************************************

All virtual users done. Summary report:

Total time: 31 seconds
http.request_rate: .................................. 12/sec
http.response_rate: ................................. 12/sec
vusers.created_by_name.test demo site: .............. 160
vusers.created.total: ............................... 160
vusers.failed: ...................................... 161
http.requests: ...................................... 160
http.codes.404: ..................................... 161
http.responses: ..................................... 161
http.response_time:
  min: .............................................. 88.2
  max: .............................................. 354.4
  median: ........................................... 133
  p95: .............................................. 206.5
  p99: .............................................. 262.5
1reaction
idpbondcommented, May 11, 2021

@xyngfei

  1. Does this happen on artillery@1.7.2 ?
  2. If so, can you provide a stripped down way (CLI or yml) to reproduce the issue?
Read more comments on GitHub >

github_iconTop Results From Across the Web

Using Environment Variables | Cloud Functions Documentation
Setting runtime environment variables · Open the Functions Overview page in the Google Cloud console: · Click Create function. · Fill in the...
Read more >
Jenkins Pipeline Environment Variables - The Definitive Guide
In this blog post, I will show you how you can work with Jenkins pipeline environment variables effectively. You will learn how to...
Read more >
Environment variables — dynaconf 2.2.3 documentation
All configuration parameters, including custom environments and dynaconf configuration, can be overridden through environment variables.
Read more >
using process.env in TypeScript - node.js - Stack Overflow
env can be indexed with a string in order to get a string back (or undefined , if the variable isn't set). To...
Read more >
How To Handle Environment Variables With Kubernetes?
Environment variables are a common way for developers to move application and infrastructure configuration into an external source outside ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found