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

Referencing stored scripts by id does not work inside watcher actions #40212

Closed
andrershov opened this issue Mar 19, 2019 · 1 comment · Fixed by #53497
Closed

Referencing stored scripts by id does not work inside watcher actions #40212

andrershov opened this issue Mar 19, 2019 · 1 comment · Fixed by #53497

Comments

@andrershov
Copy link
Contributor

Elasticsearch version (bin/elasticsearch --version): 6.5.0

Plugins installed: none

JVM version (java -version):

java version "11" 2018-09-25
Java(TM) SE Runtime Environment 18.9 (build 11+28)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11+28, mixed mode)

Description of the problem including expected versus actual behavior:
Referencing stored scripts by id does not work inside watcher actions.

Steps to reproduce:

  1. Create a stored script
{
  "script": {
    "lang": "mustache",
    "source": "executed at {{ctx.execution_time}}"
  }
}
  1. Create a simple watcher with log action referencing this script:
{
  "trigger" : {
    "schedule" : { "interval" : "10s" }
  },
  "input" : {
    "http" : {
      "request" : {
        "host" : "localhost",
        "port" : 9200,
        "path" : "/_cluster/health"
      }
    }
  },
  "actions" : {
  "log" : { 
    "logging" : {
      "text" : {
    	 "id" : "log-action"
      }
      }
    }
  }
}

In logs you will see:

[2019-03-19T17:11:06,919][INFO ][o.e.x.w.a.l.ExecutableLoggingAction] [eQ3F5fy] log-action

instead of:

[2019-03-19T17:09:05,768][INFO ][o.e.x.w.a.l.ExecutableLoggingAction] [jR_IkMm] executed at 2019-03-19T16:09:05.739Z

This is also reproducible for other actions, such as e-mail.
The issue is not repoducible in Elasticsearch version 6.4.
The cause of the issue is most likely the following PR #33978.

In particular, this fast path triggers

int indexStartMustacheExpression = template.indexOf("{{");
if (indexStartMustacheExpression == -1) {
            return template;
 }

which treats log-action as a template.

@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-features

spinscale added a commit to spinscale/elasticsearch that referenced this issue Mar 12, 2020
The watcher TextTemplateEngine uses a fast path mechanism where it
checks for the existence of `{{` to decide if a mustache scripts
required compilation. This does not work for stored script, as the field
that is checked contains the id of the script, which means, the name of
the script is returned as its value.

This commit checks for the script type and does not involve this fast
path check if a stored script is used.

Closes elastic#40212
spinscale added a commit that referenced this issue Mar 16, 2020
The watcher TextTemplateEngine uses a fast path mechanism where it
checks for the existence of `{{` to decide if a mustache script
required compilation. This does not work for stored script, as the field
that is checked contains the id of the script, which means, the name of
the script is returned as its value.

This commit checks for the script type and does not involve this fast
path check if a stored script is used.

Closes #40212
spinscale added a commit that referenced this issue Mar 16, 2020
The watcher TextTemplateEngine uses a fast path mechanism where it
checks for the existence of `{{` to decide if a mustache script
required compilation. This does not work for stored script, as the field
that is checked contains the id of the script, which means, the name of
the script is returned as its value.

This commit checks for the script type and does not involve this fast
path check if a stored script is used.

Closes #40212
spinscale added a commit that referenced this issue Mar 16, 2020
The watcher TextTemplateEngine uses a fast path mechanism where it
checks for the existence of `{{` to decide if a mustache script
required compilation. This does not work for stored script, as the field
that is checked contains the id of the script, which means, the name of
the script is returned as its value.

This commit checks for the script type and does not involve this fast
path check if a stored script is used.

Closes #40212
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants