Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
iwysiu committed Jan 21, 2025
1 parent 0d9ba09 commit ad847b3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
10 changes: 5 additions & 5 deletions pkg/opensearch/snapshot_tests/lucene_service_map_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func Test_service_map_prefetch_request(t *testing.T) {
return err
}
interceptedRequests = append(interceptedRequests, request)

defer req.Body.Close()
return nil
}},
Expand Down Expand Up @@ -65,7 +65,7 @@ func Test_service_map__for_trace_list_request(t *testing.T) {
return err
}
interceptedRequests = append(interceptedRequests, request)

defer req.Body.Close()
return nil
}},
Expand All @@ -90,7 +90,7 @@ func Test_service_map__for_trace_list_request(t *testing.T) {
{"ignore_unavailable":true,"index":"","search_type":"query_then_fetch"}
{"aggs":{"service_name":{"aggs":{"destination_domain":{"aggs":{"destination_resource":{"terms":{"field":"destination.resource","size":1000}}},"terms":{"field":"destination.domain","size":1000}},"target_domain":{"aggs":{"target_resource":{"terms":{"field":"target.resource","size":1000}}},"terms":{"field":"target.domain","size":1000}}},"terms":{"field":"serviceName","size":1000}}},"query":{"bool":{}},"size":0}
{"ignore_unavailable":true,"index":"","search_type":"query_then_fetch"}
{"aggs":{"traces":{"aggs":{"error_count":{"filter":{"term":{"traceGroupFields.statusCode":"2"}}},"last_updated":{"max":{"field":"traceGroupFields.endTime"}},"latency":{"max":{"script":{"source":"\n if (doc.containsKey('traceGroupFields.durationInNanos') \u0026\u0026 !doc['traceGroupFields.durationInNanos'].empty) {\n return Math.round(doc['traceGroupFields.durationInNanos'].value / 10000) / 100.0\n }\n return 0\n ","lang":"painless"}}},"trace_group":{"terms":{"field":"traceGroup","size":1}}},"terms":{"field":"traceId","size":100,"order":{"_key":"asc"}}}},"query":{"bool":{"must":[{"range":{"startTime":{"gte":1668422437218,"lte":1668422625668}}},{"query_string":{"analyze_wildcard":true,"query":"*"}}]}},"size":10}
{"aggs":{"traces":{"aggs":{"error_count":{"filter":{"term":{"traceGroupFields.statusCode":"2"}}},"last_updated":{"max":{"field":"traceGroupFields.endTime"}},"latency":{"max":{"script":{"source":"\n if (doc.containsKey('traceGroupFields.durationInNanos') \u0026\u0026 !doc['traceGroupFields.durationInNanos'].empty) {\n return Math.round(doc['traceGroupFields.durationInNanos'].value / 10000) / 100.0\n }\n return 0\n ","lang":"painless"}}},"trace_group":{"terms":{"field":"traceGroup","size":1}}},"terms":{"field":"traceId","size":1000,"order":{"_key":"asc"}}}},"query":{"bool":{"must":[{"range":{"startTime":{"gte":1668422437218,"lte":1668422625668}}},{"query_string":{"analyze_wildcard":true,"query":"*"}}]}},"size":10}
`
assert.Equal(t, expectedRequestPrefetch, string(interceptedRequests[0]))
assert.Equal(t, expectedRequestMain, string(interceptedRequests[1]))
Expand All @@ -111,7 +111,7 @@ func Test_service_map_for_single_trace_request(t *testing.T) {
return err
}
interceptedRequests = append(interceptedRequests, request)

defer req.Body.Close()
return nil
}},
Expand Down Expand Up @@ -140,4 +140,4 @@ func Test_service_map_for_single_trace_request(t *testing.T) {
`
assert.Equal(t, expectedRequestPrefetch, string(interceptedRequests[0]))
assert.Equal(t, expectedRequestMain, string(interceptedRequests[1]))
}
}
7 changes: 3 additions & 4 deletions pkg/opensearch/snapshot_tests/lucene_trace_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func Test_trace_list_request(t *testing.T) {

// assert request's header and query
expectedRequest := `{"ignore_unavailable":true,"index":"","search_type":"query_then_fetch"}
{"aggs":{"traces":{"aggs":{"error_count":{"filter":{"term":{"traceGroupFields.statusCode":"2"}}},"last_updated":{"max":{"field":"traceGroupFields.endTime"}},"latency":{"max":{"script":{"source":"\n if (doc.containsKey('traceGroupFields.durationInNanos') \u0026\u0026 !doc['traceGroupFields.durationInNanos'].empty) {\n return Math.round(doc['traceGroupFields.durationInNanos'].value / 10000) / 100.0\n }\n return 0\n ","lang":"painless"}}},"trace_group":{"terms":{"field":"traceGroup","size":1}}},"terms":{"field":"traceId","size":100,"order":{"_key":"asc"}}}},"query":{"bool":{"must":[{"range":{"startTime":{"gte":1668422437218,"lte":1668422625668}}},{"query_string":{"analyze_wildcard":true,"query":"some query"}}]}},"size":10}
{"aggs":{"traces":{"aggs":{"error_count":{"filter":{"term":{"traceGroupFields.statusCode":"2"}}},"last_updated":{"max":{"field":"traceGroupFields.endTime"}},"latency":{"max":{"script":{"source":"\n if (doc.containsKey('traceGroupFields.durationInNanos') \u0026\u0026 !doc['traceGroupFields.durationInNanos'].empty) {\n return Math.round(doc['traceGroupFields.durationInNanos'].value / 10000) / 100.0\n }\n return 0\n ","lang":"painless"}}},"trace_group":{"terms":{"field":"traceGroup","size":1}}},"terms":{"field":"traceId","size":1000,"order":{"_key":"asc"}}}},"query":{"bool":{"must":[{"range":{"startTime":{"gte":1668422437218,"lte":1668422625668}}},{"query_string":{"analyze_wildcard":true,"query":"some query"}}]}},"size":10}
`
assert.Equal(t, expectedRequest, string(interceptedRequest))
}
Expand Down Expand Up @@ -73,9 +73,9 @@ func Test_trace_list_request_with_multiple_list_queries(t *testing.T) {

// assert request's header and query
expectedRequest := `{"ignore_unavailable":true,"index":"","search_type":"query_then_fetch"}
{"aggs":{"traces":{"aggs":{"error_count":{"filter":{"term":{"traceGroupFields.statusCode":"2"}}},"last_updated":{"max":{"field":"traceGroupFields.endTime"}},"latency":{"max":{"script":{"source":"\n if (doc.containsKey('traceGroupFields.durationInNanos') \u0026\u0026 !doc['traceGroupFields.durationInNanos'].empty) {\n return Math.round(doc['traceGroupFields.durationInNanos'].value / 10000) / 100.0\n }\n return 0\n ","lang":"painless"}}},"trace_group":{"terms":{"field":"traceGroup","size":1}}},"terms":{"field":"traceId","size":100,"order":{"_key":"asc"}}}},"query":{"bool":{"must":[{"range":{"startTime":{"gte":1668422437218,"lte":1668422625668}}},{"query_string":{"analyze_wildcard":true,"query":"some query"}}]}},"size":10}
{"aggs":{"traces":{"aggs":{"error_count":{"filter":{"term":{"traceGroupFields.statusCode":"2"}}},"last_updated":{"max":{"field":"traceGroupFields.endTime"}},"latency":{"max":{"script":{"source":"\n if (doc.containsKey('traceGroupFields.durationInNanos') \u0026\u0026 !doc['traceGroupFields.durationInNanos'].empty) {\n return Math.round(doc['traceGroupFields.durationInNanos'].value / 10000) / 100.0\n }\n return 0\n ","lang":"painless"}}},"trace_group":{"terms":{"field":"traceGroup","size":1}}},"terms":{"field":"traceId","size":1000,"order":{"_key":"asc"}}}},"query":{"bool":{"must":[{"range":{"startTime":{"gte":1668422437218,"lte":1668422625668}}},{"query_string":{"analyze_wildcard":true,"query":"some query"}}]}},"size":10}
{"ignore_unavailable":true,"index":"","search_type":"query_then_fetch"}
{"aggs":{"traces":{"aggs":{"error_count":{"filter":{"term":{"traceGroupFields.statusCode":"2"}}},"last_updated":{"max":{"field":"traceGroupFields.endTime"}},"latency":{"max":{"script":{"source":"\n if (doc.containsKey('traceGroupFields.durationInNanos') \u0026\u0026 !doc['traceGroupFields.durationInNanos'].empty) {\n return Math.round(doc['traceGroupFields.durationInNanos'].value / 10000) / 100.0\n }\n return 0\n ","lang":"painless"}}},"trace_group":{"terms":{"field":"traceGroup","size":1}}},"terms":{"field":"traceId","size":100,"order":{"_key":"asc"}}}},"query":{"bool":{"must":[{"range":{"startTime":{"gte":1668422437218,"lte":1668422625668}}},{"query_string":{"analyze_wildcard":true,"query":"some query"}}]}},"size":10}
{"aggs":{"traces":{"aggs":{"error_count":{"filter":{"term":{"traceGroupFields.statusCode":"2"}}},"last_updated":{"max":{"field":"traceGroupFields.endTime"}},"latency":{"max":{"script":{"source":"\n if (doc.containsKey('traceGroupFields.durationInNanos') \u0026\u0026 !doc['traceGroupFields.durationInNanos'].empty) {\n return Math.round(doc['traceGroupFields.durationInNanos'].value / 10000) / 100.0\n }\n return 0\n ","lang":"painless"}}},"trace_group":{"terms":{"field":"traceGroup","size":1}}},"terms":{"field":"traceId","size":1000,"order":{"_key":"asc"}}}},"query":{"bool":{"must":[{"range":{"startTime":{"gte":1668422437218,"lte":1668422625668}}},{"query_string":{"analyze_wildcard":true,"query":"some query"}}]}},"size":10}
`
assert.Equal(t, expectedRequest, string(interceptedRequest))
}
Expand Down Expand Up @@ -128,4 +128,3 @@ func Test_trace_list_response_with_multiple_list_queries(t *testing.T) {
experimental.CheckGoldenJSONResponse(t, "testdata", "lucene_trace_list.expected_result_generated_snapshot.golden", &responseForRefIdA, false)
experimental.CheckGoldenJSONResponse(t, "testdata", "lucene_trace_list.expected_result_generated_snapshot.golden", &responseForRefIdB, false)
}

