streamnative / apache-pulsar-grafana-dashboard

Apache Pulsar Grafana Dashboard
Apache License 2.0
91 stars 93 forks source link

Fix escape problem of double curly-braces in jinja2 template #85

Closed ciiiii closed 2 years ago

ciiiii commented 2 years ago

Fix errors like this:

Traceback (most recent call last):
  File "/opt/homebrew/bin/j2", line 8, in <module>
    sys.exit(main())
  File "/opt/homebrew/lib/python3.9/site-packages/j2cli/cli.py", line 202, in main
    output = render_command(
  File "/opt/homebrew/lib/python3.9/site-packages/j2cli/cli.py", line 186, in render_command
    result = renderer.render(args.template, context)
  File "/opt/homebrew/lib/python3.9/site-packages/j2cli/cli.py", line 85, in render
    return self._env \
  File "/opt/homebrew/lib/python3.9/site-packages/jinja2/environment.py", line 1301, in render
    self.environment.handle_exception()
  File "/opt/homebrew/lib/python3.9/site-packages/jinja2/environment.py", line 936, in handle_exception
    raise rewrite_traceback_stack(source=source)
  File "/path/to/apache-pulsar-grafana-dashboard/dashboards.template/zookeeper-3.6.json.j2", line 140, in top-level template code
    "legendFormat": "{{instance}} znode_count",
jinja2.exceptions.UndefinedError: 'instance' is undefinedTraceback (most recent call last):
  File "/opt/homebrew/bin/j2", line 8, in <module>
    sys.exit(main())
  File "/opt/homebrew/lib/python3.9/site-packages/j2cli/cli.py", line 202, in main
    output = render_command(
  File "/opt/homebrew/lib/python3.9/site-packages/j2cli/cli.py", line 186, in render_command
    result = renderer.render(args.template, context)
  File "/opt/homebrew/lib/python3.9/site-packages/j2cli/cli.py", line 85, in render
    return self._env \
  File "/opt/homebrew/lib/python3.9/site-packages/jinja2/environment.py", line 1301, in render
    self.environment.handle_exception()
  File "/opt/homebrew/lib/python3.9/site-packages/jinja2/environment.py", line 936, in handle_exception
    raise rewrite_traceback_stack(source=source)
  File "/path/to/apache-pulsar-grafana-dashboard/dashboards.template/zookeeper-3.6.json.j2", line 140, in top-level template code
    "legendFormat": "{{instance}} znode_count",
jinja2.exceptions.UndefinedError: 'instance' is undefined
ciiiii commented 2 years ago

also referred in https://github.com/streamnative/apache-pulsar-grafana-dashboard/issues/66#issuecomment-1076396148