mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Elasticsearch: Fix respecting of precision in geo hash grid (#73917)
* Elasticsearch: Fix ignoring precision when running queries trough backend
* Unify default value
* Revert "Unify default value"
This reverts commit d8e1d207a2.
* Update test
This commit is contained in:
@@ -269,7 +269,7 @@ func addFiltersAgg(aggBuilder es.AggBuilder, bucketAgg *BucketAgg) es.AggBuilder
|
||||
|
||||
func addGeoHashGridAgg(aggBuilder es.AggBuilder, bucketAgg *BucketAgg) es.AggBuilder {
|
||||
aggBuilder.GeoHashGrid(bucketAgg.ID, bucketAgg.Field, func(a *es.GeoHashGridAggregation, b es.AggBuilder) {
|
||||
a.Precision = bucketAgg.Settings.Get("precision").MustInt(3)
|
||||
a.Precision = stringToIntWithDefaultValue(bucketAgg.Settings.Get("precision").MustString(), 3)
|
||||
aggBuilder = b
|
||||
})
|
||||
|
||||
|
||||
@@ -612,7 +612,7 @@ func TestExecuteElasticsearchDataQuery(t *testing.T) {
|
||||
"id": "3",
|
||||
"type": "geohash_grid",
|
||||
"field": "@location",
|
||||
"settings": { "precision": 3 }
|
||||
"settings": { "precision": "6" }
|
||||
}
|
||||
],
|
||||
"metrics": [{"type": "count", "id": "1" }]
|
||||
@@ -625,6 +625,56 @@ func TestExecuteElasticsearchDataQuery(t *testing.T) {
|
||||
require.Equal(t, firstLevel.Aggregation.Type, "geohash_grid")
|
||||
ghGridAgg := firstLevel.Aggregation.Aggregation.(*es.GeoHashGridAggregation)
|
||||
require.Equal(t, ghGridAgg.Field, "@location")
|
||||
require.Equal(t, ghGridAgg.Precision, 6)
|
||||
})
|
||||
|
||||
t.Run("With geo hash grid agg with invalid int precision", func(t *testing.T) {
|
||||
c := newFakeClient()
|
||||
_, err := executeElasticsearchDataQuery(c, `{
|
||||
"bucketAggs": [
|
||||
{
|
||||
"id": "3",
|
||||
"type": "geohash_grid",
|
||||
"field": "@location",
|
||||
"settings": { "precision": 7 }
|
||||
}
|
||||
],
|
||||
"metrics": [{"type": "count", "id": "1" }]
|
||||
}`, from, to)
|
||||
require.NoError(t, err)
|
||||
sr := c.multisearchRequests[0].Requests[0]
|
||||
|
||||
firstLevel := sr.Aggs[0]
|
||||
require.Equal(t, firstLevel.Key, "3")
|
||||
require.Equal(t, firstLevel.Aggregation.Type, "geohash_grid")
|
||||
ghGridAgg := firstLevel.Aggregation.Aggregation.(*es.GeoHashGridAggregation)
|
||||
require.Equal(t, ghGridAgg.Field, "@location")
|
||||
// It should default to 3
|
||||
require.Equal(t, ghGridAgg.Precision, 3)
|
||||
})
|
||||
|
||||
t.Run("With geo hash grid agg with no precision", func(t *testing.T) {
|
||||
c := newFakeClient()
|
||||
_, err := executeElasticsearchDataQuery(c, `{
|
||||
"bucketAggs": [
|
||||
{
|
||||
"id": "3",
|
||||
"type": "geohash_grid",
|
||||
"field": "@location",
|
||||
"settings": {}
|
||||
}
|
||||
],
|
||||
"metrics": [{"type": "count", "id": "1" }]
|
||||
}`, from, to)
|
||||
require.NoError(t, err)
|
||||
sr := c.multisearchRequests[0].Requests[0]
|
||||
|
||||
firstLevel := sr.Aggs[0]
|
||||
require.Equal(t, firstLevel.Key, "3")
|
||||
require.Equal(t, firstLevel.Aggregation.Type, "geohash_grid")
|
||||
ghGridAgg := firstLevel.Aggregation.Aggregation.(*es.GeoHashGridAggregation)
|
||||
require.Equal(t, ghGridAgg.Field, "@location")
|
||||
// It should default to 3
|
||||
require.Equal(t, ghGridAgg.Precision, 3)
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user