Advanced usage

This page details some of the more advanced ways of setting up and optimizing Pivot.

Monitoring queries

You can enable query monitoring to see what queries Pivot is making.

monitor queries

It is possible to disable the query monitoring ability in Pivot from the Settings.

Druid authentication

Pivot can authenticate to a Druid server via request decoration.

In the config add a key of druidRequestDecorator that point to a relative js file:

druidRequestDecorator: './druid-request-decorator.js'

Then the contract is that your module should export a function druidRequestDecorator that has to return a decorator.

A decorator is a function that gets called on every request and receives a Druid query and may return an object with the key headers where you can set whatever headers you want.

Here is an example decorator:

exports.version = 1;

// logger - is just a collection of functions that you should use instead of console to have your logs included with the Pivot logs
// options - is an object with the following keys:
//   * cluster: Cluster - the cluster object
exports.druidRequestDecoratorFactory = function (logger, params) {
  var options = params.options;
  var myUsername = options.myUsername; // pretend we store the username and password
  var myPassword = options.myPassword; // in the config

  if (!myUsername) throw new Error('must have username');
  if (!myPassword) throw new Error('must have password');

  logger.log("Decorator init for username: " + myUsername);

  var auth = "Basic " + Buffer.from(myUsername + ":" + myPassword).toString('base64');

  // decoratorRequest: DecoratorRequest - is an object that has the following keys:
  //   * method: string - the method that is used (POST or GET)
  //   * url: string -
  //   * query: Druid.Query -
  return function (decoratorRequest) {

    var decoration = {
      headers: {
        "Authorization": auth,
        "X-I-Like": "Koalas"
      }
    };

    // This can also be async if instead of a value of a promise is returned.
    return decoration;
  };
};

This would result in all Druid requests being tagged as:

decoration example

Pivot

Advanced

Api