Commit 717ef06
committed
refactor(plugin): make the factory an object with create_plugin
A reviewer asked for the registration type to be an object with a method
rather than a bare callable, and the reason is future extensibility
rather than taste. A callable type alias has no member to add anything
to. So adding a process-level hook later -- a flush when the execution
environment shuts down, for example -- would have to change the
registration type from callable to object, which is a second breaking
change on the same public surface. An object with one method can gain an
optional second member additively, so doing this now costs one break
instead of two.
`DurableInstrumentationPluginFactory` is therefore a Protocol declaring
`create_plugin(info)`, not `Callable[[InvocationStartInfo], ...]`. The
type's name and the returned type's name are both unchanged, so no
identifier changes meaning. The method is `create_plugin` rather than
`new_invocation` because what it returns is still called a plugin, so
the verb and the noun agree. This is the shape the Java SDK already had,
as `DurableExecutionPluginFactory.createPlugin(InvocationInfo)`, so the
three SDKs now describe one contract.
The protocol is deliberately not `@runtime_checkable`, for three
reasons. An `isinstance` check against a runtime-checkable protocol
tests only that the member name exists, so it accepts an object whose
`create_plugin` is a string. The SDK also has to name what an invalid
entry actually was, which a boolean cannot supply. And such a check
requires every declared member, which would make the optional second
member above non-additive for any caller who wrote one.
`_is_plugin_factory` tests for a callable `create_plugin` instead,
structurally, so a factory need not import the protocol.
`info` is positional-only on the protocol method. A protocol parameter
that is positional-or-keyword is part of the structural contract, so a
factory naming it `invocation` would otherwise be a type error.
One consequence reverses guidance added earlier in this branch. A plugin
class used to be a valid factory, because calling a class constructs an
instance, and the docs said so. A class carries no `create_plugin`, so
`plugins=[MyPlugin]` now fails at handler initialization, and the test
that pinned the old behaviour is replaced by one pinning the new. A
class that declares `create_plugin` itself, as a classmethod, is still
valid, because the requirement is the member and not the kind of object.
The reversal is an improvement for a reason the earlier round raised
separately: `CONTRIBUTING.md:246` asks for light constructors, and
class-as-factory encouraged `__init__(self, info)` to do setup work. A
factory object puts that work in the factory's own constructor, where it
can fail before any invocation depends on it.
Migrated with it: both bundled plugins' factory classes, whose
`__call__` becomes `create_plugin`; 23 conformance plugin handlers, each
gaining a small factory class beside its plugin; two examples; one
testing-package e2e test that previously aborted collection of that
whole suite; and the prose in four READMEs.
No handler's observable behaviour changed, and that was measured rather
than assumed. The pre-migration handlers were extracted against the pre-
migration SDK, every handler was driven through the local runner in both
trees, and the emitted records were compared after dropping the
execution ARN and wall-clock fields: 23 handlers, 89 records, 23
identical streams, 0 differing. Registration order is preserved in both
handlers that register two plugins.1 parent f8b4f31 commit 717ef06
46 files changed
Lines changed: 985 additions & 301 deletions
File tree
- packages
- aws-durable-execution-sdk-python-conformance-tests-otel
- src
- aws-durable-execution-sdk-python-conformance-tests/handlers/plugin
- aws-durable-execution-sdk-python-examples/src/plugin
- aws-durable-execution-sdk-python-insight
- src/aws_durable_execution_sdk_python_insight
- tests
- aws-durable-execution-sdk-python-otel
- src/aws_durable_execution_sdk_python_otel
- tests
- e2e
- aws-durable-execution-sdk-python-testing/tests/e2e
- aws-durable-execution-sdk-python
- src/aws_durable_execution_sdk_python
- tests
- e2e
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
182 | 182 | | |
183 | 183 | | |
184 | 184 | | |
185 | | - | |
186 | | - | |
| 185 | + | |
| 186 | + | |
187 | 187 | | |
188 | 188 | | |
189 | 189 | | |
| |||
Lines changed: 3 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
27 | | - | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
28 | 29 | | |
29 | 30 | | |
30 | 31 | | |
| |||
Lines changed: 16 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
82 | 97 | | |
83 | 98 | | |
84 | 99 | | |
| |||
89 | 104 | | |
90 | 105 | | |
91 | 106 | | |
92 | | - | |
| 107 | + | |
93 | 108 | | |
94 | 109 | | |
95 | 110 | | |
| |||
Lines changed: 16 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
82 | 97 | | |
83 | 98 | | |
84 | 99 | | |
85 | 100 | | |
86 | 101 | | |
87 | 102 | | |
88 | 103 | | |
89 | | - | |
| 104 | + | |
90 | 105 | | |
91 | 106 | | |
92 | 107 | | |
| |||
Lines changed: 16 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
82 | 97 | | |
83 | 98 | | |
84 | 99 | | |
| |||
94 | 109 | | |
95 | 110 | | |
96 | 111 | | |
97 | | - | |
| 112 | + | |
98 | 113 | | |
99 | 114 | | |
100 | 115 | | |
| |||
Lines changed: 16 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
82 | 82 | | |
83 | 83 | | |
84 | 84 | | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
85 | 100 | | |
86 | 101 | | |
87 | 102 | | |
88 | 103 | | |
89 | 104 | | |
90 | | - | |
| 105 | + | |
91 | 106 | | |
92 | 107 | | |
93 | 108 | | |
Lines changed: 16 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
68 | | - | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
69 | 84 | | |
70 | 85 | | |
71 | 86 | | |
Lines changed: 36 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
4 | | - | |
5 | | - | |
6 | | - | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
| |||
103 | 104 | | |
104 | 105 | | |
105 | 106 | | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
106 | 122 | | |
107 | 123 | | |
108 | 124 | | |
| |||
182 | 198 | | |
183 | 199 | | |
184 | 200 | | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
185 | 216 | | |
186 | 217 | | |
187 | 218 | | |
188 | 219 | | |
189 | 220 | | |
190 | | - | |
191 | | - | |
192 | | - | |
| 221 | + | |
193 | 222 | | |
194 | 223 | | |
195 | 224 | | |
Lines changed: 16 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
50 | | - | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
51 | 66 | | |
52 | 67 | | |
53 | 68 | | |
Lines changed: 16 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
61 | | - | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
62 | 77 | | |
63 | 78 | | |
64 | 79 | | |
0 commit comments