diff --git a/pkg/query-service/app/clickhouseReader/reader.go b/pkg/query-service/app/clickhouseReader/reader.go index 4def0e802b3..49524673e3d 100644 --- a/pkg/query-service/app/clickhouseReader/reader.go +++ b/pkg/query-service/app/clickhouseReader/reader.go @@ -4466,46 +4466,6 @@ func (r *ClickHouseReader) GetQBFilterSuggestionsForLogs( } } - // if len(suggestions.AttributeKeys) > 0 { - // topAttrib := suggestions.AttributeKeys[0] - - // resp, err := r.GetLogAttributeValues(ctx, &v3.FilterAttributeValueRequest{ - // DataSource: v3.DataSourceLogs, - // FilterAttributeKey: topAttrib.Key, - // FilterAttributeKeyDataType: topAttrib.DataType, - // TagType: v3.TagType(topAttrib.Type), - // Limit: 1, - // }) - - // if err != nil { - // // Do not fail the entire request if only example query generation fails - // zap.L().Error("could not find attribute values for creating example query", zap.Error(err)) - - // } else { - // addExampleQuerySuggestion := func(value any) { - // exampleQuery := newExampleQuery() - - // exampleQuery.Items = append(exampleQuery.Items, v3.FilterItem{ - // Key: topAttrib, - // Operator: "=", - // Value: value, - // }) - - // suggestions.ExampleQueries = append( - // suggestions.ExampleQueries, exampleQuery, - // ) - // } - - // if len(resp.StringAttributeValues) > 0 { - // addExampleQuerySuggestion(resp.StringAttributeValues[0]) - // } else if len(resp.NumberAttributeValues) > 0 { - // addExampleQuerySuggestion(resp.NumberAttributeValues[0]) - // } else if len(resp.BoolAttributeValues) > 0 { - // addExampleQuerySuggestion(resp.BoolAttributeValues[0]) - // } - // } - // } - // Suggest static example queries for standard log attributes if needed. if len(suggestions.ExampleQueries) < req.ExamplesLimit { exampleQuery := newExampleQuery() diff --git a/pkg/query-service/tests/integration/filter_suggestions_test.go b/pkg/query-service/tests/integration/filter_suggestions_test.go index 5f7fcea5419..03f64dcd6f6 100644 --- a/pkg/query-service/tests/integration/filter_suggestions_test.go +++ b/pkg/query-service/tests/integration/filter_suggestions_test.go @@ -59,7 +59,9 @@ func TestLogsFilterSuggestionsWithoutExistingFilter(t *testing.T) { testAttribValue := "test-container" tb.mockAttribKeysQueryResponse([]v3.AttributeKey{testAttrib}) - tb.mockAttribValuesQueryResponse(testAttrib, []string{testAttribValue}) + tb.mockAttribValuesQueryResponse( + []v3.AttributeKey{testAttrib}, [][]string{[]string{testAttribValue}}, + ) suggestionsQueryParams := map[string]string{} suggestionsResp := tb.GetQBFilterSuggestionsForLogs(suggestionsQueryParams) @@ -114,7 +116,9 @@ func TestLogsFilterSuggestionsWithExistingFilter(t *testing.T) { } tb.mockAttribKeysQueryResponse([]v3.AttributeKey{testAttrib, testFilterAttrib}) - tb.mockAttribValuesQueryResponse(testAttrib, []string{testAttribValue}) + tb.mockAttribValuesQueryResponse( + []v3.AttributeKey{testAttrib}, [][]string{[]string{testAttribValue}}, + ) testFilterJson, err := json.Marshal(testFilter) require.Nil(err, "couldn't serialize existing filter to JSON") @@ -170,22 +174,29 @@ func (tb *FilterSuggestionsTestBed) mockAttribKeysQueryResponse( // Mocks response for CH queries made by reader.GetLogAttributeValues func (tb *FilterSuggestionsTestBed) mockAttribValuesQueryResponse( - expectedAttrib v3.AttributeKey, - stringValuesToReturn []string, + expectedAttribs []v3.AttributeKey, + expectedStringValues [][]string, ) { cols := []mockhouse.ColumnType{} + cols = append(cols, mockhouse.ColumnType{Type: "String", Name: "tagKey"}) cols = append(cols, mockhouse.ColumnType{Type: "String", Name: "stringTagValue"}) + cols = append(cols, mockhouse.ColumnType{Type: "Nullable(Int64)", Name: "int64TagValue"}) + cols = append(cols, mockhouse.ColumnType{Type: "Nullable(Float64)", Name: "float64TagValue"}) + expectedAttribKeys := []string{} values := [][]any{} - for _, v := range stringValuesToReturn { - rowValues := []any{} - rowValues = append(rowValues, v) - values = append(values, rowValues) + for idx, attrib := range expectedAttribs { + expectedAttribKeys = append(expectedAttribKeys, attrib.Key) + for _, val := range expectedStringValues[idx] { + rowValues := []any{} + rowValues = append(rowValues, attrib.Key, val, nil, nil) + values = append(values, rowValues) + } } tb.mockClickhouse.ExpectQuery( - "select distinct.*stringTagValue.*from.*signoz_logs.distributed_tag_attributes.*", - ).WithArgs(string(expectedAttrib.Key), v3.TagType(expectedAttrib.Type), 1).WillReturnRows(mockhouse.NewRows(cols, values)) + "select.*tagKey.*stringTagValue.*int64TagValue.*float64TagValue.*distributed_tag_attributes.*tagKey.*IN.*", + ).WithArgs(expectedAttribKeys).WillReturnRows(mockhouse.NewRows(cols, values)) } type FilterSuggestionsTestBed struct {