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

[BUG] script_exception Runtime Error When Previewing Trigger Condition in Per Cluster Metrics Monitor #978

Open
getsolaris opened this issue Oct 22, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@getsolaris
Copy link

What is the bug?

When creating a Per Cluster Metrics Monitor in the OpenSearch Plugins tab, selecting "Nodes stats" as the request type and clicking on "Preview condition response" after setting the trigger results in a script_exception runtime error.

How can one reproduce the bug?

Steps to reproduce the behavior:

  1. Go to OpenSearch Dashboards.
  2. Navigate to the "Plugins" tab and click on "Create Monitor."
  3. Select "Per Cluster Metrics Monitor" as the monitor type.
  4. For the query request type, choose "Nodes stats."
  5. Click on "Preview query" to check the query response.
  6. Set a trigger and leave the "Trigger condition" as default.
  7. Click on "Preview condition response."
  8. See the script_exception runtime error.

What is the expected behavior?

The trigger condition preview should return a valid response without throwing a script_exception runtime error.

What is your host/environment?

  • OpenSearch Version: OpenSearch 2.15 (OpenSearch_2_15_R20240904-P2)
  • �Dashboard Version: v 2.15.0
  • OS: Mac OS
  • Browser and version: Version 129.0.6668.100 (Official Build) (arm64)

Do you have any screenshots?

Screenshot 2024-10-17 at 6 01 57 PM

  • Trigger condition
ctx.results[0].nodes.NODE_ID.jvm.mem.heap_used_percent > 60
  • Trigger condition response
{
  "type" : "script_exception",
  "reason" : "runtime error",
  "script_stack" : [
    "ctx.results[0].nodes.NODE_ID.jvm.mem.heap_used_percent > 60",
    "                            ^---- HERE"
  ],
  "script" : "ctx.results[0].nodes.NODE_ID.jvm.mem.heap_used_percent > 60",
  "lang" : "painless",
  "position" : {
    "offset" : 28,
    "start" : 0,
    "end" : 59
  },
  "caused_by" : {
    "type" : "null_pointer_exception",
    "reason" : "Cannot invoke \"Object.getClass()\" because \"callArgs[0]\" is null"
  }
}

Do you have any additional context?

This error only occurs when trying to preview the trigger condition. Query preview works as expected, and the error appears during the preview of the trigger condition response.

@getsolaris getsolaris added bug Something isn't working untriaged labels Oct 22, 2024
@dblock dblock transferred this issue from opensearch-project/opensearch-plugins Oct 22, 2024
@dblock dblock transferred this issue from opensearch-project/OpenSearch Oct 22, 2024
@dblock dblock transferred this issue from opensearch-project/alerting Oct 23, 2024
@dblock dblock removed the untriaged label Nov 11, 2024
@dblock
Copy link
Member

dblock commented Nov 11, 2024

[Catch All Triage - 1, 2, 3, 4]

@AWSHurneyt
Copy link
Contributor

Hi @getsolaris,
That error is calling out that the mustache template used for the message content is malformed in some way. The error is calling out that the issue is caused by the NODE_ID portion.

{{ctx.results[0].nodes.NODE_ID.jvm.mem.heap_used_percent}}

The NODE_ID text is just a placeholder in the sample template; you'd want to supply your own node ID, as that's what will be available in the nodes stats response.

You could otherwise consider iterating through the list of nodes in the response. Although it doesn't discuss the nodes/stats API specifically, this blog post discusses iterating through results in cat/indices and cat/shards responses.
https://opensearch.org/blog/cluster-metrics-monitors-blog/#:~:text=are%20%22UNASSIGNED.%22%0A%7B%7B%23ctx.-,results,-.0.shards%7D%7D%0A%2D%20%7B%7Bindex

Here's the related mustache template for reference as well.
https://mustache.github.io/mustache.5.html#:~:text=Shown.-,Non%2DEmpty%20Lists,-If%20the%20person

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants