diff --git a/.golangci.yml b/.golangci.yml index b63b813ebc2e..60d77f468000 100755 --- a/.golangci.yml +++ b/.golangci.yml @@ -120,6 +120,11 @@ linters-settings: - errors - fmt reason: "This package is deprecated, use `fmt.Errorf` with `%w` instead" + - github.com/google/uuid: + # Recommended modules that should be used instead. (Optional) + recommendations: + - github.com/gofrs/uuid/v5 + reason: "Use one uuid library consistently across the codebase" gosimple: # Select the Go version to target. The default is '1.13'. diff --git a/NOTICE.txt b/NOTICE.txt index e691397655f2..1144db8a2605 100644 --- a/NOTICE.txt +++ b/NOTICE.txt @@ -17497,12 +17497,12 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- -Dependency : github.com/gofrs/uuid -Version: v4.4.0+incompatible +Dependency : github.com/gofrs/uuid/v5 +Version: v5.2.0 Licence type (autodetected): MIT -------------------------------------------------------------------------------- -Contents of probable licence file $GOMODCACHE/github.com/gofrs/uuid@v4.4.0+incompatible/LICENSE: +Contents of probable licence file $GOMODCACHE/github.com/gofrs/uuid/v5@v5.2.0/LICENSE: Copyright (C) 2013-2018 by Maxim Bublis @@ -18556,43 +18556,6 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --------------------------------------------------------------------------------- -Dependency : github.com/google/uuid -Version: v1.6.0 -Licence type (autodetected): BSD-3-Clause --------------------------------------------------------------------------------- - -Contents of probable licence file $GOMODCACHE/github.com/google/uuid@v1.6.0/LICENSE: - -Copyright (c) 2009,2014 Google Inc. All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - - * Redistributions of source code must retain the above copyright -notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above -copyright notice, this list of conditions and the following disclaimer -in the documentation and/or other materials provided with the -distribution. - * Neither the name of Google Inc. nor the names of its -contributors may be used to endorse or promote products derived from -this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - -------------------------------------------------------------------------------- Dependency : github.com/googleapis/gax-go/v2 Version: v2.13.0 @@ -40751,36 +40714,6 @@ Contents of probable licence file $GOMODCACHE/github.com/godror/knownpb@v0.1.0/L limitations under the License. --------------------------------------------------------------------------------- -Dependency : github.com/gofrs/uuid/v5 -Version: v5.2.0 -Licence type (autodetected): MIT --------------------------------------------------------------------------------- - -Contents of probable licence file $GOMODCACHE/github.com/gofrs/uuid/v5@v5.2.0/LICENSE: - -Copyright (C) 2013-2018 by Maxim Bublis - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - - -------------------------------------------------------------------------------- Dependency : github.com/golang-jwt/jwt/v4 Version: v4.5.0 @@ -42984,6 +42917,43 @@ Contents of probable licence file $GOMODCACHE/github.com/google/shlex@v0.0.0-201 limitations under the License. +-------------------------------------------------------------------------------- +Dependency : github.com/google/uuid +Version: v1.6.0 +Licence type (autodetected): BSD-3-Clause +-------------------------------------------------------------------------------- + +Contents of probable licence file $GOMODCACHE/github.com/google/uuid@v1.6.0/LICENSE: + +Copyright (c) 2009,2014 Google Inc. All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + * Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above +copyright notice, this list of conditions and the following disclaimer +in the documentation and/or other materials provided with the +distribution. + * Neither the name of Google Inc. nor the names of its +contributors may be used to endorse or promote products derived from +this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + -------------------------------------------------------------------------------- Dependency : github.com/googleapis/enterprise-certificate-proxy Version: v0.3.2 diff --git a/filebeat/fileset/factory.go b/filebeat/fileset/factory.go index 9b3808e79137..ca7895a90fd9 100644 --- a/filebeat/fileset/factory.go +++ b/filebeat/fileset/factory.go @@ -21,7 +21,7 @@ import ( "fmt" "sync" - "github.com/gofrs/uuid" + "github.com/gofrs/uuid/v5" "github.com/mitchellh/hashstructure" "github.com/elastic/beats/v7/libbeat/beat" diff --git a/filebeat/harvester/harvester.go b/filebeat/harvester/harvester.go index 39f9b45bb2bd..4d1b7211a7b2 100644 --- a/filebeat/harvester/harvester.go +++ b/filebeat/harvester/harvester.go @@ -18,7 +18,7 @@ package harvester import ( - "github.com/gofrs/uuid" + "github.com/gofrs/uuid/v5" ) // Harvester contains all methods which must be supported by each harvester diff --git a/filebeat/harvester/registry.go b/filebeat/harvester/registry.go index 989557d08bc9..0097bb82a079 100644 --- a/filebeat/harvester/registry.go +++ b/filebeat/harvester/registry.go @@ -21,7 +21,7 @@ import ( "errors" "sync" - "github.com/gofrs/uuid" + "github.com/gofrs/uuid/v5" "github.com/elastic/elastic-agent-libs/logp" ) diff --git a/filebeat/input/log/harvester.go b/filebeat/input/log/harvester.go index ee08a3ff1844..84a62bcdfa42 100644 --- a/filebeat/input/log/harvester.go +++ b/filebeat/input/log/harvester.go @@ -37,7 +37,7 @@ import ( "sync" "time" - "github.com/gofrs/uuid" + "github.com/gofrs/uuid/v5" "golang.org/x/text/transform" "github.com/elastic/beats/v7/libbeat/beat" @@ -191,7 +191,7 @@ func (h *Harvester) ID() uuid.UUID { func (h *Harvester) Setup() error { err := h.open() if err != nil { - return fmt.Errorf("Harvester setup failed. Unexpected file opening error: %s", err) + return fmt.Errorf("Harvester setup failed. Unexpected file opening error: %w", err) } h.reader, err = h.newLogFileReader() @@ -199,7 +199,7 @@ func (h *Harvester) Setup() error { if h.source != nil { h.source.Close() } - return fmt.Errorf("Harvester setup failed. Unexpected encoding line reader error: %s", err) + return fmt.Errorf("Harvester setup failed. Unexpected encoding line reader error: %w", err) } h.metrics = newHarvesterProgressMetrics(h.id.String()) @@ -325,20 +325,20 @@ func (h *Harvester) Run() error { message, err := h.reader.Next() if err != nil { - switch err { - case ErrFileTruncate: + switch { + case errors.Is(err, ErrFileTruncate): logger.Info("File was truncated. Begin reading file from offset 0.") h.state.Offset = 0 filesTruncated.Add(1) - case ErrRemoved: + case errors.Is(err, ErrRemoved): logger.Info("File was removed. Closing because close_removed is enabled.") - case ErrRenamed: + case errors.Is(err, ErrRenamed): logger.Info("File was renamed. Closing because close_renamed is enabled.") - case ErrClosed: + case errors.Is(err, ErrClosed): logger.Info("Reader was closed. Closing.") - case io.EOF: + case errors.Is(err, io.EOF): logger.Info("End of file reached. Closing because close_eof is enabled.") - case ErrInactive: + case errors.Is(err, ErrInactive): logger.Infof("File is inactive. Closing because close_inactive of %v reached.", h.config.CloseInactive) default: logger.Errorf("Read line error: %v", err) @@ -519,7 +519,7 @@ func (h *Harvester) shouldExportLine(line string) bool { func (h *Harvester) openFile() error { fi, err := os.Stat(h.state.Source) if err != nil { - return fmt.Errorf("failed to stat source file %s: %v", h.state.Source, err) + return fmt.Errorf("failed to stat source file %s: %w", h.state.Source, err) } if fi.Mode()&os.ModeNamedPipe != 0 { return fmt.Errorf("failed to open file %s, named pipes are not supported", h.state.Source) @@ -527,7 +527,7 @@ func (h *Harvester) openFile() error { f, err := file_helper.ReadOpen(h.state.Source) if err != nil { - return fmt.Errorf("Failed opening %s: %s", h.state.Source, err) + return fmt.Errorf("Failed opening %s: %w", h.state.Source, err) } harvesterOpenFiles.Add(1) @@ -549,7 +549,7 @@ func (h *Harvester) validateFile(f *os.File) error { info, err := f.Stat() if err != nil { - return fmt.Errorf("Failed getting stats for file %s: %s", h.state.Source, err) + return fmt.Errorf("Failed getting stats for file %s: %w", h.state.Source, err) } if !info.Mode().IsRegular() { @@ -563,8 +563,7 @@ func (h *Harvester) validateFile(f *os.File) error { h.encoding, err = h.encodingFactory(f) if err != nil { - - if err == transform.ErrShortSrc { + if errors.Is(err, transform.ErrShortSrc) { logger.Infof("Initialising encoding for '%v' failed due to file being too short", f) } else { logger.Errorf("Initialising encoding for '%v' failed: %v", f, err) @@ -588,12 +587,12 @@ func (h *Harvester) initFileOffset(file *os.File) (int64, error) { // continue from last known offset if h.state.Offset > 0 { h.logger.Debugf("Set previous offset: %d ", h.state.Offset) - return file.Seek(h.state.Offset, os.SEEK_SET) + return file.Seek(h.state.Offset, io.SeekStart) } // get offset from file in case of encoding factory was required to read some data. h.logger.Debug("Setting offset to: 0") - return file.Seek(0, os.SEEK_CUR) + return file.Seek(0, io.SeekCurrent) } // getState returns an updated copy of the harvester state diff --git a/filebeat/input/log/input.go b/filebeat/input/log/input.go index 40c42ddeebdf..ad93632b372c 100644 --- a/filebeat/input/log/input.go +++ b/filebeat/input/log/input.go @@ -27,7 +27,7 @@ import ( "sync" "time" - "github.com/gofrs/uuid" + "github.com/gofrs/uuid/v5" "github.com/elastic/beats/v7/filebeat/channel" "github.com/elastic/beats/v7/filebeat/harvester" diff --git a/filebeat/input/redis/harvester.go b/filebeat/input/redis/harvester.go index 79929a4ee4fd..141c5f157738 100644 --- a/filebeat/input/redis/harvester.go +++ b/filebeat/input/redis/harvester.go @@ -22,7 +22,7 @@ import ( "strings" "time" - "github.com/gofrs/uuid" + "github.com/gofrs/uuid/v5" rd "github.com/gomodule/redigo/redis" "github.com/elastic/beats/v7/libbeat/beat" @@ -82,8 +82,12 @@ func (h *Harvester) Run() error { default: } // Writes Slowlog get and slowlog reset both to the buffer so they are executed together - h.conn.Send("SLOWLOG", "GET") - h.conn.Send("SLOWLOG", "RESET") + if err := h.conn.Send("SLOWLOG", "GET"); err != nil { + return fmt.Errorf("error sending slowlog get: %w", err) + } + if err := h.conn.Send("SLOWLOG", "RESET"); err != nil { + return fmt.Errorf("error sending slowlog reset: %w", err) + } // Flush the buffer to execute both commands and receive the reply from SLOWLOG GET h.conn.Flush() @@ -91,13 +95,13 @@ func (h *Harvester) Run() error { // Receives first reply from redis which is the one from GET logs, err := rd.Values(h.conn.Receive()) if err != nil { - return fmt.Errorf("error receiving slowlog data: %s", err) + return fmt.Errorf("error receiving slowlog data: %w", err) } // Read reply from RESET _, err = h.conn.Receive() if err != nil { - return fmt.Errorf("error receiving reset data: %s", err) + return fmt.Errorf("error receiving reset data: %w", err) } for _, item := range logs { @@ -115,7 +119,11 @@ func (h *Harvester) Run() error { var log log var args []string - rd.Scan(entry, &log.id, &log.timestamp, &log.duration, &args) + _, err = rd.Scan(entry, &log.id, &log.timestamp, &log.duration, &args) + if err != nil { + logp.Err("Error scanning slowlog entry: %s", err) + continue + } // This splits up the args into cmd, key, args. argsLen := len(args) @@ -144,7 +152,7 @@ func (h *Harvester) Run() error { slowlogEntry["args"] = log.args } - h.forwarder.Send(beat.Event{ + err = h.forwarder.Send(beat.Event{ Timestamp: time.Unix(log.timestamp, 0).UTC(), Fields: mapstr.M{ "message": strings.Join(args, " "), @@ -156,6 +164,10 @@ func (h *Harvester) Run() error { }, }, }) + if err != nil { + logp.Err("Error sending beat event: %s", err) + continue + } } return nil } diff --git a/go.mod b/go.mod index a47bf7ec1543..5081c345039d 100644 --- a/go.mod +++ b/go.mod @@ -87,7 +87,6 @@ require ( github.com/godbus/dbus/v5 v5.1.0 github.com/godror/godror v0.33.2 github.com/gofrs/flock v0.8.1 - github.com/gofrs/uuid v4.4.0+incompatible github.com/gogo/protobuf v1.3.2 github.com/golang/mock v1.6.0 github.com/golang/snappy v0.0.4 @@ -95,7 +94,7 @@ require ( github.com/google/flatbuffers v23.5.26+incompatible github.com/google/go-cmp v0.6.0 github.com/google/gopacket v1.1.19 - github.com/google/uuid v1.6.0 + github.com/google/uuid v1.6.0 // indirect github.com/gorhill/cronexpr v0.0.0-20180427100037-88b0669f7d75 github.com/h2non/filetype v1.1.1 github.com/hashicorp/go-retryablehttp v0.7.7 @@ -202,6 +201,7 @@ require ( github.com/elastic/toutoumomoma v0.0.0-20240626215117-76e39db18dfb github.com/foxcpp/go-mockdns v0.0.0-20201212160233-ede2f9158d15 github.com/go-ldap/ldap/v3 v3.4.6 + github.com/gofrs/uuid/v5 v5.2.0 github.com/golang-jwt/jwt/v5 v5.2.1 github.com/google/cel-go v0.19.0 github.com/googleapis/gax-go/v2 v2.13.0 @@ -294,7 +294,6 @@ require ( github.com/gobuffalo/here v0.6.7 // indirect github.com/goccy/go-json v0.10.2 // indirect github.com/godror/knownpb v0.1.0 // indirect - github.com/gofrs/uuid/v5 v5.2.0 // indirect github.com/golang-jwt/jwt/v4 v4.5.0 // indirect github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe // indirect github.com/golang-sql/sqlexp v0.1.0 // indirect diff --git a/go.sum b/go.sum index ec32ee823dde..838744dab133 100644 --- a/go.sum +++ b/go.sum @@ -862,8 +862,6 @@ github.com/gofrs/flock v0.8.1 h1:+gYjHKf32LDeiEEFhQaotPbLuUXjY5ZqxKgXy7n59aw= github.com/gofrs/flock v0.8.1/go.mod h1:F1TvTiK9OcQqauNUHlbJvyl9Qa1QvF/gOUDKA14jxHU= github.com/gofrs/uuid v3.3.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= github.com/gofrs/uuid v4.0.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= -github.com/gofrs/uuid v4.4.0+incompatible h1:3qXRTX8/NbyulANqlc0lchS1gqAVxRgsuW1YrTJupqA= -github.com/gofrs/uuid v4.4.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= github.com/gofrs/uuid/v5 v5.2.0 h1:qw1GMx6/y8vhVsx626ImfKMuS5CvJmhIKKtuyvfajMM= github.com/gofrs/uuid/v5 v5.2.0/go.mod h1:CDOjlDMVAtN56jqyRUZh58JT31Tiw7/oQyEXZV+9bD8= github.com/gogo/googleapis v1.1.0/go.mod h1:gf4bu3Q80BeJ6H1S1vYPm8/ELATdvryBaNFGgqEef3s= diff --git a/heartbeat/monitors/mocks.go b/heartbeat/monitors/mocks.go index f8747a804005..c172d24464c8 100644 --- a/heartbeat/monitors/mocks.go +++ b/heartbeat/monitors/mocks.go @@ -24,7 +24,7 @@ import ( "testing" "time" - "github.com/gofrs/uuid" + "github.com/gofrs/uuid/v5" "github.com/stretchr/testify/require" "github.com/elastic/elastic-agent-libs/config" diff --git a/heartbeat/monitors/wrappers/monitorstate/esloader_test.go b/heartbeat/monitors/wrappers/monitorstate/esloader_test.go index db70c1cc72e7..88664f562c85 100644 --- a/heartbeat/monitors/wrappers/monitorstate/esloader_test.go +++ b/heartbeat/monitors/wrappers/monitorstate/esloader_test.go @@ -27,7 +27,7 @@ import ( "testing" "time" - "github.com/gofrs/uuid" + "github.com/gofrs/uuid/v5" "github.com/stretchr/testify/require" "github.com/elastic/go-elasticsearch/v8" diff --git a/heartbeat/monitors/wrappers/summarizer/plugstatestat.go b/heartbeat/monitors/wrappers/summarizer/plugstatestat.go index cf7e90af5f30..1c3dc8876809 100644 --- a/heartbeat/monitors/wrappers/summarizer/plugstatestat.go +++ b/heartbeat/monitors/wrappers/summarizer/plugstatestat.go @@ -20,7 +20,7 @@ package summarizer import ( "fmt" - "github.com/gofrs/uuid" + "github.com/gofrs/uuid/v5" "github.com/elastic/beats/v7/heartbeat/eventext" "github.com/elastic/beats/v7/heartbeat/look" diff --git a/heartbeat/tracer/tracer_test.go b/heartbeat/tracer/tracer_test.go index 45d0a4125e79..654ec53fcf67 100644 --- a/heartbeat/tracer/tracer_test.go +++ b/heartbeat/tracer/tracer_test.go @@ -27,7 +27,7 @@ import ( "testing" "time" - "github.com/google/uuid" + "github.com/gofrs/uuid/v5" "github.com/stretchr/testify/require" ) @@ -63,7 +63,7 @@ func TestSockTracer(t *testing.T) { t.Run(tt.name, func(t *testing.T) { t.Parallel() - sockName, err := uuid.NewRandom() + sockName, err := uuid.NewV4() require.NoError(t, err) sockPath := filepath.Join(os.TempDir(), sockName.String()) @@ -94,7 +94,7 @@ func TestSockTracerWaitSuccess(t *testing.T) { waitFor := 5 * time.Second delay := time.Millisecond * 1500 - sockName, err := uuid.NewRandom() + sockName, err := uuid.NewV4() require.NoError(t, err) sockPath := filepath.Join(os.TempDir(), sockName.String()) diff --git a/libbeat/autodiscover/autodiscover_test.go b/libbeat/autodiscover/autodiscover_test.go index 93918180a928..5343c0939415 100644 --- a/libbeat/autodiscover/autodiscover_test.go +++ b/libbeat/autodiscover/autodiscover_test.go @@ -26,7 +26,7 @@ import ( "testing" "time" - "github.com/gofrs/uuid" + "github.com/gofrs/uuid/v5" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -129,7 +129,7 @@ func (m *mockAdapter) Create(_ beat.PipelineConnector, config *conf.C) (cfgfile. func (m *mockAdapter) Runners() []*mockRunner { m.mutex.Lock() defer m.mutex.Unlock() - var res []*mockRunner + res := make([]*mockRunner, 0, len(m.runners)) for _, r := range m.runners { res = append(res, r.Clone()) } diff --git a/libbeat/autodiscover/provider.go b/libbeat/autodiscover/provider.go index 8d70e80ee290..74a6d56f23d6 100644 --- a/libbeat/autodiscover/provider.go +++ b/libbeat/autodiscover/provider.go @@ -21,7 +21,7 @@ import ( "fmt" "strings" - "github.com/gofrs/uuid" + "github.com/gofrs/uuid/v5" "github.com/elastic/beats/v7/libbeat/cfgfile" "github.com/elastic/elastic-agent-autodiscover/bus" diff --git a/libbeat/autodiscover/providers/docker/docker.go b/libbeat/autodiscover/providers/docker/docker.go index a659135c7e70..8398762aa27a 100644 --- a/libbeat/autodiscover/providers/docker/docker.go +++ b/libbeat/autodiscover/providers/docker/docker.go @@ -25,7 +25,7 @@ import ( "strconv" "time" - "github.com/gofrs/uuid" + "github.com/gofrs/uuid/v5" "github.com/elastic/beats/v7/libbeat/autodiscover" "github.com/elastic/beats/v7/libbeat/autodiscover/template" diff --git a/libbeat/autodiscover/providers/docker/docker_integration_test.go b/libbeat/autodiscover/providers/docker/docker_integration_test.go index f8a760779782..80106998fc69 100644 --- a/libbeat/autodiscover/providers/docker/docker_integration_test.go +++ b/libbeat/autodiscover/providers/docker/docker_integration_test.go @@ -23,7 +23,7 @@ import ( "testing" "time" - "github.com/gofrs/uuid" + "github.com/gofrs/uuid/v5" "github.com/stretchr/testify/assert" "github.com/elastic/beats/v7/libbeat/autodiscover/template" @@ -73,12 +73,18 @@ func TestDockerStart(t *testing.T) { if err != nil { t.Fatal(err) } - defer d.ContainerRemove(ID) + defer func() { + if err := d.ContainerRemove(ID); err != nil { + t.Log(err) + } + }() checkEvent(t, listener, ID, true) // Kill - d.ContainerKill(ID) + if err := d.ContainerKill(ID); err != nil { + t.Log(err) + } checkEvent(t, listener, ID, false) } diff --git a/libbeat/autodiscover/providers/jolokia/discovery.go b/libbeat/autodiscover/providers/jolokia/discovery.go index cf0f1f5199d3..1834766dd36f 100644 --- a/libbeat/autodiscover/providers/jolokia/discovery.go +++ b/libbeat/autodiscover/providers/jolokia/discovery.go @@ -25,7 +25,7 @@ import ( "sync" "time" - "github.com/gofrs/uuid" + "github.com/gofrs/uuid/v5" s "github.com/elastic/beats/v7/libbeat/common/schema" c "github.com/elastic/beats/v7/libbeat/common/schema/mapstriface" @@ -238,7 +238,9 @@ func (d *Discovery) sendProbe(config InterfaceConfig) { if timeout > config.Interval { timeout = config.Interval } - conn.SetDeadline(time.Now().Add(timeout)) + if err := conn.SetDeadline(time.Now().Add(timeout)); err != nil { + log.Error(err.Error()) + } if _, err := conn.WriteTo(queryMessage, &discoveryAddress); err != nil { log.Error(err.Error()) @@ -249,6 +251,7 @@ func (d *Discovery) sendProbe(config InterfaceConfig) { for { n, _, err := conn.ReadFrom(b) if err != nil { + //nolint:errorlint // false positive if netErr, ok := err.(net.Error); !ok || !netErr.Timeout() { log.Error(err.Error()) } diff --git a/libbeat/autodiscover/providers/jolokia/jolokia.go b/libbeat/autodiscover/providers/jolokia/jolokia.go index beb566805c44..0c3cfa62b7e9 100644 --- a/libbeat/autodiscover/providers/jolokia/jolokia.go +++ b/libbeat/autodiscover/providers/jolokia/jolokia.go @@ -20,7 +20,7 @@ package jolokia import ( "fmt" - "github.com/gofrs/uuid" + "github.com/gofrs/uuid/v5" "github.com/elastic/beats/v7/libbeat/autodiscover" "github.com/elastic/beats/v7/libbeat/autodiscover/template" @@ -30,6 +30,7 @@ import ( ) func init() { + //nolint:errcheck // init function autodiscover.Registry.AddProvider("jolokia", AutodiscoverBuilder) } @@ -42,7 +43,6 @@ type DiscoveryProber interface { // Provider is the Jolokia Discovery autodiscover provider type Provider struct { - config *Config bus bus.Bus builders autodiscover.Builders appenders autodiscover.Appenders diff --git a/libbeat/autodiscover/providers/kubernetes/kubernetes.go b/libbeat/autodiscover/providers/kubernetes/kubernetes.go index 1ee4d01a06c5..823989787fdb 100644 --- a/libbeat/autodiscover/providers/kubernetes/kubernetes.go +++ b/libbeat/autodiscover/providers/kubernetes/kubernetes.go @@ -29,7 +29,7 @@ import ( "k8s.io/client-go/tools/leaderelection" "k8s.io/client-go/tools/leaderelection/resourcelock" - "github.com/gofrs/uuid" + "github.com/gofrs/uuid/v5" "github.com/elastic/beats/v7/libbeat/autodiscover" "github.com/elastic/beats/v7/libbeat/autodiscover/template" diff --git a/libbeat/autodiscover/providers/kubernetes/kubernetes_test.go b/libbeat/autodiscover/providers/kubernetes/kubernetes_test.go index b767d87be044..12f5c824423d 100644 --- a/libbeat/autodiscover/providers/kubernetes/kubernetes_test.go +++ b/libbeat/autodiscover/providers/kubernetes/kubernetes_test.go @@ -23,7 +23,7 @@ import ( "testing" "time" - "github.com/gofrs/uuid" + "github.com/gofrs/uuid/v5" "github.com/stretchr/testify/require" v1 "k8s.io/api/coordination/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" diff --git a/libbeat/autodiscover/providers/kubernetes/node.go b/libbeat/autodiscover/providers/kubernetes/node.go index 4747c751cbfc..27957998575f 100644 --- a/libbeat/autodiscover/providers/kubernetes/node.go +++ b/libbeat/autodiscover/providers/kubernetes/node.go @@ -25,7 +25,7 @@ import ( "github.com/elastic/elastic-agent-autodiscover/utils" - "github.com/gofrs/uuid" + "github.com/gofrs/uuid/v5" v1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/equality" k8s "k8s.io/client-go/kubernetes" diff --git a/libbeat/autodiscover/providers/kubernetes/node_test.go b/libbeat/autodiscover/providers/kubernetes/node_test.go index 5336ddde758b..bd4aa1fa2111 100644 --- a/libbeat/autodiscover/providers/kubernetes/node_test.go +++ b/libbeat/autodiscover/providers/kubernetes/node_test.go @@ -21,7 +21,7 @@ import ( "testing" "time" - "github.com/gofrs/uuid" + "github.com/gofrs/uuid/v5" "github.com/stretchr/testify/assert" v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" diff --git a/libbeat/autodiscover/providers/kubernetes/pod.go b/libbeat/autodiscover/providers/kubernetes/pod.go index c5f9c721eb90..764dab44f462 100644 --- a/libbeat/autodiscover/providers/kubernetes/pod.go +++ b/libbeat/autodiscover/providers/kubernetes/pod.go @@ -24,7 +24,7 @@ import ( "sync" "time" - "github.com/gofrs/uuid" + "github.com/gofrs/uuid/v5" k8s "k8s.io/client-go/kubernetes" "github.com/elastic/elastic-agent-autodiscover/bus" diff --git a/libbeat/autodiscover/providers/kubernetes/pod_test.go b/libbeat/autodiscover/providers/kubernetes/pod_test.go index 84712615ec1d..bb8731275b36 100644 --- a/libbeat/autodiscover/providers/kubernetes/pod_test.go +++ b/libbeat/autodiscover/providers/kubernetes/pod_test.go @@ -22,7 +22,7 @@ import ( "testing" "time" - "github.com/gofrs/uuid" + "github.com/gofrs/uuid/v5" "github.com/stretchr/testify/assert" v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" diff --git a/libbeat/autodiscover/providers/kubernetes/service.go b/libbeat/autodiscover/providers/kubernetes/service.go index e9e71c921bd8..c1604cd0fe45 100644 --- a/libbeat/autodiscover/providers/kubernetes/service.go +++ b/libbeat/autodiscover/providers/kubernetes/service.go @@ -25,7 +25,7 @@ import ( "github.com/elastic/elastic-agent-autodiscover/utils" - "github.com/gofrs/uuid" + "github.com/gofrs/uuid/v5" k8s "k8s.io/client-go/kubernetes" "github.com/elastic/elastic-agent-autodiscover/bus" diff --git a/libbeat/autodiscover/providers/kubernetes/service_test.go b/libbeat/autodiscover/providers/kubernetes/service_test.go index 90ff678e11ce..b7e0701fbd6f 100644 --- a/libbeat/autodiscover/providers/kubernetes/service_test.go +++ b/libbeat/autodiscover/providers/kubernetes/service_test.go @@ -21,7 +21,7 @@ import ( "testing" "time" - "github.com/gofrs/uuid" + "github.com/gofrs/uuid/v5" "github.com/stretchr/testify/assert" v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -511,6 +511,7 @@ func TestServiceEventer_NamespaceWatcher(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { config := conf.MustNewConfigFrom(&test.cfg) diff --git a/libbeat/beat/info.go b/libbeat/beat/info.go index 23dfe9be0be4..57f9a570fbc3 100644 --- a/libbeat/beat/info.go +++ b/libbeat/beat/info.go @@ -20,7 +20,7 @@ package beat import ( "time" - "github.com/gofrs/uuid" + "github.com/gofrs/uuid/v5" ) // Info stores a beats instance meta data. diff --git a/libbeat/cmd/instance/beat.go b/libbeat/cmd/instance/beat.go index 42f377a76e74..137c5577d81d 100644 --- a/libbeat/cmd/instance/beat.go +++ b/libbeat/cmd/instance/beat.go @@ -38,7 +38,7 @@ import ( "sync" "time" - "github.com/gofrs/uuid" + "github.com/gofrs/uuid/v5" "go.uber.org/zap" "github.com/elastic/beats/v7/libbeat/api" @@ -265,11 +265,6 @@ func NewBeat(name, indexPrefix, v string, elasticLicensed bool, initFuncs []func return nil, err } - eid, err := uuid.FromString(metricreport.EphemeralID().String()) - if err != nil { - return nil, fmt.Errorf("failed to generate EphemeralID from UUID string: %w", err) - } - b := beat.Beat{ Info: beat.Info{ Beat: name, @@ -281,7 +276,7 @@ func NewBeat(name, indexPrefix, v string, elasticLicensed bool, initFuncs []func ID: id, FirstStart: time.Now(), StartTime: time.Now(), - EphemeralID: eid, + EphemeralID: metricreport.EphemeralID(), }, Fields: fields, Registry: reload.NewRegistry(), diff --git a/libbeat/cmd/instance/beat_test.go b/libbeat/cmd/instance/beat_test.go index e3df2a6b5be0..ebfecf191c7b 100644 --- a/libbeat/cmd/instance/beat_test.go +++ b/libbeat/cmd/instance/beat_test.go @@ -35,7 +35,7 @@ import ( "github.com/elastic/elastic-agent-libs/logp" "github.com/elastic/go-ucfg/yaml" - "github.com/gofrs/uuid" + "github.com/gofrs/uuid/v5" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/libbeat/common/event_test.go b/libbeat/common/event_test.go index 0d598d021745..d6bd9eab99f2 100644 --- a/libbeat/common/event_test.go +++ b/libbeat/common/event_test.go @@ -22,7 +22,7 @@ import ( "testing" "time" - "github.com/gofrs/uuid" + "github.com/gofrs/uuid/v5" "github.com/stretchr/testify/assert" "github.com/elastic/elastic-agent-libs/logp" @@ -206,7 +206,6 @@ func TestConvertWithNullEmission(t *testing.T) { Output mapstr.M } - type String string type TestStruct struct { A interface{} } diff --git a/libbeat/idxmgmt/lifecycle/client_handler_integration_test.go b/libbeat/idxmgmt/lifecycle/client_handler_integration_test.go index 2df919d55d54..67b9a1cfb06d 100644 --- a/libbeat/idxmgmt/lifecycle/client_handler_integration_test.go +++ b/libbeat/idxmgmt/lifecycle/client_handler_integration_test.go @@ -25,7 +25,7 @@ import ( "testing" "time" - "github.com/gofrs/uuid" + "github.com/gofrs/uuid/v5" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" diff --git a/libbeat/monitoring/inputmon/input.go b/libbeat/monitoring/inputmon/input.go index 7814f79234f9..38876aed8488 100644 --- a/libbeat/monitoring/inputmon/input.go +++ b/libbeat/monitoring/inputmon/input.go @@ -21,7 +21,7 @@ import ( "encoding/json" "strings" - "github.com/google/uuid" + "github.com/gofrs/uuid/v5" "github.com/elastic/elastic-agent-libs/logp" "github.com/elastic/elastic-agent-libs/monitoring" @@ -59,7 +59,7 @@ func NewInputRegistry(inputType, id string, optionalParent *monitoring.Registry) // logs during support interactions. log := logp.NewLogger("metric_registry") // Make an orthogonal ID to allow tracking register/deregister pairs. - uuid := uuid.New().String() + uuid := uuid.Must(uuid.NewV4()).String() log.Infow("registering", "input_type", inputType, "id", id, "key", key, "uuid", uuid) reg = parentRegistry.NewRegistry(key) diff --git a/libbeat/outputs/elasticsearch/callbacks.go b/libbeat/outputs/elasticsearch/callbacks.go index dcbbd971adb9..5196fe13802c 100644 --- a/libbeat/outputs/elasticsearch/callbacks.go +++ b/libbeat/outputs/elasticsearch/callbacks.go @@ -22,7 +22,7 @@ import ( "github.com/elastic/beats/v7/libbeat/esleg/eslegclient" - "github.com/gofrs/uuid" + "github.com/gofrs/uuid/v5" ) // ConnectCallback defines the type for the function to be called when the Elasticsearch client successfully connects to the cluster diff --git a/libbeat/processors/add_host_metadata/add_host_metadata.go b/libbeat/processors/add_host_metadata/add_host_metadata.go index 5fe28194b555..3a7e7b40c55f 100644 --- a/libbeat/processors/add_host_metadata/add_host_metadata.go +++ b/libbeat/processors/add_host_metadata/add_host_metadata.go @@ -23,7 +23,7 @@ import ( "sync" "time" - "github.com/gofrs/uuid" + "github.com/gofrs/uuid/v5" "github.com/elastic/elastic-agent-libs/monitoring" "github.com/elastic/go-sysinfo" diff --git a/libbeat/publisher/processing/default_test.go b/libbeat/publisher/processing/default_test.go index 6fe057850373..81bdb25dcbab 100644 --- a/libbeat/publisher/processing/default_test.go +++ b/libbeat/publisher/processing/default_test.go @@ -22,7 +22,7 @@ import ( "testing" "time" - "github.com/gofrs/uuid" + "github.com/gofrs/uuid/v5" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" diff --git a/libbeat/tests/integration/framework.go b/libbeat/tests/integration/framework.go index bb7e0f6c447b..1daf8948bc14 100644 --- a/libbeat/tests/integration/framework.go +++ b/libbeat/tests/integration/framework.go @@ -38,7 +38,7 @@ import ( "testing" "time" - "github.com/gofrs/uuid" + "github.com/gofrs/uuid/v5" "github.com/stretchr/testify/require" "github.com/elastic/beats/v7/libbeat/common/atomic" @@ -319,7 +319,7 @@ func (b *BeatProc) LogMatch(match string) bool { logFile := b.openLogFile() defer logFile.Close() - found := false + var found bool found, b.logFileOffset = b.logRegExpMatch(re, logFile, b.logFileOffset) if found { return found @@ -382,7 +382,7 @@ func (b *BeatProc) LogContains(s string) bool { logFile := b.openLogFile() defer logFile.Close() - found := false + var found bool found, b.logFileOffset = b.searchStrInLogs(logFile, s, b.logFileOffset) if found { return found diff --git a/metricbeat/mb/builders.go b/metricbeat/mb/builders.go index c9b1ace587d9..4c55e3e39442 100644 --- a/metricbeat/mb/builders.go +++ b/metricbeat/mb/builders.go @@ -22,7 +22,7 @@ import ( "fmt" "strings" - "github.com/gofrs/uuid" + "github.com/gofrs/uuid/v5" "github.com/joeshaw/multierror" conf "github.com/elastic/elastic-agent-libs/config" @@ -108,8 +108,7 @@ func createModule(r *Register, bm BaseModule) (Module, error) { func initMetricSets(r *Register, m Module) ([]MetricSet, error) { var ( - errs multierror.Errors - metricsets []MetricSet + errs multierror.Errors ) bms, err := newBaseMetricSets(r, m) @@ -117,6 +116,7 @@ func initMetricSets(r *Register, m Module) ([]MetricSet, error) { return nil, err } + metricsets := make([]MetricSet, 0, len(bms)) for _, bm := range bms { registration, err := r.metricSetRegistration(bm.Module().Name(), bm.Name()) if err != nil { diff --git a/x-pack/auditbeat/module/system/package/package.go b/x-pack/auditbeat/module/system/package/package.go index 944bc083b332..14aaadfdc563 100644 --- a/x-pack/auditbeat/module/system/package/package.go +++ b/x-pack/auditbeat/module/system/package/package.go @@ -24,7 +24,7 @@ import ( "time" "github.com/cespare/xxhash/v2" - "github.com/gofrs/uuid" + "github.com/gofrs/uuid/v5" "github.com/joeshaw/multierror" "go.etcd.io/bbolt" diff --git a/x-pack/auditbeat/module/system/process/process.go b/x-pack/auditbeat/module/system/process/process.go index b835a03bfb96..793bb70a4fb0 100644 --- a/x-pack/auditbeat/module/system/process/process.go +++ b/x-pack/auditbeat/module/system/process/process.go @@ -14,7 +14,7 @@ import ( "time" "github.com/cespare/xxhash/v2" - "github.com/gofrs/uuid" + "github.com/gofrs/uuid/v5" "github.com/elastic/beats/v7/auditbeat/ab" "github.com/elastic/beats/v7/auditbeat/datastore" @@ -115,7 +115,9 @@ type Process struct { // Hash creates a hash for Process. func (p Process) Hash() uint64 { h := xxhash.New() + //nolint:errcheck // always return nil err h.WriteString(strconv.Itoa(p.Info.PID)) + //nolint:errcheck // always return nil err h.WriteString(p.Info.StartTime.String()) return h.Sum64() } @@ -139,7 +141,9 @@ func (p Process) toMapStr() mapstr.M { func (p Process) entityID(hostID string) string { h := system.NewEntityHash() h.Write([]byte(hostID)) + //nolint:errcheck // no error handling binary.Write(h, binary.LittleEndian, int64(p.Info.PID)) + //nolint:errcheck // no error handling binary.Write(h, binary.LittleEndian, int64(p.Info.StartTime.Nanosecond())) return h.Sum() } @@ -445,13 +449,12 @@ func convertToCacheable(processes []*Process) []cache.Cacheable { } func (ms *MetricSet) getProcesses() ([]*Process, error) { - var processes []*Process - sysinfoProcs, err := sysinfo.Processes() if err != nil { return nil, fmt.Errorf("failed to fetch processes: %w", err) } + processes := make([]*Process, 0, len(sysinfoProcs)) for _, sysinfoProc := range sysinfoProcs { var process *Process diff --git a/x-pack/auditbeat/module/system/user/user.go b/x-pack/auditbeat/module/system/user/user.go index 3220c7ffeb41..f48019af5720 100644 --- a/x-pack/auditbeat/module/system/user/user.go +++ b/x-pack/auditbeat/module/system/user/user.go @@ -10,6 +10,7 @@ import ( "bytes" "encoding/binary" "encoding/gob" + "errors" "fmt" "io" "os/user" @@ -19,7 +20,7 @@ import ( "time" "github.com/cespare/xxhash/v2" - "github.com/gofrs/uuid" + "github.com/gofrs/uuid/v5" "github.com/joeshaw/multierror" "github.com/elastic/beats/v7/auditbeat/ab" @@ -136,17 +137,27 @@ type User struct { func (user User) Hash() uint64 { h := xxhash.New() // Use everything except userInfo + //nolint:errcheck // err always nil h.WriteString(user.Name) + //nolint:errcheck // err always nil binary.Write(h, binary.BigEndian, uint8(user.PasswordType)) + //nolint:errcheck // err always nil h.WriteString(user.PasswordChanged.String()) + //nolint:errcheck // err always nil h.Write(user.PasswordHashHash) + //nolint:errcheck // err always nil h.WriteString(user.UID) + //nolint:errcheck // err always nil h.WriteString(user.GID) + //nolint:errcheck // err always nil h.WriteString(user.Dir) + //nolint:errcheck // err always nil h.WriteString(user.Shell) for _, group := range user.Groups { + //nolint:errcheck // err always nil h.WriteString(group.Name) + //nolint:errcheck // err always nil h.WriteString(group.Gid) } @@ -199,11 +210,11 @@ func (user User) PrimaryGroup() *user.Group { } // entityID creates an ID that uniquely identifies this user across machines. -func (u User) entityID(hostID string) string { +func (user User) entityID(hostID string) string { h := system.NewEntityHash() h.Write([]byte(hostID)) - h.Write([]byte(u.Name)) - h.Write([]byte(u.UID)) + h.Write([]byte(user.Name)) + h.Write([]byte(user.UID)) return h.Sum() } @@ -555,7 +566,7 @@ func (ms *MetricSet) restoreUsersFromDisk() (users []*User, err error) { err = decoder.Decode(user) if err == nil { users = append(users, user) - } else if err == io.EOF { + } else if errors.Is(err, io.EOF) { // Read all users break } else { @@ -594,6 +605,7 @@ func (ms *MetricSet) haveFilesChanged() (bool, error) { return true, fmt.Errorf("failed to stat %v: %w", path, err) } + //nolint:unconvert // false positive ctime := time.Unix(int64(stats.Ctim.Sec), int64(stats.Ctim.Nsec)) if ms.lastRead.Before(ctime) { ms.log.Debugf("File changed: %v (lastRead=%v, ctime=%v)", path, ms.lastRead, ctime) diff --git a/x-pack/dockerlogbeat/pipelinemanager/libbeattools.go b/x-pack/dockerlogbeat/pipelinemanager/libbeattools.go index de3436156b42..b4820f734088 100644 --- a/x-pack/dockerlogbeat/pipelinemanager/libbeattools.go +++ b/x-pack/dockerlogbeat/pipelinemanager/libbeattools.go @@ -11,7 +11,7 @@ import ( "os" "time" - "github.com/gofrs/uuid" + "github.com/gofrs/uuid/v5" "github.com/elastic/beats/v7/libbeat/beat" "github.com/elastic/beats/v7/libbeat/cloudid" diff --git a/x-pack/filebeat/input/awss3/sqs_test.go b/x-pack/filebeat/input/awss3/sqs_test.go index cf82f03c6dec..8ad01a032dc5 100644 --- a/x-pack/filebeat/input/awss3/sqs_test.go +++ b/x-pack/filebeat/input/awss3/sqs_test.go @@ -14,7 +14,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/sqs/types" - "github.com/gofrs/uuid" + "github.com/gofrs/uuid/v5" "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" diff --git a/x-pack/filebeat/input/entityanalytics/internal/collections/uuid_set.go b/x-pack/filebeat/input/entityanalytics/internal/collections/uuid_set.go index 1a36edec554b..46f6422c3038 100644 --- a/x-pack/filebeat/input/entityanalytics/internal/collections/uuid_set.go +++ b/x-pack/filebeat/input/entityanalytics/internal/collections/uuid_set.go @@ -9,7 +9,7 @@ import ( "encoding/json" "sort" - "github.com/google/uuid" + "github.com/gofrs/uuid/v5" ) type UUIDSet struct { diff --git a/x-pack/filebeat/input/entityanalytics/internal/collections/uuid_set_test.go b/x-pack/filebeat/input/entityanalytics/internal/collections/uuid_set_test.go index cc9cdba83b96..f3d05077b027 100644 --- a/x-pack/filebeat/input/entityanalytics/internal/collections/uuid_set_test.go +++ b/x-pack/filebeat/input/entityanalytics/internal/collections/uuid_set_test.go @@ -9,7 +9,7 @@ import ( "fmt" "testing" - "github.com/google/uuid" + "github.com/gofrs/uuid/v5" "github.com/stretchr/testify/require" ) @@ -22,11 +22,11 @@ const ( ) var ( - testUUID1 = uuid.MustParse(testUUID1Str) - testUUID2 = uuid.MustParse(testUUID2Str) - testUUID3 = uuid.MustParse(testUUID3Str) - testUUID4 = uuid.MustParse(testUUID4Str) - testUUID5 = uuid.MustParse(testUUID5Str) + testUUID1 = uuid.Must(uuid.FromString(testUUID1Str)) + testUUID2 = uuid.Must(uuid.FromString(testUUID2Str)) + testUUID3 = uuid.Must(uuid.FromString(testUUID3Str)) + testUUID4 = uuid.Must(uuid.FromString(testUUID4Str)) + testUUID5 = uuid.Must(uuid.FromString(testUUID5Str)) ) func TestNewUUIDSet(t *testing.T) { diff --git a/x-pack/filebeat/input/entityanalytics/internal/collections/uuid_tree.go b/x-pack/filebeat/input/entityanalytics/internal/collections/uuid_tree.go index 07b35284301a..1ebda5ebf41e 100644 --- a/x-pack/filebeat/input/entityanalytics/internal/collections/uuid_tree.go +++ b/x-pack/filebeat/input/entityanalytics/internal/collections/uuid_tree.go @@ -7,7 +7,7 @@ package collections import ( "encoding/json" - "github.com/google/uuid" + "github.com/gofrs/uuid/v5" ) type UUIDTree struct { diff --git a/x-pack/filebeat/input/entityanalytics/internal/collections/uuid_tree_test.go b/x-pack/filebeat/input/entityanalytics/internal/collections/uuid_tree_test.go index f82e7e74267c..01b1e8b6e744 100644 --- a/x-pack/filebeat/input/entityanalytics/internal/collections/uuid_tree_test.go +++ b/x-pack/filebeat/input/entityanalytics/internal/collections/uuid_tree_test.go @@ -9,7 +9,7 @@ import ( "fmt" "testing" - "github.com/google/uuid" + "github.com/gofrs/uuid/v5" "github.com/stretchr/testify/require" ) @@ -36,7 +36,7 @@ func TestUUIDTree_UnmarshalJSON(t *testing.T) { }, "err-bad-uuid-key": { In: []byte(fmt.Sprintf(`{"1":["%s"]}`, testUUID1)), - WantErr: "invalid UUID length: 1", + WantErr: "uuid: incorrect UUID length 1 in string \"1\"", }, "err-bad-uuid-set": { In: []byte(fmt.Sprintf(`{"%s":[1]}`, testUUID1)), diff --git a/x-pack/filebeat/input/entityanalytics/provider/azuread/azure.go b/x-pack/filebeat/input/entityanalytics/provider/azuread/azure.go index 42104ebd8e9e..e6faa4667722 100644 --- a/x-pack/filebeat/input/entityanalytics/provider/azuread/azure.go +++ b/x-pack/filebeat/input/entityanalytics/provider/azuread/azure.go @@ -11,7 +11,7 @@ import ( "fmt" "time" - "github.com/google/uuid" + "github.com/gofrs/uuid/v5" v2 "github.com/elastic/beats/v7/filebeat/input/v2" "github.com/elastic/beats/v7/libbeat/beat" diff --git a/x-pack/filebeat/input/entityanalytics/provider/azuread/fetcher/device.go b/x-pack/filebeat/input/entityanalytics/provider/azuread/fetcher/device.go index 46139d278208..2a8bc0e2561d 100644 --- a/x-pack/filebeat/input/entityanalytics/provider/azuread/fetcher/device.go +++ b/x-pack/filebeat/input/entityanalytics/provider/azuread/fetcher/device.go @@ -5,7 +5,7 @@ package fetcher import ( - "github.com/google/uuid" + "github.com/gofrs/uuid/v5" "github.com/elastic/beats/v7/x-pack/filebeat/input/entityanalytics/internal/collections" "github.com/elastic/elastic-agent-libs/mapstr" diff --git a/x-pack/filebeat/input/entityanalytics/provider/azuread/fetcher/device_test.go b/x-pack/filebeat/input/entityanalytics/provider/azuread/fetcher/device_test.go index 37e6563eb3aa..5f9e1bd11cee 100644 --- a/x-pack/filebeat/input/entityanalytics/provider/azuread/fetcher/device_test.go +++ b/x-pack/filebeat/input/entityanalytics/provider/azuread/fetcher/device_test.go @@ -7,7 +7,7 @@ package fetcher import ( "testing" - "github.com/google/uuid" + "github.com/gofrs/uuid/v5" "github.com/stretchr/testify/require" "github.com/elastic/beats/v7/x-pack/filebeat/input/entityanalytics/internal/collections" @@ -20,59 +20,59 @@ func TestDevice_Merge(t *testing.T) { Want *Device }{ "id-mismatch": { - In: &Device{ID: uuid.MustParse("187f924c-e867-477e-8d74-dd762d6379dd")}, - InOther: &Device{ID: uuid.MustParse("80c3f9af-75ae-45f5-b22b-53f005d5880d")}, - Want: &Device{ID: uuid.MustParse("187f924c-e867-477e-8d74-dd762d6379dd")}, + In: &Device{ID: uuid.Must(uuid.FromString("187f924c-e867-477e-8d74-dd762d6379dd"))}, + InOther: &Device{ID: uuid.Must(uuid.FromString("80c3f9af-75ae-45f5-b22b-53f005d5880d"))}, + Want: &Device{ID: uuid.Must(uuid.FromString("187f924c-e867-477e-8d74-dd762d6379dd"))}, }, "ok": { In: &Device{ - ID: uuid.MustParse("187f924c-e867-477e-8d74-dd762d6379dd"), + ID: uuid.Must(uuid.FromString("187f924c-e867-477e-8d74-dd762d6379dd")), Fields: map[string]interface{}{ "a": "alpha", }, - MemberOf: collections.NewUUIDSet(uuid.MustParse("fcda226a-c920-4d99-81bc-d2d691a6c212")), - TransitiveMemberOf: collections.NewUUIDSet(uuid.MustParse("ca777ad5-9abf-4c9b-be1f-c38c6ec28f28")), - RegisteredOwners: collections.NewUUIDSet(uuid.MustParse("c59fbdb8-e442-46b1-8d72-c8ac0b78ec0a")), + MemberOf: collections.NewUUIDSet(uuid.Must(uuid.FromString("fcda226a-c920-4d99-81bc-d2d691a6c212"))), + TransitiveMemberOf: collections.NewUUIDSet(uuid.Must(uuid.FromString("ca777ad5-9abf-4c9b-be1f-c38c6ec28f28"))), + RegisteredOwners: collections.NewUUIDSet(uuid.Must(uuid.FromString("c59fbdb8-e442-46b1-8d72-c8ac0b78ec0a"))), RegisteredUsers: collections.NewUUIDSet( - uuid.MustParse("27cea005-7377-4175-b2ef-e9d64c977f4d"), - uuid.MustParse("c59fbdb8-e442-46b1-8d72-c8ac0b78ec0a"), + uuid.Must(uuid.FromString("27cea005-7377-4175-b2ef-e9d64c977f4d")), + uuid.Must(uuid.FromString("c59fbdb8-e442-46b1-8d72-c8ac0b78ec0a")), ), }, InOther: &Device{ - ID: uuid.MustParse("187f924c-e867-477e-8d74-dd762d6379dd"), + ID: uuid.Must(uuid.FromString("187f924c-e867-477e-8d74-dd762d6379dd")), Fields: map[string]interface{}{ "b": "beta", }, - MemberOf: collections.NewUUIDSet(uuid.MustParse("a77e8cbb-27a5-49d3-9d5e-801997621f87")), - TransitiveMemberOf: collections.NewUUIDSet(uuid.MustParse("c550d32c-09b2-4851-b0f2-1bc431e26d01")), - RegisteredOwners: collections.NewUUIDSet(uuid.MustParse("81d1b5cd-7cd6-469d-9fe8-0a5c6cf2a7b6")), + MemberOf: collections.NewUUIDSet(uuid.Must(uuid.FromString("a77e8cbb-27a5-49d3-9d5e-801997621f87"))), + TransitiveMemberOf: collections.NewUUIDSet(uuid.Must(uuid.FromString("c550d32c-09b2-4851-b0f2-1bc431e26d01"))), + RegisteredOwners: collections.NewUUIDSet(uuid.Must(uuid.FromString("81d1b5cd-7cd6-469d-9fe8-0a5c6cf2a7b6"))), RegisteredUsers: collections.NewUUIDSet( - uuid.MustParse("5e6d279a-ce2b-43b8-a38f-3110907e1974"), - uuid.MustParse("c59fbdb8-e442-46b1-8d72-c8ac0b78ec0a"), + uuid.Must(uuid.FromString("5e6d279a-ce2b-43b8-a38f-3110907e1974")), + uuid.Must(uuid.FromString("c59fbdb8-e442-46b1-8d72-c8ac0b78ec0a")), ), }, Want: &Device{ - ID: uuid.MustParse("187f924c-e867-477e-8d74-dd762d6379dd"), + ID: uuid.Must(uuid.FromString("187f924c-e867-477e-8d74-dd762d6379dd")), Fields: map[string]interface{}{ "a": "alpha", "b": "beta", }, MemberOf: collections.NewUUIDSet( - uuid.MustParse("fcda226a-c920-4d99-81bc-d2d691a6c212"), - uuid.MustParse("a77e8cbb-27a5-49d3-9d5e-801997621f87"), + uuid.Must(uuid.FromString("fcda226a-c920-4d99-81bc-d2d691a6c212")), + uuid.Must(uuid.FromString("a77e8cbb-27a5-49d3-9d5e-801997621f87")), ), TransitiveMemberOf: collections.NewUUIDSet( - uuid.MustParse("ca777ad5-9abf-4c9b-be1f-c38c6ec28f28"), - uuid.MustParse("c550d32c-09b2-4851-b0f2-1bc431e26d01"), + uuid.Must(uuid.FromString("ca777ad5-9abf-4c9b-be1f-c38c6ec28f28")), + uuid.Must(uuid.FromString("c550d32c-09b2-4851-b0f2-1bc431e26d01")), ), RegisteredOwners: collections.NewUUIDSet( - uuid.MustParse("81d1b5cd-7cd6-469d-9fe8-0a5c6cf2a7b6"), - uuid.MustParse("c59fbdb8-e442-46b1-8d72-c8ac0b78ec0a"), + uuid.Must(uuid.FromString("81d1b5cd-7cd6-469d-9fe8-0a5c6cf2a7b6")), + uuid.Must(uuid.FromString("c59fbdb8-e442-46b1-8d72-c8ac0b78ec0a")), ), RegisteredUsers: collections.NewUUIDSet( - uuid.MustParse("27cea005-7377-4175-b2ef-e9d64c977f4d"), - uuid.MustParse("5e6d279a-ce2b-43b8-a38f-3110907e1974"), - uuid.MustParse("c59fbdb8-e442-46b1-8d72-c8ac0b78ec0a"), + uuid.Must(uuid.FromString("27cea005-7377-4175-b2ef-e9d64c977f4d")), + uuid.Must(uuid.FromString("5e6d279a-ce2b-43b8-a38f-3110907e1974")), + uuid.Must(uuid.FromString("c59fbdb8-e442-46b1-8d72-c8ac0b78ec0a")), ), }, }, diff --git a/x-pack/filebeat/input/entityanalytics/provider/azuread/fetcher/graph/graph.go b/x-pack/filebeat/input/entityanalytics/provider/azuread/fetcher/graph/graph.go index 1f526fb31bb7..c360c590913d 100644 --- a/x-pack/filebeat/input/entityanalytics/provider/azuread/fetcher/graph/graph.go +++ b/x-pack/filebeat/input/entityanalytics/provider/azuread/fetcher/graph/graph.go @@ -20,7 +20,7 @@ import ( "path/filepath" "strings" - "github.com/google/uuid" + "github.com/gofrs/uuid/v5" "go.elastic.co/ecszap" "go.uber.org/zap" "go.uber.org/zap/zapcore" @@ -488,7 +488,7 @@ func newUserFromAPI(u userAPI) (*fetcher.User, error) { if idRaw, ok := newUser.Fields["id"]; ok { idStr, _ := idRaw.(string) - if newUser.ID, err = uuid.Parse(idStr); err != nil { + if newUser.ID, err = uuid.FromString(idStr); err != nil { return nil, fmt.Errorf("unable to unmarshal user, invalid ID: %w", err) } delete(newUser.Fields, "id") @@ -542,7 +542,7 @@ func newDeviceFromAPI(d deviceAPI) (*fetcher.Device, error) { if idRaw, ok := newDevice.Fields["id"]; ok { idStr, _ := idRaw.(string) - if newDevice.ID, err = uuid.Parse(idStr); err != nil { + if newDevice.ID, err = uuid.FromString(idStr); err != nil { return nil, fmt.Errorf("unable to unmarshal device, invalid ID: %w", err) } delete(newDevice.Fields, "id") diff --git a/x-pack/filebeat/input/entityanalytics/provider/azuread/fetcher/graph/graph_test.go b/x-pack/filebeat/input/entityanalytics/provider/azuread/fetcher/graph/graph_test.go index bafddc20a00a..64f31be104de 100644 --- a/x-pack/filebeat/input/entityanalytics/provider/azuread/fetcher/graph/graph_test.go +++ b/x-pack/filebeat/input/entityanalytics/provider/azuread/fetcher/graph/graph_test.go @@ -17,8 +17,8 @@ import ( "testing" "time" + "github.com/gofrs/uuid/v5" "github.com/google/go-cmp/cmp" - "github.com/google/uuid" "github.com/stretchr/testify/require" "gopkg.in/natefinch/lumberjack.v2" @@ -143,11 +143,11 @@ var deviceUserResponses = map[string]apiUserResponse{ var groupsResponse1 = apiGroupResponse{ Groups: []groupAPI{ { - ID: uuid.MustParse("331676df-b8fd-4492-82ed-02b927f8dd80"), + ID: uuid.Must(uuid.FromString("331676df-b8fd-4492-82ed-02b927f8dd80")), DisplayName: "group1", MembersDelta: []memberAPI{ { - ID: uuid.MustParse("5ebc6a0f-05b7-4f42-9c8a-682bbc75d0fc"), + ID: uuid.Must(uuid.FromString("5ebc6a0f-05b7-4f42-9c8a-682bbc75d0fc")), Type: apiUserType, }, }, @@ -158,15 +158,15 @@ var groupsResponse1 = apiGroupResponse{ var groupsResponse2 = apiGroupResponse{ Groups: []groupAPI{ { - ID: uuid.MustParse("d140978f-d641-4f01-802f-4ecc1acf8935"), + ID: uuid.Must(uuid.FromString("d140978f-d641-4f01-802f-4ecc1acf8935")), DisplayName: "group2", MembersDelta: []memberAPI{ { - ID: uuid.MustParse("331676df-b8fd-4492-82ed-02b927f8dd80"), + ID: uuid.Must(uuid.FromString("331676df-b8fd-4492-82ed-02b927f8dd80")), Type: apiGroupType, }, { - ID: uuid.MustParse("5ebc6a0f-05b7-4f42-9c8a-682bbc75d0fc"), + ID: uuid.Must(uuid.FromString("5ebc6a0f-05b7-4f42-9c8a-682bbc75d0fc")), Type: apiGroupType, Removed: &removed{Reason: "changed"}, }, @@ -288,25 +288,25 @@ func TestGraph_Groups(t *testing.T) { wantDeltaLink := "http://" + testSrv.addr + "/groups/delta?$deltatoken=test" wantGroups := []*fetcher.Group{ { - ID: uuid.MustParse("331676df-b8fd-4492-82ed-02b927f8dd80"), + ID: uuid.Must(uuid.FromString("331676df-b8fd-4492-82ed-02b927f8dd80")), Name: "group1", Members: []fetcher.Member{ { - ID: uuid.MustParse("5ebc6a0f-05b7-4f42-9c8a-682bbc75d0fc"), + ID: uuid.Must(uuid.FromString("5ebc6a0f-05b7-4f42-9c8a-682bbc75d0fc")), Type: fetcher.MemberUser, }, }, }, { - ID: uuid.MustParse("d140978f-d641-4f01-802f-4ecc1acf8935"), + ID: uuid.Must(uuid.FromString("d140978f-d641-4f01-802f-4ecc1acf8935")), Name: "group2", Members: []fetcher.Member{ { - ID: uuid.MustParse("331676df-b8fd-4492-82ed-02b927f8dd80"), + ID: uuid.Must(uuid.FromString("331676df-b8fd-4492-82ed-02b927f8dd80")), Type: fetcher.MemberGroup, }, { - ID: uuid.MustParse("5ebc6a0f-05b7-4f42-9c8a-682bbc75d0fc"), + ID: uuid.Must(uuid.FromString("5ebc6a0f-05b7-4f42-9c8a-682bbc75d0fc")), Type: fetcher.MemberGroup, Deleted: true, }, @@ -347,7 +347,7 @@ func TestGraph_Users(t *testing.T) { wantDeltaLink := "http://" + testSrv.addr + "/users/delta?$deltatoken=test" wantUsers := []*fetcher.User{ { - ID: uuid.MustParse("5ebc6a0f-05b7-4f42-9c8a-682bbc75d0fc"), + ID: uuid.Must(uuid.FromString("5ebc6a0f-05b7-4f42-9c8a-682bbc75d0fc")), Fields: map[string]interface{}{ "userPrincipalName": "user.one@example.com", "mail": "user.one@example.com", @@ -362,7 +362,7 @@ func TestGraph_Users(t *testing.T) { }, }, { - ID: uuid.MustParse("d897d560-3d17-4dae-81b3-c898fe82bf84"), + ID: uuid.Must(uuid.FromString("d897d560-3d17-4dae-81b3-c898fe82bf84")), Fields: map[string]interface{}{ "userPrincipalName": "user.two@example.com", "mail": "user.two@example.com", @@ -411,7 +411,7 @@ func TestGraph_Devices(t *testing.T) { wantDeltaLink := "http://" + testSrv.addr + "/devices/delta?$deltatoken=test" wantDevices := []*fetcher.Device{ { - ID: uuid.MustParse("6a59ea83-02bd-468f-a40b-f2c3d1821983"), + ID: uuid.Must(uuid.FromString("6a59ea83-02bd-468f-a40b-f2c3d1821983")), Fields: map[string]interface{}{ "accountEnabled": true, "deviceId": "eab73519-780d-4d43-be6d-a4a89af2a348", @@ -434,15 +434,15 @@ func TestGraph_Devices(t *testing.T) { }, }, RegisteredOwners: collections.NewUUIDSet( - uuid.MustParse("5ebc6a0f-05b7-4f42-9c8a-682bbc75d0fc"), + uuid.Must(uuid.FromString("5ebc6a0f-05b7-4f42-9c8a-682bbc75d0fc")), ), RegisteredUsers: collections.NewUUIDSet( - uuid.MustParse("5ebc6a0f-05b7-4f42-9c8a-682bbc75d0fc"), - uuid.MustParse("d897d560-3d17-4dae-81b3-c898fe82bf84"), + uuid.Must(uuid.FromString("5ebc6a0f-05b7-4f42-9c8a-682bbc75d0fc")), + uuid.Must(uuid.FromString("d897d560-3d17-4dae-81b3-c898fe82bf84")), ), }, { - ID: uuid.MustParse("adbbe40a-0627-4328-89f1-88cac84dbc7f"), + ID: uuid.Must(uuid.FromString("adbbe40a-0627-4328-89f1-88cac84dbc7f")), Fields: map[string]interface{}{ "accountEnabled": true, "deviceId": "2fbbb8f9-ff67-4a21-b867-a344d18a4198", @@ -465,10 +465,10 @@ func TestGraph_Devices(t *testing.T) { }, }, RegisteredOwners: collections.NewUUIDSet( - uuid.MustParse("5ebc6a0f-05b7-4f42-9c8a-682bbc75d0fc"), + uuid.Must(uuid.FromString("5ebc6a0f-05b7-4f42-9c8a-682bbc75d0fc")), ), RegisteredUsers: collections.NewUUIDSet( - uuid.MustParse("5ebc6a0f-05b7-4f42-9c8a-682bbc75d0fc"), + uuid.Must(uuid.FromString("5ebc6a0f-05b7-4f42-9c8a-682bbc75d0fc")), ), }, } diff --git a/x-pack/filebeat/input/entityanalytics/provider/azuread/fetcher/group.go b/x-pack/filebeat/input/entityanalytics/provider/azuread/fetcher/group.go index 77a7c24deebb..b3dc6809382c 100644 --- a/x-pack/filebeat/input/entityanalytics/provider/azuread/fetcher/group.go +++ b/x-pack/filebeat/input/entityanalytics/provider/azuread/fetcher/group.go @@ -4,7 +4,7 @@ package fetcher -import "github.com/google/uuid" +import "github.com/gofrs/uuid/v5" // MemberType indicates the type of member in a Group. type MemberType int diff --git a/x-pack/filebeat/input/entityanalytics/provider/azuread/fetcher/group_test.go b/x-pack/filebeat/input/entityanalytics/provider/azuread/fetcher/group_test.go index a9958ef22450..7c6a1ff5ba33 100644 --- a/x-pack/filebeat/input/entityanalytics/provider/azuread/fetcher/group_test.go +++ b/x-pack/filebeat/input/entityanalytics/provider/azuread/fetcher/group_test.go @@ -7,13 +7,13 @@ package fetcher import ( "testing" - "github.com/google/uuid" + "github.com/gofrs/uuid/v5" "github.com/stretchr/testify/require" ) func TestGroup_ToECS(t *testing.T) { in := Group{ - ID: uuid.MustParse("88ecb4e8-5a1a-461e-a062-f1d3c5aa4ca4"), + ID: uuid.Must(uuid.FromString("88ecb4e8-5a1a-461e-a062-f1d3c5aa4ca4")), Name: "group1", } want := GroupECS{ diff --git a/x-pack/filebeat/input/entityanalytics/provider/azuread/fetcher/mock/mock.go b/x-pack/filebeat/input/entityanalytics/provider/azuread/fetcher/mock/mock.go index 11d77871f3bc..4385385367d1 100644 --- a/x-pack/filebeat/input/entityanalytics/provider/azuread/fetcher/mock/mock.go +++ b/x-pack/filebeat/input/entityanalytics/provider/azuread/fetcher/mock/mock.go @@ -8,7 +8,7 @@ package mock import ( "context" - "github.com/google/uuid" + "github.com/gofrs/uuid/v5" "github.com/elastic/beats/v7/x-pack/filebeat/input/entityanalytics/provider/azuread/fetcher" "github.com/elastic/elastic-agent-libs/logp" @@ -22,43 +22,43 @@ var ( var GroupResponse = []*fetcher.Group{ { - ID: uuid.MustParse("331676df-b8fd-4492-82ed-02b927f8dd80"), + ID: uuid.Must(uuid.FromString("331676df-b8fd-4492-82ed-02b927f8dd80")), Name: "group1", Members: []fetcher.Member{ { - ID: uuid.MustParse("5ebc6a0f-05b7-4f42-9c8a-682bbc75d0fc"), + ID: uuid.Must(uuid.FromString("5ebc6a0f-05b7-4f42-9c8a-682bbc75d0fc")), Type: fetcher.MemberUser, }, { - ID: uuid.MustParse("6a59ea83-02bd-468f-a40b-f2c3d1821983"), + ID: uuid.Must(uuid.FromString("6a59ea83-02bd-468f-a40b-f2c3d1821983")), Type: fetcher.MemberDevice, }, }, }, { - ID: uuid.MustParse("d140978f-d641-4f01-802f-4ecc1acf8935"), + ID: uuid.Must(uuid.FromString("d140978f-d641-4f01-802f-4ecc1acf8935")), Name: "group2", Members: []fetcher.Member{ { - ID: uuid.MustParse("331676df-b8fd-4492-82ed-02b927f8dd80"), + ID: uuid.Must(uuid.FromString("331676df-b8fd-4492-82ed-02b927f8dd80")), Type: fetcher.MemberGroup, }, { - ID: uuid.MustParse("d897d560-3d17-4dae-81b3-c898fe82bf84"), + ID: uuid.Must(uuid.FromString("d897d560-3d17-4dae-81b3-c898fe82bf84")), Type: fetcher.MemberUser, }, { - ID: uuid.MustParse("adbbe40a-0627-4328-89f1-88cac84dbc7f"), + ID: uuid.Must(uuid.FromString("adbbe40a-0627-4328-89f1-88cac84dbc7f")), Type: fetcher.MemberDevice, }, }, }, { - ID: uuid.MustParse("10db9800-3908-40cc-81c5-511fa8ccf7fd"), + ID: uuid.Must(uuid.FromString("10db9800-3908-40cc-81c5-511fa8ccf7fd")), Name: "group3", Members: []fetcher.Member{ { - ID: uuid.MustParse("d140978f-d641-4f01-802f-4ecc1acf8935"), + ID: uuid.Must(uuid.FromString("d140978f-d641-4f01-802f-4ecc1acf8935")), Type: fetcher.MemberGroup, }, }, @@ -67,7 +67,7 @@ var GroupResponse = []*fetcher.Group{ var UserResponse = []*fetcher.User{ { - ID: uuid.MustParse("5ebc6a0f-05b7-4f42-9c8a-682bbc75d0fc"), + ID: uuid.Must(uuid.FromString("5ebc6a0f-05b7-4f42-9c8a-682bbc75d0fc")), Fields: map[string]interface{}{ "userPrincipalName": "user.one@example.com", "mail": "user.one@example.com", @@ -80,7 +80,7 @@ var UserResponse = []*fetcher.User{ }, }, { - ID: uuid.MustParse("d897d560-3d17-4dae-81b3-c898fe82bf84"), + ID: uuid.Must(uuid.FromString("d897d560-3d17-4dae-81b3-c898fe82bf84")), Fields: map[string]interface{}{ "userPrincipalName": "user.two@example.com", "mail": "user.two@example.com", @@ -96,7 +96,7 @@ var UserResponse = []*fetcher.User{ var DeviceResponse = []*fetcher.Device{ { - ID: uuid.MustParse("6a59ea83-02bd-468f-a40b-f2c3d1821983"), + ID: uuid.Must(uuid.FromString("6a59ea83-02bd-468f-a40b-f2c3d1821983")), Fields: map[string]interface{}{ "accountEnabled": true, "deviceId": "eab73519-780d-4d43-be6d-a4a89af2a348", @@ -120,7 +120,7 @@ var DeviceResponse = []*fetcher.Device{ }, }, { - ID: uuid.MustParse("adbbe40a-0627-4328-89f1-88cac84dbc7f"), + ID: uuid.Must(uuid.FromString("adbbe40a-0627-4328-89f1-88cac84dbc7f")), Fields: map[string]interface{}{ "accountEnabled": true, "deviceId": "2fbbb8f9-ff67-4a21-b867-a344d18a4198", diff --git a/x-pack/filebeat/input/entityanalytics/provider/azuread/fetcher/user.go b/x-pack/filebeat/input/entityanalytics/provider/azuread/fetcher/user.go index d629e3ef7bfd..1a99e4ea889a 100644 --- a/x-pack/filebeat/input/entityanalytics/provider/azuread/fetcher/user.go +++ b/x-pack/filebeat/input/entityanalytics/provider/azuread/fetcher/user.go @@ -5,7 +5,7 @@ package fetcher import ( - "github.com/google/uuid" + "github.com/gofrs/uuid/v5" "github.com/elastic/beats/v7/x-pack/filebeat/input/entityanalytics/internal/collections" "github.com/elastic/elastic-agent-libs/mapstr" diff --git a/x-pack/filebeat/input/entityanalytics/provider/azuread/fetcher/user_test.go b/x-pack/filebeat/input/entityanalytics/provider/azuread/fetcher/user_test.go index af5488b2424d..afb361f982fe 100644 --- a/x-pack/filebeat/input/entityanalytics/provider/azuread/fetcher/user_test.go +++ b/x-pack/filebeat/input/entityanalytics/provider/azuread/fetcher/user_test.go @@ -7,7 +7,7 @@ package fetcher import ( "testing" - "github.com/google/uuid" + "github.com/gofrs/uuid/v5" "github.com/stretchr/testify/require" "github.com/elastic/beats/v7/x-pack/filebeat/input/entityanalytics/internal/collections" @@ -20,40 +20,40 @@ func TestUser_Merge(t *testing.T) { Want *User }{ "id-mismatch": { - In: &User{ID: uuid.MustParse("187f924c-e867-477e-8d74-dd762d6379dd")}, - InOther: &User{ID: uuid.MustParse("80c3f9af-75ae-45f5-b22b-53f005d5880d")}, - Want: &User{ID: uuid.MustParse("187f924c-e867-477e-8d74-dd762d6379dd")}, + In: &User{ID: uuid.Must(uuid.FromString("187f924c-e867-477e-8d74-dd762d6379dd"))}, + InOther: &User{ID: uuid.Must(uuid.FromString("80c3f9af-75ae-45f5-b22b-53f005d5880d"))}, + Want: &User{ID: uuid.Must(uuid.FromString("187f924c-e867-477e-8d74-dd762d6379dd"))}, }, "ok": { In: &User{ - ID: uuid.MustParse("187f924c-e867-477e-8d74-dd762d6379dd"), + ID: uuid.Must(uuid.FromString("187f924c-e867-477e-8d74-dd762d6379dd")), Fields: map[string]interface{}{ "a": "alpha", }, - MemberOf: collections.NewUUIDSet(uuid.MustParse("fcda226a-c920-4d99-81bc-d2d691a6c212")), - TransitiveMemberOf: collections.NewUUIDSet(uuid.MustParse("ca777ad5-9abf-4c9b-be1f-c38c6ec28f28")), + MemberOf: collections.NewUUIDSet(uuid.Must(uuid.FromString("fcda226a-c920-4d99-81bc-d2d691a6c212"))), + TransitiveMemberOf: collections.NewUUIDSet(uuid.Must(uuid.FromString("ca777ad5-9abf-4c9b-be1f-c38c6ec28f28"))), }, InOther: &User{ - ID: uuid.MustParse("187f924c-e867-477e-8d74-dd762d6379dd"), + ID: uuid.Must(uuid.FromString("187f924c-e867-477e-8d74-dd762d6379dd")), Fields: map[string]interface{}{ "b": "beta", }, - MemberOf: collections.NewUUIDSet(uuid.MustParse("a77e8cbb-27a5-49d3-9d5e-801997621f87")), - TransitiveMemberOf: collections.NewUUIDSet(uuid.MustParse("c550d32c-09b2-4851-b0f2-1bc431e26d01")), + MemberOf: collections.NewUUIDSet(uuid.Must(uuid.FromString("a77e8cbb-27a5-49d3-9d5e-801997621f87"))), + TransitiveMemberOf: collections.NewUUIDSet(uuid.Must(uuid.FromString("c550d32c-09b2-4851-b0f2-1bc431e26d01"))), }, Want: &User{ - ID: uuid.MustParse("187f924c-e867-477e-8d74-dd762d6379dd"), + ID: uuid.Must(uuid.FromString("187f924c-e867-477e-8d74-dd762d6379dd")), Fields: map[string]interface{}{ "a": "alpha", "b": "beta", }, MemberOf: collections.NewUUIDSet( - uuid.MustParse("fcda226a-c920-4d99-81bc-d2d691a6c212"), - uuid.MustParse("a77e8cbb-27a5-49d3-9d5e-801997621f87"), + uuid.Must(uuid.FromString("fcda226a-c920-4d99-81bc-d2d691a6c212")), + uuid.Must(uuid.FromString("a77e8cbb-27a5-49d3-9d5e-801997621f87")), ), TransitiveMemberOf: collections.NewUUIDSet( - uuid.MustParse("ca777ad5-9abf-4c9b-be1f-c38c6ec28f28"), - uuid.MustParse("c550d32c-09b2-4851-b0f2-1bc431e26d01"), + uuid.Must(uuid.FromString("ca777ad5-9abf-4c9b-be1f-c38c6ec28f28")), + uuid.Must(uuid.FromString("c550d32c-09b2-4851-b0f2-1bc431e26d01")), ), }, }, diff --git a/x-pack/filebeat/input/entityanalytics/provider/azuread/statestore.go b/x-pack/filebeat/input/entityanalytics/provider/azuread/statestore.go index 392ce5f04605..dfa425c6c6ef 100644 --- a/x-pack/filebeat/input/entityanalytics/provider/azuread/statestore.go +++ b/x-pack/filebeat/input/entityanalytics/provider/azuread/statestore.go @@ -10,7 +10,7 @@ import ( "fmt" "time" - "github.com/google/uuid" + "github.com/gofrs/uuid/v5" "github.com/elastic/beats/v7/x-pack/filebeat/input/entityanalytics/internal/collections" "github.com/elastic/beats/v7/x-pack/filebeat/input/entityanalytics/internal/kvstore" diff --git a/x-pack/filebeat/input/entityanalytics/provider/azuread/statestore_test.go b/x-pack/filebeat/input/entityanalytics/provider/azuread/statestore_test.go index ef1ba2b240a6..66f08d018d5e 100644 --- a/x-pack/filebeat/input/entityanalytics/provider/azuread/statestore_test.go +++ b/x-pack/filebeat/input/entityanalytics/provider/azuread/statestore_test.go @@ -11,7 +11,7 @@ import ( "testing" "time" - "github.com/google/uuid" + "github.com/gofrs/uuid/v5" "github.com/stretchr/testify/require" "github.com/elastic/beats/v7/x-pack/filebeat/input/entityanalytics/internal/collections" @@ -116,10 +116,10 @@ func TestStateStore_Close(t *testing.T) { ss.devicesLink = "devices-link" ss.groupsLink = "groups-link" - user1ID := uuid.MustParse("a77e8cbb-27a5-49d3-9d5e-801997621f87") - device1ID := uuid.MustParse("adbbe40a-0627-4328-89f1-88cac84dbc7f") - group1ID := uuid.MustParse("331676df-b8fd-4492-82ed-02b927f8dd80") - group2ID := uuid.MustParse("ec8b17ae-ce9d-4099-97ee-4a959638bc29") + user1ID := uuid.Must(uuid.FromString("a77e8cbb-27a5-49d3-9d5e-801997621f87")) + device1ID := uuid.Must(uuid.FromString("adbbe40a-0627-4328-89f1-88cac84dbc7f")) + group1ID := uuid.Must(uuid.FromString("331676df-b8fd-4492-82ed-02b927f8dd80")) + group2ID := uuid.Must(uuid.FromString("ec8b17ae-ce9d-4099-97ee-4a959638bc29")) ss.users = map[uuid.UUID]*fetcher.User{ user1ID: { diff --git a/x-pack/filebeat/input/entityanalytics/provider/jamf/internal/jamf/jamf_test.go b/x-pack/filebeat/input/entityanalytics/provider/jamf/internal/jamf/jamf_test.go index e11269878cf2..47e6c27f6d30 100644 --- a/x-pack/filebeat/input/entityanalytics/provider/jamf/internal/jamf/jamf_test.go +++ b/x-pack/filebeat/input/entityanalytics/provider/jamf/internal/jamf/jamf_test.go @@ -6,7 +6,6 @@ package jamf import ( "context" - "crypto/tls" "encoding/json" "flag" "fmt" @@ -19,8 +18,8 @@ import ( _ "embed" + "github.com/gofrs/uuid/v5" "github.com/google/go-cmp/cmp" - "github.com/google/uuid" ) var logResponses = flag.Bool("log_response", false, "use to log users/devices returned from the API") @@ -70,16 +69,18 @@ var jamfTests = []struct { if !ok || user != username || pass != password { w.WriteHeader(http.StatusUnauthorized) w.Header().Set("content-type", "application/json;charset=UTF-8") + //nolint:errcheck // no error handling w.Write([]byte("{\n \"httpStatus\" : 401,\n \"errors\" : [ ]\n}")) return } if r.Method != http.MethodPost { w.WriteHeader(http.StatusMethodNotAllowed) w.Header().Set("content-type", "application/json;charset=UTF-8") + //nolint:errcheck // no error handling w.Write([]byte("{\n \"httpStatus\" : 405,\n \"errors\" : [ ]\n}")) return } - tok.Token = uuid.New().String() + tok.Token = uuid.Must(uuid.NewV4()).String() tok.Expires = time.Now().In(time.UTC).Add(time.Hour) fmt.Fprintf(w, "{\n \"token\" : \"%s\",\n \"expires\" : \"%s\"\n}", tok.Token, tok.Expires.Format(time.RFC3339)) })) @@ -87,12 +88,14 @@ var jamfTests = []struct { if r.Header.Get("Authorization") != "Bearer "+tok.Token || !tok.IsValidFor(0) { w.WriteHeader(http.StatusUnauthorized) w.Header().Set("content-type", "application/json;charset=UTF-8") + //nolint:errcheck // no error handling w.Write([]byte("{\n \"httpStatus\" : 401,\n \"errors\" : [ {\n \"code\" : \"INVALID_TOKEN\",\n \"description\" : \"Unauthorized\",\n \"id\" : \"0\",\n \"field\" : null\n } ]\n}")) return false } if r.Method != http.MethodGet { w.WriteHeader(http.StatusMethodNotAllowed) w.Header().Set("content-type", "application/json;charset=UTF-8") + //nolint:errcheck // no error handling w.Write([]byte("{\n \"httpStatus\" : 405,\n \"errors\" : [ ]\n}")) return false } @@ -100,11 +103,13 @@ var jamfTests = []struct { } mux.Handle("/api/preview/computers", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if isValidRequest(w, r) { + //nolint:errcheck // no error handling w.Write(computers) } })) mux.Handle("/JSSResource/users", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if isValidRequest(w, r) { + //nolint:errcheck // no error handling w.Write(users) } })) @@ -117,13 +122,7 @@ var jamfTests = []struct { } tenant = u.Host - cli := &http.Client{ - Transport: &http.Transport{ - TLSClientConfig: &tls.Config{ - InsecureSkipVerify: true, - }, - }, - } + cli := srv.Client() return tenant, username, password, cli, srv.Close, nil }, @@ -147,6 +146,7 @@ func TestJamf(t *testing.T) { for _, test := range jamfTests { t.Run(test.name, func(t *testing.T) { tenant, username, password, client, cleanup, err := test.context() + //nolint:errorlint // false positive switch err := err.(type) { case nil: case skipError: diff --git a/x-pack/filebeat/input/entityanalytics/provider/jamf/jamf_test.go b/x-pack/filebeat/input/entityanalytics/provider/jamf/jamf_test.go index dc759166d7b6..9ca7128d11c3 100644 --- a/x-pack/filebeat/input/entityanalytics/provider/jamf/jamf_test.go +++ b/x-pack/filebeat/input/entityanalytics/provider/jamf/jamf_test.go @@ -6,7 +6,6 @@ package jamf import ( "context" - "crypto/tls" "encoding/json" "flag" "fmt" @@ -18,8 +17,8 @@ import ( _ "embed" + "github.com/gofrs/uuid/v5" "github.com/google/go-cmp/cmp" - "github.com/google/uuid" "gopkg.in/natefinch/lumberjack.v2" "github.com/elastic/beats/v7/x-pack/filebeat/input/entityanalytics/provider/jamf/internal/jamf" @@ -38,14 +37,12 @@ func TestJamfDoFetch(t *testing.T) { testCleanupStore(store, dbFilename) }) - var ( - wantComputers []*Computer - rawComputers jamf.Computers - ) + var rawComputers jamf.Computers err := json.Unmarshal(computers, &rawComputers) if err != nil { t.Fatalf("failed to unmarshal device data: %v", err) } + wantComputers := make([]*Computer, 0, len(rawComputers.Results)) for _, c := range rawComputers.Results { wantComputers = append(wantComputers, &Computer{ Computer: c, @@ -109,16 +106,18 @@ func testContext() (tenant string, username string, password string, client *htt if !ok || user != username || pass != password { w.WriteHeader(http.StatusUnauthorized) w.Header().Set("content-type", "application/json;charset=UTF-8") + //nolint:errcheck // ignore w.Write([]byte("{\n \"httpStatus\" : 401,\n \"errors\" : [ ]\n}")) return } if r.Method != http.MethodPost { w.WriteHeader(http.StatusMethodNotAllowed) w.Header().Set("content-type", "application/json;charset=UTF-8") + //nolint:errcheck // ignore w.Write([]byte("{\n \"httpStatus\" : 405,\n \"errors\" : [ ]\n}")) return } - tok.Token = uuid.New().String() + tok.Token = uuid.Must(uuid.NewV4()).String() tok.Expires = time.Now().In(time.UTC).Add(time.Hour) fmt.Fprintf(w, "{\n \"token\" : \"%s\",\n \"expires\" : \"%s\"\n}", tok.Token, tok.Expires.Format(time.RFC3339)) })) @@ -126,15 +125,18 @@ func testContext() (tenant string, username string, password string, client *htt if r.Header.Get("Authorization") != "Bearer "+tok.Token || !tok.IsValidFor(0) { w.WriteHeader(http.StatusUnauthorized) w.Header().Set("content-type", "application/json;charset=UTF-8") + //nolint:errcheck // ignore w.Write([]byte("{\n \"httpStatus\" : 401,\n \"errors\" : [ {\n \"code\" : \"INVALID_TOKEN\",\n \"description\" : \"Unauthorized\",\n \"id\" : \"0\",\n \"field\" : null\n } ]\n}")) return } if r.Method != http.MethodGet { w.WriteHeader(http.StatusMethodNotAllowed) w.Header().Set("content-type", "application/json;charset=UTF-8") + //nolint:errcheck // ignore w.Write([]byte("{\n \"httpStatus\" : 405,\n \"errors\" : [ ]\n}")) return } + //nolint:errcheck // ignore w.Write(computers) })) @@ -146,13 +148,7 @@ func testContext() (tenant string, username string, password string, client *htt } tenant = u.Host - cli := &http.Client{ - Transport: &http.Transport{ - TLSClientConfig: &tls.Config{ - InsecureSkipVerify: true, - }, - }, - } + cli := srv.Client() return tenant, username, password, cli, srv.Close, nil } diff --git a/x-pack/filebeat/input/httpjson/value_tpl.go b/x-pack/filebeat/input/httpjson/value_tpl.go index cf7e43cf8e4c..b7258680dea4 100644 --- a/x-pack/filebeat/input/httpjson/value_tpl.go +++ b/x-pack/filebeat/input/httpjson/value_tpl.go @@ -24,7 +24,7 @@ import ( "text/template" "time" - "github.com/google/uuid" + "github.com/gofrs/uuid/v5" "github.com/elastic/beats/v7/libbeat/version" "github.com/elastic/elastic-agent-libs/logp" @@ -483,7 +483,7 @@ func hexDecode(enc string) string { } func uuidString() string { - uuid, err := uuid.NewRandom() + uuid, err := uuid.NewV4() if err != nil { return "" } diff --git a/x-pack/functionbeat/manager/aws/op_cloudformation.go b/x-pack/functionbeat/manager/aws/op_cloudformation.go index 3298d8660805..028c78cd4a4e 100644 --- a/x-pack/functionbeat/manager/aws/op_cloudformation.go +++ b/x-pack/functionbeat/manager/aws/op_cloudformation.go @@ -14,7 +14,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/cloudformation" - "github.com/gofrs/uuid" + "github.com/gofrs/uuid/v5" "github.com/elastic/beats/v7/x-pack/functionbeat/manager/executor" "github.com/elastic/elastic-agent-libs/logp" diff --git a/x-pack/functionbeat/manager/aws/op_delete_cloudformation.go b/x-pack/functionbeat/manager/aws/op_delete_cloudformation.go index 0f9fb60c5936..4954e70b2666 100644 --- a/x-pack/functionbeat/manager/aws/op_delete_cloudformation.go +++ b/x-pack/functionbeat/manager/aws/op_delete_cloudformation.go @@ -9,7 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/cloudformation" - "github.com/gofrs/uuid" + "github.com/gofrs/uuid/v5" "github.com/elastic/beats/v7/x-pack/functionbeat/manager/executor" "github.com/elastic/elastic-agent-libs/logp" diff --git a/x-pack/functionbeat/manager/aws/op_update_cloudformation.go b/x-pack/functionbeat/manager/aws/op_update_cloudformation.go index 8441c89ca2cb..9a75909f2479 100644 --- a/x-pack/functionbeat/manager/aws/op_update_cloudformation.go +++ b/x-pack/functionbeat/manager/aws/op_update_cloudformation.go @@ -11,7 +11,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/cloudformation" - "github.com/gofrs/uuid" + "github.com/gofrs/uuid/v5" "github.com/elastic/beats/v7/x-pack/functionbeat/manager/executor" "github.com/elastic/elastic-agent-libs/logp" diff --git a/x-pack/heartbeat/monitors/browser/synthexec/enrich.go b/x-pack/heartbeat/monitors/browser/synthexec/enrich.go index 05d726d6398a..9201c11d1e58 100644 --- a/x-pack/heartbeat/monitors/browser/synthexec/enrich.go +++ b/x-pack/heartbeat/monitors/browser/synthexec/enrich.go @@ -13,7 +13,7 @@ import ( "github.com/elastic/beats/v7/libbeat/processors/add_data_stream" "github.com/elastic/elastic-agent-libs/mapstr" - "github.com/gofrs/uuid" + "github.com/gofrs/uuid/v5" "github.com/elastic/beats/v7/heartbeat/eventext" "github.com/elastic/beats/v7/heartbeat/monitors/stdfields" diff --git a/x-pack/heartbeat/scenarios/framework/framework.go b/x-pack/heartbeat/scenarios/framework/framework.go index c6dc0ae9ad6d..a2fb77e63070 100644 --- a/x-pack/heartbeat/scenarios/framework/framework.go +++ b/x-pack/heartbeat/scenarios/framework/framework.go @@ -16,7 +16,7 @@ import ( "github.com/elastic/beats/v7/heartbeat/monitors/stdfields" "github.com/elastic/beats/v7/heartbeat/monitors/wrappers/monitorstate" - "github.com/gofrs/uuid" + "github.com/gofrs/uuid/v5" "github.com/stretchr/testify/require" "github.com/elastic/elastic-agent-libs/config" diff --git a/x-pack/libbeat/autodiscover/providers/aws/ec2/provider.go b/x-pack/libbeat/autodiscover/providers/aws/ec2/provider.go index 0c4d77209749..c58967c37c9c 100644 --- a/x-pack/libbeat/autodiscover/providers/aws/ec2/provider.go +++ b/x-pack/libbeat/autodiscover/providers/aws/ec2/provider.go @@ -10,7 +10,7 @@ import ( awssdk "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/ec2" - "github.com/gofrs/uuid" + "github.com/gofrs/uuid/v5" "github.com/elastic/beats/v7/libbeat/autodiscover" "github.com/elastic/beats/v7/libbeat/autodiscover/template" @@ -79,7 +79,7 @@ func AutodiscoverBuilder( config.Regions = completeRegionsList } - var clients []ec2.DescribeInstancesAPIClient + clients := make([]ec2.DescribeInstancesAPIClient, 0, len(config.Regions)) for _, region := range config.Regions { if err != nil { logp.Error(fmt.Errorf("error loading AWS config for aws_ec2 autodiscover provider: %w", err)) diff --git a/x-pack/libbeat/autodiscover/providers/aws/ec2/provider_test.go b/x-pack/libbeat/autodiscover/providers/aws/ec2/provider_test.go index a157d2878826..335acc3080ff 100644 --- a/x-pack/libbeat/autodiscover/providers/aws/ec2/provider_test.go +++ b/x-pack/libbeat/autodiscover/providers/aws/ec2/provider_test.go @@ -9,7 +9,7 @@ import ( "testing" "time" - "github.com/gofrs/uuid" + "github.com/gofrs/uuid/v5" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -59,8 +59,8 @@ func Test_internalBuilder(t *testing.T) { // Let run twice to ensure that duplicates don't create two start events // Since we're turning a list of assets into a list of changes the second once() call should be a noop - provider.watcher.once() - provider.watcher.once() + require.NoError(t, provider.watcher.once()) + require.NoError(t, provider.watcher.once()) events.WaitForNumEvents(t, 1, time.Second) assert.Equal(t, 1, events.Len()) @@ -86,8 +86,8 @@ func Test_internalBuilder(t *testing.T) { fetcher.setEC2s([]*ec2Instance{}) // Let run twice to ensure that duplicates don't cause an issue - provider.watcher.once() - provider.watcher.once() + require.NoError(t, provider.watcher.once()) + require.NoError(t, provider.watcher.once()) events.WaitForNumEvents(t, 2, time.Second) require.Equal(t, 2, events.Len()) @@ -105,7 +105,9 @@ func Test_internalBuilder(t *testing.T) { fetcher.setError(errors.New("oops")) // Let run twice to ensure that duplicates don't cause an issue + //nolint:errcheck // ignore provider.watcher.once() + //nolint:errcheck // ignore provider.watcher.once() assert.Equal(t, preErrorEventCount, events.Len()) diff --git a/x-pack/libbeat/autodiscover/providers/aws/elb/provider.go b/x-pack/libbeat/autodiscover/providers/aws/elb/provider.go index ea44596e52af..2440f2c6f83f 100644 --- a/x-pack/libbeat/autodiscover/providers/aws/elb/provider.go +++ b/x-pack/libbeat/autodiscover/providers/aws/elb/provider.go @@ -8,7 +8,7 @@ import ( awssdk "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/ec2" "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2" - "github.com/gofrs/uuid" + "github.com/gofrs/uuid/v5" "github.com/elastic/beats/v7/libbeat/autodiscover" "github.com/elastic/beats/v7/libbeat/autodiscover/template" diff --git a/x-pack/libbeat/autodiscover/providers/aws/elb/provider_test.go b/x-pack/libbeat/autodiscover/providers/aws/elb/provider_test.go index 688323e26f22..a6b08c8afe86 100644 --- a/x-pack/libbeat/autodiscover/providers/aws/elb/provider_test.go +++ b/x-pack/libbeat/autodiscover/providers/aws/elb/provider_test.go @@ -10,7 +10,7 @@ import ( "testing" "time" - "github.com/gofrs/uuid" + "github.com/gofrs/uuid/v5" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -52,7 +52,7 @@ func (tea *testEventAccumulator) get() []bus.Event { func (tea *testEventAccumulator) waitForNumEvents(t *testing.T, targetLen int, timeout time.Duration) { start := time.Now() - for time.Now().Sub(start) < timeout { + for time.Since(start) < timeout { if tea.len() >= targetLen { return } @@ -100,8 +100,8 @@ func Test_internalBuilder(t *testing.T) { // Let run twice to ensure that duplicates don't create two start events // Since we're turning a list of assets into a list of changes the second once() call should be a noop - provider.watcher.once() - provider.watcher.once() + require.NoError(t, provider.watcher.once()) + require.NoError(t, provider.watcher.once()) events.waitForNumEvents(t, 1, time.Second) assert.Equal(t, 1, events.len()) @@ -129,8 +129,8 @@ func Test_internalBuilder(t *testing.T) { fetcher.setLbls([]*lbListener{}) // Let run twice to ensure that duplicates don't cause an issue - provider.watcher.once() - provider.watcher.once() + require.NoError(t, provider.watcher.once()) + require.NoError(t, provider.watcher.once()) events.waitForNumEvents(t, 2, time.Second) require.Equal(t, 2, events.len()) @@ -148,7 +148,9 @@ func Test_internalBuilder(t *testing.T) { fetcher.setError(errors.New("oops")) // Let run twice to ensure that duplicates don't cause an issue + //nolint:errcheck // ignore provider.watcher.once() + //nolint:errcheck // ignore provider.watcher.once() assert.Equal(t, preErrorEventCount, events.len()) diff --git a/x-pack/libbeat/autodiscover/providers/nomad/nomad.go b/x-pack/libbeat/autodiscover/providers/nomad/nomad.go index 3cfd4ce5feec..4d1bba4bc258 100644 --- a/x-pack/libbeat/autodiscover/providers/nomad/nomad.go +++ b/x-pack/libbeat/autodiscover/providers/nomad/nomad.go @@ -9,7 +9,7 @@ import ( "strings" "time" - "github.com/gofrs/uuid" + "github.com/gofrs/uuid/v5" "github.com/elastic/elastic-agent-autodiscover/utils" diff --git a/x-pack/libbeat/autodiscover/providers/nomad/nomad_test.go b/x-pack/libbeat/autodiscover/providers/nomad/nomad_test.go index 6f88261a1f04..95d24f8bad88 100644 --- a/x-pack/libbeat/autodiscover/providers/nomad/nomad_test.go +++ b/x-pack/libbeat/autodiscover/providers/nomad/nomad_test.go @@ -12,7 +12,7 @@ import ( "testing" "time" - "github.com/gofrs/uuid" + "github.com/gofrs/uuid/v5" "github.com/hashicorp/nomad/api" "github.com/stretchr/testify/assert" diff --git a/x-pack/libbeat/common/cloudfoundry/cache_test.go b/x-pack/libbeat/common/cloudfoundry/cache_test.go index d77ba9633d55..8d4cef2c2fb3 100644 --- a/x-pack/libbeat/common/cloudfoundry/cache_test.go +++ b/x-pack/libbeat/common/cloudfoundry/cache_test.go @@ -11,7 +11,7 @@ import ( "time" "github.com/cloudfoundry-community/go-cfclient" - "github.com/gofrs/uuid" + "github.com/gofrs/uuid/v5" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" diff --git a/x-pack/libbeat/common/cloudfoundry/test/config.go b/x-pack/libbeat/common/cloudfoundry/test/config.go index 45059fc559c6..c9f2293eb308 100644 --- a/x-pack/libbeat/common/cloudfoundry/test/config.go +++ b/x-pack/libbeat/common/cloudfoundry/test/config.go @@ -8,7 +8,7 @@ import ( "os" "testing" - "github.com/gofrs/uuid" + "github.com/gofrs/uuid/v5" ) func GetConfigFromEnv(t *testing.T) map[string]interface{} { diff --git a/x-pack/libbeat/common/nomad/metadata_test.go b/x-pack/libbeat/common/nomad/metadata_test.go index 16855fa9c414..08616be9f83f 100644 --- a/x-pack/libbeat/common/nomad/metadata_test.go +++ b/x-pack/libbeat/common/nomad/metadata_test.go @@ -7,9 +7,10 @@ package nomad import ( "testing" - "github.com/gofrs/uuid" + "github.com/gofrs/uuid/v5" "github.com/hashicorp/nomad/api" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" conf "github.com/elastic/elastic-agent-libs/config" "github.com/elastic/elastic-agent-libs/mapstr" @@ -75,6 +76,7 @@ func TestAllocationMetadata(t *testing.T) { "annotations.dedot": false, "include_annotations": []string{"b", "b.key"}, }) + require.NoError(t, err) metaGen, err := NewMetaGenerator(config, nil) if err != nil { @@ -105,6 +107,7 @@ func TestExcludeMetadata(t *testing.T) { config, err := conf.NewConfigFrom(map[string]interface{}{ "exclude_labels": []string{"key1", "canary_tags"}, }) + require.NoError(t, err) metaGen, err := NewMetaGenerator(config, nil) if err != nil { @@ -158,6 +161,7 @@ func TestCronJob(t *testing.T) { } config, err := conf.NewConfigFrom(map[string]interface{}{}) + require.NoError(t, err) metaGen, err := NewMetaGenerator(config, nil) if err != nil { diff --git a/x-pack/libbeat/common/nomad/watcher_test.go b/x-pack/libbeat/common/nomad/watcher_test.go index a8cd6555acc8..488d9ef8bf84 100644 --- a/x-pack/libbeat/common/nomad/watcher_test.go +++ b/x-pack/libbeat/common/nomad/watcher_test.go @@ -12,9 +12,10 @@ import ( "testing" "time" - "github.com/gofrs/uuid" + "github.com/gofrs/uuid/v5" api "github.com/hashicorp/nomad/api" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/elastic/beats/v7/libbeat/tests/resources" ) @@ -31,10 +32,12 @@ func nomadRoutes(node api.Node, allocs []api.Allocation, waitIndex uint64) *http payload, err := json.Marshal([]interface{}{node}) if err != nil { w.WriteHeader(http.StatusInternalServerError) + //nolint:errcheck // ignore w.Write([]byte(err.Error())) } w.Header().Add(NomadIndexHeader, fmt.Sprint(time.Now().Unix())) + //nolint:errcheck // ignore w.Write(payload) }) @@ -42,10 +45,12 @@ func nomadRoutes(node api.Node, allocs []api.Allocation, waitIndex uint64) *http payload, err := json.Marshal(allocs) if err != nil { w.WriteHeader(http.StatusInternalServerError) + //nolint:errcheck // ignore w.Write([]byte(err.Error())) } w.Header().Add(NomadIndexHeader, fmt.Sprint(waitIndex)) + //nolint:errcheck // ignore w.Write(payload) }) @@ -300,7 +305,8 @@ func TestAllocationWatcher(t *testing.T) { goroutines := resources.NewGoroutinesChecker() defer goroutines.Check(t) - watcher.Start() + err = watcher.Start() + require.NoError(t, err) defer watcher.Stop() assert.Equal(t, tt.expected, events) diff --git a/x-pack/libbeat/persistentcache/persistentcache_test.go b/x-pack/libbeat/persistentcache/persistentcache_test.go index 416905d2e40b..7a3b61b8cb3a 100644 --- a/x-pack/libbeat/persistentcache/persistentcache_test.go +++ b/x-pack/libbeat/persistentcache/persistentcache_test.go @@ -6,15 +6,13 @@ package persistentcache import ( "fmt" - "io/ioutil" "math/rand" - "os" "path/filepath" "strconv" "testing" "time" - "github.com/gofrs/uuid" + "github.com/gofrs/uuid/v5" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -277,6 +275,7 @@ func BenchmarkPut(b *testing.B) { for i := 0; i < b.N; i++ { cache := c.factory(b, b.Name()) for _, object := range objects { + //nolint:errcheck // benchmarks cache.Put(object.ID, object) } cache.Close() @@ -392,6 +391,7 @@ func BenchmarkGet(b *testing.B) { b.ResetTimer() for i := 0; i < b.N; i++ { expected := objects[rand.Intn(size)] + //nolint:errcheck // benchmarks cache.Get(expected.ID, &result) if expected.ID != result.ID { b.Fatalf("%s != %s", expected.ID, result.ID) @@ -408,29 +408,7 @@ func BenchmarkGet(b *testing.B) { func testOptions(t testing.TB) Options { t.Helper() - tempDir, err := ioutil.TempDir("", "beat-data-dir-") - require.NoError(t, err) - - t.Cleanup(func() { os.RemoveAll(tempDir) }) - return Options{ - RootPath: filepath.Join(tempDir, cacheFile), + RootPath: filepath.Join(t.TempDir(), cacheFile), } } - -func dirSize(tb testing.TB, path string) int64 { - var size int64 - - err := filepath.Walk(path, func(_ string, info os.FileInfo, err error) error { - if err != nil { - return err - } - if !info.IsDir() { - size += info.Size() - } - return nil - }) - require.NoError(tb, err) - - return size -} diff --git a/x-pack/libbeat/processors/add_cloudfoundry_metadata/add_cloudfoundry_metadata.go b/x-pack/libbeat/processors/add_cloudfoundry_metadata/add_cloudfoundry_metadata.go index f20d713c7b6a..26afdbf925b2 100644 --- a/x-pack/libbeat/processors/add_cloudfoundry_metadata/add_cloudfoundry_metadata.go +++ b/x-pack/libbeat/processors/add_cloudfoundry_metadata/add_cloudfoundry_metadata.go @@ -9,7 +9,7 @@ package add_cloudfoundry_metadata import ( "fmt" - "github.com/gofrs/uuid" + "github.com/gofrs/uuid/v5" "github.com/elastic/beats/v7/libbeat/beat" "github.com/elastic/beats/v7/libbeat/processors" diff --git a/x-pack/libbeat/processors/add_cloudfoundry_metadata/add_cloudfoundry_metadata_test.go b/x-pack/libbeat/processors/add_cloudfoundry_metadata/add_cloudfoundry_metadata_test.go index 002418c98254..6154d6f0b90a 100644 --- a/x-pack/libbeat/processors/add_cloudfoundry_metadata/add_cloudfoundry_metadata_test.go +++ b/x-pack/libbeat/processors/add_cloudfoundry_metadata/add_cloudfoundry_metadata_test.go @@ -10,7 +10,7 @@ import ( "testing" "github.com/cloudfoundry-community/go-cfclient" - "github.com/gofrs/uuid" + "github.com/gofrs/uuid/v5" "github.com/stretchr/testify/assert" "github.com/elastic/beats/v7/libbeat/beat" diff --git a/x-pack/metricbeat/module/azure/app_insights/client.go b/x-pack/metricbeat/module/azure/app_insights/client.go index d2bed8fbf0ee..75e931b71321 100644 --- a/x-pack/metricbeat/module/azure/app_insights/client.go +++ b/x-pack/metricbeat/module/azure/app_insights/client.go @@ -8,7 +8,7 @@ import ( "fmt" "time" - "github.com/gofrs/uuid" + "github.com/gofrs/uuid/v5" "github.com/Azure/azure-sdk-for-go/services/preview/appinsights/v1/insights" @@ -40,6 +40,7 @@ func (client *Client) GetMetricValues() (insights.ListMetricsResultsItem, error) var bodyMetrics []insights.MetricsPostBodySchema var result insights.ListMetricsResultsItem for _, metrics := range client.Config.Metrics { + metrics := metrics var aggregations []insights.MetricsAggregation var segments []insights.MetricsSegment for _, agg := range metrics.Aggregation { diff --git a/x-pack/osquerybeat/beater/action_handler_test.go b/x-pack/osquerybeat/beater/action_handler_test.go index f3008e4ee769..d446b883175a 100644 --- a/x-pack/osquerybeat/beater/action_handler_test.go +++ b/x-pack/osquerybeat/beater/action_handler_test.go @@ -9,7 +9,7 @@ import ( "testing" "time" - "github.com/gofrs/uuid" + "github.com/gofrs/uuid/v5" "github.com/google/go-cmp/cmp" "github.com/elastic/beats/v7/x-pack/osquerybeat/internal/ecs" diff --git a/x-pack/osquerybeat/beater/osquerybeat.go b/x-pack/osquerybeat/beater/osquerybeat.go index 119d72cdd5af..7ed65de2dc69 100644 --- a/x-pack/osquerybeat/beater/osquerybeat.go +++ b/x-pack/osquerybeat/beater/osquerybeat.go @@ -11,7 +11,7 @@ import ( "sync" "time" - "github.com/gofrs/uuid" + "github.com/gofrs/uuid/v5" lru "github.com/hashicorp/golang-lru" "github.com/osquery/osquery-go" kconfig "github.com/osquery/osquery-go/plugin/config" diff --git a/x-pack/osquerybeat/internal/fetch/fetch_test.go b/x-pack/osquerybeat/internal/fetch/fetch_test.go index f234a78f2569..3e89ada6f5a4 100644 --- a/x-pack/osquerybeat/internal/fetch/fetch_test.go +++ b/x-pack/osquerybeat/internal/fetch/fetch_test.go @@ -11,7 +11,7 @@ import ( "os" "testing" - "github.com/gofrs/uuid" + "github.com/gofrs/uuid/v5" "github.com/google/go-cmp/cmp" ) diff --git a/x-pack/osquerybeat/internal/osqd/osqueryd_test.go b/x-pack/osquerybeat/internal/osqd/osqueryd_test.go index 8a07cfd9d738..12b20b4e09cd 100644 --- a/x-pack/osquerybeat/internal/osqd/osqueryd_test.go +++ b/x-pack/osquerybeat/internal/osqd/osqueryd_test.go @@ -15,7 +15,7 @@ import ( "github.com/elastic/beats/v7/x-pack/osquerybeat/internal/fileutil" "github.com/elastic/elastic-agent-libs/logp" - "github.com/gofrs/uuid" + "github.com/gofrs/uuid/v5" "github.com/google/go-cmp/cmp" ) diff --git a/x-pack/osquerybeat/internal/osqd/osqueryd_windows.go b/x-pack/osquerybeat/internal/osqd/osqueryd_windows.go index 0d14c417cbf3..65550e4332ae 100644 --- a/x-pack/osquerybeat/internal/osqd/osqueryd_windows.go +++ b/x-pack/osquerybeat/internal/osqd/osqueryd_windows.go @@ -11,7 +11,7 @@ import ( "os/exec" "syscall" - "github.com/gofrs/uuid" + "github.com/gofrs/uuid/v5" ) const ( diff --git a/x-pack/osquerybeat/internal/pub/publisher_test.go b/x-pack/osquerybeat/internal/pub/publisher_test.go index ad592bf7ec67..7b7d2120e847 100644 --- a/x-pack/osquerybeat/internal/pub/publisher_test.go +++ b/x-pack/osquerybeat/internal/pub/publisher_test.go @@ -9,7 +9,7 @@ import ( "testing" "time" - "github.com/gofrs/uuid" + "github.com/gofrs/uuid/v5" "github.com/google/go-cmp/cmp" "github.com/elastic/beats/v7/libbeat/beat/events"