Skip to content

feat(pricing): add -unitScale flag, deprecate -pixelsPerUnit#3942

Open
rickstaa wants to merge 1 commit into
masterfrom
rs/deprecate-pixelsperunit-flag
Open

feat(pricing): add -unitScale flag, deprecate -pixelsPerUnit#3942
rickstaa wants to merge 1 commit into
masterfrom
rs/deprecate-pixelsperunit-flag

Conversation

@rickstaa

@rickstaa rickstaa commented Jun 9, 2026

Copy link
Copy Markdown
Member

What

pixelsPerUnit is really just a pricing scale factor: price is quoted per N work units (price_per_work_unit = pricePerUnit / pixelsPerUnit). The "pixels" name is transcoding-era legacy and is confusing for non-video / BYOC / general-runner workloads, where there are no pixels.

This adds -unitScale as the clearer primary flag and keeps -pixelsPerUnit as a deprecated alias writing to the same config value, following the existing datadir/dataDir deprecation pattern.

@j0sh not really set on the naming, if you have a better naming let me know. However the pixelsPerUnit feels less accurate.

Changes

  • -unitScale flag (primary) + -pixelsPerUnit kept as a [Deprecated] alias to the same cfg.PixelsPerUnit.
  • Updated -pricePerUnit / -maxPricePerUnit help text to reference unitScale.
  • Added a unit test asserting both flags set PixelsPerUnit.

Compatibility

No wire or config-format changes. The proto field (PriceInfo.pixelsPerUnit), the config struct field, discovery JSON, and all existing configs are untouched, so existing clients and deployments keep working. Only the user-facing flag is renamed, with the old name still accepted.

A follow-up could rename the proto/JSON field in a coordinated, versioned way, but that is intentionally out of scope here to avoid breaking clients.

Summary by CodeRabbit

  • New Features

    • Added -unitScale command-line flag for configuring work-unit pricing scale
  • Documentation

    • Updated pricing help text to reference work units instead of pixels
    • Marked -pixelsPerUnit as deprecated in favor of -unitScale
  • Tests

    • Added tests to verify flag parsing and backward compatibility with the deprecated flag

@github-actions github-actions Bot added the go Pull requests that update Go code label Jun 9, 2026
@coderabbitai

coderabbitai Bot commented Jun 9, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

This PR renames the CLI pricing scale flag from pixelsPerUnit to unitScale (marking the old name as deprecated) and updates help text to describe pricing in terms of work units. A test verifies both flag names correctly populate the underlying configuration field.

Changes

Unit Scale Flag Aliasing

Layer / File(s) Summary
Unit scale flag definition and help text updates
cmd/livepeer/starter/flags.go
The maxPricePerUnit help text is updated to reference work units, and -unitScale is introduced as the primary flag with -pixelsPerUnit retained as a deprecated alias; both set the same PixelsPerUnit config field.
Flag parsing test
cmd/livepeer/starter/starter_test.go
TestNewLivepeerConfig_UnitScaleFlag verifies that -unitScale and the deprecated -pixelsPerUnit flag both correctly parse into cfg.PixelsPerUnit.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A flag renamed with care so fine,
Old pixelsPerUnit steps aside,
While unitScale takes the line—
Both aliases work side by side!
Work units now bloom in the help text wide. ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The pull request title clearly and accurately summarizes the main changes: adding a new -unitScale flag while deprecating the -pixelsPerUnit flag for pricing scale configuration.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch rs/deprecate-pixelsperunit-flag

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@rickstaa rickstaa force-pushed the rs/deprecate-pixelsperunit-flag branch from ca923a0 to cf8e7c8 Compare June 9, 2026 10:23

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
cmd/livepeer/starter/starter_test.go (1)

403-417: ⚡ Quick win

Add a precedence case when both flags are passed.

This test is solid for one-flag inputs; add a case with both -unitScale and -pixelsPerUnit in the same parse to lock expected precedence behavior.

