diff --git a/common/persistence/visibility/store/elasticsearch/visibility_store.go b/common/persistence/visibility/store/elasticsearch/visibility_store.go index dab68fec65d..5f21f5dff8e 100644 --- a/common/persistence/visibility/store/elasticsearch/visibility_store.go +++ b/common/persistence/visibility/store/elasticsearch/visibility_store.go @@ -683,6 +683,12 @@ func (s *visibilityStore) buildSearchParametersV2( return nil, serviceerror.NewInvalidArgument("ORDER BY clause is not supported") } + if len(fieldSorts) > 0 { + // If fieldSorts is not empty, then it's using custom order by. + s.metricsHandler.WithTags(metrics.NamespaceTag(request.Namespace.String())). + Counter(metrics.ElasticsearchCustomOrderByClauseCount.GetMetricName()).Record(1) + } + params := &client.SearchParameters{ Index: s.index, Query: boolQuery, @@ -735,7 +741,6 @@ func (s *visibilityStore) setDefaultFieldSort(fieldSorts []*elastic.FieldSort) [ return defaultSorter } - s.metricsHandler.Counter(metrics.ElasticsearchCustomOrderByClauseCount.GetMetricName()).Record(1) res := make([]elastic.Sorter, len(fieldSorts)+1) for i, fs := range fieldSorts { res[i] = fs diff --git a/common/persistence/visibility/store/elasticsearch/visibility_store_read_test.go b/common/persistence/visibility/store/elasticsearch/visibility_store_read_test.go index 1a302ee5735..ae24e369715 100644 --- a/common/persistence/visibility/store/elasticsearch/visibility_store_read_test.go +++ b/common/persistence/visibility/store/elasticsearch/visibility_store_read_test.go @@ -460,6 +460,7 @@ func (s *ESVisibilitySuite) TestBuildSearchParametersV2() { // test custom sort request.Query = `Order bY WorkflowId` boolQuery = elastic.NewBoolQuery().Filter(matchNamespaceQuery).MustNot(namespaceDivisionExists) + s.mockMetricsHandler.EXPECT().WithTags(metrics.NamespaceTag(request.Namespace.String())).Return(s.mockMetricsHandler) s.mockMetricsHandler.EXPECT().Counter(metrics.ElasticsearchCustomOrderByClauseCount.GetMetricName()).Return(metrics.NoopCounterMetricFunc) p, err = s.visibilityStore.buildSearchParametersV2(request) s.NoError(err)