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

Add note about mustache template #826

Merged
merged 10 commits into from
Dec 18, 2019
Merged

Conversation

hub-cap
Copy link
Contributor

@hub-cap hub-cap commented Nov 21, 2019

closes #823

@hub-cap hub-cap added enhancement Improves the status quo :Docs Changes to the documentation labels Nov 21, 2019
@hub-cap hub-cap added this to the 1.4.0 milestone Nov 21, 2019
@hub-cap
Copy link
Contributor Author

hub-cap commented Nov 21, 2019

image

The links are the same ones from the GH issue.

Copy link
Contributor

@dliappis dliappis left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! Left a few suggestions, the main one about giving a concrete example in the put-pipeline operation docs.

@@ -626,6 +626,9 @@ Template Language

Rally uses `Jinja2 <http://jinja.pocoo.org/docs/dev/>`_ as a template language so you can use Jinja2 expressions in track files.

.. note::
Copy link
Contributor

Choose a reason for hiding this comment

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

Reading the ticket (and thinking about the maximum visibility and benefit) I think we want to have a small example besides an operation.

What if we place a second example inside the put pipeline operation doc page showing a similar example to what we have in the Elasticsearch docs for handling failure in pipelines.
We could raise the attention with a note that "if you need to use Elasticsearch Mustache {{ }} syntax you must escape it properly" (and link the note you added in this PR), for example:

