Skip to content
Open
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
136 changes: 70 additions & 66 deletions internal/testrunner/runners/system/tester.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,40 +41,75 @@ import (
"github.com/elastic/elastic-package/internal/wait"
)

const FieldsQuery = `{
Copy link
Member

Choose a reason for hiding this comment

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

This name seems too generic, I wonder if we should refer to the kind of request this is used for.

Suggested change
const FieldsQuery = `{
const SearchDocsQueryBody = `{

"fields": [
"*"
],
"runtime_mappings": {
"my_ignored": {
"type": "keyword",
"script": {
"source": "for (def v : params['_fields']._ignored.values) { emit(v); }"
}
}
},
"aggs": {
"all_ignored": {
"filter": {
"exists": {
"field": "_ignored"
}
},
"aggs": {
"ignored_fields": {
"terms": {
"size": 100,
"field": "my_ignored"
}
},
"ignored_docs": {
"top_hits": {
"size": 5
}
}
}
}
}
}`

type FieldsQueryResult struct {
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if this type should be moved to internal/elasticsearch.

Hits struct {
Total struct {
Value int
}
Hits []struct {
Source common.MapStr `json:"_source"`
Fields common.MapStr `json:"fields"`
}
}
Aggregations struct {
AllIgnored struct {
DocCount int `json:"doc_count"`
IgnoredFields struct {
Buckets []struct {
Key string `json:"key"`
} `json:"buckets"`
} `json:"ignored_fields"`
IgnoredDocs struct {
Hits struct {
Hits []common.MapStr `json:"hits"`
} `json:"hits"`
} `json:"ignored_docs"`
} `json:"all_ignored"`
} `json:"aggregations"`
Error *struct {
Type string
Reason string
}
Status int
}

const (
checkFieldsBody = `{
"fields": ["*"],
"runtime_mappings": {
"my_ignored": {
"type": "keyword",
"script": {
"source": "for (def v : params['_fields']._ignored.values) { emit(v); }"
}
}
},
"aggs": {
"all_ignored": {
"filter": {
"exists": {
"field": "_ignored"
}
},
"aggs": {
"ignored_fields": {
"terms": {
"size": 100,
"field": "my_ignored"
}
},
"ignored_docs": {
"top_hits": {
"size": 5
}
}
}
}
}
}`
DevDeployDir = "_dev/deploy"

// TestType defining system tests
Expand Down Expand Up @@ -764,7 +799,7 @@ func (r *tester) getDocs(ctx context.Context, dataStream string) (*hits, error)
r.esAPI.Search.WithSort("@timestamp:asc"),
r.esAPI.Search.WithSize(elasticsearchQuerySize),
r.esAPI.Search.WithSource("true"),
r.esAPI.Search.WithBody(strings.NewReader(checkFieldsBody)),
r.esAPI.Search.WithBody(strings.NewReader(FieldsQuery)),
r.esAPI.Search.WithIgnoreUnavailable(true),
)
if err != nil {
Expand All @@ -781,38 +816,7 @@ func (r *tester) getDocs(ctx context.Context, dataStream string) (*hits, error)
return nil, fmt.Errorf("failed to search docs for data stream %s: %s", dataStream, resp.String())
}

var results struct {
Hits struct {
Total struct {
Value int
}
Hits []struct {
Source common.MapStr `json:"_source"`
Fields common.MapStr `json:"fields"`
}
}
Aggregations struct {
AllIgnored struct {
DocCount int `json:"doc_count"`
IgnoredFields struct {
Buckets []struct {
Key string `json:"key"`
} `json:"buckets"`
} `json:"ignored_fields"`
IgnoredDocs struct {
Hits struct {
Hits []common.MapStr `json:"hits"`
} `json:"hits"`
} `json:"ignored_docs"`
} `json:"all_ignored"`
} `json:"aggregations"`
Error *struct {
Type string
Reason string
}
Status int
}

var results FieldsQueryResult
if err := json.NewDecoder(resp.Body).Decode(&results); err != nil {
return nil, fmt.Errorf("could not decode search results response: %w", err)
}
Expand Down