diff --git a/functionaltests/8_15_test.go b/functionaltests/8_15_test.go index aa80d04d610..efc3c07b162 100644 --- a/functionaltests/8_15_test.go +++ b/functionaltests/8_15_test.go @@ -30,6 +30,7 @@ import ( "github.com/elastic/apm-server/functionaltests/internal/terraform" "github.com/elastic/go-elasticsearch/v8/typedapi/types" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -145,6 +146,7 @@ func TestUpgrade_8_15_4_to_8_16_0(t *testing.T) { }, dss2) t.Logf("time elapsed: %s", time.Now().Sub(start)) - // check ES logs, there should be no errors - // TODO: how to get these from Elastic Cloud? Is it possible? + res, err := ecc.GetESErrorLogs(ctx) + require.NoError(t, err) + assert.Zero(t, res.Hits.Total.Value) } diff --git a/functionaltests/internal/esclient/client.go b/functionaltests/internal/esclient/client.go index 29c0adad164..eb2b99e0a36 100644 --- a/functionaltests/internal/esclient/client.go +++ b/functionaltests/internal/esclient/client.go @@ -27,6 +27,7 @@ import ( "time" "github.com/elastic/go-elasticsearch/v8" + "github.com/elastic/go-elasticsearch/v8/typedapi/core/search" "github.com/elastic/go-elasticsearch/v8/typedapi/esql/query" "github.com/elastic/go-elasticsearch/v8/typedapi/security/createapikey" "github.com/elastic/go-elasticsearch/v8/typedapi/types" @@ -157,3 +158,36 @@ line 1:1: Unknown index [traces-apm*,apm-*,traces-*.otel-*,logs-apm*,apm-*,logs- return res, nil } + +// GetESErrorLogs retrieves Elasticsearch error logs. +// The search query is on the Index used by Elasticsearch monitoring to store logs. +func (c *Client) GetESErrorLogs(ctx context.Context) (*search.Response, error) { + res, err := c.es.Search(). + Index("elastic-cloud-logs-8"). + Request(&search.Request{ + Query: &types.Query{ + Bool: &types.BoolQuery{ + Must: []types.Query{ + { + Match: map[string]types.MatchQuery{ + "service.type": {Query: "elasticsearch"}, + }, + }, + { + Match: map[string]types.MatchQuery{ + "log.level": {Query: "ERROR"}, + }, + }, + }, + }, + }, + }).Do(ctx) + if err != nil { + return search.NewResponse(), fmt.Errorf("cannot run search query: %w", err) + } + + fmt.Printf("%+v\n", res) + fmt.Println(res.Hits.Total.Value) + + return res, nil +}