Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include endpointUrl in RpcService event listener data #5225

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mcmire
Copy link
Contributor

@mcmire mcmire commented Jan 30, 2025

Explanation

Modify RpcService so that when it emits the onRetry, onBreak, or onDegraded event, it passes the URL of the endpoint it is requesting to the respective event listener.

This will be useful when we add the ability to create a chain of RPC service objects, where we start out hitting a primary node and then keep failing over to successive nodes in the chain until the request succeeds. By including the endpoint URL in the event listener data, we are able to identify which RPC service was active when the event occurred.

References

Progresses #5222.

Changelog

(Updated in PR.)

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've highlighted breaking changes using the "BREAKING" category above as appropriate
  • I've prepared draft pull requests for clients and consumer packages to resolve any breaking changes

@mcmire mcmire force-pushed the add-endpoint-url-to-rpc-service-callbacks branch 2 times, most recently from 0fb406d to 3ef16d9 Compare January 30, 2025 23:04
Modify RpcService so that when it emits the `onRetry`, `onBreak`, or
`onDegraded` event, it passes the URL of the endpoint it is requesting
to the respective event listener.

This will be useful when we add the ability to create a chain of RPC
service objects, where we start out hitting a primary node and then keep
failing over to successive nodes in the chain until the request
succeeds. By including the endpoint URL in the event listener data, we
are able to identify which RPC service was active when the event
occurred.
@mcmire mcmire force-pushed the add-endpoint-url-to-rpc-service-callbacks branch from 3ef16d9 to c9c747f Compare January 30, 2025 23:19
@@ -18,7 +18,7 @@ module.exports = merge(baseConfig, {
coverageThreshold: {
global: {
branches: 78.12,
functions: 80.7,
functions: 80.35,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've checked the coverage report and all of the lines I added are tested.

@mcmire mcmire marked this pull request as ready for review January 30, 2025 23:25
@mcmire mcmire requested review from a team as code owners January 30, 2025 23:25
@@ -203,27 +207,21 @@ export function createServicePolicy({
});
const onBreak = circuitBreakerPolicy.onBreak.bind(circuitBreakerPolicy);

const onDegradedListeners: (() => void)[] = [];
const onDegradedEventEmitter = new CockatielEventEmitter<void>();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we are reusing the Cockatiel built-in EventEmitter class instead of implementing the EventEmitter pattern ourselves. We do this because we want the signature of the onDegraded method to match the signatures for onRetry and onBreak (onDegraded is a custom hook we add, whereas onRetry and onBreak essentially come directly from Cockatiel).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant