Skip to content

Commit

Permalink
Merge pull request #566 from authzed/remove-revision-fuzzing
Browse files Browse the repository at this point in the history
remove remaining references to revision fuzzing
  • Loading branch information
jakedt authored Apr 27, 2022
2 parents 57a215c + 3e30a6f commit 02e2d53
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
6 changes: 3 additions & 3 deletions internal/middleware/pertoken/pertoken.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import (
)

const (
gcWindow = 1 * time.Hour
revisionFuzzingDuration = 10 * time.Millisecond
gcWindow = 1 * time.Hour
revisionQuantization = 10 * time.Millisecond
)

// MiddlewareForTesting is used to create a unique datastore for each token. It is intended for use in the
Expand All @@ -47,7 +47,7 @@ func (m *MiddlewareForTesting) getOrCreateDatastore(ctx context.Context) (datast
}

log.Debug().Str("token", tokenStr).Msg("initializing new upstream for token")
ds, err := memdb.NewMemdbDatastore(0, revisionFuzzingDuration, gcWindow, 0)
ds, err := memdb.NewMemdbDatastore(0, revisionQuantization, gcWindow, 0)
if err != nil {
return nil, fmt.Errorf("failed to init datastore: %w", err)
}
Expand Down
4 changes: 2 additions & 2 deletions internal/testserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ import (
)

func NewTestServer(require *require.Assertions,
revisionFuzzingTimedelta time.Duration,
revisionQuantization time.Duration,
gcWindow time.Duration,
simulatedLatency time.Duration,
schemaPrefixRequired bool,
dsInitFunc func(datastore.Datastore, *require.Assertions) (datastore.Datastore, datastore.Revision),
) (*grpc.ClientConn, func(), decimal.Decimal) {
emptyDS, err := memdb.NewMemdbDatastore(0, revisionFuzzingTimedelta, gcWindow, simulatedLatency)
emptyDS, err := memdb.NewMemdbDatastore(0, revisionQuantization, gcWindow, simulatedLatency)
require.NoError(err)
ds, revision := dsInitFunc(emptyDS, require)
ns, err := namespace.NewCachingNamespaceManager(nil)
Expand Down
13 changes: 12 additions & 1 deletion pkg/cmd/datastore/datastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type Config struct {
Engine string
URI string
GCWindow time.Duration
LegacyFuzzing time.Duration
RevisionQuantization time.Duration

// Options
Expand Down Expand Up @@ -96,7 +97,7 @@ func RegisterDatastoreFlags(cmd *cobra.Command, opts *Config) {
cmd.Flags().DurationVar(&opts.GCWindow, "datastore-gc-window", 24*time.Hour, "amount of time before revisions are garbage collected")
cmd.Flags().DurationVar(&opts.GCInterval, "datastore-gc-interval", 3*time.Minute, "amount of time between passes of garbage collection (postgres driver only)")
cmd.Flags().DurationVar(&opts.GCMaxOperationTime, "datastore-gc-max-operation-time", 1*time.Minute, "maximum amount of time a garbage collection pass can operate before timing out (postgres driver only)")
cmd.Flags().DurationVar(&opts.RevisionQuantization, "datastore-revision-fuzzing-duration", 5*time.Second, "amount of time to advertize stale revisions")
cmd.Flags().DurationVar(&opts.RevisionQuantization, "datastore-revision-quantization-interval", 5*time.Second, "boundary interval to which to round the quantized revision")
cmd.Flags().BoolVar(&opts.ReadOnly, "datastore-readonly", false, "set the service to read-only mode")
cmd.Flags().StringSliceVar(&opts.BootstrapFiles, "datastore-bootstrap-files", []string{}, "bootstrap data yaml files to load")
cmd.Flags().BoolVar(&opts.BootstrapOverwrite, "datastore-bootstrap-overwrite", false, "overwrite any existing data with bootstrap data")
Expand All @@ -113,6 +114,11 @@ func RegisterDatastoreFlags(cmd *cobra.Command, opts *Config) {
cmd.Flags().StringVar(&opts.OverlapKey, "datastore-tx-overlap-key", "key", "static key to touch when writing to ensure transactions overlap (only used if --datastore-tx-overlap-strategy=static is set; cockroach driver only)")
cmd.Flags().StringVar(&opts.SpannerCredentialsFile, "datastore-spanner-credentials", "", "path to service account key credentials file with access to the cloud spanner instance")
cmd.Flags().StringVar(&opts.TablePrefix, "datastore-mysql-table-prefix", "", "prefix to add to the name of all SpiceDB database tables")

cmd.Flags().DurationVar(&opts.LegacyFuzzing, "datastore-revision-fuzzing-duration", -1, "amount of time to advertize stale revisions")
if err := cmd.Flags().MarkDeprecated("datastore-revision-fuzzing-duration", "please use datastore-revision-quantization-interval instead"); err != nil {
panic("failed to mark flag deprecated: " + err.Error())
}
}

func DefaultDatastoreConfig() *Config {
Expand Down Expand Up @@ -141,6 +147,11 @@ func NewDatastore(options ...ConfigOption) (datastore.Datastore, error) {
o(opts)
}

if opts.LegacyFuzzing >= 0 {
log.Warn().Stringer("period", opts.LegacyFuzzing).Msg("deprecated datastore-revision-fuzzing-duration flag specified")
opts.RevisionQuantization = opts.LegacyFuzzing
}

dsBuilder, ok := BuilderForEngine[opts.Engine]
if !ok {
return nil, fmt.Errorf("unknown datastore engine type: %s", opts.Engine)
Expand Down
8 changes: 8 additions & 0 deletions pkg/cmd/datastore/zz_generated.options.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 02e2d53

Please sign in to comment.