VMware Modern Apps Community
corey_r
Community Manager
Community Manager

What can / can't I do with aliases on a query line?

Aliases have very little documentation at https://community.wavefront.com/docs/DOC-1011#variables  . It'd be great if that could be fleshed out more, because it isn't clear how to use them.

I've figured out that you can do expressions like  (1 as variable) + $variable  and  default((0 as variable), ts(...)) + default($variable, ts(...))  .

However, some things you can't seem to do in version 3.0.12 (and I don't know if they are bugs or part of the spec):

The documentation claims that an alias can be "any string of text" that appears in the query, but that doesn't appear to be true. It looks like it can only be a full ts-expression (e.g. for anything that I might want to use an alias for, I could also use a query line variable for).

I can use an alias outside of the expression where it is defined, but not inside it.  default($variable, default($variable, (1 as variable)))  works, but  default((1 as variable), default($variable, $variable))  does not, and neither does  default($variable, default((1 as variable), $variable))  .

An alias can't be used for a time window.  last((1m as variable), 0)  does not work. It'd be really great if this could be made to work. I like creating graphs that look like

  1. default(0, last(1m, sum(align(1m, sum, ts(...))))) 

and it'd be great if I could use an alias for the time window, so that I don't accidentally use two different time windows in the expression.

========

Tangentially, it'd be really nice if we could have a feature which was the inverse of dashboard variables. In a dashboard section, I'd like to be able to define one or more expressions, with undefined variables in them. And for a chart, I'd like to be able to define those variables. That way you could have a dashboard with multiple queries that are all the same, but with different input parameters. Right now that is only possible by manually copying/pasting the chart queries, and manually keeping them synced with each other.

And similarly for alerts too!

Reply
0 Kudos
3 Replies
corey_r
Community Manager
Community Manager

Hi Jordon,

Our apologies on a delayed response here and we greatly appreciate your feedback. We have corrected our documentation (please review here )around alias.

We will also explicitly mention the additional limitations you spotted  to explain in detail how an alias gets evaluated in a expression. We will also add probably a short article that compares and contrasts these different types of variables - query line, dashboard variable and alias that can be used in ts expressions.

Once again greatly appreciate your inputs here.

You are correct here that the alias can only be defined for ts expressions and not "any string of text " and also that alias and query line variable have same functionality. It is just that alias give you flexibility to simply reuse valid ts expressions (sub expressions) within same source query .

For your use case where you want to replace a time window with a variable you could use Simple Dashboard variable which acts as a placeholder in ts() expressions and should allow you to replace it with "any string of text"

Also thanks for the suggesting the feature enhancements. It is probably on our Product roadmap to add global variables that can be used across dashboards and we might allow those for alerts too.

It would be very helpful if you could elaborate on your use case where you would want to have variables per chart. If I understand it correctly you should be able to do it using our dashboard variables as it is fully flexible and up to the user to add these variables to one or more or all charts of a dashboard. So you can have some variables that affect all charts and then have few other variables which are specific to each chart and this way I think you should able to achieve what you are looking for. Still it would be great if you could share more details around this so that I can help you better.

You could also directly send these details to support@wavefront.com or salil@wavefront.com if you don't want to post details around your data on the community.

Hope this is helpful.

Thanks,

Salil D

Reply
0 Kudos
corey_r
Community Manager
Community Manager

Thanks salil@wavefront.com

We have corrected our documentation (please review here )around alias. We will also explicitly mention the additional limitations you spotted  to explain in detail how an alias gets evaluated in a expression.

The documentation doesn't seem much clearer. It now says "any expression" instead of "any string of text", which is better (though it'd be clearer, I think, if it specified "any ts() expression"). But everything else seems mostly the same. It'd be great for a bit more clarity in the language reference. A simple usage example would go a long way in clarifying the feature.

For your use case where you want to replace a time window with a variable you could use Simple Dashboard variable which acts as a placeholder in ts() expressions and should allow you to replace it with "any string of text"

This doesn't completely solve the use case I had in mind.

If I create a dashboard where every chart uses the same time window, then yes, this will work. I can create a Simple Dashboard variable TIME_WINDOW, set it to whatever I'd like, and then use that in all of my charts. Then I can update it whenever I like, knowing that all of the charts will update correctly.

