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

Cappl 588/rate limit per workflow #16672

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from

Conversation

MStreet3
Copy link
Contributor

@MStreet3 MStreet3 commented Mar 4, 2025

Requires

Supports

Copy link
Contributor

github-actions bot commented Mar 4, 2025

AER Report: CI Core

aer_workflow , commit , Clean Go Tidy & Generate , Detect Changes , Scheduled Run Frequency , Core Tests (go_core_tests) , Core Tests (go_core_tests_integration) , Core Tests (go_core_fuzz) , Core Tests (go_core_race_tests) , Core Tests (go_core_ccip_deployment_tests) , GolangCI Lint (.) , test-scripts , lint , SonarQube Scan

1. GolangCI Lint errors:[lint]

Source of Error:
Golang Lint (.)	2025-03-08T05:13:38.1275296Z ##[error]core/services/gateway/api/message.go:24:2: var-naming: don't use underscores in Go names; const Method_InternalError should be MethodInternalError (revive)
Golang Lint (.)	2025-03-08T05:13:38.1276661Z 	Method_InternalError = "internal_error"
Golang Lint (.)	2025-03-08T05:13:38.1277090Z 	^
Golang Lint (.)	2025-03-08T05:13:38.1279879Z ##[error]core/capabilities/webapi/outgoing_connector_handler.go:23:2: var-naming: don't use underscores in Go names; const error_outgoing_ratelimit_global should be errorOutgoingRatelimitGlobal (revive)
Golang Lint (.)	2025-03-08T05:13:38.1281364Z 	error_outgoing_ratelimit_global = "global limit of gateways requests has been exceeded"
Golang Lint (.)	2025-03-08T05:13:38.1281964Z 	^
Golang Lint (.)	2025-03-08T05:13:38.1283778Z ##[error]core/capabilities/webapi/outgoing_connector_handler.go:24:2: var-naming: don't use underscores in Go names; const error_outgoing_ratelimit_workflow should be errorOutgoingRatelimitWorkflow (revive)
Golang Lint (.)	2025-03-08T05:13:38.1285265Z 	error_outgoing_ratelimit_workflow = "workflow exceeded limit of gateways requests"
Golang Lint (.)	2025-03-08T05:13:38.1285849Z 	^
Golang Lint (.)	2025-03-08T05:13:38.1287765Z ##[error]core/capabilities/webapi/outgoing_connector_handler.go:25:2: var-naming: don't use underscores in Go names; const error_incoming_ratelimit_global should be errorIncomingRatelimitGlobal (revive)
Golang Lint (.)	2025-03-08T05:13:38.1289200Z 	error_incoming_ratelimit_global = "message from gateway exceeded global rate limit"
Golang Lint (.)	2025-03-08T05:13:38.1289785Z 	^
Golang Lint (.)	2025-03-08T05:13:38.1291545Z ##[error]core/capabilities/webapi/outgoing_connector_handler.go:26:2: var-naming: don't use underscores in Go names; const error_incoming_ratelimit_sender should be errorIncomingRatelimitSender (revive)
Golang Lint (.)	2025-03-08T05:13:38.1292980Z 	error_incoming_ratelimit_sender = "message from gateway exceeded per sender rate limit"
Golang Lint (.)	2025-03-08T05:13:38.1293576Z 	^
Golang Lint (.)	2025-03-08T05:13:38.1294585Z ##[error]core/capabilities/webapi/outgoing_connector_handler.go:162:2: var-naming: var errJson should be errJSON (revive)
Golang Lint (.)	2025-03-08T05:13:38.1295899Z 	errJson := api.JsonRPCError{
Golang Lint (.)	2025-03-08T05:13:38.1296247Z 	^
Golang Lint (.)	2025-03-08T05:13:38.1298413Z ##[error]core/capabilities/webapi/outgoing_connector_handler.go:170:3: assignOp: replace `errJson.Message = errJson.Message + error_incoming_ratelimit_global` with `errJson.Message += error_incoming_ratelimit_global` (gocritic)
Golang Lint (.)	2025-03-08T05:13:38.1299915Z 		errJson.Message = errJson.Message + error_incoming_ratelimit_global
Golang Lint (.)	2025-03-08T05:13:38.1300432Z 		^
Golang Lint (.)	2025-03-08T05:13:38.1301679Z ##[error]core/capabilities/webapi/outgoing_connector_handler.go:134:25: unmarshal: call of Unmarshal passes non-pointer as second argument (govet)
Golang Lint (.)	2025-03-08T05:13:38.1303044Z 			err := json.Unmarshal(resp.Body.Payload, errPayload)
Golang Lint (.)	2025-03-08T05:13:38.1303608Z 			 ^

Why: The errors are caused by violations of Go naming conventions and improper usage of Go syntax. Specifically, the use of underscores in variable names, improper variable naming, and incorrect usage of the json.Unmarshal function.

Suggested fix: Rename the variables to follow Go naming conventions (e.g., MethodInternalError, errorOutgoingRatelimitGlobal). Correct the assignment operation and ensure the second argument of json.Unmarshal is a pointer.

AER Report: Operator UI CI ran successfully ✅

aer_workflow , commit

@MStreet3 MStreet3 force-pushed the cappl-588/rate-limit-per-workflow-id branch from ad6dcae to 059bb26 Compare March 5, 2025 00:11
Copy link
Contributor

github-actions bot commented Mar 7, 2025

Flakeguard Summary

Ran new or updated tests between develop and 6a81de5 (cappl-588/rate-limit-per-workflow-id).

View Flaky Detector Details | Compare Changes

Found Flaky Tests ❌

1 Results
Name Pass Ratio Panicked? Timed Out? Race? Runs Successes Failures Skips Package Package Panicked? Avg Duration Code Owners
TestHandleSingleNodeRequest/rate_limits_outgoing_traffic_by_workflow 0% false false false 3 0 3 0 github.com/smartcontractkit/chainlink/v2/core/capabilities/webapi false 0s @smartcontractkit/keystone, @smartcontractkit/capabilities-team

Artifacts

For detailed logs of the failed tests, please refer to the artifact failed-test-results-with-logs.json.

@justinkaseman justinkaseman force-pushed the cappl-588/rate-limit-per-workflow-id branch from ce9c1de to 9925ad8 Compare March 7, 2025 19:02
@@ -836,7 +836,7 @@ func (e *Engine) workerForStepRequest(ctx context.Context, msg stepRequest) {

var stepStatus string
switch {
case errors.Is(capabilities.ErrStopExecution, err):
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you say more about why this change was necessary?

Copy link
Contributor

@justinkaseman justinkaseman Mar 7, 2025

Choose a reason for hiding this comment

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

Tagging @MStreet3 , because he made the original change, I just fixed it to work from what he had.

I'm guessing that he noticed that the usage was wrong, which flipped it from

// Not intended usage, see errors.Is doc
	case errors.Is(capabilities.ErrStopExecution, err):
// Intended usage
	case errors.Is(err, capabilities.ErrStopExecution):

Moving it to case errors.Is(err, capabilities.ErrStopExecution): caused tests to fail, so I changed it to what it is now.

@justinkaseman justinkaseman marked this pull request as ready for review March 7, 2025 20:48
@justinkaseman justinkaseman requested review from a team as code owners March 7, 2025 20:48
if !c.rateLimiter.Allow(body.Sender) {
// error is logged here instead of warning because if a message from gateway is rate-limited,
// the workflow will eventually fail with timeout as there are no retries in place yet
c.lggr.Errorw("request rate-limited")
l.Errorw("request rate-limited")
return
Copy link
Contributor

Choose a reason for hiding this comment

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

Technically out of scope, but could we return an error here back to the caller? I think this results in nicer UX by telling users they were rate limited rather than returning a timeout.

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed. Changing.

Copy link
Contributor

Choose a reason for hiding this comment

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

@cl-sonarqube-production
Copy link

Quality Gate failed Quality Gate failed

Failed conditions
C Reliability Rating on New Code (required ≥ A)
8 New Major Issues (required ≤ 5)

See analysis details on SonarQube

Catch issues before they fail your Quality Gate with our IDE extension SonarQube IDE SonarQube IDE

@@ -36,7 +37,13 @@ const (

var defaultConfig = Config{
ServiceConfig: webapi.ServiceConfig{
RateLimiter: common.RateLimiterConfig{
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a breaking API change I think 🤔 ?

PerWorkflowRPS: 100.0,
PerWorkflowBurst: 100,
},
IncomingRateLimiter: gwcommon.RateLimiterConfig{
Copy link
Contributor

Choose a reason for hiding this comment

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

IMO not worth having an extra struct + a duplicated implementation -- can we somehow either reuse gwcommon.RateLimiterConfig but with a different struct and constructor for config?

eg.

type OutgoingRateLimiter struct {
    ...
    PerWorkflowRPS
    PerWorkflowBurst
}

func NewOutgoingRateLimiter(rl ...) gwcommon.RateLimiter {
    return gwcommon.RateLimiter{
        ... convert between the two types
    }
}

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

Successfully merging this pull request may close these issues.

3 participants