Skip to content
This repository has been archived by the owner on Mar 22, 2023. It is now read-only.

Add prefix code to add to all requests #48

Open
tristan-ovh opened this issue Dec 3, 2019 · 4 comments
Open

Add prefix code to add to all requests #48

tristan-ovh opened this issue Dec 3, 2019 · 4 comments

Comments

@tristan-ovh
Copy link

tristan-ovh commented Dec 3, 2019

Hello,
It is possible to set variables in the warp10 data source that are available in all requests.
But it would be even better to be able to add any code (not just a variable) that would be inserted in all requests. For example I could add one line to raise the quota of number of points that can be fetched.

@StevenLeRoux
Copy link
Contributor

Hello Tristan,

Sure! It's called "Execution constants" in the data source and you can put whatever you need in it.

Here is an example on how we use it :

  • set a token string, reuse it in the scripts using this source

TOKEN 1234...abcd

  • set a macro, call it in the script

MAXOPS <% 'stack.maxops.hard' STACKATTRIBUTE DUP <% ISNULL ! %> <% MAXOPS %> <% DROP %> IFTE %>

  • set a secure script, call it in the script

MYMACRO <% 'tIf2DfGEegGrewJb5O5LRfa4T3LHL8yUeVPEt4V4nykgn4_iYowmJ1ydGwVItcRVfFP.L34pfRwZ_ecg7LVc0bbJdMWuCEetsf0jnGCBE3(64frer.EZERzETGT789FgNAWdBluPsPhcwCcVa4kJnhkRwhH7yn_802TiwZVTzgZPtghkRgBkpIQt.NHJeEs9zq4LeNwBz9EeezZEffR53F' EVALSECURE %>

@miton18
Copy link
Contributor

miton18 commented Dec 4, 2019

Hi !
There is a tips, the variables you put in the datasource configuration can be a Warp10 macro.
Your execution variable value must starts with a <% and ends with a %> else it will be interpreted as a string

Example:

Variable hello in the datasource

<% 'Hello !' %>

In your panel query:

@hello

@aurrelhebert
Copy link
Contributor

Yes but this doesn't fix Tristan issue here, as he still have to call the Macro in each of its scripts to be executed :/
However it could be a new option in the DataSource? Something like "executed macro"

@tristan-ovh
Copy link
Author

Indeed using a macro and calling it everywhere could help factorize a bit the code. If it were executed directly, it would be even simpler :)

But thinking again about this problem, for us, having this "script header" in the datasource would not be so great: we have 3 different data sources, and they are in an organization where datasource modification is complicated. The most logical would be to have this code common to all panels of a dashboard, but I guess Grafana doesn't allow that.

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

No branches or pull requests

4 participants