Skip to content

Commit

Permalink
chore: start updating integration test to account for new approach fo…
Browse files Browse the repository at this point in the history
…r getting log attrib values
  • Loading branch information
raj-k-singh committed Aug 15, 2024
1 parent a2d34d1 commit 1b3c363
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 50 deletions.
40 changes: 0 additions & 40 deletions pkg/query-service/app/clickhouseReader/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
31 changes: 21 additions & 10 deletions pkg/query-service/tests/integration/filter_suggestions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 1b3c363

Please sign in to comment.