Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: consistently use one uuid library #40161

Merged
merged 52 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
a88bcb4
refactor: consistently use one uuid library
kruskall Jul 10, 2024
e8c21b5
lint: fix linting issues
kruskall Jul 10, 2024
aa7304f
Merge branch 'main' into feat/standard-uuid-lib
kruskall Jul 10, 2024
0fee800
refactor: move to gofrs/uuid
kruskall Jul 10, 2024
fb77a5a
lint: add gomodguard setting
kruskall Jul 10, 2024
74beaf9
lint: fix more linter issues
kruskall Jul 10, 2024
3e40b83
lint: more linting errors
kruskall Jul 11, 2024
7772b15
lint: completely remove gofrs/uuid v4
kruskall Jul 11, 2024
f500379
lint: more linting errors
kruskall Jul 11, 2024
ec7de41
lint: more linting errors
kruskall Jul 11, 2024
29af9f1
Merge branch 'main' into feat/standard-uuid-lib
kruskall Jul 11, 2024
9eaa809
lint: fix more linting errors
kruskall Jul 11, 2024
f3ecc1f
fix: replace uuid.MustParse with uuid.Must(uuid.FromString())
kruskall Jul 11, 2024
9e33175
refactor: update uuid.Parse to uuid.FromString
kruskall Jul 11, 2024
9096808
lint: fix linting errors
kruskall Jul 11, 2024
1c17360
lint: fix linting errors
kruskall Jul 12, 2024
d6d7ee3
docs: fix nolint comments
kruskall Jul 12, 2024
bd1db14
lint: fix linting errors
kruskall Jul 12, 2024
4ed1ee3
docs: update nolint comments
kruskall Jul 12, 2024
8acb07e
Merge branch 'main' into feat/standard-uuid-lib
kruskall Jul 12, 2024
25cf98a
test: update uuid parsing err
kruskall Jul 12, 2024
1b9e4c3
Merge branch 'main' into feat/standard-uuid-lib
kruskall Jul 12, 2024
46615a1
Merge branch 'main' into feat/standard-uuid-lib
kruskall Jul 15, 2024
b16de08
Merge branch 'main' into feat/standard-uuid-lib
kruskall Jul 15, 2024
bc7f278
lint: fix linter issues
kruskall Jul 15, 2024
9436142
lint: fix linter issues
kruskall Jul 15, 2024
ce1af44
Merge branch 'main' into feat/standard-uuid-lib
kruskall Jul 15, 2024
736b471
Merge branch 'main' into feat/standard-uuid-lib
kruskall Jul 16, 2024
6f0ebeb
Merge branch 'main' into feat/standard-uuid-lib
kruskall Jul 16, 2024
ce59b70
Merge branch 'main' into feat/standard-uuid-lib
kruskall Jul 16, 2024
055c223
lint: run go mod tidy
kruskall Jul 17, 2024
56b0e58
lint: regenerate notice
kruskall Jul 17, 2024
66555cb
Merge branch 'main' into feat/standard-uuid-lib
kruskall Jul 17, 2024
b523946
Merge branch 'main' into feat/standard-uuid-lib
kruskall Jul 19, 2024
1b62afd
Merge branch 'main' into feat/standard-uuid-lib
kruskall Jul 21, 2024
cafe665
Merge branch 'main' into feat/standard-uuid-lib
kruskall Jul 22, 2024
2d7a8c1
Merge remote-tracking branch 'upstream/main' into feat/standard-uuid-lib
kruskall Jul 22, 2024
cd282a6
build: regenerate notice
kruskall Jul 22, 2024
bade374
Merge branch 'main' into feat/standard-uuid-lib
kruskall Jul 23, 2024
cbe3070
Merge branch 'main' into feat/standard-uuid-lib
kruskall Jul 24, 2024
9047bf0
Merge branch 'main' into feat/standard-uuid-lib
kruskall Jul 24, 2024
8454631
Merge remote-tracking branch 'upstream/main' into feat/standard-uuid-lib
kruskall Jul 26, 2024
2302448
build: regenerate notice
kruskall Jul 26, 2024
aa74525
refactor: cleanup double uuid conversion
kruskall Jul 26, 2024
4602e5d
Merge branch 'main' into feat/standard-uuid-lib
kruskall Jul 28, 2024
05cbada
Merge branch 'main' into feat/standard-uuid-lib
kruskall Jul 29, 2024
46694a3
Merge branch 'main' into feat/standard-uuid-lib
kruskall Jul 29, 2024
e4cdd74
Merge branch 'main' into feat/standard-uuid-lib
kruskall Jul 31, 2024
e7566f1
Merge branch 'main' into feat/standard-uuid-lib
kruskall Aug 1, 2024
4c5cf4c
test: gracefully log the error
kruskall Aug 1, 2024
cad2258
Merge branch 'main' into feat/standard-uuid-lib
kruskall Aug 2, 2024
285779f
Merge branch 'main' into feat/standard-uuid-lib
kruskall Aug 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,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'.
Expand Down
110 changes: 40 additions & 70 deletions NOTICE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17435,12 +17435,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 <b@codemonkey.ru>

Expand Down Expand Up @@ -18494,43 +18494,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.12.5
Expand Down Expand Up @@ -40690,36 +40653,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 <b@codemonkey.ru>

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
Expand Down Expand Up @@ -42923,6 +42856,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
Expand Down
2 changes: 1 addition & 1 deletion filebeat/fileset/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion filebeat/harvester/harvester.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion filebeat/harvester/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"errors"
"sync"

"github.com/gofrs/uuid"
"github.com/gofrs/uuid/v5"

"github.com/elastic/elastic-agent-libs/logp"
)
Expand Down
33 changes: 16 additions & 17 deletions filebeat/input/log/harvester.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -191,15 +191,15 @@ 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()
if err != nil {
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())
Expand Down Expand Up @@ -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):
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see any cases that these error values are returned wrapped so (disclaimer: as a non-owner) I'm not convinced of the value of this, but if this change is going to be made, the tests that look at error values should be updated to match (ErrInactive is the target of an exact value check).

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)
Expand Down Expand Up @@ -519,15 +519,15 @@ 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)
}

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)
Expand All @@ -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() {
Expand All @@ -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)
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion filebeat/input/log/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
26 changes: 19 additions & 7 deletions filebeat/input/redis/harvester.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -82,22 +82,26 @@ 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()

// 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 {
Expand All @@ -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)
Expand Down Expand Up @@ -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, " "),
Expand All @@ -156,6 +164,10 @@ func (h *Harvester) Run() error {
},
},
})
if err != nil {
logp.Err("Error sending beat event: %s", err)
continue
}
}
return nil
}
Expand Down
Loading
Loading