5 changes: 3 additions & 2 deletions pkg/opensearch/snapshot_tests/lucene_trace_spans_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,10 @@ func Test_trace_spans_request_with_trace_list_request(t *testing.T) {
expectedRequest := `{"ignore_unavailable":true,"index":"","search_type":"query_then_fetch"}
{"query":{"bool":{"must":[{"range":{"startTime":{"gte":1668422437218,"lte":1668422625668}}},{"term":{"traceId":"test"}}]}},"size":1000}
{"ignore_unavailable":true,"index":"","search_type":"query_then_fetch"}
{"aggs":{"traces":{"aggs":{"error_count":{"filter":{"term":{"traceGroupFields.statusCode":"2"}}},"last_updated":{"max":{"field":"traceGroupFields.endTime"}},"latency":{"max":{"script":{"source":"\n if (doc.containsKey('traceGroupFields.durationInNanos') \u0026\u0026 !doc['traceGroupFields.durationInNanos'].empty) {\n return Math.round(doc['traceGroupFields.durationInNanos'].value / 10000) / 100.0\n }\n return 0\n ","lang":"painless"}}},"trace_group":{"terms":{"field":"traceGroup","size":1}}},"terms":{"field":"traceId","size":100,"order":{"_key":"asc"}}}},"query":{"bool":{"must":[{"range":{"startTime":{"gte":1668422437218,"lte":1668422625668}}},{"query_string":{"analyze_wildcard":true,"query":"some query"}}]}},"size":10}
{"aggs":{"traces":{"aggs":{"error_count":{"filter":{"term":{"traceGroupFields.statusCode":"2"}}},"last_updated":{"max":{"field":"traceGroupFields.endTime"}},"latency":{"max":{"script":{"source":"\n if (doc.containsKey('traceGroupFields.durationInNanos') \u0026\u0026 !doc['traceGroupFields.durationInNanos'].empty) {\n return Math.round(doc['traceGroupFields.durationInNanos'].value / 10000) / 100.0\n }\n return 0\n ","lang":"painless"}}},"trace_group":{"terms":{"field":"traceGroup","size":1}}},"terms":{"field":"traceId","size":1000,"order":{"_key":"asc"}}}},"query":{"bool":{"must":[{"range":{"startTime":{"gte":1668422437218,"lte":1668422625668}}},{"query_string":{"analyze_wildcard":true,"query":"some query"}}]}},"size":10}
`
assert.Equal(t, expectedRequest, string(interceptedRequest))
}
// Couldn't get the snapshot test for the trace span responses to work because the response processing uses maps, so the result has slightly different order every time.

// Couldn't get the snapshot test for the trace span responses to work because the response processing uses maps, so the result has slightly different order every time.
// Added a test for the response in response_processing.test.go instead

0 comments on commit ad847b3

Please sign in to comment.