Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
22 changes: 10 additions & 12 deletions broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import (
"fmt"
"sync"
"time"

"github.com/hashicorp/go-multierror"
)

// RegistrationPolicy is used to specify what kind of policy should apply when
Expand Down Expand Up @@ -434,7 +432,7 @@ func (b *Broker) RemovePipeline(t EventType, id PipelineID) error {
// neither the pipeline nor nodes will be deleted.
//
// Once we start deleting the pipeline and nodes, we will continue until completion,
// but we'll return true along with any errors encountered (as multierror.Error).
// but we'll return true along with any errors encountered.
func (b *Broker) RemovePipelineAndNodes(ctx context.Context, t EventType, id PipelineID) (bool, error) {
switch {
case t == "":
Expand All @@ -458,16 +456,16 @@ func (b *Broker) RemovePipelineAndNodes(ctx context.Context, t EventType, id Pip

g.roots.Delete(id)

var nodeErr error
var nodeErrs []error

for _, nodeID := range nodes {
err = b.removeNode(ctx, nodeID, true)
if err != nil {
nodeErr = multierror.Append(nodeErr, err)
nodeErrs = append(nodeErrs, err)
}
}

return true, nodeErr
return true, errors.Join(nodeErrs...)
}

// SetSuccessThreshold sets the success threshold per EventType. For the
Expand Down Expand Up @@ -579,26 +577,26 @@ func (b *Broker) IsAnyPipelineRegistered(e EventType) bool {
// validate ensures that the Pipeline has the required configuration to allow
// registration, removal or usage, without issue.
func (p Pipeline) validate() error {
var err error
var errs []error

if p.PipelineID == "" {
err = multierror.Append(err, errors.New("pipeline ID is required"))
errs = append(errs, fmt.Errorf("pipeline ID is required"))
}

if p.EventType == "" {
err = multierror.Append(err, errors.New("event type is required"))
errs = append(errs, fmt.Errorf("event type is required"))
}

if len(p.NodeIDs) == 0 {
err = multierror.Append(err, errors.New("node IDs are required"))
errs = append(errs, fmt.Errorf("node IDs are required"))
}

for _, n := range p.NodeIDs {
if n == "" {
err = multierror.Append(err, errors.New("node ID cannot be empty"))
errs = append(errs, fmt.Errorf("node ID cannot be empty"))
break
}
}

return err
return errors.Join(errs...)
}
17 changes: 10 additions & 7 deletions broker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"time"

"github.com/go-test/deep"
"github.com/hashicorp/go-multierror"
"github.com/hashicorp/go-uuid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -475,9 +474,10 @@ func TestRemovePipelineAndNodes(t *testing.T) {
ok, err = broker.RemovePipelineAndNodes(ctx, EventType("t"), "p2")
require.Error(t, err)
require.True(t, ok)
me, ok := err.(*multierror.Error)
unwrapped, ok := err.(interface{ Unwrap() []error })
require.True(t, ok)
require.Equal(t, 2, me.Len())
errs := unwrapped.Unwrap()
require.Len(t, errs, 2)
}

// TestRemovePipelineAndNodes_BadEventType tests attempting to remove a pipeline
Expand Down Expand Up @@ -561,9 +561,11 @@ func TestRegisterPipeline_BadParameters(t *testing.T) {
})

require.Error(t, err)
me, ok := err.(*multierror.Error)
unwrapped, ok := err.(interface{ Unwrap() []error })
require.True(t, ok)
require.EqualError(t, me.Unwrap(), tc.error)
errs := unwrapped.Unwrap()
require.Len(t, errs, 1)
require.EqualError(t, errs[0], tc.error)
})
}
}
Expand Down Expand Up @@ -692,9 +694,10 @@ func TestPipelineValidate(t *testing.T) {
require.NoError(t, err)
default:
require.Error(t, err)
me, ok := err.(*multierror.Error)
unwrapped, ok := err.(interface{ Unwrap() []error })
require.True(t, ok)
require.Equal(t, tc.expectErrorCount, me.Len())
errs := unwrapped.Unwrap()
require.Len(t, errs, tc.expectErrorCount)
}
})
}
Expand Down
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ go 1.23.0

require (
github.com/go-test/deep v1.1.1
github.com/hashicorp/go-multierror v1.1.1
github.com/hashicorp/go-secure-stdlib/base62 v0.1.2
github.com/hashicorp/go-secure-stdlib/strutil v0.1.2
github.com/hashicorp/go-uuid v1.0.3
Expand All @@ -16,7 +15,6 @@ require (
require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/ryanuber/go-glob v1.0.0 // indirect
golang.org/x/mod v0.24.0 // indirect
Expand Down
5 changes: 0 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ github.com/go-test/deep v1.1.1 h1:0r/53hagsehfO4bzD2Pgr/+RgHqhmf+k1Bpse2cTu1U=
github.com/go-test/deep v1.1.1/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I=
github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
github.com/hashicorp/go-secure-stdlib/base62 v0.1.2 h1:ET4pqyjiGmY09R5y+rSd70J2w45CtbWDNvGqWp/R3Ng=
github.com/hashicorp/go-secure-stdlib/base62 v0.1.2/go.mod h1:EdWO6czbmthiwZ3/PUsDV+UD1D5IRU4ActiaWGwt0Yw=
github.com/hashicorp/go-secure-stdlib/strutil v0.1.2 h1:kes8mmyCpxJsI7FTwtzRqEy9CdjCtrXrXGuOpxEA7Ts=
Expand Down
15 changes: 7 additions & 8 deletions graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ package eventlogger

import (
"context"
"errors"
"fmt"
"sync"

"github.com/hashicorp/go-multierror"
)

// graph
Expand Down Expand Up @@ -129,17 +128,17 @@ func (g *graph) doProcess(ctx context.Context, node *linkedNode, e *Event, statu
}

func (g *graph) reopen(ctx context.Context) error {
var errors *multierror.Error
var errs []error

g.roots.Range(func(_ PipelineID, pipeline *registeredPipeline) bool {
err := g.doReopen(ctx, pipeline.rootNode)
if err != nil {
errors = multierror.Append(errors, err)
errs = append(errs, err)
}
return true
})

return errors.ErrorOrNil()
return errors.Join(errs...)
}

// Recursively reopen every node in the graph.
Expand All @@ -163,17 +162,17 @@ func (g *graph) doReopen(ctx context.Context, node *linkedNode) error {
}

func (g *graph) validate() error {
var errors *multierror.Error
var errs []error

g.roots.Range(func(_ PipelineID, pipeline *registeredPipeline) bool {
err := g.doValidate(nil, pipeline.rootNode)
if err != nil {
errors = multierror.Append(errors, err)
errs = append(errs, err)
}
return true
})

return errors.ErrorOrNil()
return errors.Join(errs...)
}

func (g *graph) doValidate(parent, node *linkedNode) error {
Expand Down