However, suppose I have a single dashboard with charts that use different time windows. For example, let's say I have one chart that buckets a metric by hour, and another chart that buckets the same metric by day. So one chart is defined as last(1h, align(1h, sum, ts(...))), while the other is defined as last(1d, align(1d, sum, ts(...))). This works fine, but I'd get an incorrect graph if I updated one time window but forgot to keep the other in-sync, e.g. last(1d, align(1h, sum, ts(...))). What I'd really like to be able to do is something like last((1h as bucketSize), align($bucketSize, sum, ts(...))). Then, if I copy the query to a new chart but change the bucketSize, I only need to change it in one place, and it's guaranteed to stay correct.

Here's what it would look like using Simple Dashboard variables. I could create variables BUCKET_SIZE_HOUR=1h and BUCKET_SIZE_DAY=1d. Then I'd create my charts last(BUCKET_SIZE_HOUR, align(BUCKET_SIZE_HOUR, sum, ts(...))) and last(BUCKET_SIZE_DAY, align(BUCKET_SIZE_DAY, sum, ts(...))). These charts aren't any better than the original ones, since the constant variables are just as immutable as the constants 1h and 1d. Furthermore, this also suffers from the copy-paste problem; I might accidentally create last(BUCKET_SIZE_DAY, align(BUCKET_SIZE_HOUR, sum, ts(...))) by mistake. Having locally-scoped aliases is the only way to solve that problem.

It would be very helpful if you could elaborate on your use case where you would want to have variables per chart. If I understand it correctly you should be able to do it using our dashboard variables as it is fully flexible and up to the user to add these variables to one or more or all charts of a dashboard. So you can have some variables that affect all charts and then have few other variables which are specific to each chart and this way I think you should able to achieve what you are looking for. Still it would be great if you could share more details around this so that I can help you better.

That isn't what I'm looking for. Let me use my previous example again. I have a dashboard with two charts. The queries for both charts are identical, except that I want to bucket them differently. So I have last(1h, align(1h, sum, ts(...))) and last(1d, align(1d, sum, ts(...))).

Now let's say that I realize that isn't what I want. I also want to add a condition on the tags. So I edit the first chart to be last(1h, align(1h, sum, ts(..., foo=bar))). And after I'm done with that, I have to remember to make the same exact change to the second chart: last(1d, align(1d, sum, ts(..., foo=bar))). This is very tedious and error-prone. And when we're talking about mission-critical alerts, this is very important to get right (my team has many alert pairs that are identical, except for a threshold value).

It would be great if we could do something like this:

Dashboard variable: expression=last(${bucket_size}, align(${bucket_size}, sum, ts(..., foo=bar)))

Chart 1 variable: bucket_size=1h

Chart 1 query: ${expression}

Chart 2 variable: bucket_size=1d

Chart 2 query: ${expression}

Essentially... I want to be able to define functions. I want to be able to have a dashboard-level variable which uses undefined, non-dashboard-level variables. Then, in a lower level (in a chart, or in a query-line alias), you can specify the values of the missing variables, and use the dashboard-level variable as a ts()-expression in your query lines.

It could be done like I've shown above, or it can be more like traditional functions:

Dashboard function: expression($bucket_size)=last($bucket_size, align($bucket_size, sum, ts(..., foo=bar)))

Chart 1 query: expression(1h)

Chart 2 query: expression(1d)

And then it'd be really great to be able to define groups of alerts (just like a dashboard is a group of charts), and then allow functions there too, that way we can get rid of copy-pasting in our alerts.

Alert group function: expression($threshold)=last(1m, align(1m, sum, ts(..., foo=bar))) > $threshold

Alert 1 query: expression(500)

Alert 2 query: expression(1000)

Reply
0 Kudos
corey_r
Community Manager
Community Manager

Hi Jordan,

Thanks a lot for sending such a detail spec on this use case. I see how the feature to allow inverse dashboard variables where the value for same variable can be set differently for each chart would makes sense in such use cases. I will share this idea with our product team for further consideration.

Also we will update our documentation with examples at the earliest.

Greatly appreciate your inputs and feedback.

Thanks,

Salil D

Reply
0 Kudos