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

Auto 4601/add log retry integration test #10355

Merged
merged 9 commits into from
Sep 13, 2023

Conversation

EasterTheBunny
Copy link
Contributor

This PR offers a proposal for completing an integration test that runs log
trigger upkeeps, a full check pipeline, fails mercury server calls, and allows
the application to retry the upkeeps.

Additions include:

  • mock mercury server that can have a custom handler per test
  • upkeep setup helpers for creating/registering log triggered upkeeps
  • integration test for log event retry flow

@github-actions
Copy link
Contributor

I see that you haven't updated any CHANGELOG files. Would it make sense to do so?

@github-actions
Copy link
Contributor

I see that you haven't updated any README files. Would it make sense to do so?

@EasterTheBunny EasterTheBunny force-pushed the AUTO-4601/add-log-retry-integration-test branch from 91cbaaa to 96390f0 Compare August 25, 2023 15:57
@@ -66,6 +66,17 @@ func (p *abiPacker) UnpackCheckResult(payload ocr2keepers.UpkeepPayload, raw str
return result, nil
}

func (p *abiPacker) UnpackGetUpkeepPrivilegeConfig(resp []byte) ([]byte, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

add test

@@ -217,10 +217,37 @@ func (r *EvmRegistry) allowedToUseMercury(opts *bind.CallOpts, upkeepId *big.Int
return encoding.NoPipelineError, encoding.UpkeepFailureReasonNone, false, allowed.(bool), nil
}

cfg, err := r.registry.GetUpkeepPrivilegeConfig(opts, upkeepId)
payload, err := r.abi.Pack("getUpkeepPrivilegeConfig", upkeepId)
Copy link
Collaborator

Choose a reason for hiding this comment

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

extract to packer.PackGetUpkeepPrivilegeConfig

@EasterTheBunny EasterTheBunny force-pushed the AUTO-4601/add-log-retry-integration-test branch from 9261892 to 8f0d764 Compare August 30, 2023 15:21
// pack error, no retryable
r.lggr.Warnf("failed to pack getUpkeepPrivilegeConfig data for upkeepId %s: %s", upkeepId, err)

return encoding.RpcFlakyFailure, encoding.UpkeepFailureReasonNone, true, false, fmt.Errorf("failed to pack upkeepId: %w", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

will need to fix this error instead of RpcFlakyFailure

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 can create a new error type that makes more sense in this case.

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.

agree that this should be PackUnpackDecodeFailed

Copy link
Contributor

Choose a reason for hiding this comment

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

and this should be not retryable

return encoding.RpcFlakyFailure, encoding.UpkeepFailureReasonNone, true, false, fmt.Errorf("failed to get upkeep privilege config: %v", err)
}

cfg, err := r.packer.UnpackGetUpkeepPrivilegeConfig(b)
if err != nil {
return encoding.RpcFlakyFailure, encoding.UpkeepFailureReasonNone, true, false, fmt.Errorf("failed to get upkeep privilege config: %v", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

same here

@@ -217,21 +217,43 @@ func (r *EvmRegistry) allowedToUseMercury(opts *bind.CallOpts, upkeepId *big.Int
return encoding.NoPipelineError, encoding.UpkeepFailureReasonNone, false, allowed.(bool), nil
}

cfg, err := r.registry.GetUpkeepPrivilegeConfig(opts, upkeepId)
payload, err := r.packer.PackGetUpkeepPrivilegeConfig(upkeepId)
Copy link
Contributor

Choose a reason for hiding this comment

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

let's ensure we get Felix's review on this file if we go ahead with this approach

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'll ping him on it

return encoding.RpcFlakyFailure, encoding.UpkeepFailureReasonNone, true, false, fmt.Errorf("failed to get upkeep privilege config: %v", err)
}

cfg, err := r.packer.UnpackGetUpkeepPrivilegeConfig(b)
if err != nil {
return encoding.RpcFlakyFailure, encoding.UpkeepFailureReasonNone, true, false, fmt.Errorf("failed to get upkeep privilege config: %v", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

unpack error should be not retryable

@EasterTheBunny EasterTheBunny force-pushed the AUTO-4601/add-log-retry-integration-test branch from 255f4b2 to 9b02e7d Compare September 7, 2023 18:13
@github-actions
Copy link
Contributor

github-actions bot commented Sep 7, 2023

@EasterTheBunny EasterTheBunny force-pushed the AUTO-4601/add-log-retry-integration-test branch from 9b02e7d to 6ab372d Compare September 8, 2023 15:14
@github-actions
Copy link
Contributor

github-actions bot commented Sep 8, 2023

@EasterTheBunny EasterTheBunny force-pushed the AUTO-4601/add-log-retry-integration-test branch from 6174617 to 13c47c7 Compare September 12, 2023 14:10
@github-actions
Copy link
Contributor

@github-actions
Copy link
Contributor

@github-actions
Copy link
Contributor

@github-actions
Copy link
Contributor

@EasterTheBunny EasterTheBunny marked this pull request as ready for review September 12, 2023 15:44
@EasterTheBunny EasterTheBunny requested a review from a team as a code owner September 12, 2023 15:44
// the actual struct to unmarshal into is not available to this
// package so basic json encoding is the limit of the following test
var data map[string]interface{}
err = json.Unmarshal(b, &data)
Copy link
Contributor

Choose a reason for hiding this comment

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

does it make sense to compare the output bytes of unpack() and our expected bytes?

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 can add a test that b adheres to the correct json structure in byte form. It's a little brittle but it should work.

return encoding.PackUnpackDecodeFailed, encoding.UpkeepFailureReasonNone, false, false, fmt.Errorf("failed to pack upkeepId: %w", err)
}

var b hexutil.Bytes
Copy link
Contributor

Choose a reason for hiding this comment

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

super nit, i would recommend a more meaningful name, e.g. result or resultBytes.

if len(cfg) == 0 {
r.mercury.allowListCache.Set(upkeepId.String(), false, cache.DefaultExpiration)
return encoding.NoPipelineError, encoding.UpkeepFailureReasonMercuryAccessNotAllowed, false, false, fmt.Errorf("upkeep privilege config is empty")
}

var a UpkeepPrivilegeConfig
err = json.Unmarshal(cfg, &a)
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto, how about something like privilegeConfig?

// the simulation here should force the streams lookup process to return
// retryable 2 times.
// the total count of failures should be (upkeepCount * 3 * tryCount)
if count <= mercuryFailCount {
Copy link
Contributor

Choose a reason for hiding this comment

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

i didnt get this math. mercury, by default, retries 3 times before returning a retryable, so for 1 upkeep, we should hit the mercury server 5 times(1st is regular query, 2,3,4 are retries, and then the 5th will return a retryable) in order to get 1 retryable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For each call to CheckUpkeeps, mercury is tried 3 times in total for each upkeep. The expectation is that for each upkeep, 2 calls to CheckUpkeeps should result in a Retryable result and one should succeed. So for each upkeep that should be 3 'tries' * 2 'retries' for the failure condition and one more 'try' for the success condition. I think it's right?


// using sleep here is not the right way to go, but it currently work on
// a local machine. this does have issues in CI
time.Sleep(10 * time.Second)
Copy link
Contributor

Choose a reason for hiding this comment

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

curious, what is the issue in CI?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's avoid the sleep as it might be flaky, can't we wait for something to happen?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually I'll try removing this. Amir did some updates where this timer wasn't needed.


func (c *feedLookupUpkeepController) RegisterAndFund(
t *testing.T,
f registerAndFundFunc,
Copy link
Contributor

Choose a reason for hiding this comment

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

is it possible to move the type registerAndFundFunc and the function definition in core/services/ocr2/plugins/ocr2keeper/integration_21_test.go to here? So we can remove the additional layer?

This commit offers a proposal for completing an integration test that runs log
trigger upkeeps, a full check pipeline, fails mercury server calls, and allows
the application to retry the upkeeps.

Additions include:
- mock mercury server that can have a custom handler per test
- upkeep setup helpers for creating/registering log triggered upkeeps
- integration test for log event retry flow
@EasterTheBunny EasterTheBunny force-pushed the AUTO-4601/add-log-retry-integration-test branch from 32b60c5 to b99cb4a Compare September 13, 2023 16:05
@cl-sonarqube-production
Copy link

@EasterTheBunny EasterTheBunny added this pull request to the merge queue Sep 13, 2023
Merged via the queue into develop with commit 50134ee Sep 13, 2023
98 checks passed
@EasterTheBunny EasterTheBunny deleted the AUTO-4601/add-log-retry-integration-test branch September 13, 2023 17:15
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.

5 participants