vimeo/graph-explorer — pull request #122 by bnkr (2014-08-08 11:25:57+00:00)
Title: Percent by type

This is a "first thing that works" implementation for a query `percent by ` as discussed in #121 which will result in graph targets roughly meaning (for `percent by tag2`):

asPercent(metric.tag1=x.tag2=y, sumSeries(metric.tag1=x.tag2=*))

This also works when you do something like `percent by type sum by core`, you get a metric like:

asPercent(sumSeries(metric.core=*.metric=idle), sumSeries(metric.core=*.metric=*))

Additionally I added a utility to introspect the process of generating a query and give a very simple graphite url for testing purposes. Could come in handy for other people.

I expect this pull request needs some refactoring but I wanted to create it early so you can get an idea of where I went with it.

A couple of things I intend to fix:

* not constructing proper objects in the debugging utility -- it would be much better and probably pretty easy to load the Config and Preferences object.

* I did I string.replace() hack to insert the asPercent context which is probably unnecessary but I didn't want to get too far into understanding how the function application works yet.

* computing the context for the percent is pretty messy.

I think in general `build_from_targets` would be easier to change if it had a bit more of an object language, rather than just dicts everywhere. In particular I found it quite hard to work out if I was computing something which had already been done elsewhere.