feat(observability): implement injectable Token-API decorators and circuit breaker (#1644) - #2157
Open
SurbhiAgarwal1 wants to merge 3 commits into
Open
Conversation
Signed-off-by: Surbhi Agarwal <SurbhiAgarwal1@users.noreply.github.com>
…rcuit breaker Implement a clean, injectable decorator architecture for Token-API entry points (WalletService, OwnerWallet, IssuerWallet) using gowrap templates. Includes metrics collection (counter, gauge, histogram) and circuit breaker protection with back-pressure signal (ErrCircuitOpen). Signed-off-by: Surbhi Agarwal <SurbhiAgarwal1@users.noreply.github.com>
Fix nlreturn blank line formatting in decorator.go and update error assertions to require in observability_test.go per testifylint rules. Signed-off-by: Surbhi Agarwal <SurbhiAgarwal1@users.noreply.github.com>
Contributor
|
Thanks a lot for submitting this PR! Regards, |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1644
Summary
This PR implements a clean, injectable decorator architecture for Token-API entry points (
driver.WalletService,driver.OwnerWallet,driver.IssuerWallet) incorporating Prometheus-compatible metrics and circuit breaker back-pressure protection, following @adecaro's recommendation to usegowrapgenerator templates.Proposed Changes
1. Circuit Breaker (
token/services/observability/circuitbreaker.go)StateClosed,StateOpen,StateHalfOpen).ErrCircuitOpenwhen open to limit blast radius during DoS attacks.2. Metrics Instrumentation (
token/services/observability/metrics.go)metrics.Provider.requests_total(Counter),errors_total(Counter),request_duration_seconds(Histogram), andinflight_requests(Gauge).3. Injectable Decorators (
token/services/observability/decorator.go)NewWalletServiceDecorator,NewOwnerWalletDecorator,NewIssuerWalletDecoratorwrap services non-intrusively without modifying underlying concrete driver logic.4. GoWrap Template (
token/services/observability/templates/gowrap_prometheus_cb.tmpl)gowrap.5. Unit Tests & Race Detection (
token/services/observability/observability_test.go)go test -race).Verification & Compliance
go test -v ./token/services/observability/...go test -v -race ./token/services/observability/...gofmt -l -s ./token/services/observabilitygithub.com/hyperledger-labs/fabric-smart-client/pkg/utils/errors.Signed-off-by: Surbhi Agarwal <SurbhiAgarwal1@users.noreply.github.com>).