|
|
|
@ -30,7 +30,7 @@ export class ElasticResponse { |
|
|
|
|
|
|
|
|
|
|
|
switch (metric.type) { |
|
|
|
switch (metric.type) { |
|
|
|
case 'count': { |
|
|
|
case 'count': { |
|
|
|
newSeries = { datapoints: [], metric: 'count', props: props }; |
|
|
|
newSeries = { datapoints: [], metric: 'count', props: props, refId: target.refId }; |
|
|
|
for (i = 0; i < esAgg.buckets.length; i++) { |
|
|
|
for (i = 0; i < esAgg.buckets.length; i++) { |
|
|
|
bucket = esAgg.buckets[i]; |
|
|
|
bucket = esAgg.buckets[i]; |
|
|
|
value = bucket.doc_count; |
|
|
|
value = bucket.doc_count; |
|
|
|
@ -53,6 +53,7 @@ export class ElasticResponse { |
|
|
|
metric: 'p' + percentileName, |
|
|
|
metric: 'p' + percentileName, |
|
|
|
props: props, |
|
|
|
props: props, |
|
|
|
field: metric.field, |
|
|
|
field: metric.field, |
|
|
|
|
|
|
|
refId: target.refId, |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < esAgg.buckets.length; i++) { |
|
|
|
for (i = 0; i < esAgg.buckets.length; i++) { |
|
|
|
@ -76,6 +77,7 @@ export class ElasticResponse { |
|
|
|
metric: statName, |
|
|
|
metric: statName, |
|
|
|
props: props, |
|
|
|
props: props, |
|
|
|
field: metric.field, |
|
|
|
field: metric.field, |
|
|
|
|
|
|
|
refId: target.refId, |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < esAgg.buckets.length; i++) { |
|
|
|
for (i = 0; i < esAgg.buckets.length; i++) { |
|
|
|
@ -101,6 +103,7 @@ export class ElasticResponse { |
|
|
|
field: metric.field, |
|
|
|
field: metric.field, |
|
|
|
metricId: metric.id, |
|
|
|
metricId: metric.id, |
|
|
|
props: props, |
|
|
|
props: props, |
|
|
|
|
|
|
|
refId: target.refId, |
|
|
|
}; |
|
|
|
}; |
|
|
|
for (i = 0; i < esAgg.buckets.length; i++) { |
|
|
|
for (i = 0; i < esAgg.buckets.length; i++) { |
|
|
|
bucket = esAgg.buckets[i]; |
|
|
|
bucket = esAgg.buckets[i]; |
|
|
|
@ -200,7 +203,7 @@ export class ElasticResponse { |
|
|
|
|
|
|
|
|
|
|
|
// This is quite complex
|
|
|
|
// This is quite complex
|
|
|
|
// need to recurse down the nested buckets to build series
|
|
|
|
// need to recurse down the nested buckets to build series
|
|
|
|
processBuckets(aggs: any, target: any, seriesList: any, table: any, props: any, depth: any) { |
|
|
|
processBuckets(aggs: any, target: any, seriesList: any, table: TableModel, props: any, depth: any) { |
|
|
|
let bucket, aggDef: any, esAgg, aggId; |
|
|
|
let bucket, aggDef: any, esAgg, aggId; |
|
|
|
const maxDepth = target.bucketAggs.length - 1; |
|
|
|
const maxDepth = target.bucketAggs.length - 1; |
|
|
|
|
|
|
|
|
|
|
|
@ -324,12 +327,13 @@ export class ElasticResponse { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
processHits(hits: { total: { value: any }; hits: any[] }, seriesList: any[]) { |
|
|
|
processHits(hits: { total: { value: any }; hits: any[] }, seriesList: any[], target: any) { |
|
|
|
const hitsTotal = typeof hits.total === 'number' ? hits.total : hits.total.value; // <- Works with Elasticsearch 7.0+
|
|
|
|
const hitsTotal = typeof hits.total === 'number' ? hits.total : hits.total.value; // <- Works with Elasticsearch 7.0+
|
|
|
|
|
|
|
|
|
|
|
|
const series: any = { |
|
|
|
const series: any = { |
|
|
|
target: 'docs', |
|
|
|
target: target.refId, |
|
|
|
type: 'docs', |
|
|
|
type: 'docs', |
|
|
|
|
|
|
|
refId: target.refId, |
|
|
|
datapoints: [], |
|
|
|
datapoints: [], |
|
|
|
total: hitsTotal, |
|
|
|
total: hitsTotal, |
|
|
|
filterable: true, |
|
|
|
filterable: true, |
|
|
|
@ -438,6 +442,8 @@ export class ElasticResponse { |
|
|
|
if (isLogsRequest) { |
|
|
|
if (isLogsRequest) { |
|
|
|
series = addPreferredVisualisationType(series, 'logs'); |
|
|
|
series = addPreferredVisualisationType(series, 'logs'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
const target = this.targets[n]; |
|
|
|
|
|
|
|
series.refId = target.refId; |
|
|
|
dataFrame.push(series); |
|
|
|
dataFrame.push(series); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -453,7 +459,9 @@ export class ElasticResponse { |
|
|
|
this.nameSeries(tmpSeriesList, target); |
|
|
|
this.nameSeries(tmpSeriesList, target); |
|
|
|
|
|
|
|
|
|
|
|
if (table.rows.length > 0) { |
|
|
|
if (table.rows.length > 0) { |
|
|
|
dataFrame.push(toDataFrame(table)); |
|
|
|
const series = toDataFrame(table); |
|
|
|
|
|
|
|
series.refId = target.refId; |
|
|
|
|
|
|
|
dataFrame.push(series); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for (let y = 0; y < tmpSeriesList.length; y++) { |
|
|
|
for (let y = 0; y < tmpSeriesList.length; y++) { |
|
|
|
@ -464,6 +472,7 @@ export class ElasticResponse { |
|
|
|
series = addPreferredVisualisationType(series, 'graph'); |
|
|
|
series = addPreferredVisualisationType(series, 'graph'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
series.refId = target.refId; |
|
|
|
dataFrame.push(series); |
|
|
|
dataFrame.push(series); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -477,19 +486,21 @@ export class ElasticResponse { |
|
|
|
|
|
|
|
|
|
|
|
for (let i = 0; i < this.response.responses.length; i++) { |
|
|
|
for (let i = 0; i < this.response.responses.length; i++) { |
|
|
|
const response = this.response.responses[i]; |
|
|
|
const response = this.response.responses[i]; |
|
|
|
|
|
|
|
const target = this.targets[i]; |
|
|
|
|
|
|
|
|
|
|
|
if (response.error) { |
|
|
|
if (response.error) { |
|
|
|
throw this.getErrorFromElasticResponse(this.response, response.error); |
|
|
|
throw this.getErrorFromElasticResponse(this.response, response.error); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (response.hits && response.hits.hits.length > 0) { |
|
|
|
if (response.hits && response.hits.hits.length > 0) { |
|
|
|
this.processHits(response.hits, seriesList); |
|
|
|
this.processHits(response.hits, seriesList, target); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (response.aggregations) { |
|
|
|
if (response.aggregations) { |
|
|
|
const aggregations = response.aggregations; |
|
|
|
const aggregations = response.aggregations; |
|
|
|
const target = this.targets[i]; |
|
|
|
|
|
|
|
const tmpSeriesList: any[] = []; |
|
|
|
const tmpSeriesList: any[] = []; |
|
|
|
const table = new TableModel(); |
|
|
|
const table = new TableModel(); |
|
|
|
|
|
|
|
table.refId = target.refId; |
|
|
|
|
|
|
|
|
|
|
|
this.processBuckets(aggregations, target, tmpSeriesList, table, {}, 0); |
|
|
|
this.processBuckets(aggregations, target, tmpSeriesList, table, {}, 0); |
|
|
|
this.trimDatapoints(tmpSeriesList, target); |
|
|
|
this.trimDatapoints(tmpSeriesList, target); |
|
|
|
|