Skip to content

Commit

Permalink
assert elasticsearch logs
Browse files Browse the repository at this point in the history
  • Loading branch information
endorama committed Jan 16, 2025
1 parent 0a02a50 commit db94233
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
6 changes: 4 additions & 2 deletions functionaltests/8_15_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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)
}
34 changes: 34 additions & 0 deletions functionaltests/internal/esclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}

0 comments on commit db94233

Please sign in to comment.