Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Wire up dynamic config-backed history DLQ
- Loading branch information
1 parent
ea5d1b5
commit c8ccf1e
Showing
6 changed files
with
236 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// The MIT License | ||
// | ||
// Copyright (c) 2020 Temporal Technologies Inc. All rights reserved. | ||
// | ||
// Copyright (c) 2020 Uber Technologies, Inc. | ||
// | ||
// 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. | ||
|
||
package history | ||
|
||
import ( | ||
"go.temporal.io/server/common/clock" | ||
"go.temporal.io/server/service/history/configs" | ||
"go.uber.org/fx" | ||
|
||
"go.temporal.io/server/common/cluster" | ||
"go.temporal.io/server/common/dynamicconfig" | ||
"go.temporal.io/server/common/persistence" | ||
"go.temporal.io/server/service/history/queues" | ||
) | ||
|
||
type ( | ||
executableDLQWrapper struct { | ||
historyTaskQueueManager persistence.HistoryTaskQueueManager | ||
clusterName string | ||
timeSource clock.TimeSource | ||
useDLQ dynamicconfig.BoolPropertyFn | ||
} | ||
executableDLQWrapperParams struct { | ||
fx.In | ||
|
||
HistoryTaskQueueManager persistence.HistoryTaskQueueManager | ||
ClusterMetadata cluster.Metadata | ||
Config *configs.Config | ||
TimeSource clock.TimeSource | ||
} | ||
dlqToggle struct { | ||
queues.Executable | ||
executableDLQ *queues.ExecutableDLQ | ||
useDLQ dynamicconfig.BoolPropertyFn | ||
} | ||
) | ||
|
||
func NewExecutableDLQWrapper(params executableDLQWrapperParams) queues.ExecutableWrapper { | ||
return executableDLQWrapper{ | ||
historyTaskQueueManager: params.HistoryTaskQueueManager, | ||
clusterName: params.ClusterMetadata.GetCurrentClusterName(), | ||
timeSource: params.TimeSource, | ||
useDLQ: params.Config.TaskDLQEnabled, | ||
} | ||
} | ||
|
||
func (d executableDLQWrapper) Wrap(e queues.Executable) queues.Executable { | ||
executableDLQ := queues.NewExecutableDLQ( | ||
e, | ||
d.historyTaskQueueManager, | ||
d.timeSource, | ||
d.clusterName, | ||
) | ||
return &dlqToggle{ | ||
Executable: e, | ||
executableDLQ: executableDLQ, | ||
useDLQ: d.useDLQ, | ||
} | ||
} | ||
|
||
func (t *dlqToggle) Execute() error { | ||
if t.useDLQ() { | ||
return t.executableDLQ.Execute() | ||
} | ||
return t.Executable.Execute() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
// The MIT License | ||
// | ||
// Copyright (c) 2020 Temporal Technologies Inc. All rights reserved. | ||
// | ||
// Copyright (c) 2020 Uber Technologies, Inc. | ||
// | ||
// 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. | ||
|
||
package history_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"go.temporal.io/server/common/clock" | ||
"go.temporal.io/server/service/history/configs" | ||
"go.uber.org/fx" | ||
"go.uber.org/fx/fxtest" | ||
|
||
"go.temporal.io/server/common/cluster" | ||
"go.temporal.io/server/common/dynamicconfig" | ||
"go.temporal.io/server/common/log" | ||
"go.temporal.io/server/common/persistence" | ||
"go.temporal.io/server/common/persistence/serialization" | ||
"go.temporal.io/server/service/history" | ||
"go.temporal.io/server/service/history/queues" | ||
"go.temporal.io/server/service/history/queues/queuestest" | ||
) | ||
|
||
type ( | ||
testHistoryTaskQueueManager struct { | ||
persistence.HistoryTaskQueueManager | ||
requests []*persistence.EnqueueTaskRequest | ||
} | ||
fakeMetadata struct { | ||
cluster.Metadata | ||
} | ||
) | ||
|
||
var errTerminal = new(serialization.DeserializationError) | ||
|
||
func TestNewExecutableDLQWrapper(t *testing.T) { | ||
t.Parallel() | ||
|
||
for _, tc := range []struct { | ||
name string | ||
enableDLQ bool | ||
}{ | ||
{ | ||
name: "DLQ enabled", | ||
enableDLQ: true, | ||
}, | ||
{ | ||
name: "DLQ disabled", | ||
enableDLQ: false, | ||
}, | ||
} { | ||
tc := tc | ||
t.Run(tc.name, func(t *testing.T) { | ||
t.Parallel() | ||
|
||
tqm := &testHistoryTaskQueueManager{} | ||
var w queues.ExecutableWrapper | ||
fxtest.New( | ||
t, | ||
fx.Provide( | ||
func() persistence.HistoryTaskQueueManager { | ||
return tqm | ||
}, | ||
func() cluster.Metadata { | ||
return fakeMetadata{} | ||
}, | ||
func() *configs.Config { | ||
dc := dynamicconfig.NewCollection(dynamicconfig.StaticClient(map[dynamicconfig.Key]interface{}{ | ||
dynamicconfig.HistoryTaskDLQEnabled: tc.enableDLQ, | ||
}), log.NewTestLogger()) | ||
return configs.NewConfig(dc, 1, false, false) | ||
}, | ||
func() clock.TimeSource { | ||
return clock.NewEventTimeSource() | ||
}, | ||
fx.Annotate(history.NewExecutableDLQWrapper, fx.As(new(queues.ExecutableWrapper))), | ||
), | ||
fx.Populate(&w), | ||
) | ||
executable := w.Wrap(queuestest.NewFakeExecutable(nil, errTerminal)) | ||
|
||
err := executable.Execute() | ||
if tc.enableDLQ { | ||
assert.ErrorIs(t, err, queues.ErrTerminalTaskFailure) | ||
} else { | ||
assert.NotErrorIs(t, err, queues.ErrTerminalTaskFailure) | ||
assert.ErrorIs(t, err, errTerminal) | ||
} | ||
err = executable.Execute() | ||
if tc.enableDLQ { | ||
assert.NoError(t, err) | ||
assert.Len(t, tqm.requests, 1) | ||
} else { | ||
assert.ErrorIs(t, err, errTerminal) | ||
assert.Empty(t, tqm.requests) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func (f fakeMetadata) GetCurrentClusterName() string { | ||
return "test-cluster-name" | ||
} | ||
|
||
func (t *testHistoryTaskQueueManager) EnqueueTask( | ||
_ context.Context, | ||
request *persistence.EnqueueTaskRequest, | ||
) (*persistence.EnqueueTaskResponse, error) { | ||
t.requests = append(t.requests, request) | ||
return nil, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters