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

feat: Evaluation snapshot service #2330

Merged
merged 15 commits into from
Nov 7, 2023
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
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