0

I'm attempting to write a YAML config script for a load testing utility called Artillery.

The YAML syntax is not making any sense to me though. Artillery appears to deserialize the YAML to a Javascript object syntax so it expects nodes in the YAML file to have a certain structure.

config:
  target: https://mhhs-prod-webapp.azurewebsites.net/
  phases:
    - duration: 60
      arrivalRate: 50
scenarios:
  - flow:
    - get:
      url: '/'

Given the above file though it fails complaining that 'get' must be of type object. In the file above the get node has a child node url of key value type, so I'm expecting it to be of type object.

After much trial and error I've managed to get it to work using the following layout.

config:
  target: https://mhhs-prod-webapp.azurewebsites.net/
  phases:
    - duration: 60
      arrivalRate: 50
scenarios:
  - flow:
    - get:
        url: '/'

But the bizarre thing is that this file is identical to the previous one apart from the fact that the url node is indented 4 spaces instead of the 2 spaces of indentation used throughout the rest of the file.

Is this correct? I'm having trouble finding an explanation of YAML that is understandable but so far I haven't come across anything that suggests that different amounts of indentation do completely different things.

Neutrino
  • 8,496
  • 4
  • 57
  • 83
  • I'll just summarize my answer o'er here. It's like Python indentation, you mistakingly indent it and you make a lot of unintended consequences. – JumperBot_ Jul 14 '22 at 08:23
  • I added a second comment to my last comment. I might've forgot to mention you there. – JumperBot_ Jul 14 '22 at 09:36

1 Answers1

1

Hohoho, I understand how you feel about YAML indentations.

It's like Python-based indentation but with a mix of JSON.

In your code:

  config:
    ...
  scenarios:
    - flow:
      - get:
        url: '/'

"url" looks like a child of "flow" since it has an indent like so.

It can go in a couple of routes.

Route #1: (Where "url" is under "flow:")

  ...
  scenarios:
    - flow:
      - get:
      - url: '/'

Route #2: (Where "url" is under "get:")

  ...
  scenarios:
    - flow:
      - get:
        - url: '/'

Route #3: (Where "url" is under~ uhm...)

  config:
    ...
  scenarios:
    ...
  url: '/'
JumperBot_
  • 551
  • 1
  • 6
  • 19
  • Surely in your duplication of my example `url` is a child of `get` not a child of `flow`. It's indented under `get`. – Neutrino Jul 14 '22 at 08:30
  • @Neutrino If you take a look at it, it goes with the same indentation as "get", and "get" is under "flow", that means that "url" is also a child of "flow". A parent can have as many child(s) (or children) as necessary. – JumperBot_ Jul 14 '22 at 08:44
  • `- get` is indented 4 spaces, `url` is indented 6 spaces. Are you suggesting that whether a value is considered indented or not is dependent on whether or not its parent starts with a `- ` and if so the `- ` is ignored and the parent and child items are pretended to be at the same indentation level? – Neutrino Jul 14 '22 at 08:51
  • @Neutrino I am sorry but you are very wrong (but you corrected yourself at the very end though), "- get" is indented 6 spaces, the " - " is for readability hence it is ignored and considered as "whitespace". – JumperBot_ Jul 14 '22 at 08:53
  • I noticed the silence, yes the " - " is for readability AND for declaring a list item. All I said there was that "- get" and "url" technically have the same indent value once evaluated. – JumperBot_ Jul 14 '22 at 09:02
  • So whether it's considered indented or not isn't based purely on whether it's actually indented, but on whether it's indented and whether it has a `- ` in front of it, so it can actually be indented but considered not indented. Thanks I understand enough now to get this to work. I must say though that has to be the singular most stupid parsing rule I've ever come across in 25 years of programming. – Neutrino Jul 14 '22 at 16:38
  • 1
    @Neutrino As a self-taught youngin', I agree with you, basing indentation on the words themselves and not the symbols before them looks stupid and confusing enough that it did took me 5-10 mins to realize that it was like that when I first tried YAML. – JumperBot_ Jul 15 '22 at 00:00