grafana/grafana — pull request #454 by pfischermx (2014-05-30 08:46:14+00:00)
Title: Add URL hashing balancing

Currently grafana does round-robing balancing when a list of URLs are set. This pull request adds support for URL hashing, that means that users can also opt to select which URLs to use based on a pattern (regexp) that would be ran against the query.

For example:

influx: {
default: true,
url: 'http://datacenter.XYZ.example.com:8086/db/foo,http://datacenter.ABC.example.com/db/foo',
lb_hashing: [
{ regexp: /XYZ/, url_index: 0 },
{ regexp: /ABC/, url_index: 1 },
],
type: 'influxdb',
username: 'test',
password: 'test',
},

So if a user has a panel with the following queries:

- select mean(value) from table WHERE datacenter = 'XYZ'
- select mean(value) from table WHERE datacenter = 'ABC'

Then the query of XYZ would match:

{ regexp: /XYZ/, url_index: 0 },

And thus use the first URL (http://datacenter.XYZ.example.com:8086/db/foo).

This is very helpful if you are using InfluxDB and have multiple datacenters (and multiple masters/leaders, or don't have replication, etc), because now in your graphs you can show data from all your datacenters with a single influx datasource.

Let me know if syntax (tabs/spaces) are right, been a while since I did javascript so my vim may be a bit more customized for other languages :)

Thanks!