Skip to content

Commit

Permalink
Check if collected documents contain errors (elastic#138)
Browse files Browse the repository at this point in the history
* Check if collected documents contain errors

* Try: set ServerName

* Fix: add license header

* Wrap multiErr
  • Loading branch information
mtojek authored Oct 13, 2020
1 parent 392c5dc commit 24a6df1
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 4 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
github.com/AlecAivazis/survey/v2 v2.1.1
github.com/Masterminds/semver v1.5.0
github.com/aymerick/raymond v2.0.2+incompatible
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f
github.com/elastic/go-elasticsearch/v7 v7.9.0
github.com/elastic/go-ucfg v0.8.3
github.com/elastic/package-spec/code/go v0.0.0-20201006155108-bc98b6baa952
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkE
github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f h1:lBNOc5arjvs8E5mO2tbpBpLoyyu8B6e44T7hJy6potg=
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
Expand Down
25 changes: 22 additions & 3 deletions internal/testrunner/runners/system/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"strings"
"time"

"github.com/coreos/pkg/multierror"
es "github.com/elastic/go-elasticsearch/v7"
"github.com/pkg/errors"

Expand Down Expand Up @@ -213,16 +214,34 @@ func (r *runner) run() error {
Total struct {
Value int
}
Hits []struct {
Source Document `json:"_source"`
}
}
}

if err := json.NewDecoder(resp.Body).Decode(&results); err != nil {
return false, errors.Wrap(err, "could not decode search results response")
}

hits := results.Hits.Total.Value
logger.Debugf("found %d hits in %s data stream", hits, dataStream)
return hits > 0, nil
numHits := results.Hits.Total.Value
logger.Debugf("found %d hits in %s data stream", numHits, dataStream)
if numHits == 0 {
return false, nil
}

var multiErr multierror.Error
for _, hit := range results.Hits.Hits {
if hit.Source.Error != nil {
multiErr = append(multiErr, errors.New(hit.Source.Error.Message))
}
}

if len(multiErr) > 0 {
return false, errors.Wrapf(multiErr, "one or more errors found in documents stored in %s data stream",
dataStream)
}
return true, nil
}, 2*time.Minute)

if err != nil {
Expand Down
12 changes: 12 additions & 0 deletions internal/testrunner/runners/system/test_result.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
// or more contributor license agreements. Licensed under the Elastic License;
// you may not use this file except in compliance with the Elastic License.

package system

// Document corresponds to the logs or metrics event stored in the data stream.
type Document struct {
Error *struct {
Message string
}
}
2 changes: 1 addition & 1 deletion test/packages/apache/_dev/deploy/docker/httpd.conf
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ ServerAdmin you@example.com
#
# If your host doesn't have a registered DNS name, enter its IP address here.
#
#ServerName www.example.com:80
ServerName localhost

#
# Deny access to the entirety of your server's filesystem. You must
Expand Down

0 comments on commit 24a6df1

Please sign in to comment.