cadence
cadence copied to clipboard
[WIP] Use outbound middleware to set max timeouts on clients.
Why?
We have lots of boilerplate code within our clients and handler, where we decorate the interface with some orthogonal functionality. This results in code explosion as we have to do it for every single API method.
Some of those decorators rely on actual types (or error types) being used. Those could only be simplified with the help of generics.
However others can be expressed as transport level middleware.
This is an example how we could simplify our clients by moving cross cutting concerns to transport layer middleware. If this seems acceptable, we could similarly simplify some other areas as well.
What changed?
-
Removed helpers that set default timeouts on outgoing calls. For admin and frontend client this was the only thing left there, thus removing the implementation all together.
-
Added outbound middleware that sets the context timeout override based on outbound method name.
-
Added mapping between method name and default (max) timeout value. This also revealed some interesting cases where we do not set any default timeouts. Left those as is, as this is purely refactoring. However concise mapping reveals such things at a quick glance.
How did you test it? Added unit tests to check that string based mapping is up to date. If API is changed without updating the map, unit test will fail to remind it.
Potential risks
Release notes
Documentation Changes
Pull Request Test Coverage Report for Build 9918175e-700d-4dfb-8bc9-4633452349e1
- 30 of 38 (78.95%) changed or added relevant lines in 5 files are covered.
- 125 unchanged lines in 15 files lost coverage.
- Overall coverage increased (+0.1%) to 56.995%
Changes Missing Coverage | Covered Lines | Changed/Added Lines | % |
---|---|---|---|
common/rpc/middleware.go | 15 | 16 | 93.75% |
client/history/client.go | 0 | 3 | 0.0% |
client/clientfactory.go | 10 | 14 | 71.43% |
<!-- | Total: | 30 | 38 |
Files with Coverage Reduction | New Missed Lines | % |
---|---|---|
common/task/weightedRoundRobinTaskScheduler.go | 1 | 89.64% |
service/history/execution/mutable_state_task_refresher.go | 1 | 73.82% |
client/clientfactory.go | 2 | 74.24% |
service/history/queue/transfer_queue_processor.go | 2 | 57.24% |
service/matching/matcher.go | 2 | 91.46% |
service/matching/taskListManager.go | 2 | 74.66% |
common/cache/lru.go | 3 | 90.73% |
common/persistence/serialization/parser.go | 4 | 65.41% |
common/persistence/serialization/thrift_decoder.go | 4 | 59.6% |
common/persistence/nosql/nosqlplugin/cassandra/workflow.go | 6 | 55.04% |
<!-- | Total: | 125 |
Totals | |
---|---|
Change from base Build 9013b6a2-f541-4284-9254-cc5d134c52f3: | 0.1% |
Covered Lines: | 82182 |
Relevant Lines: | 144191 |