Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add counter to track custom order by usage in Elasticsearch #4064

Merged
merged 1 commit into from
Mar 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions common/metrics/metric_defs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1594,6 +1594,7 @@ var (
ElasticsearchBulkProcessorBulkSize = NewDimensionlessHistogramDef("elasticsearch_bulk_processor_bulk_size")
ElasticsearchDocumentParseFailuresCount = NewCounterDef("elasticsearch_document_parse_failures_counter")
ElasticsearchDocumentGenerateFailuresCount = NewCounterDef("elasticsearch_document_generate_failures_counter")
ElasticsearchCustomOrderByClauseCount = NewCounterDef("elasticsearch_custom_order_by_clause_counter")
CatchUpReadyShardCountGauge = NewGaugeDef("catchup_ready_shard_count")
HandoverReadyShardCountGauge = NewGaugeDef("handover_ready_shard_count")
ReplicatorMessages = NewCounterDef("replicator_messages")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,7 @@ func (s *visibilityStore) setDefaultFieldSort(fieldSorts []*elastic.FieldSort) [
return defaultSorter
}

s.metricsHandler.Counter(metrics.ElasticsearchCustomOrderByClauseCount.GetMetricName()).Record(1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we check if the order by is not the same as default order.

Copy link
Contributor Author

@rodrigozhou rodrigozhou Mar 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a way, it's always different. If the user specifies ORDER BY, we're always adding run_id as tie breaker (L744 below). The default sort keys for ES is only close time and start time.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We get here only if custom sort order is specified. If it is not there is an early exit at L735.

res := make([]elastic.Sorter, len(fieldSorts)+1)
for i, fs := range fieldSorts {
res[i] = fs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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().Counter(metrics.ElasticsearchCustomOrderByClauseCount.GetMetricName()).Return(metrics.NoopCounterMetricFunc)
p, err = s.visibilityStore.buildSearchParametersV2(request)
s.NoError(err)
s.Equal(&client.SearchParameters{
Expand Down