{
  "name": "define-ip-geocoder",
  "operation-type": "put-pipeline",
  "id": "ip-geocoder",
  "body": {
    "description": "Extracts location information from the client IP.",
    "processors": [
      {
        "geoip": {
          "field": "clientip",
          "properties": [
            "city_name",
            "country_iso_code",
            "country_name",
            "location"
          ]
        }
      }
    ],
    "on_failure": [
      {
        "set" : {
          "field" : "_index",
          {% raw %}
          "value" : "failed-{{ _index }}"
          {% endraw %}
        }
      }        
    ]
}

^^ For the sake of not repeating things we could even just show "processors": [ ... ], as used in the Elasticsearch docs page.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dliappis I decided to just add to the existing example, and added a link from the adding tracks page.

@@ -626,6 +626,9 @@ Template Language

Rally uses `Jinja2 <http://jinja.pocoo.org/docs/dev/>`_ as a template language so you can use Jinja2 expressions in track files.

.. note::

Elasticsearch utilizes Mustache formatting in a few places, notably in `Search templates <https://www.elastic.co/guide/en/elasticsearch/reference/7.4/search-template.html>`_ and `Watcher templates <https://www.elastic.co/guide/en/elasticsearch/reference/7.4/actions-email.html>`_. If you are using Mustache in your rally templates you must `escape them properly <https://jinja.palletsprojects.com/en/2.10.x/templates/#escaping>`_.
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: we use Rally (capitalized) consistently everywhere.

Copy link
Member

@danielmitterdorfer danielmitterdorfer left a comment

Choose a reason for hiding this comment

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

I left a few comments.

@@ -626,6 +626,7 @@ Template Language

Rally uses `Jinja2 <http://jinja.pocoo.org/docs/dev/>`_ as a template language so you can use Jinja2 expressions in track files.

Elasticsearch utilizes Mustache formatting in a few places, notably in `Search templates <https://www.elastic.co/guide/en/elasticsearch/reference/7.4/search-template.html>`_ and `Watcher templates <https://www.elastic.co/guide/en/elasticsearch/reference/7.4/actions-email.html>`_. If you are using Mustache in your Rally templates you must `escape them properly <https://jinja.palletsprojects.com/en/2.10.x/templates/#escaping>`_. See :ref:`put_pipeline` for an example.
Copy link
Member

Choose a reason for hiding this comment

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

Any reason you've removed the .. note:: that you've added in the previous commit?

Copy link
Member

Choose a reason for hiding this comment

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

Nit: "Search templates" -> "search templates"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ya i removed it cuz it got big enough for a full paragraph and just looked like a huge note w/ a bunch of links, rather than some concise text. I can change it back tho if youd like

docs/track.rst Outdated
@@ -427,6 +429,16 @@ Example::
]
}
}
],
"on-failure": [
Copy link
Member

Choose a reason for hiding this comment

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

There is a syntax error in the pipeline. The element is called on_failureinstead of on-failure (see docs).

"set": {
"field": "_index",
{% raw %}
"value": "failed-{{ _index }}"
Copy link
Member

Choose a reason for hiding this comment

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

I think this is pretty complex to grasp. We should add a note about the raw / endraw tags below the example and we should also link to the Elasticsearch docs so users can lookup what this is actually doing.

Copy link
Contributor Author

@hub-cap hub-cap Dec 16, 2019

Choose a reason for hiding this comment

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

so are you saying to revert it, or to just add links to show what its doing better?

disregard: reread your comment and made a commit out of it.

Copy link
Member

@danielmitterdorfer danielmitterdorfer left a comment

Choose a reason for hiding this comment

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

Thanks for iterating. I left a couple more comments.

docs/track.rst Outdated
@@ -447,6 +447,8 @@ This example requires that the ``ingest-geoip`` Elasticsearch plugin is installe

This is an administrative operation. Metrics are not reported by default. Reporting can be forced by setting ``include-in-reporting`` to ``true``.

Please see `the pipeline documentation <https://www.elastic.co/guide/en/elasticsearch/reference/current/handling-failure-in-pipelines.html>`_ for details on handling failures in pipelines.
Copy link
Member

Choose a reason for hiding this comment

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

Maybe move this paragraph so it is directly below the example? Also, some introductory text would be nice; something along the lines of:

In the following example we setup a pipeline that ... . Note that we need to use raw / endraw texts to ensure that Rally passes the Mustache template as is and does not attempt to resolve it itself ...

(and then link back to your newly added note about templating Rally?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -626,6 +626,7 @@ Template Language

Rally uses `Jinja2 <http://jinja.pocoo.org/docs/dev/>`_ as a template language so you can use Jinja2 expressions in track files.

Elasticsearch utilizes Mustache formatting in a few places, notably in `search templates <https://www.elastic.co/guide/en/elasticsearch/reference/7.4/search-template.html>`_ and `Watcher templates <https://www.elastic.co/guide/en/elasticsearch/reference/7.4/actions-email.html>`_. If you are using Mustache in your Rally templates you must `escape them properly <https://jinja.palletsprojects.com/en/2.10.x/templates/#escaping>`_. See :ref:`put_pipeline` for an example.
Copy link
Member

Choose a reason for hiding this comment

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

Nit: If you are using Mustache in your Rally tracks?

Copy link
Member

@danielmitterdorfer danielmitterdorfer left a comment

Choose a reason for hiding this comment

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

Looks fine but I left one nit. Please merge without another review cycle after addressing it.

docs/track.rst Outdated
@@ -409,6 +409,8 @@ With the operation-type ``put-pipeline`` you can execute the `put pipeline API <
* `id` (mandatory): Pipeline id
* `body` (mandatory): Pipeline definition

In this example we setup a pipeline that adds location information to a ingested document as well as a pipeline failure block to change the index in which the document was supposed to be written. Note that we need to use the ``raw`` and ``endraw`` blocks to ensure that Rally does not attempt to resolve the Mustache template. See :ref:`template_language` for more information.
Copy link
Member

Choose a reason for hiding this comment

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

nit:

:ref:`template_language`

is rendered as:

Template Language

(i.e. upper-case)

How about we spell it out explicitly?

See the documentation about Rally's :ref:`template language <template_language>` for more information.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ohhh i did not know this was possible. TIL!

@hub-cap hub-cap merged commit 146a623 into elastic:master Dec 18, 2019
@hub-cap hub-cap deleted the note_for_escape branch December 18, 2019 21:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Docs Changes to the documentation enhancement Improves the status quo
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Document how to escape Mustache expressions in tracks
3 participants