-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
settings,*: use the option pattern with the setting register functions #109012
Conversation
864ba9f
to
dd64e29
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 159 of 159 files at r2, all commit messages.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @knz and @stevendanna)
-- commits
line 98 at r2:
Should we modify "NonNegative...WithMinimum" to be "...WithMinimum"? It seems somewhat redundant to have both "non-negative" (which implies "with minimum zero") and "with minimum". It seems like we always have the minimum value greater than zero, so it's non-negative by definition.
pkg/ccl/multitenantccl/tenantcostclient/tenant_side.go
line 104 at r2 (raw file):
// checkDurationInRange returns a function used to validate duration cluster // settings. Because these values are currently settable by the tenant, we need
nit: perhaps preserve the second sentence as the comments on where settings.DurationInRange
is now used.
pkg/ccl/streamingccl/streamingest/stream_ingestion_processor.go
line 56 at r2 (raw file):
"the minimum timestamp between flushes; flushes may still occur if internal buffers fill up", 5*time.Second, settings.WithPublic,
This wasn't public, was this change intentional?
pkg/settings/byte_size.go
line 54 at r2 (raw file):
hasExplicitValidationFn := false for _, opt := range opts { if opt.validateProtoFn != nil ||
nit: should we flip these checks from "blocklist" to "allowlist"? I.e. we'd only allow commonOpt
(which is skipped over) and validateInt64Fn
(which is called) to be non-nil, and we would panic in all other cases. This seems more bullet-proof in case new validation options are added (and a bit less verbose too).
pkg/settings/float.go
line 220 at r2 (raw file):
// FractionUpperExclusive requires the setting to be in the interval // [0, 1]. It can be passed to RegisterFloatSetting.
nit: I think we usually highlight "upper exclusive" as [0, 1)
interval.
pkg/settings/options.go
line 1 at r2 (raw file):
// Copyright 2021 The Cockroach Authors.
nit: s/2021/2023/
.
pkg/settings/options.go
line 52 at r2 (raw file):
// retiredSettings map (in settings/registry.go). The Retired option // exists for cases where there is a need to maintain compatibility // with autommation.
nit: s/autommation/automation/
.
pkg/sql/storageparam/tablestorageparam/table_storage_param.go
line 553 at r2 (raw file):
return func(intVal int64) error { if intVal < 0 { return errors.Newf("cannot be set to a negative interger: %d", intVal)
nit: s/interger/integer/
.
pkg/util/admission/scheduler_latency_listener.go
line 223 at r2 (raw file):
"sets the floor on per-node elastic work CPU % utilization", 0.05, // 5% settings.FloatInRange(0.05, 1.0),
Here minimum used to 0.01.
dd64e29
to
0c75f3c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @stevendanna and @yuzefovich)
Previously, yuzefovich (Yahor Yuzefovich) wrote…
Should we modify "NonNegative...WithMinimum" to be "...WithMinimum"? It seems somewhat redundant to have both "non-negative" (which implies "with minimum zero") and "with minimum". It seems like we always have the minimum value greater than zero, so it's non-negative by definition.
There's a lot of uses of the other NonNegative functions already. I felt the patch was already big enough as it is.
If you insist, I can do this - it's a simple search-and-replace.
pkg/ccl/multitenantccl/tenantcostclient/tenant_side.go
line 104 at r2 (raw file):
Previously, yuzefovich (Yahor Yuzefovich) wrote…
nit: perhaps preserve the second sentence as the comments on where
settings.DurationInRange
is now used.
It was inaccurate - since this was written the class was changed to TenantReadOnly.
pkg/ccl/streamingccl/streamingest/stream_ingestion_processor.go
line 56 at r2 (raw file):
Previously, yuzefovich (Yahor Yuzefovich) wrote…
This wasn't public, was this change intentional?
It was public (RegisterPublicDurationSetting...
in the original call)
pkg/settings/byte_size.go
line 54 at r2 (raw file):
Previously, yuzefovich (Yahor Yuzefovich) wrote…
nit: should we flip these checks from "blocklist" to "allowlist"? I.e. we'd only allow
commonOpt
(which is skipped over) andvalidateInt64Fn
(which is called) to be non-nil, and we would panic in all other cases. This seems more bullet-proof in case new validation options are added (and a bit less verbose too).
Can you show me how you would write that? I don't see it.
pkg/settings/float.go
line 220 at r2 (raw file):
Previously, yuzefovich (Yahor Yuzefovich) wrote…
nit: I think we usually highlight "upper exclusive" as
[0, 1)
interval.
Done.
pkg/settings/options.go
line 1 at r2 (raw file):
Previously, yuzefovich (Yahor Yuzefovich) wrote…
nit:
s/2021/2023/
.
Done.
pkg/settings/options.go
line 52 at r2 (raw file):
Previously, yuzefovich (Yahor Yuzefovich) wrote…
nit:
s/autommation/automation/
.
Done.
0c75f3c
to
3c48c1e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @stevendanna and @yuzefovich)
pkg/sql/storageparam/tablestorageparam/table_storage_param.go
line 553 at r2 (raw file):
Previously, yuzefovich (Yahor Yuzefovich) wrote…
nit:
s/interger/integer/
.
Done.
pkg/util/admission/scheduler_latency_listener.go
line 223 at r2 (raw file):
Previously, yuzefovich (Yahor Yuzefovich) wrote…
Here minimum used to 0.01.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 4 of 163 files at r3, 161 of 161 files at r4, all commit messages.
Reviewable status: complete! 1 of 0 LGTMs obtained (waiting on @knz and @stevendanna)
Previously, knz (Raphael 'kena' Poss) wrote…
There's a lot of uses of the other NonNegative functions already. I felt the patch was already big enough as it is.
If you insist, I can do this - it's a simple search-and-replace.
In other use cases "non-negative" prefix makes sense since it's complimentary to the other constraint imposed by the validation function (or it's the only constraint), but "non-negative with minimum" is a bit redundant. I don't feel strongly about this to insist, so I'll leave it up to you.
pkg/ccl/multitenantccl/tenantcostclient/tenant_side.go
line 104 at r2 (raw file):
Previously, knz (Raphael 'kena' Poss) wrote…
It was inaccurate - since this was written the class was changed to TenantReadOnly.
Ack, makes sense.
pkg/ccl/streamingccl/streamingest/stream_ingestion_processor.go
line 56 at r2 (raw file):
Previously, knz (Raphael 'kena' Poss) wrote…
It was public (
RegisterPublicDurationSetting...
in the original call)
Right, missed that, nvm.
pkg/settings/byte_size.go
line 54 at r2 (raw file):
Previously, knz (Raphael 'kena' Poss) wrote…
Can you show me how you would write that? I don't see it.
I was thinking something like
switch {
case opt.commonOpt != nil:
// not a validation option, skip it
case opt.validateInt64Fn != nil:
hasExplicitValidationFn = true
... fn(v)
default:
panic(errors.AssertionFailedf("wrong validator type"))
}
3c48c1e
to
094740b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @stevendanna and @yuzefovich)
Previously, yuzefovich (Yahor Yuzefovich) wrote…
In other use cases "non-negative" prefix makes sense since it's complimentary to the other constraint imposed by the validation function (or it's the only constraint), but "non-negative with minimum" is a bit redundant. I don't feel strongly about this to insist, so I'll leave it up to you.
Done.
pkg/settings/byte_size.go
line 54 at r2 (raw file):
Previously, yuzefovich (Yahor Yuzefovich) wrote…
I was thinking something like
switch { case opt.commonOpt != nil: // not a validation option, skip it case opt.validateInt64Fn != nil: hasExplicitValidationFn = true ... fn(v) default: panic(errors.AssertionFailedf("wrong validator type")) }
nice. Done.
094740b
to
7fd29ff
Compare
TFYR! bors r=yuzefovich |
bors r- |
Canceled. |
TLDR: this patch introduces the "functional option style" in the settings API. For example, this call: ```go var s = func() *settings.BoolSetting { s := settings.RegisterBoolSetting(...).WithPublic() s.SetReportable(true) }() ``` can now be written as: ```go var s = settings.RegisterBoolSetting(..., settings.WithPublic, settings.WithReportable(true), ) ``` Internally, the register function now take a last argument of type `...SettingOption`. The following options are defined: ```go var Retired SettingOption var WithPublic SettingOption func WithReportable(reportable bool) SettingOption func WithVisibility(v Visibility) SettingOption func WithValidateDuration(fn func(time.Duration) error) SettingOption // NEW var NonNegativeDuration SettingOption var PositiveDuration SettingOption func NonNegativeDurationWithMaximum(maxValue time.Duration) SettingOption func DurationWithMinimum(minValue time.Duration) SettingOption // RENAMED func DurationWithMinimumOrZeroDisable(minValue time.Duration) SettingOption // NEW func DurationInRange(minVal, maxVal int64) SettingOption // NEW func WithValidateFloat(fn func(float64) error) SettingOption // NEW var NonNegativeFloat SettingOption var PositiveFloat SettingOption func NonNegativeFloatWithMaximum(maxValue float64) SettingOption func FloatWithMinimum(minValue float64) SettingOption // NEW func FloatWithMinimumOrZeroDisable(minValue float64) SettingOption // NEW var NonZeroFloat SettingOption // NEW var Fraction SettingOption // NEW var FractionUpperExclusive SettingOption // NEW func FloatInRange(minVal, maxVal float64) SettingOption // NEW func FloatInRangeUpperExclusive(minVal, maxVal float64) SettingOption // NEW func WithValidateInt(fn func(int64) error) SettingOption // NEW var NonNegativeInt SettingOption var PositiveInt SettingOption func NonNegativeIntWithMaximum(maxValue int64) SettingOption func IntWithMinimum(minValue int64) SettingOption // NEW func IntInRange(minVal, maxVal int64) SettingOption // NEW func IntInRangeOrZeroDisable(minVal, maxVal int64) SettingOption // NEW func WithValidateProto(fn func(*Values, protoutil.Message) error) SettingOption // NEW func WithValidateString(fn func(*Values, string) error) SettingOption // NEW func ByteSizeWithMinimum(minVal int64) SettingOption // NEW ``` Release note: None
7fd29ff
to
7e4233d
Compare
bors r=yuzefovich |
Build succeeded: |
First commit from #108902.
Fixes #109011.
Informs #109046.
TLDR: this patch introduces the "functional option style" in the
settings API.
For example, this call:
can now be written as:
Internally, the register function now take a last argument of type
...SettingOption
.The following options are defined:
Release note: None
Epic: CRDB-28893