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

Unable to render snapshot when $__interval in expr #4

Open
pschonmann opened this issue Sep 25, 2024 · 1 comment
Open

Unable to render snapshot when $__interval in expr #4

pschonmann opened this issue Sep 25, 2024 · 1 comment

Comments

@pschonmann
Copy link

Using grafana 10.1.1

root@prometheus:~# grafana-snapshots -d https___google_com_2024-09-21_101558_1541855 -f 2024-09-22T00:00:00 -t 2024-09-23T00:00:00 -v
datasources OK.
panel: {'datasource': {'type': 'prometheus', 'uid': '000000001'}, 'gridPos': {'h': 4, 'w': 19, 'x': 0, 'y': 0}, 'id': 4, 'options': {'code': {'language': 'plaintext', 'showLineNumbers': False, 'showMiniMap': False}, 'content': '<table style="width:100%; height:100%;border:0px solid black;">\n     <tr>\n     <td style="text-align: center;vertical-align: middle;border:0px solid black; ">\n<span style="font-size:30px">\n    Měření doby odezvy webu\n</span>\n</td>\n</tr>\n<tr>\n     <td style="text-align: center;vertical-align: middle;border:0px solid black; ">\n<span style="font-size:30px;font-weight:900">\n    https://google.com\n</span>\n</td>\n</tr>\n</table>', 'mode': 'markdown'}, 'pluginVersion': '10.1.1', 'targets': [{'datasource': {'type': 'prometheus', 'uid': '000000001'}, 'refId': 'A'}], 'type': 'text'}
dtsrc: {'type': 'prometheus', 'uid': '000000001'}
target: [{'datasource': {'type': 'prometheus', 'uid': '000000001'}, 'refId': 'A'}]
target expr is not defined: skipped!
panel: {'datasource': {'type': 'prometheus', 'uid': '000000001'}, 'fieldConfig': {'defaults': {'color': {'mode': 'thresholds'}, 'mappings': [], 'thresholds': {'mode': 'absolute', 'steps': [{'color': 'green', 'value': None}, {'color': '#EAB839', 'value': 0.5}, {'color': 'red', 'value': 1}]}, 'unit': 's'}, 'overrides': []}, 'gridPos': {'h': 4, 'w': 5, 'x': 19, 'y': 0}, 'id': 3, 'options': {'colorMode': 'value', 'graphMode': 'none', 'justifyMode': 'auto', 'orientation': 'auto', 'reduceOptions': {'calcs': ['lastNotNull'], 'fields': '/^https://google\\.com$/', 'values': False}, 'textMode': 'auto'}, 'pluginVersion': '10.1.1', 'targets': [{'datasource': {'type': 'prometheus', 'uid': '000000001'}, 'editorMode': 'code', 'exemplar': False, 'expr': 'sum(quantile_over_time(0.9, probe_http_duration_seconds{job="blackbox",instance="https://google.com",phase="processing"}[$__interval])) by (instance)', 'format': 'time_series', 'instant': True, 'interval': '1m', 'legendFormat': 'https://google.com', 'range': False, 'refId': 'A'}], 'title': '90 PERCENTIL - 24h', 'type': 'stat'}
dtsrc: {'type': 'prometheus', 'uid': '000000001'}
target: [{'datasource': {'type': 'prometheus', 'uid': '000000001'}, 'editorMode': 'code', 'exemplar': False, 'expr': 'sum(quantile_over_time(0.9, probe_http_duration_seconds{job="blackbox",instance="https://google.com",phase="processing"}[$__interval])) by (instance)', 'format': 'time_series', 'instant': True, 'interval': '1m', 'legendFormat': 'https://google.com', 'range': False, 'refId': 'A'}]
get_var_value_from_dashboard::value $__interval
found variable $__interval => "$__interval"
extract_vars::result expr="sum(quantile_over_time(0.9, probe_http_duration_seconds{job="blackbox",instance="https://google.com",phase="processing"}[$__interval])) by (instance)"
query GET datasource proxy uri: http://localhost:3000/api
invalid results...
can't obtain dashboard data... snapshot canceled!
@peekjef72
Copy link
Collaborator

Hi,

Thank you for reporting this issue.

Currently, granfana-snapshot-tool, as you have observed, doesn't handle the grafana "computed" variables $__interval.

The actual behavior is only to detect format $var or ${var}. (So that ${var:<format>} is not handle.)

Then, when the var_name var ( from $var) is detected, it is only substituted with a user defined value (simple python str.replace() function).
So, the user has to define the corresponding value via a "context" definition for that dashboard.
That is the exact purpose of the "context" feature:
In the granfana-snapshot-tool's config file you have to add a context part:

general:
 ...

grafana:
 ...

contexts:
  "dashboard_name": # in your context: https___google_com_2024-09-21_101558_1541855
    # time_from: "now-1h"
    # time_to: "now"
    vars:
       __interval: 2m # or what ever value you want.
     

Currently that is the only way to handle vars.
But I do agree that it may be a good idea to to have the same behavior than for grafana predefined vars.
Hope it can help.

JFPIK--

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

No branches or pull requests

2 participants