jakubplichta / grafana-dashboard-builder

Generate Grafana dashboards with YAML
Apache License 2.0
147 stars 42 forks source link

Variable parsing dot char issue #174

Open manueligno78 opened 5 years ago

manueligno78 commented 5 years ago

Variable parsing fails when the variable contains a dot char inside:

- name: Test Project
  project:
    expression_variable: metricname{{label="plain_label_value", regex_label~=".*teststring.*"}}
    dashboards:
      - TestDashboard

- name: TestDashboard
  dashboard:
    title: 'TestDashboard'
    rows:
      - row:
          title: 'row'
          panels:
            - graph:
                target: '{expression_variable}'

Produce this output:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/2.7/bin/grafana-dashboard-builder", line 11, in <module>
    load_entry_point('grafana-dashboard-builder==0.5.0a2', 'console_scripts', 'grafana-dashboard-builder')()
  File "build/bdist.macosx-10.6-intel/egg/grafana_dashboards/cli.py", line 106, in main
  File "build/bdist.macosx-10.6-intel/egg/grafana_dashboards/exporter.py", line 54, in process_projects
  File "build/bdist.macosx-10.6-intel/egg/grafana_dashboards/components/base.py", line 140, in gen_json
  File "build/bdist.macosx-10.6-intel/egg/grafana_dashboards/context.py", line 59, in expand_placeholders
  File "build/bdist.macosx-10.6-intel/egg/grafana_dashboards/context.py", line 57, in expand_placeholders
  File "build/bdist.macosx-10.6-intel/egg/grafana_dashboards/context.py", line 59, in expand_placeholders
  File "build/bdist.macosx-10.6-intel/egg/grafana_dashboards/context.py", line 59, in expand_placeholders
  File "build/bdist.macosx-10.6-intel/egg/grafana_dashboards/context.py", line 57, in expand_placeholders
  File "build/bdist.macosx-10.6-intel/egg/grafana_dashboards/context.py", line 59, in expand_placeholders
  File "build/bdist.macosx-10.6-intel/egg/grafana_dashboards/context.py", line 59, in expand_placeholders
  File "build/bdist.macosx-10.6-intel/egg/grafana_dashboards/context.py", line 51, in expand_placeholders
  File "build/bdist.macosx-10.6-intel/egg/grafana_dashboards/context.py", line 69, in _expand
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/string.py", line 563, in vformat
    result = self._vformat(format_string, args, kwargs, used_args, 2)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/string.py", line 585, in _vformat
    obj, arg_used = self.get_field(field_name, args, kwargs)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/string.py", line 652, in get_field
    obj = getattr(obj, i)
AttributeError: 'unicode' object has no attribute '*teststring'
manueligno78 commented 5 years ago

This is the "workaround" I am using at the moment:

expression_variable: metricname{{{{label="plain_label_value", regex_label~=".*teststring.*"}}}}

Should be nice a more specific paragraph on READ.me about "{{{{" and "}}}}" use cases.

jammerful commented 4 years ago

Also ran into this issue