Skip to content

Commit

Permalink
feat: eventually consistency API controls (#3558)
Browse files Browse the repository at this point in the history
Adds a feature used in Ory Network which enables trading faster reads for slightly stale data.

This feature depends on Cockroach functionality and configuration, and is not possible for MySQL or PostgreSQL.
  • Loading branch information
aeneasr authored Oct 12, 2023
1 parent 0a0e1f7 commit 00cf11c
Show file tree
Hide file tree
Showing 21 changed files with 599 additions and 189 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ sdk: .bin/swagger .bin/ory node_modules
swagger generate spec -m -o spec/swagger.json \
-c github.com/ory/kratos \
-c github.com/ory/x/healthx \
-c github.com/ory/x/crdbx \
-c github.com/ory/x/openapix
ory dev swagger sanitize ./spec/swagger.json
swagger validate ./spec/swagger.json
Expand Down
7 changes: 7 additions & 0 deletions driver/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
"testing"
"time"

"github.com/ory/x/crdbx"

"github.com/go-webauthn/webauthn/protocol"
"github.com/go-webauthn/webauthn/webauthn"
"github.com/gofrs/uuid"
Expand Down Expand Up @@ -186,6 +188,7 @@ const (
ViperKeyOAuth2ProviderOverrideReturnTo = "oauth2_provider.override_return_to"
ViperKeyClientHTTPNoPrivateIPRanges = "clients.http.disallow_private_ip_ranges"
ViperKeyClientHTTPPrivateIPExceptionURLs = "clients.http.private_ip_exception_urls"
ViperKeyPreviewDefaultReadConsistencyLevel = "preview.default_read_consistency_level"
ViperKeyVersion = "version"
)

Expand Down Expand Up @@ -1488,3 +1491,7 @@ func (p *Config) TokenizeTemplate(ctx context.Context, key string) (_ *SessionTo

return &result, nil
}

func (p *Config) DefaultConsistencyLevel(ctx context.Context) crdbx.ConsistencyLevel {
return crdbx.ConsistencyLevelFromString(p.GetProvider(ctx).String(ViperKeyPreviewDefaultReadConsistencyLevel))
}
16 changes: 16 additions & 0 deletions embedx/config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2179,6 +2179,22 @@
},
"additionalProperties": false
},
"preview": {
"title": "Configure Preview Features",
"type": "object",
"properties": {
"default_read_consistency_level": {
"type": "string",
"title": "Default Read Consistency Level",
"description": "The default consistency level to use when reading from the database. Defaults to `strong` to not break existing API contracts. Only set this to `eventual` if you can accept that other read APIs will suddenly return eventually consistent results. It is only effective in Ory Network.",
"enum": [
"strong",
"eventual"
],
"default": "strong"
}
}
},
"serve": {
"type": "object",
"properties": {
Expand Down
58 changes: 29 additions & 29 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ replace (
)

require (
github.com/Masterminds/sprig/v3 v3.2.2
github.com/Masterminds/sprig/v3 v3.2.3
github.com/arbovm/levenshtein v0.0.0-20160628152529-48b4e1c0c4d0
github.com/avast/retry-go/v3 v3.1.1
github.com/bradleyjkemp/cupaloy/v2 v2.8.0
Expand All @@ -32,9 +32,9 @@ require (
github.com/ghodss/yaml v1.0.0
github.com/go-crypt/crypt v0.2.9
github.com/go-errors/errors v1.0.1
github.com/go-openapi/strfmt v0.21.3
github.com/go-openapi/strfmt v0.21.7
github.com/go-playground/validator/v10 v10.4.1
github.com/go-swagger/go-swagger v0.30.3
github.com/go-swagger/go-swagger v0.30.5
github.com/go-webauthn/webauthn v0.8.4
github.com/gobuffalo/fizz v1.14.4
github.com/gobuffalo/httptest v1.5.2
Expand All @@ -49,7 +49,7 @@ require (
github.com/google/go-jsonnet v0.19.0
github.com/gorilla/sessions v1.2.1
github.com/gtank/cryptopasta v0.0.0-20170601214702-1f550f6f2f69
github.com/hashicorp/consul/api v1.18.0
github.com/hashicorp/consul/api v1.20.0
github.com/hashicorp/go-retryablehttp v0.7.2
github.com/hashicorp/golang-lru v0.5.4
github.com/imdario/mergo v0.3.13
Expand Down Expand Up @@ -77,7 +77,7 @@ require (
github.com/ory/jsonschema/v3 v3.0.8
github.com/ory/mail/v3 v3.0.0
github.com/ory/nosurf v1.2.7
github.com/ory/x v0.0.591
github.com/ory/x v0.0.595
github.com/peterhellberg/link v1.2.0
github.com/phayes/freeport v0.0.0-20180830031419-95f893ade6f2
github.com/pkg/errors v0.9.1
Expand All @@ -96,13 +96,13 @@ require (
github.com/urfave/negroni v1.0.0
github.com/zmb3/spotify/v2 v2.0.0
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.36.4
go.opentelemetry.io/otel v1.11.1
go.opentelemetry.io/otel/trace v1.11.1
go.opentelemetry.io/otel v1.14.0
go.opentelemetry.io/otel/trace v1.14.0
golang.org/x/crypto v0.12.0
golang.org/x/exp v0.0.0-20220303212507-bbda1eaf7a17
golang.org/x/net v0.14.0
golang.org/x/oauth2 v0.11.0
golang.org/x/sync v0.1.0
golang.org/x/sync v0.2.0
golang.org/x/text v0.12.0
golang.org/x/tools/cmd/cover v0.1.0-deprecated
google.golang.org/grpc v1.55.0
Expand All @@ -112,14 +112,14 @@ require (
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/semver v1.5.0 // indirect
github.com/Masterminds/semver/v3 v3.1.1 // indirect
github.com/Masterminds/semver/v3 v3.2.0 // indirect
github.com/Microsoft/go-winio v0.6.0 // indirect
github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 // indirect
github.com/a8m/envsubst v1.3.0 // indirect
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect
github.com/alecthomas/units v0.0.0-20210208195552-ff826a37aa15 // indirect
github.com/armon/go-metrics v0.4.0 // indirect
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d // indirect
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
github.com/avast/retry-go/v4 v4.3.0 // indirect
github.com/aymerick/douceur v0.2.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
Expand Down Expand Up @@ -150,15 +150,15 @@ require (
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-openapi/analysis v0.21.4 // indirect
github.com/go-openapi/errors v0.20.3 // indirect
github.com/go-openapi/errors v0.20.4 // indirect
github.com/go-openapi/inflect v0.19.0 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.20.0 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/loads v0.21.2 // indirect
github.com/go-openapi/runtime v0.24.2 // indirect
github.com/go-openapi/spec v0.20.7 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
github.com/go-openapi/validate v0.22.0 // indirect
github.com/go-openapi/runtime v0.26.0 // indirect
github.com/go-openapi/spec v0.20.9 // indirect
github.com/go-openapi/swag v0.22.4 // indirect
github.com/go-openapi/validate v0.22.1 // indirect
github.com/go-playground/locales v0.13.0 // indirect
github.com/go-playground/universal-translator v0.17.0 // indirect
github.com/go-sql-driver/mysql v1.7.0 // indirect
Expand Down Expand Up @@ -199,7 +199,7 @@ require (
github.com/hashicorp/go-rootcerts v1.0.2 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hashicorp/serf v0.10.1 // indirect
github.com/huandu/xstrings v1.3.2 // indirect
github.com/huandu/xstrings v1.3.3 // indirect
github.com/ian-kent/envconf v0.0.0-20141026121121-c19809918c02 // indirect
github.com/ian-kent/go-log v0.0.0-20160113211217-5731446c36ab // indirect
github.com/ian-kent/goose v0.0.0-20141221090059-c3541ea826ad // indirect
Expand All @@ -224,7 +224,7 @@ require (
github.com/knadh/koanf/parsers/yaml v0.1.0 // indirect
github.com/knadh/koanf/providers/posflag v0.1.0 // indirect
github.com/knadh/koanf/v2 v2.0.1 // indirect
github.com/kr/pretty v0.3.0 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/leodido/go-urn v1.2.0 // indirect
github.com/lestrrat-go/backoff/v2 v2.0.8 // indirect
Expand Down Expand Up @@ -260,7 +260,7 @@ require (
github.com/opencontainers/runc v1.1.5 // indirect
github.com/openzipkin/zipkin-go v0.4.1 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.0.7 // indirect
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
github.com/philhofer/fwd v1.1.2 // indirect
github.com/pkg/profile v1.7.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
Expand All @@ -280,9 +280,9 @@ require (
github.com/sourcegraph/annotate v0.0.0-20160123013949-f4cad6c6324d // indirect
github.com/sourcegraph/syntaxhighlight v0.0.0-20170531221838-bd320f5d308e // indirect
github.com/spf13/afero v1.9.5 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/cast v1.5.1 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/viper v1.15.0 // indirect
github.com/spf13/viper v1.16.0 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
github.com/t-k/fluent-logger-golang v1.0.0 // indirect
github.com/tidwall/match v1.1.1 // indirect
Expand All @@ -296,23 +296,23 @@ require (
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
github.com/xtgo/uuid v0.0.0-20140804021211-a0b114877d4c // indirect
go.mongodb.org/mongo-driver v1.10.3 // indirect
go.mongodb.org/mongo-driver v1.11.3 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.36.4 // indirect
go.opentelemetry.io/contrib/propagators/b3 v1.11.1 // indirect
go.opentelemetry.io/contrib/propagators/jaeger v1.11.1 // indirect
go.opentelemetry.io/contrib/samplers/jaegerremote v0.5.2 // indirect
go.opentelemetry.io/otel/exporters/jaeger v1.11.1 // indirect
go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.11.1 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.9.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.9.0 // indirect
go.opentelemetry.io/otel/exporters/zipkin v1.11.1 // indirect
go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.14.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.14.0 // indirect; / indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.14.0 // indirect; / indirect
go.opentelemetry.io/otel/exporters/zipkin v1.14.0 // indirect; / indirect
go.opentelemetry.io/otel/metric v0.33.0 // indirect
go.opentelemetry.io/otel/sdk v1.11.1 // indirect
go.opentelemetry.io/otel/sdk v1.14.0 // indirect
go.opentelemetry.io/proto/otlp v0.19.0 // indirect
golang.org/x/mod v0.10.0 // indirect
golang.org/x/sys v0.11.0 // indirect
golang.org/x/term v0.11.0 // indirect
golang.org/x/tools v0.7.0 // indirect
golang.org/x/tools v0.9.3 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20230530153820-e85fd2cbaebc // indirect
Expand Down
Loading

0 comments on commit 00cf11c

Please sign in to comment.