Proposed test extension
 func TestNewLivepeerConfig_UnitScaleFlag(t *testing.T) {
 	require := require.New(t)

 	// -unitScale sets PixelsPerUnit.
 	fs := flag.NewFlagSet("livepeer-test", flag.ContinueOnError)
 	cfg := NewLivepeerConfig(fs)
 	require.NoError(fs.Parse([]string{"-unitScale", "1000000000000"}))
 	require.Equal("1000000000000", *cfg.PixelsPerUnit)

 	// -pixelsPerUnit is a deprecated alias for the same value.
 	fs = flag.NewFlagSet("livepeer-test", flag.ContinueOnError)
 	cfg = NewLivepeerConfig(fs)
 	require.NoError(fs.Parse([]string{"-pixelsPerUnit", "42"}))
 	require.Equal("42", *cfg.PixelsPerUnit)
+
+	// If both are present, last one wins (Go flag parse order).
+	fs = flag.NewFlagSet("livepeer-test", flag.ContinueOnError)
+	cfg = NewLivepeerConfig(fs)
+	require.NoError(fs.Parse([]string{"-unitScale", "10", "-pixelsPerUnit", "20"}))
+	require.Equal("20", *cfg.PixelsPerUnit)
 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cmd/livepeer/starter/starter_test.go` around lines 403 - 417, Add a
precedence test inside TestNewLivepeerConfig_UnitScaleFlag that parses both
flags together to lock expected behavior: call fs.Parse with both
"-pixelsPerUnit" and "-unitScale" (e.g.
[]string{"-pixelsPerUnit","42","-unitScale","1000000000000"}) on a
NewLivepeerConfig(fs) and assert cfg.PixelsPerUnit equals the value for
-unitScale (the newer flag), and optionally repeat with the flags reversed to
ensure order-independent precedence; reference NewLivepeerConfig and
cfg.PixelsPerUnit when locating where to add the assertion.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@cmd/livepeer/starter/flags.go`:
- Around line 106-109: Update the runtime validation and log messages in
cmd/livepeer/starter/starter.go to use the new primary flag name "-unitScale"
(and mention "-pixelsPerUnit" only as deprecated) and to say "price per unit"
(or "work unit") instead of "price per pixel"; locate the checks and log/error
strings that reference cfg.PixelsPerUnit, "-pixelsPerUnit", or "price per pixel"
and change their wording to prefer "-unitScale" and "price per unit" so users
setting -unitScale see correct guidance.

---

Nitpick comments:
In `@cmd/livepeer/starter/starter_test.go`:
- Around line 403-417: Add a precedence test inside
TestNewLivepeerConfig_UnitScaleFlag that parses both flags together to lock
expected behavior: call fs.Parse with both "-pixelsPerUnit" and "-unitScale"
(e.g. []string{"-pixelsPerUnit","42","-unitScale","1000000000000"}) on a
NewLivepeerConfig(fs) and assert cfg.PixelsPerUnit equals the value for
-unitScale (the newer flag), and optionally repeat with the flags reversed to
ensure order-independent precedence; reference NewLivepeerConfig and
cfg.PixelsPerUnit when locating where to add the assertion.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8e411cba-2c9d-4c68-a712-d278132ad85d

📥 Commits

Reviewing files that changed from the base of the PR and between e628b9c and ca923a0.

📒 Files selected for processing (2)
  • cmd/livepeer/starter/flags.go
  • cmd/livepeer/starter/starter_test.go

Comment thread cmd/livepeer/starter/flags.go Outdated
Comment on lines +106 to +109
// Scale factor for both O's pricePerUnit and B's maxPricePerUnit: price is
// quoted per this many work units. -pixelsPerUnit is the deprecated alias.
fs.StringVar(cfg.PixelsPerUnit, "unitScale", *cfg.PixelsPerUnit, "Scale factor for pricing: price is quoted per this many work units. Set > 1 for finer price granularity than 1 wei per unit.")
fs.StringVar(cfg.PixelsPerUnit, "pixelsPerUnit", *cfg.PixelsPerUnit, "[Deprecated] Use -unitScale. Amount of pixels per unit; set > 1 for smaller price granularity than 1 wei / pixel.")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Align runtime validation/log wording with -unitScale as primary flag.

After this rename, startup validation/logging still refers to -pixelsPerUnit and “price per pixel” in cmd/livepeer/starter/starter.go (Lines 1137-1166 in the provided snippet). Users setting -unitScale will get misleading guidance on failures. Please update those messages to prefer -unitScale (optionally mention -pixelsPerUnit as deprecated alias).

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cmd/livepeer/starter/flags.go` around lines 106 - 109, Update the runtime
validation and log messages in cmd/livepeer/starter/starter.go to use the new
primary flag name "-unitScale" (and mention "-pixelsPerUnit" only as deprecated)
and to say "price per unit" (or "work unit") instead of "price per pixel";
locate the checks and log/error strings that reference cfg.PixelsPerUnit,
"-pixelsPerUnit", or "price per pixel" and change their wording to prefer
"-unitScale" and "price per unit" so users setting -unitScale see correct
guidance.

`pixelsPerUnit` is really just a pricing scale factor: price is quoted per N
work units (`price_per_work_unit = pricePerUnit / pixelsPerUnit`). The "pixels"
name is transcoding-era legacy and is confusing for non-video / BYOC runners,
where there are no pixels.

Add `-unitScale` as the clearer primary flag and keep `-pixelsPerUnit` as a
deprecated alias writing to the same config (following the datadir/dataDir
pattern). Update the pricePerUnit/maxPricePerUnit help text to reference
unitScale.

No wire or config-format changes: the proto field and the config struct are
untouched, so existing clients, discovery JSON, and configs keep working. Only
the user-facing flag is renamed, with the old name still accepted.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@rickstaa rickstaa force-pushed the rs/deprecate-pixelsperunit-flag branch from cf8e7c8 to daa6847 Compare June 9, 2026 10:26
@rickstaa rickstaa requested a review from j0sh June 9, 2026 10:39
@codecov

codecov Bot commented Jun 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 33.28986%. Comparing base (e628b9c) to head (daa6847).

Additional details and impacted files

Impacted file tree graph

@@                 Coverage Diff                 @@
##              master       #3942         +/-   ##
===================================================
- Coverage   33.30014%   33.28986%   -0.01028%     
===================================================
  Files            171         171                 
  Lines          42174       42175          +1     
===================================================
- Hits           14044       14040          -4     
- Misses         27077       27080          +3     
- Partials        1053        1055          +2     
Files with missing lines Coverage Δ
cmd/livepeer/starter/flags.go 87.40741% <100.00000%> (+0.09398%) ⬆️

... and 3 files with indirect coverage changes


Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e628b9c...daa6847. Read the comment docs.

Files with missing lines Coverage Δ
cmd/livepeer/starter/flags.go 87.40741% <100.00000%> (+0.09398%) ⬆️

... and 3 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

Labels

go Pull requests that update Go code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant