mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Elasticsearch: Add Top Metrics Aggregation and X-Pack support (#33041)
* Elasticsearch: Add Top Metrics Aggregation * Adding support for non-timeseries visualizations * removing console.logs * restoring loadOptions type * Honor xpack setting * Adding test for elastic_response * adding test for query builder * Adding support of alerting * Fixing separator spelling * Fixing linting issues * attempting to reduce cyclomatic complexity * Adding elastic77 Docker block * Update public/app/plugins/datasource/elasticsearch/components/QueryEditor/MetricAggregationsEditor/MetricEditor.test.tsx Co-authored-by: Giordano Ricci <grdnricci@gmail.com> * refactoring MetricsEditor tests * Fixing typo * Change getFields type & move TopMetrics to a separate component * Fix SegmentAsync styles in TopMetrics Settings * Fix field types for TopMetrics * WIP * Refactoring client side to support multiple top metrics * Adding tests and finishing go implimentation * removing fmt lib from debugging * fixing tests * reducing the cyclomatic complexity * Update public/app/plugins/datasource/elasticsearch/elastic_response.ts Co-authored-by: Giordano Ricci <grdnricci@gmail.com> * Update public/app/plugins/datasource/elasticsearch/hooks/useFields.ts Co-authored-by: Giordano Ricci <grdnricci@gmail.com> * Checking for possible nil value * Fixing types * fix fake-data-gen param * fix useFields hook * Removing aggregateBy and size * Fixing go tests * Fixing TS tests * fixing tests * Fixes * Remove date from top_metrics fields * Restore previous formatting * Update pkg/tsdb/elasticsearch/client/models.go Co-authored-by: Dimitris Sotirakis <dimitrios.sotirakis@grafana.com> * Update pkg/tsdb/elasticsearch/client/models.go Co-authored-by: Dimitris Sotirakis <dimitrios.sotirakis@grafana.com> * Fix code review comments on processTopMetricValue * Remove underscore from variable names * Remove intermediate array definition * Refactor test to use testify Co-authored-by: Giordano Ricci <grdnricci@gmail.com> Co-authored-by: Elfo404 <me@giordanoricci.com> Co-authored-by: Dimitris Sotirakis <dimitrios.sotirakis@grafana.com>
This commit is contained in:
@@ -53,6 +53,8 @@ func coerceVersion(v *simplejson.Json) (*semver.Version, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Legacy version numbers (before Grafana 8)
|
||||
// valid values were 2,5,56,60,70
|
||||
switch versionNumber {
|
||||
case 2:
|
||||
return semver.NewVersion("2.0.0")
|
||||
|
||||
@@ -274,12 +274,41 @@ type GeoHashGridAggregation struct {
|
||||
|
||||
// MetricAggregation represents a metric aggregation
|
||||
type MetricAggregation struct {
|
||||
Type string
|
||||
Field string
|
||||
Settings map[string]interface{}
|
||||
}
|
||||
|
||||
// MarshalJSON returns the JSON encoding of the metric aggregation
|
||||
func (a *MetricAggregation) MarshalJSON() ([]byte, error) {
|
||||
if a.Type == "top_metrics" {
|
||||
root := map[string]interface{}{}
|
||||
var rootMetrics []map[string]string
|
||||
|
||||
order, hasOrder := a.Settings["order"]
|
||||
orderBy, hasOrderBy := a.Settings["orderBy"]
|
||||
|
||||
root["size"] = "1"
|
||||
|
||||
metrics, hasMetrics := a.Settings["metrics"].([]interface{})
|
||||
if hasMetrics {
|
||||
for _, v := range metrics {
|
||||
metricValue := map[string]string{"field": v.(string)}
|
||||
rootMetrics = append(rootMetrics, metricValue)
|
||||
}
|
||||
root["metrics"] = rootMetrics
|
||||
}
|
||||
|
||||
if hasOrderBy && hasOrder {
|
||||
root["sort"] = []map[string]interface{}{
|
||||
{
|
||||
orderBy.(string): order,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
return json.Marshal(root)
|
||||
}
|
||||
root := map[string]interface{}{}
|
||||
|
||||
if a.Field != "" {
|
||||
|
||||
@@ -419,9 +419,11 @@ func (b *aggBuilderImpl) GeoHashGrid(key, field string, fn func(a *GeoHashGridAg
|
||||
|
||||
func (b *aggBuilderImpl) Metric(key, metricType, field string, fn func(a *MetricAggregation)) AggBuilder {
|
||||
innerAgg := &MetricAggregation{
|
||||
Type: metricType,
|
||||
Field: field,
|
||||
Settings: make(map[string]interface{}),
|
||||
}
|
||||
|
||||
aggDef := newAggDef(key, &aggContainer{
|
||||
Type: metricType,
|
||||
Aggregation: innerAgg,
|
||||
|
||||
Reference in New Issue
Block a user