2017-09-28 05:52:39 -05:00
|
|
|
///<reference path="../../../headers/common.d.ts" />
|
|
|
|
|
2017-12-19 09:06:54 -06:00
|
|
|
import _ from "lodash";
|
2017-09-28 05:52:39 -05:00
|
|
|
|
|
|
|
export const metricAggTypes = [
|
2017-12-19 09:06:54 -06:00
|
|
|
{ text: "Count", value: "count", requiresField: false },
|
|
|
|
{
|
|
|
|
text: "Average",
|
|
|
|
value: "avg",
|
|
|
|
requiresField: true,
|
|
|
|
supportsInlineScript: true,
|
|
|
|
supportsMissing: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text: "Sum",
|
|
|
|
value: "sum",
|
|
|
|
requiresField: true,
|
|
|
|
supportsInlineScript: true,
|
|
|
|
supportsMissing: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text: "Max",
|
|
|
|
value: "max",
|
|
|
|
requiresField: true,
|
|
|
|
supportsInlineScript: true,
|
|
|
|
supportsMissing: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text: "Min",
|
|
|
|
value: "min",
|
|
|
|
requiresField: true,
|
|
|
|
supportsInlineScript: true,
|
|
|
|
supportsMissing: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text: "Extended Stats",
|
|
|
|
value: "extended_stats",
|
|
|
|
requiresField: true,
|
|
|
|
supportsMissing: true,
|
|
|
|
supportsInlineScript: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text: "Percentiles",
|
|
|
|
value: "percentiles",
|
|
|
|
requiresField: true,
|
|
|
|
supportsMissing: true,
|
|
|
|
supportsInlineScript: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text: "Unique Count",
|
|
|
|
value: "cardinality",
|
|
|
|
requiresField: true,
|
|
|
|
supportsMissing: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text: "Moving Average",
|
|
|
|
value: "moving_avg",
|
|
|
|
requiresField: false,
|
|
|
|
isPipelineAgg: true,
|
|
|
|
minVersion: 2
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text: "Derivative",
|
|
|
|
value: "derivative",
|
|
|
|
requiresField: false,
|
|
|
|
isPipelineAgg: true,
|
|
|
|
minVersion: 2
|
|
|
|
},
|
|
|
|
{ text: "Raw Document", value: "raw_document", requiresField: false }
|
2017-09-28 05:52:39 -05:00
|
|
|
];
|
|
|
|
|
|
|
|
export const bucketAggTypes = [
|
2017-12-19 09:06:54 -06:00
|
|
|
{ text: "Terms", value: "terms", requiresField: true },
|
|
|
|
{ text: "Filters", value: "filters" },
|
|
|
|
{ text: "Geo Hash Grid", value: "geohash_grid", requiresField: true },
|
|
|
|
{ text: "Date Histogram", value: "date_histogram", requiresField: true },
|
|
|
|
{ text: "Histogram", value: "histogram", requiresField: true }
|
2017-09-28 05:52:39 -05:00
|
|
|
];
|
|
|
|
|
|
|
|
export const orderByOptions = [
|
2017-12-19 09:06:54 -06:00
|
|
|
{ text: "Doc Count", value: "_count" },
|
|
|
|
{ text: "Term value", value: "_term" }
|
2017-09-28 05:52:39 -05:00
|
|
|
];
|
|
|
|
|
|
|
|
export const orderOptions = [
|
2017-12-19 09:06:54 -06:00
|
|
|
{ text: "Top", value: "desc" },
|
|
|
|
{ text: "Bottom", value: "asc" }
|
2017-09-28 05:52:39 -05:00
|
|
|
];
|
|
|
|
|
|
|
|
export const sizeOptions = [
|
2017-12-19 09:06:54 -06:00
|
|
|
{ text: "No limit", value: "0" },
|
|
|
|
{ text: "1", value: "1" },
|
|
|
|
{ text: "2", value: "2" },
|
|
|
|
{ text: "3", value: "3" },
|
|
|
|
{ text: "5", value: "5" },
|
|
|
|
{ text: "10", value: "10" },
|
|
|
|
{ text: "15", value: "15" },
|
|
|
|
{ text: "20", value: "20" }
|
2017-09-28 05:52:39 -05:00
|
|
|
];
|
|
|
|
|
|
|
|
export const extendedStats = [
|
2017-12-19 09:06:54 -06:00
|
|
|
{ text: "Avg", value: "avg" },
|
|
|
|
{ text: "Min", value: "min" },
|
|
|
|
{ text: "Max", value: "max" },
|
|
|
|
{ text: "Sum", value: "sum" },
|
|
|
|
{ text: "Count", value: "count" },
|
|
|
|
{ text: "Std Dev", value: "std_deviation" },
|
|
|
|
{ text: "Std Dev Upper", value: "std_deviation_bounds_upper" },
|
|
|
|
{ text: "Std Dev Lower", value: "std_deviation_bounds_lower" }
|
2017-09-28 05:52:39 -05:00
|
|
|
];
|
|
|
|
|
|
|
|
export const intervalOptions = [
|
2017-12-19 09:06:54 -06:00
|
|
|
{ text: "auto", value: "auto" },
|
|
|
|
{ text: "10s", value: "10s" },
|
|
|
|
{ text: "1m", value: "1m" },
|
|
|
|
{ text: "5m", value: "5m" },
|
|
|
|
{ text: "10m", value: "10m" },
|
|
|
|
{ text: "20m", value: "20m" },
|
|
|
|
{ text: "1h", value: "1h" },
|
|
|
|
{ text: "1d", value: "1d" }
|
2017-09-28 05:52:39 -05:00
|
|
|
];
|
|
|
|
|
|
|
|
export const movingAvgModelOptions = [
|
2017-12-19 09:06:54 -06:00
|
|
|
{ text: "Simple", value: "simple" },
|
|
|
|
{ text: "Linear", value: "linear" },
|
|
|
|
{ text: "Exponentially Weighted", value: "ewma" },
|
|
|
|
{ text: "Holt Linear", value: "holt" },
|
|
|
|
{ text: "Holt Winters", value: "holt_winters" }
|
2017-09-28 05:52:39 -05:00
|
|
|
];
|
|
|
|
|
|
|
|
export const pipelineOptions = {
|
2017-12-19 09:06:54 -06:00
|
|
|
moving_avg: [
|
|
|
|
{ text: "window", default: 5 },
|
|
|
|
{ text: "model", default: "simple" },
|
|
|
|
{ text: "predict", default: undefined },
|
|
|
|
{ text: "minimize", default: false }
|
2017-09-28 05:52:39 -05:00
|
|
|
],
|
2017-12-19 09:06:54 -06:00
|
|
|
derivative: [{ text: "unit", default: undefined }]
|
2017-09-28 05:52:39 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
export const movingAvgModelSettings = {
|
2017-12-19 09:06:54 -06:00
|
|
|
simple: [],
|
|
|
|
linear: [],
|
|
|
|
ewma: [{ text: "Alpha", value: "alpha", default: undefined }],
|
|
|
|
holt: [
|
|
|
|
{ text: "Alpha", value: "alpha", default: undefined },
|
|
|
|
{ text: "Beta", value: "beta", default: undefined }
|
|
|
|
],
|
|
|
|
holt_winters: [
|
|
|
|
{ text: "Alpha", value: "alpha", default: undefined },
|
|
|
|
{ text: "Beta", value: "beta", default: undefined },
|
|
|
|
{ text: "Gamma", value: "gamma", default: undefined },
|
|
|
|
{ text: "Period", value: "period", default: undefined },
|
|
|
|
{ text: "Pad", value: "pad", default: undefined, isCheckbox: true }
|
|
|
|
]
|
2017-09-28 05:52:39 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
export function getMetricAggTypes(esVersion) {
|
|
|
|
return _.filter(metricAggTypes, function(f) {
|
|
|
|
if (f.minVersion) {
|
|
|
|
return f.minVersion <= esVersion;
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getPipelineOptions(metric) {
|
|
|
|
if (!isPipelineAgg(metric.type)) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
return pipelineOptions[metric.type];
|
|
|
|
}
|
|
|
|
|
|
|
|
export function isPipelineAgg(metricType) {
|
|
|
|
if (metricType) {
|
|
|
|
var po = pipelineOptions[metricType];
|
|
|
|
return po !== null && po !== undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getPipelineAggOptions(targets) {
|
|
|
|
var result = [];
|
|
|
|
_.each(targets.metrics, function(metric) {
|
|
|
|
if (!isPipelineAgg(metric.type)) {
|
2017-12-19 09:06:54 -06:00
|
|
|
result.push({ text: describeMetric(metric), value: metric.id });
|
2017-09-28 05:52:39 -05:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getMovingAvgSettings(model, filtered) {
|
|
|
|
var filteredResult = [];
|
|
|
|
if (filtered) {
|
|
|
|
_.each(movingAvgModelSettings[model], function(setting) {
|
2017-12-19 09:06:54 -06:00
|
|
|
if (!setting.isCheckbox) {
|
2017-09-28 05:52:39 -05:00
|
|
|
filteredResult.push(setting);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return filteredResult;
|
|
|
|
}
|
|
|
|
return movingAvgModelSettings[model];
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getOrderByOptions(target) {
|
|
|
|
var metricRefs = [];
|
|
|
|
_.each(target.metrics, function(metric) {
|
2017-12-19 09:06:54 -06:00
|
|
|
if (metric.type !== "count") {
|
|
|
|
metricRefs.push({ text: describeMetric(metric), value: metric.id });
|
2017-09-28 05:52:39 -05:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return orderByOptions.concat(metricRefs);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function describeOrder(order) {
|
2017-12-19 09:06:54 -06:00
|
|
|
var def = _.find(orderOptions, { value: order });
|
2017-09-28 05:52:39 -05:00
|
|
|
return def.text;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function describeMetric(metric) {
|
2017-12-19 09:06:54 -06:00
|
|
|
var def = _.find(metricAggTypes, { value: metric.type });
|
|
|
|
return def.text + " " + metric.field;
|
2017-09-28 05:52:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
export function describeOrderBy(orderBy, target) {
|
2017-12-19 09:06:54 -06:00
|
|
|
var def = _.find(orderByOptions, { value: orderBy });
|
2017-09-28 05:52:39 -05:00
|
|
|
if (def) {
|
|
|
|
return def.text;
|
|
|
|
}
|
2017-12-19 09:06:54 -06:00
|
|
|
var metric = _.find(target.metrics, { id: orderBy });
|
2017-09-28 05:52:39 -05:00
|
|
|
if (metric) {
|
|
|
|
return describeMetric(metric);
|
|
|
|
} else {
|
|
|
|
return "metric not found";
|
|
|
|
}
|
2017-10-07 03:31:39 -05:00
|
|
|
}
|