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

Add Basic Metering Report to Workflow Engine #16398

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

Conversation

EasterTheBunny
Copy link
Contributor

@EasterTheBunny EasterTheBunny commented Feb 13, 2025

This commit adds a metering report struct to the workflow engine such that each step can be individually added to the report. Metering units and values are generally treated as string values, but post values are verified to be valid numeric.

The metering report can provide a calculated median value for all posted units.

CRE-282

Copy link
Contributor

github-actions bot commented Feb 13, 2025

AER Report: CI Core ran successfully ✅

aer_workflow , commit

AER Report: Operator UI CI ran successfully ✅

aer_workflow , commit

@EasterTheBunny EasterTheBunny marked this pull request as ready for review February 14, 2025 19:04
@EasterTheBunny EasterTheBunny requested a review from a team as a code owner February 14, 2025 19:04
@EasterTheBunny EasterTheBunny marked this pull request as draft February 14, 2025 19:05
return MeteringSpendValue(value.String())
}

type MeteringSpendValue string
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did you think to represent this as a string value?

This one is tricky to me - we can either represent the value in double (i.e. float64) to match the user facing credit values. Or we can do away with rounding error and establish a true minimum unit for each credit type and track everything in integer values. What do you think?

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 went with a string value here as a starting point because it is the least common denominator between all possible numeric value representations and is the standard for JSON encoding floats. However, if we intend to do division calculations, we probably should use a decimal.Decimal.

The intent of this code was to define a distinct type that represented the value such that we can change it to our needs as we learn more.

Copy link
Contributor Author

@EasterTheBunny EasterTheBunny Feb 25, 2025

Choose a reason for hiding this comment

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

Maybe we can use the type to contain our expected calculations:

type MeteringSpendValue struct {
    value int64 // we can choose int64, decimal.Decimal, *big.Int, float64, etc.
    decimal uint8 // examples: BTC: 8, ETH: 18, USDT: 0
}

func (v *MeteringSpendValue) Add(*MeteringSpendValue) *MeteringSpendValue {
    // ... do addition
}

// ... other calculation functions

// String will likely be necessary for encoding in some transport layer either GRPC or something which could handle the rounding operation (since we likely should not do rounding after every calculation)
func (v MeteringSpendValue) String() string {
    // ... do a string representation based on desired rounding method and decimal (standard, bank, floor, ceil)
}

Doing this, we can control the operations we need per value denomination (btc, eth, solana, usdt, etc.)

"sort"
"sync"

"github.com/shopspring/decimal"
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't recognize this import - do we use other decimal libraries in core?

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'm quite certain this is the package we use in core. I have used it quite a bit before and it handles floating point errors quite well to my knowledge.

@@ -616,6 +619,12 @@ func (e *Engine) handleStepUpdate(ctx context.Context, stepUpdate store.Workflow
return err
}

e.meterReport.AddStep(MeteringReportStepRef(stepUpdate.ExecutionID), MeteringReportStep{
Copy link
Contributor

Choose a reason for hiding this comment

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

we can keep this first PR clean of adding any mocked reports

This commit adds a metering report struct to the workflow engine such that each step can be individually added to the
report. Metering units and values are generally treated as string values, but post values are verified to be valid
numeric.

The metering report can provide a calculated median value for all posted units.
@EasterTheBunny EasterTheBunny force-pushed the CRE-282/implement-aggregated-metering branch from bfbfcf2 to 3133362 Compare February 25, 2025 21:51
Copy link
Contributor

Flakeguard Summary

Ran new or updated tests between develop and 3133362 (CRE-282/implement-aggregated-metering).

View Flaky Detector Details | Compare Changes

Found Flaky Tests ❌

4 Results
Name Pass Ratio Panicked? Timed Out? Race? Runs Successes Failures Skips Package Package Panicked? Avg Duration Code Owners
TestMeteringReport 0% false false false 3 0 3 0 github.com/smartcontractkit/chainlink/v2/core/services/workflows false 0s @smartcontractkit/keystone
TestMeteringReport/MedianSpend_returns_median_as_average_for_even_number_of_spend_values 0% false false false 3 0 3 0 github.com/smartcontractkit/chainlink/v2/core/services/workflows false 0s @smartcontractkit/keystone
TestMeteringReport/MedianSpend_returns_median_for_multiple_spend_units 66.6667% false false false 3 2 1 0 github.com/smartcontractkit/chainlink/v2/core/services/workflows false 0s @smartcontractkit/keystone
TestMeteringReport/MedianSpend_returns_median_odd_number_of_spend_values 0% false false false 3 0 3 0 github.com/smartcontractkit/chainlink/v2/core/services/workflows false 0s @smartcontractkit/keystone

Artifacts

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

@EasterTheBunny EasterTheBunny marked this pull request as ready for review February 26, 2025 16:36
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.

2 participants