Skip to content

Commit

Permalink
Check async query status (#130)
Browse files Browse the repository at this point in the history
We broke the async search status; let's add a test to detect this key
functionality.
  • Loading branch information
jakozaur authored May 16, 2024
1 parent 7f80784 commit 43034fa
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 15 deletions.
34 changes: 28 additions & 6 deletions smoke-test/async_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"fmt"
"github.com/qri-io/jsonpointer"
"io"
"log"
"net/http"
"reflect"
"strings"
Expand Down Expand Up @@ -237,21 +236,26 @@ func checkTypeExpectation(expectedType string, path string, response map[string]

}

type asyncQueryType struct {
Id string `json:"id"`
}

func waitForAsyncQuery(timeout time.Duration) {
serviceName := "async query: "
for _, query := range sampleQueries {
var body []byte
res := waitFor(serviceName+query.name, func() bool {
resp, err := http.Post(asyncQueryUrl, "application/json", bytes.NewBuffer([]byte(query.body)))

if err == nil {
defer resp.Body.Close()
if resp.StatusCode == 200 {
body, err := io.ReadAll(resp.Body)
if err == nil {
return validateResponse(query, resp, body)
} else {
log.Println(err)
body, err = io.ReadAll(resp.Body)
if err != nil {
fmt.Println("Failed to read the body", err)
panic("can't read response body")
}
return validateResponse(query, resp, body)
}
}
return false
Expand All @@ -260,6 +264,24 @@ func waitForAsyncQuery(timeout time.Duration) {
if !res {
panic(serviceName + " is not alive or is not receiving logs")
}

var asyncQuery asyncQueryType
err := json.Unmarshal(body, &asyncQuery)
if err != nil {
fmt.Println("Parsing JSON out of _async_search failed", err)
panic("can't parse async query response")
}

resp, err := http.Get(asyncGetQueryUrlPrefix + asyncQuery.Id)
if err != nil {
fmt.Println("Getting _async_status failed", err)
panic("can't get async query status")
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
fmt.Printf("async query status is %d %s\n", resp.StatusCode, asyncGetQueryUrlPrefix+asyncQuery.Id)
panic("async query status is not 200")
}
}
checkLogs()
}
Expand Down
20 changes: 11 additions & 9 deletions smoke-test/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,17 @@ import (
)

const (
clickhouseUrl = "http://localhost:8123"
kibanaUrl = "http://localhost:5601"
kibanaHealthCheckUrl = "http://localhost:5601/api/status"
kibanaDataViewsUrl = "http://localhost:5601/api/data_views"
kibanaCsvReportUrl = "http://localhost:5601/api/reporting/generate/csv_searchsource"
elasticsearchBaseUrl = "http://localhost:9201"
elasticIndexCountUrl = "http://localhost:9201/logs-generic-default,logs-*/_count"
quesmaIndexCountUrl = "http://localhost:9200/logs-generic-default,logs-*/_count"
asyncQueryUrl = "http://localhost:8080/logs-*/_async_search?pretty"
clickhouseUrl = "http://localhost:8123"
kibanaUrl = "http://localhost:5601"
kibanaHealthCheckUrl = "http://localhost:5601/api/status"
kibanaDataViewsUrl = "http://localhost:5601/api/data_views"
kibanaCsvReportUrl = "http://localhost:5601/api/reporting/generate/csv_searchsource"
elasticsearchBaseUrl = "http://localhost:9201"
elasticIndexCountUrl = "http://localhost:9201/logs-generic-default,logs-*/_count"
quesmaIndexCountUrl = "http://localhost:9200/logs-generic-default,logs-*/_count"
asyncQueryUrl = "http://localhost:8080/logs-*/_async_search?pretty&keep_on_completion=true"
asyncGetQueryUrlPrefix = "http://localhost:8080/_async_search/"

kibanaLogExplorerMainUrl = "http://localhost:5601/app/observability-log-explorer/?controlPanels=(data_stream.namespace:(explicitInput:(fieldName:data_stream.namespace,id:data_stream.namespace,title:Namespace),grow:!f,order:0,type:optionsListControl,width:medium))&_a=(columns:!(service.name,host.name,message),filters:!(),grid:(columns:(host.name:(width:320),service.name:(width:240))),index:BQZwpgNmDGAuCWB7AdgFQJ4AcwC4CGEEAlEA,interval:auto,query:(language:kuery,query:%27%27),rowHeight:0,sort:!(!(%27@timestamp%27,desc)))&_g=(filters:!(),refreshInterval:(pause:!t,value:60000),time:(from:now-15m,to:now))"
kibanaLogInternalUrl = "http://localhost:5601/internal/controls/optionsList/logs-*-*"
)
Expand Down

0 comments on commit 43034fa

Please sign in to comment.