Skip to content

Commit a16def8

Browse files
authored
Allow ignore compat in Go sync and add explicit unsupported messages for gen (#452)
* Allow ignore compat in Go sync and add explicit unsupported messages for gen * Update tests
1 parent 79e8226 commit a16def8

File tree

5 files changed

+81
-146
lines changed

5 files changed

+81
-146
lines changed

cmd/lekko/sync_test.go

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -196,23 +196,6 @@ func TestDefault(t *testing.T) {
196196
})
197197
}
198198

199-
func TestDuration(t *testing.T) {
200-
t.Run("default", func(t *testing.T) {
201-
ctx := context.Background()
202-
f, err := os.ReadFile("./testdata/duration.go")
203-
if err != nil {
204-
panic(err)
205-
}
206-
if got := goToGo(ctx, f); got != string(f) {
207-
diff, err := DiffStyleOutput(string(f), got)
208-
if err != nil {
209-
panic(err)
210-
}
211-
t.Errorf("Difference Found: %s\n", diff)
212-
}
213-
})
214-
}
215-
216199
/*
217200
Here to just run the code, but I really don't want to have an unrelated node thing as a dep for the test
218201
func Test_ProtoJsonToTs(t *testing.T) {

cmd/lekko/testdata/default.go

Lines changed: 71 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@ import (
44
"strings"
55

66
"golang.org/x/exp/slices"
7-
durationpb "google.golang.org/protobuf/types/known/durationpb"
87
)
98

109
type DBConfig struct {
1110
MaxIdleConns int64
1211
MaxOpenConns int64
1312
}
1413

15-
type ErrorFilter struct {
14+
type ErrorFilterConfig struct {
1615
LogLevel int64
1716
}
1817

@@ -21,11 +20,6 @@ type MemcachedConfig struct {
2120
TimeoutMs int64
2221
}
2322

24-
type MiddlewareConfig struct {
25-
TeamExemptProcedures map[string]bool
26-
RequireOauthProcedures map[string]bool
27-
}
28-
2923
type OAuthDeviceConfig struct {
3024
VerificationUri string
3125
PollingIntervalSeconds int64
@@ -38,20 +32,24 @@ type RegistrationConfig struct {
3832
EmailSubject string
3933
}
4034

41-
type RolloutConfig struct {
42-
LockTtl *durationpb.Duration
35+
type RolloutConfiguration struct {
36+
LockTtl int64
4337
NumRolloutWorkers int64
44-
RolloutTimeout *durationpb.Duration
38+
RolloutTimeout int64
39+
Delay int64
40+
Jitter int64
4541
ChanBufferSize int64
46-
Delay *durationpb.Duration
47-
Jitter *durationpb.Duration
4842
}
4943

5044
type RolloutContentsConfig struct {
5145
Compare bool
5246
UseGitContents bool
5347
}
5448

49+
type TeamExemptProcedures struct {
50+
Procedures []string
51+
}
52+
5553
// Whether or not the backend returns the statically parsed feature for a feature of type Proto..
5654
func getBffShowStaticProto(env string, feature string, owner string, repo string) bool {
5755
if repo == "staging-types" && feature == "proto_test" {
@@ -133,9 +131,9 @@ func getContextKeyMetricsLookbackDays() int64 {
133131
return 3
134132
}
135133

136-
// How many hours after creation does a Lekko browser cookie expire
137-
func getCookieExpirationDuration() *durationpb.Duration {
138-
return &durationpb.Duration{Seconds: 86400}
134+
// How many seconds after creation does a Lekko browser cookie expire
135+
func getCookieExpirationDuration() int64 {
136+
return 86400
139137
}
140138

141139
// Config options for backend DB client
@@ -177,27 +175,27 @@ func getEnableMembershipsByDomainName(env string, username string) bool {
177175
}
178176

179177
// Dynamically change error logs' levels. The context key "message" refers to the "error" field while "log" refers to "msg".
180-
func getErrorFilter(grpcErrorCode float64, log string, message string) *ErrorFilter {
178+
func getErrorFilterConfig(grpcErrorCode float64, log string, message string) *ErrorFilterConfig {
181179
if slices.Contains([]float64{3, 5, 6, 7, 11, 16}, grpcErrorCode) {
182-
return &ErrorFilter{LogLevel: 3}
180+
return &ErrorFilterConfig{LogLevel: 3}
183181
} else if strings.Contains(message, "unsupported static parsing") {
184-
return &ErrorFilter{LogLevel: 3}
182+
return &ErrorFilterConfig{LogLevel: 3}
185183
} else if strings.Contains(message, "Found feature(s) with compilation or formatting diffs") {
186-
return &ErrorFilter{LogLevel: 3}
184+
return &ErrorFilterConfig{LogLevel: 3}
187185
} else if strings.Contains(message, "deleting invalid in-mem repo") {
188-
return &ErrorFilter{LogLevel: 3}
186+
return &ErrorFilterConfig{LogLevel: 3}
189187
} else if strings.Contains(message, "context canceled") {
190-
return &ErrorFilter{LogLevel: 3}
188+
return &ErrorFilterConfig{LogLevel: 3}
191189
} else if strings.Contains(message, "acquire lock") {
192-
return &ErrorFilter{LogLevel: 3}
190+
return &ErrorFilterConfig{LogLevel: 3}
193191
} else if strings.Contains(log, "unable to get reset_at cache value") {
194-
return &ErrorFilter{LogLevel: 3}
192+
return &ErrorFilterConfig{LogLevel: 3}
195193
} else if strings.Contains(log, "unable to reset quota") {
196-
return &ErrorFilter{LogLevel: 3}
194+
return &ErrorFilterConfig{LogLevel: 3}
197195
} else if strings.Contains(message, "field contextProto not found in type metadata.NamespaceConfigRepoMetadata") {
198-
return &ErrorFilter{LogLevel: 3}
196+
return &ErrorFilterConfig{LogLevel: 3}
199197
}
200-
return &ErrorFilter{LogLevel: 1}
198+
return &ErrorFilterConfig{LogLevel: 1}
201199
}
202200

203201
// example bool config pushed from backend
@@ -265,41 +263,6 @@ func getMetricsBatchSize() int64 {
265263
return 2000
266264
}
267265

268-
// Configuration for the backend rpc middleware
269-
func getMiddleware() *MiddlewareConfig {
270-
return &MiddlewareConfig{
271-
RequireOauthProcedures: map[string]bool{
272-
"AddFeature": true,
273-
"AddNamespace": true,
274-
"CreateBranch": true,
275-
"CreateRepository": true,
276-
"DeleteRepository": true,
277-
"GetPR": true,
278-
"GetPRInfo": true,
279-
"GetUserOAuth": true,
280-
"Merge": true,
281-
"MergePR": true,
282-
"RemoveFeature": true,
283-
"RemoveNamespace": true,
284-
"Restore": true,
285-
"Review": true,
286-
"Save": true,
287-
},
288-
TeamExemptProcedures: map[string]bool{
289-
"AuthorizeDevice": true,
290-
"ChangePassword": true,
291-
"CreateTeam": true,
292-
"DeleteUserOAuth": true,
293-
"GetUserGitHubInstallations": true,
294-
"GetUserLoggedInInfo": true,
295-
"GetUserOAuth": true,
296-
"ListUserMemberships": true,
297-
"OAuthUser": true,
298-
"UseTeam": true,
299-
},
300-
}
301-
}
302-
303266
func getNewButtonThree(env string) string {
304267
if env == "production" {
305268
return "prod"
@@ -314,6 +277,11 @@ func getNewFeatureFlag(env string) bool {
314277
return false
315278
}
316279

280+
// Whether to only return the default branch info in the ListBranches endpoint. Switching branches and viewing PRs is disabled on the web UI for now, so this should be a quick temp fix for GitHub rate limit issues.
281+
func getOnlyListDefaultBranch() bool {
282+
return true
283+
}
284+
317285
// Settings for Lekko registration flow
318286
func getRegistrationConfig(env string, userExists bool) *RegistrationConfig {
319287
if userExists && env == "development" {
@@ -468,11 +436,8 @@ func getRegistrationConfig(env string, userExists bool) *RegistrationConfig {
468436
}
469437
}
470438

471-
func getReturnFdsToFe(username string) bool {
472-
if username == "jonathan@lekko.com" {
473-
return true
474-
}
475-
return false
439+
func getReturnFdsToFe() bool {
440+
return true
476441
}
477442

478443
// log level for rockset client, see https://github.com/rs/zerolog/blob/master/globals.go#L35-L48 for supported values
@@ -488,34 +453,34 @@ func getRocksetRetryMaxElapsedTimeSecs() int64 {
488453
return 15
489454
}
490455

491-
// Controls how config repo contents are derived during rollout. Formerly a JSON config.
492-
func getRolloutContentsProto(env string) *RolloutContentsConfig {
493-
if slices.Contains([]string{"staging", "development"}, env) {
494-
return &RolloutContentsConfig{UseGitContents: true}
495-
}
496-
return &RolloutContentsConfig{UseGitContents: true}
497-
}
498-
499-
// Rollout handler configuration
500-
func getRollout(env string) *RolloutConfig {
456+
// Rollout handler configuration. All durations are in seconds.
457+
func getRolloutConfiguration(env string) *RolloutConfiguration {
501458
if env == "staging" {
502-
return &RolloutConfig{
459+
return &RolloutConfiguration{
503460
ChanBufferSize: 100,
504-
Delay: &durationpb.Duration{Seconds: 180},
505-
Jitter: &durationpb.Duration{Seconds: 30},
506-
LockTtl: &durationpb.Duration{Seconds: 60},
461+
Delay: 300,
462+
Jitter: 30,
463+
LockTtl: 60,
507464
NumRolloutWorkers: 250,
508-
RolloutTimeout: &durationpb.Duration{Seconds: 60},
465+
RolloutTimeout: 120,
509466
}
510467
}
511-
return &RolloutConfig{
468+
return &RolloutConfiguration{
512469
ChanBufferSize: 100,
513-
Delay: &durationpb.Duration{Seconds: 900},
514-
Jitter: &durationpb.Duration{Seconds: 60},
515-
LockTtl: &durationpb.Duration{Seconds: 300},
470+
Delay: 900,
471+
Jitter: 60,
472+
LockTtl: 300,
516473
NumRolloutWorkers: 250,
517-
RolloutTimeout: &durationpb.Duration{Seconds: 480},
474+
RolloutTimeout: 480,
475+
}
476+
}
477+
478+
// Controls how config repo contents are derived during rollout. Formerly a JSON config.
479+
func getRolloutContentsProto(env string) *RolloutContentsConfig {
480+
if slices.Contains([]string{"staging", "development"}, env) {
481+
return &RolloutContentsConfig{UseGitContents: true}
518482
}
483+
return &RolloutContentsConfig{UseGitContents: true}
519484
}
520485

521486
// Controls whether we sync with GitHub to fetch updated branch information after saving changes through BFF
@@ -544,10 +509,30 @@ func getShouldValidateTeam(procedure string) bool {
544509
return false
545510
} else if procedure == "DeleteAPIKey" {
546511
return false
512+
} else if slices.Contains([]string{"CreateBranch", "Save", "Review", "Merge", "GetRepositoryContents"}, procedure) {
513+
return false
547514
}
548515
return true
549516
}
550517

518+
// Configuration for BFF procedures that don't need to be checked for team info
519+
func getTeamExemptProcedures() *TeamExemptProcedures {
520+
return &TeamExemptProcedures{
521+
Procedures: []string{
522+
"AuthorizeDevice",
523+
"ChangePassword",
524+
"CreateTeam",
525+
"DeleteUserOAuth",
526+
"GetUserGitHubInstallations",
527+
"GetUserLoggedInInfo",
528+
"GetUserOAuth",
529+
"ListUserMemberships",
530+
"OAuthUser",
531+
"UseTeam",
532+
},
533+
}
534+
}
535+
551536
// Whether or not to rely on lekko's custom Any protobuf definition as source of truth..
552537
func getUseCustomAny() bool {
553538
return true

cmd/lekko/testdata/duration.go

Lines changed: 0 additions & 41 deletions
This file was deleted.

pkg/gen/golang.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,10 @@ func (g *goGenerator) genGoForFeature(ctx context.Context, r repo.ConfigurationR
560560
fd := mt.Descriptor().Fields().Get(i)
561561
fieldName := fd.Name()
562562
fieldType := FieldDescriptorToGoTypeString(fd)
563+
if fd.Kind() == protoreflect.MessageKind {
564+
// This includes durationpb.Duration
565+
return nil, fmt.Errorf("generate code for field %s: nested complex types are currently not supported", fd.FullName())
566+
}
563567
if fd.IsList() {
564568
protoStructFilling = protoStructFilling + fmt.Sprintf(`
565569
case "%[1]s":
@@ -575,8 +579,10 @@ func (g *goGenerator) genGoForFeature(ctx context.Context, r repo.ConfigurationR
575579
return true
576580
}
577581
}`, string(fieldName), strcase.ToCamel(string(fieldName)), fieldType, fd.Kind().String())
578-
} else {
582+
} else if fd.IsMap() {
579583
// TODO: Maps don't work because the value is a dynamicpb.dynamicMap that can't be cast to map[key]value
584+
return nil, fmt.Errorf("generate code for field %s: maps are currently not supported", fd.FullName())
585+
} else {
580586
protoStructFilling = protoStructFilling + fmt.Sprintf(`
581587
case "%s":
582588
fv, ok := v.Interface().(%s)

pkg/sync/golang.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,9 @@ func (g *goSyncer) Sync(ctx context.Context, repoPath *string) (*Namespace, erro
536536
return nil, errors.Wrap(err, "final rebuild type registry")
537537
}
538538
// Final compile to verify healthy sync
539-
if _, err := r.Compile(ctx, &repo.CompileRequest{}); err != nil {
539+
if _, err := r.Compile(ctx, &repo.CompileRequest{
540+
IgnoreBackwardsCompatibility: true,
541+
}); err != nil {
540542
return nil, errors.Wrap(err, "final compile")
541543
}
542544
}

0 commit comments

Comments
 (0)