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

chore(wip): refactor internal storage types to use proto types #2335

Closed
wants to merge 46 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
84645b8
chore(wip): gah
markphelps Nov 1, 2023
66483c7
feat(wip): snapshot api
markphelps Nov 2, 2023
cfd794e
feat: finish proto server
markphelps Nov 2, 2023
67c1400
chore: fix linter errors
markphelps Nov 2, 2023
4e25e7f
chore: move
markphelps Nov 3, 2023
eff5b41
chore: fix build
markphelps Nov 3, 2023
528a402
chore: add ability to skip generating sdks
markphelps Nov 3, 2023
f043c4e
chore: dont generate interface method
markphelps Nov 3, 2023
9ab4672
Merge branch 'main' into evaluation-snapshot-service
markphelps Nov 3, 2023
e82cea9
chore: fix build
markphelps Nov 3, 2023
d904b08
Merge branch 'evaluation-snapshot-service' of https://github.com/flip…
markphelps Nov 3, 2023
3b30b45
chore: refactor internal storage types to use proto types
markphelps Nov 3, 2023
bc167d2
chore: fix tests
markphelps Nov 4, 2023
b84f26c
chore: variable cleanup
markphelps Nov 4, 2023
d21513b
chore: more variable renaming
markphelps Nov 4, 2023
4c4de0e
chore(wip): gah
markphelps Nov 1, 2023
b654587
feat(wip): snapshot api
markphelps Nov 2, 2023
58179a1
feat: finish proto server
markphelps Nov 2, 2023
5cb67a8
chore: fix linter errors
markphelps Nov 2, 2023
e4df56d
chore: move
markphelps Nov 3, 2023
7baf908
chore: fix build
markphelps Nov 3, 2023
a2390a3
chore: add ability to skip generating sdks
markphelps Nov 3, 2023
720accd
chore: dont generate interface method
markphelps Nov 3, 2023
672c02e
chore: fix build
markphelps Nov 3, 2023
ddb5fb5
chore: merge upstream
markphelps Nov 6, 2023
f176718
chore(wip): fixing tests
markphelps Nov 6, 2023
7b965a8
fix: mount api
markphelps Nov 6, 2023
e2d7efe
Merge branch 'evaluation-snapshot-service' into redo-storage-types
markphelps Nov 6, 2023
8884282
chore: fix snapshot tests
markphelps Nov 6, 2023
2365671
chore: use protos for caching evaluation rules
markphelps Nov 6, 2023
f7fc369
chore: mod tidy
markphelps Nov 6, 2023
4a35fda
chore: rename cache getters/setters
markphelps Nov 6, 2023
f6a455b
chore: add namespace key to resp
markphelps Nov 6, 2023
8d85a60
Merge branch 'evaluation-snapshot-service' into redo-storage-types
markphelps Nov 6, 2023
8d45d51
chore: dont fail db unit tests fast
markphelps Nov 6, 2023
3227839
chore: try to fix mysql/postgres tests
markphelps Nov 6, 2023
a743c05
chore: detect boolean flag types
yquansah Nov 6, 2023
189b5a4
chore: cache woes
markphelps Nov 6, 2023
23fa229
chore: merge upstream
markphelps Nov 6, 2023
748aae3
chore: does having namespace key in teh query matter?
markphelps Nov 6, 2023
3407d5f
chore: try to fix tests
markphelps Nov 6, 2023
0f8334e
chore: create own types for evaluation service
markphelps Nov 7, 2023
126619f
chore: rm spaces
markphelps Nov 7, 2023
db31e44
chore: rename cmp type fields
markphelps Nov 7, 2023
10bcb70
chore: merge/refactor
markphelps Nov 7, 2023
a74551b
chore: update tests
markphelps Nov 7, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ jobs:
name: "Tests (Go)"
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
database: ["mysql", "postgres", "cockroachdb", "sqlite", "libsql"]
steps:
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ require (
github.com/go-sql-driver/mysql v1.7.1
github.com/gobwas/glob v0.2.3
github.com/gofrs/uuid v4.4.0+incompatible
github.com/gogo/protobuf v1.3.2
github.com/golang-migrate/migrate/v4 v4.16.2
github.com/google/go-cmp v0.6.0
github.com/google/go-github/v32 v32.1.0
Expand Down Expand Up @@ -127,7 +128,6 @@ require (
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/go-querystring v1.1.0 // indirect
Expand Down
3 changes: 1 addition & 2 deletions go.work.sum
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ cloud.google.com/go/compute v1.18.0/go.mod h1:1X7yHxec2Ga+Ss6jPyjxRxpu2uu7PLgsOV
cloud.google.com/go/compute v1.19.3/go.mod h1:qxvISKp/gYnXkSAD1ppcSOveRAmzxicEv/JlizULFrI=
cloud.google.com/go/compute v1.20.1/go.mod h1:4tCnrn48xsqlwSAiLf1HXMQk8CONslYbdiEZc9FEIbM=
cloud.google.com/go/compute v1.21.0/go.mod h1:4tCnrn48xsqlwSAiLf1HXMQk8CONslYbdiEZc9FEIbM=
cloud.google.com/go/compute v1.23.2/go.mod h1:JJ0atRC0J/oWYiiVBmsSsrRnh92DhZPG4hFDcR04Rns=
cloud.google.com/go/contactcenterinsights v1.11.0/go.mod h1:hutBdImE4XNZ1NV4vbPJKSFOnQruhC5Lj9bZqWMTKiU=
cloud.google.com/go/contactcenterinsights v1.11.2/go.mod h1:A9PIR5ov5cRcd28KlDbmmXE8Aay+Gccer2h4wzkYFso=
cloud.google.com/go/container v1.26.0/go.mod h1:YJCmRet6+6jnYYRS000T6k0D0xUXQgBSaJ7VwI8FBj4=
Expand Down Expand Up @@ -648,7 +647,6 @@ github.com/google/go-containerregistry v0.14.0/go.mod h1:aiJ2fp/SXvkWgmYHioXnbMd
github.com/google/go-github/v39 v39.2.0/go.mod h1:C1s8C5aCC9L+JXIYpJM5GYytdX52vC1bLvHEF1IhBrE=
github.com/google/go-pkcs11 v0.2.1-0.20230907215043-c6f79328ddf9/go.mod h1:6eQoGcuNJpa7jnd5pMGdkSaQpNDYvPlXWMcjXXThLlY=
github.com/google/gofuzz v1.1.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/martian/v3 v3.3.2/go.mod h1:oBOf6HBosgwRXnUGWUB05QECsc6uvmMiJ3+6W4l/CUk=
github.com/google/pprof v0.0.0-20210122040257-d980be63207e/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
github.com/google/pprof v0.0.0-20210226084205-cbba55b83ad5/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
Expand Down Expand Up @@ -769,6 +767,7 @@ github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa02
github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pty v1.1.5/go.mod h1:9r2w37qlBe7rQ6e1fg1S/9xpWHSnaqNdHD3WcMdbPDA=
github.com/ktrysmt/go-bitbucket v0.6.4/go.mod h1:9u0v3hsd2rqCHRIpbir1oP7F58uo5dq19sBYvuMoyQ4=
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
github.com/lestrrat-go/backoff/v2 v2.0.8/go.mod h1:rHP/q/r9aT27n24JQLa7JhSQZCKBBOiM/uP402WwN8Y=
github.com/lestrrat-go/blackmagic v1.0.0/go.mod h1:TNgH//0vYSs8VXDCfkZLgIrVTTXQELZffUV0tz3MtdQ=
Expand Down
2 changes: 1 addition & 1 deletion internal/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ type Cacher interface {
}

func Key(k string) string {
return fmt.Sprintf("flipt:%x", md5.Sum([]byte(k)))
return fmt.Sprintf("flipt:v1:%x", md5.Sum([]byte(k)))
}
26 changes: 26 additions & 0 deletions internal/cache/cache_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package cache

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestKey(t *testing.T) {
type args struct {
k string
}
tests := []struct {
name string
args args
want string
}{
{"empty", args{k: ""}, "flipt:v1:d41d8cd98f00b204e9800998ecf8427e"},
{"non-empty", args{k: "foo"}, "flipt:v1:acbd18db4cc2f85cedef654fccc4a4d8"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equal(t, tt.want, Key(tt.args.k))
})
}
}
11 changes: 7 additions & 4 deletions internal/cmd/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"go.flipt.io/flipt/internal/server/audit/webhook"
"go.flipt.io/flipt/internal/server/auth"
"go.flipt.io/flipt/internal/server/evaluation"
evaluationdata "go.flipt.io/flipt/internal/server/evaluation/data"
"go.flipt.io/flipt/internal/server/metadata"
middlewaregrpc "go.flipt.io/flipt/internal/server/middleware/grpc"
"go.flipt.io/flipt/internal/storage"
Expand Down Expand Up @@ -282,10 +283,11 @@ func NewGRPCServer(
}

var (
fliptsrv = fliptserver.New(logger, store)
metasrv = metadata.New(cfg, info)
evalsrv = evaluation.New(logger, store)
healthsrv = health.NewServer()
fliptsrv = fliptserver.New(logger, store)
metasrv = metadata.New(cfg, info)
evalsrv = evaluation.New(logger, store)
evalDataSrv = evaluationdata.New(logger, store)
healthsrv = health.NewServer()
)

var (
Expand Down Expand Up @@ -340,6 +342,7 @@ func NewGRPCServer(
register.Add(fliptsrv)
register.Add(metasrv)
register.Add(evalsrv)
register.Add(evalDataSrv)

// forward internal gRPC logging to zap
grpcLogLevel, err := zapcore.ParseLevel(cfg.Log.GRPCLevel)
Expand Down
14 changes: 10 additions & 4 deletions internal/cmd/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,11 @@ func NewHTTPServer(
}
isConsole = cfg.Log.Encoding == config.LogEncodingConsole

r = chi.NewRouter()
api = gateway.NewGatewayServeMux(logger)
evaluateAPI = gateway.NewGatewayServeMux(logger)
httpPort = cfg.Server.HTTPPort
r = chi.NewRouter()
api = gateway.NewGatewayServeMux(logger)
evaluateAPI = gateway.NewGatewayServeMux(logger)
evaluateDataAPI = gateway.NewGatewayServeMux(logger)
httpPort = cfg.Server.HTTPPort
)

if cfg.Server.Protocol == config.HTTPS {
Expand All @@ -74,6 +75,10 @@ func NewHTTPServer(
return nil, fmt.Errorf("registering grpc gateway: %w", err)
}

if err := evaluation.RegisterDataServiceHandler(ctx, evaluateDataAPI, conn); err != nil {
return nil, fmt.Errorf("registering grpc gateway: %w", err)
}

if cfg.Cors.Enabled {
cors := cors.New(cors.Options{
AllowedOrigins: cfg.Cors.AllowedOrigins,
Expand Down Expand Up @@ -140,6 +145,7 @@ func NewHTTPServer(

r.Mount("/api/v1", api)
r.Mount("/evaluate/v1", evaluateAPI)
r.Mount("/internal/v1", evaluateDataAPI)

// mount all authentication related HTTP components
// to the chi router.
Expand Down
13 changes: 13 additions & 0 deletions internal/cmd/protoc-gen-go-flipt-sdk/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"flag"
"fmt"
"os"
"slices"
"strings"

"google.golang.org/protobuf/compiler/protogen"
Expand All @@ -13,6 +14,8 @@ import (
const (
importPath = "go.flipt.io/flipt/sdk/go"
emptyImport = "google.golang.org/protobuf/types/known/emptypb"

ignoreDecl = "flipt:sdk:ignore"
)

func main() {
Expand All @@ -34,6 +37,8 @@ func main() {
continue
}

f.Services = slices.DeleteFunc(f.Services, shouldIgnoreService)

generateSubSDK(gen, f)
}

Expand Down Expand Up @@ -261,3 +266,11 @@ func New(t Transport, opts ...Option) SDK {

return sdk
}`

func shouldIgnoreService(srv *protogen.Service) bool {
if srv.Comments.Leading != "" {
leading := strings.TrimPrefix(string(srv.Comments.Leading), "//")
return strings.TrimSpace(leading) == ignoreDecl
}
return false
}
4 changes: 2 additions & 2 deletions internal/ext/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (e *Exporter) Export(ctx context.Context, w io.Writer) error {

intermediateNamespaces := make([]string, 0)

for batch := int32(0); remaining; batch++ {
for remaining {
resp, err := e.store.ListNamespaces(ctx, &flipt.ListNamespaceRequest{
PageToken: nextPage,
Limit: batchSize,
Expand Down Expand Up @@ -246,7 +246,7 @@ func (e *Exporter) Export(ctx context.Context, w io.Writer) error {
nextPage = ""

// export segments/constraints in batches
for batch := int32(0); remaining; batch++ {
for remaining {
resp, err := e.store.ListSegments(
ctx,
&flipt.ListSegmentRequest{
Expand Down
Loading
Loading