yes-core 2.6.0 → 2.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/lib/yes/core/authorization/cerbos_grpc_retry_policy.rb +17 -1
- data/lib/yes/core/commands/bus.rb +28 -4
- data/lib/yes/core/commands/processor.rb +13 -5
- data/lib/yes/core/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 533a9586de144c8b2a48bb212fc5bd9aaf601649d17493c9900c61e3ef5a2bba
|
|
4
|
+
data.tar.gz: 5db80562bbbda0ae1b89f316eeff38d775af52d2a069b3eabf859ff096354c65
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 06aeaf2d330a0af42aee1cab4bb66091cd641f64a6ee656458efd5f28a9383ea6f7d4ecea7ff63b5878857c78aa777c5c52bcf4ac2e0275efaa7344a5037dc9d
|
|
7
|
+
data.tar.gz: 3790c827bde9187ff82a7d69d3aa4557f588eb813132f6e942bc912f32b14a4cb08bfc9f29e8783455d709cec06ec1f5843c3504b7cc18ab35f09598e8f305a9
|
data/CHANGELOG.md
CHANGED
|
@@ -11,7 +11,14 @@ module Yes
|
|
|
11
11
|
# caller never sees a `Cerbos::Error::Unavailable` for a blip that a second attempt on a
|
|
12
12
|
# healthy pod would have answered.
|
|
13
13
|
#
|
|
14
|
+
# A refused connection (a pod that stopped listening but is still routed to) also puts the
|
|
15
|
+
# channel into reconnect backoff, during which every call fails immediately. gRPC's default
|
|
16
|
+
# backoff (1s, growing to 120s) outlasts the retry window above, so a single process would
|
|
17
|
+
# keep failing every request for many seconds. The reconnect backoff is therefore capped to
|
|
18
|
+
# the same order of magnitude as the retry backoff.
|
|
19
|
+
#
|
|
14
20
|
# @see https://grpc.io/docs/guides/retry/
|
|
21
|
+
# @see https://github.com/grpc/grpc/blob/master/doc/connection-backoff.md
|
|
15
22
|
module CerbosGrpcRetryPolicy
|
|
16
23
|
SERVICE_NAME = 'cerbos.svc.v1.CerbosService'
|
|
17
24
|
MAX_ATTEMPTS = 4
|
|
@@ -23,12 +30,21 @@ module Yes
|
|
|
23
30
|
ENABLE_RETRIES_ARG = 'grpc.enable_retries'
|
|
24
31
|
SERVICE_CONFIG_ARG = 'grpc.service_config'
|
|
25
32
|
|
|
33
|
+
RECONNECT_BACKOFF_MS = 100
|
|
34
|
+
MAX_RECONNECT_BACKOFF_MS = 1_000
|
|
35
|
+
MIN_RECONNECT_BACKOFF_ARG = 'grpc.min_reconnect_backoff_ms'
|
|
36
|
+
INITIAL_RECONNECT_BACKOFF_ARG = 'grpc.initial_reconnect_backoff_ms'
|
|
37
|
+
MAX_RECONNECT_BACKOFF_ARG = 'grpc.max_reconnect_backoff_ms'
|
|
38
|
+
|
|
26
39
|
class << self
|
|
27
40
|
# @return [Hash{String => Integer, String}] channel arguments for `Cerbos::Client.new`
|
|
28
41
|
def channel_args
|
|
29
42
|
{
|
|
30
43
|
ENABLE_RETRIES_ARG => 1,
|
|
31
|
-
SERVICE_CONFIG_ARG => service_config.to_json
|
|
44
|
+
SERVICE_CONFIG_ARG => service_config.to_json,
|
|
45
|
+
MIN_RECONNECT_BACKOFF_ARG => RECONNECT_BACKOFF_MS,
|
|
46
|
+
INITIAL_RECONNECT_BACKOFF_ARG => RECONNECT_BACKOFF_MS,
|
|
47
|
+
MAX_RECONNECT_BACKOFF_ARG => MAX_RECONNECT_BACKOFF_MS
|
|
32
48
|
}
|
|
33
49
|
end
|
|
34
50
|
|
|
@@ -23,23 +23,47 @@ module Yes
|
|
|
23
23
|
# @param origin [String] Origin of the command
|
|
24
24
|
# @param notifier_options [Hash] Options for command notifier
|
|
25
25
|
# @param batch_id [String] Batch ID
|
|
26
|
+
# @param extra_notifier_classes [Array<Class>] Notifier classes to run for this call only, in addition
|
|
27
|
+
# to the configured +command_notifier_classes+. They also run when commands are processed inline.
|
|
26
28
|
# @return [void]
|
|
29
|
+
# @raise [ArgumentError] if an extra notifier class is anonymous or cannot be found again by its name
|
|
27
30
|
def call(
|
|
28
31
|
command_or_commands,
|
|
29
32
|
origin: nil,
|
|
30
33
|
notifier_options: {},
|
|
31
|
-
batch_id: nil
|
|
34
|
+
batch_id: nil,
|
|
35
|
+
extra_notifier_classes: []
|
|
32
36
|
)
|
|
37
|
+
ensure_notifier_classes_resolvable!(extra_notifier_classes)
|
|
38
|
+
|
|
33
39
|
origin ||= Utils::CallerUtils.origin_from_caller(caller_locations(1..1).first)
|
|
34
40
|
|
|
35
41
|
perform_method = perform_inline ? :perform_now : :perform_later
|
|
36
42
|
self.class.current_span&.add_attributes({ perform_method: perform_method.to_s, origin: }.stringify_keys)
|
|
37
43
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
44
|
+
# The extra argument is only passed when needed: during a rolling deploy an older worker runs jobs
|
|
45
|
+
# enqueued by this code, and a custom processor may still have the 5-argument signature.
|
|
46
|
+
# Only class names are passed, as the processor is an ActiveJob and its arguments must serialize.
|
|
47
|
+
processor_args = [origin, command_or_commands, notifier_options, batch_id, perform_inline]
|
|
48
|
+
processor_args << extra_notifier_classes.map(&:name) if extra_notifier_classes.any?
|
|
49
|
+
|
|
50
|
+
command_processor.public_send(perform_method, *processor_args)
|
|
41
51
|
end
|
|
42
52
|
otl_trackable :call, Yes::Core::OpenTelemetry::OtlSpan::OtlData.new(span_name: 'Command Bus Schedule')
|
|
53
|
+
|
|
54
|
+
private
|
|
55
|
+
|
|
56
|
+
# The processor finds the classes again by name, so fail here instead of inside the enqueued job.
|
|
57
|
+
# @param notifier_classes [Array<Class>] the per-call notifier classes
|
|
58
|
+
# @return [void]
|
|
59
|
+
# @raise [ArgumentError] if a class is anonymous or its name does not resolve to the same class
|
|
60
|
+
def ensure_notifier_classes_resolvable!(notifier_classes)
|
|
61
|
+
notifier_classes.each do |notifier_class|
|
|
62
|
+
next if notifier_class.name&.safe_constantize == notifier_class
|
|
63
|
+
|
|
64
|
+
raise ArgumentError, "extra_notifier_classes must be named, constantizable classes: #{notifier_class.inspect}"
|
|
65
|
+
end
|
|
66
|
+
end
|
|
43
67
|
end
|
|
44
68
|
end
|
|
45
69
|
end
|
|
@@ -22,10 +22,16 @@ module Yes
|
|
|
22
22
|
# @param command_or_commands [Command, Array<Command>] the command or commands to process
|
|
23
23
|
# @param notifier_options [Hash] options to pass to the command notifier
|
|
24
24
|
# @param custom_batch_id [String] Custom batch ID
|
|
25
|
+
# @param inline [Boolean] whether the commands are processed inline, which skips the configured notifiers
|
|
26
|
+
# @param extra_notifier_classes [Array<String>] names of notifier classes to run for this call only, in
|
|
27
|
+
# addition to the configured ones; they run also when inline
|
|
25
28
|
# @return [Array<Response>] the responses from the performed commands
|
|
26
29
|
# @raise [UnregisteredCommand] if any command lacks a handler
|
|
27
|
-
def perform(
|
|
28
|
-
|
|
30
|
+
def perform(
|
|
31
|
+
origin, command_or_commands, notifier_options, custom_batch_id = nil, inline = false,
|
|
32
|
+
extra_notifier_classes = []
|
|
33
|
+
)
|
|
34
|
+
setup(notifier_options, custom_batch_id, inline, extra_notifier_classes)
|
|
29
35
|
singleton_class.current_span&.add_event('Command Processor Setup Done')
|
|
30
36
|
|
|
31
37
|
commands = [*command_or_commands]
|
|
@@ -53,17 +59,19 @@ module Yes
|
|
|
53
59
|
|
|
54
60
|
private
|
|
55
61
|
|
|
56
|
-
# Instantiates the command
|
|
57
|
-
# @param notifier_options [Hash] the options to pass to the command
|
|
62
|
+
# Instantiates the command notifiers from the config and the per-call extra ones, using the given options.
|
|
63
|
+
# @param notifier_options [Hash] the options to pass to the command notifiers
|
|
58
64
|
# @param custom_batch_id [String] Custom batch ID
|
|
59
65
|
# @param inline [Boolean] whether to process the commands inline
|
|
66
|
+
# @param extra_notifier_classes [Array<String>] names of the per-call notifier classes
|
|
60
67
|
# @return [void]
|
|
61
|
-
def setup(notifier_options, custom_batch_id, inline = false)
|
|
68
|
+
def setup(notifier_options, custom_batch_id, inline = false, extra_notifier_classes = [])
|
|
62
69
|
@command_notifiers = [] if inline
|
|
63
70
|
|
|
64
71
|
@command_notifiers ||= Yes::Core.configuration.command_notifier_classes&.map do |notifier_class|
|
|
65
72
|
notifier_class.new(notifier_options)
|
|
66
73
|
end || []
|
|
74
|
+
@command_notifiers += extra_notifier_classes.map { _1.constantize.new(notifier_options) }
|
|
67
75
|
@custom_batch_id = custom_batch_id
|
|
68
76
|
end
|
|
69
77
|
|
data/lib/yes/core/version.rb
CHANGED