Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 pkg/error/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (

const (
AccountPackageName = "account"
FeaturePackageName = "feature"
NotificationPackageName = "notification"
PushPackageName = "push"
TagPackageName = "tag"
Expand Down
19 changes: 3 additions & 16 deletions pkg/feature/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

"github.com/bucketeer-io/bucketeer/pkg/api/api"
v2fs "github.com/bucketeer-io/bucketeer/pkg/feature/storage/v2"
v2ts "github.com/bucketeer-io/bucketeer/pkg/tag/storage"
featureproto "github.com/bucketeer-io/bucketeer/proto/feature"
Expand Down Expand Up @@ -190,14 +191,7 @@ func (s *FeatureService) checkEnvironmentRole(
zap.String("environmentId", environmentId),
)...,
)
dt, err := statusInternal.WithDetails(&errdetails.LocalizedMessage{
Locale: localizer.GetLocale(),
Message: localizer.MustLocalize(locale.InternalServerError),
})
if err != nil {
return nil, statusInternal.Err()
}
return nil, dt.Err()
return nil, api.NewGRPCStatus(err).Err()
}
}
return editor, nil
Expand All @@ -216,12 +210,5 @@ func (s *FeatureService) reportInternalServerError(
zap.String("environmentId", environmentId),
)...,
)
dt, err := statusInternal.WithDetails(&errdetails.LocalizedMessage{
Locale: localizer.GetLocale(),
Message: localizer.MustLocalize(locale.InternalServerError),
})
if err != nil {
return statusInternal.Err()
}
return dt.Err()
return api.NewGRPCStatus(err).Err()
}
315 changes: 186 additions & 129 deletions pkg/feature/api/error.go

Large diffs are not rendered by default.

187 changes: 24 additions & 163 deletions pkg/feature/api/feature.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"google.golang.org/grpc/status"

evaluation "github.com/bucketeer-io/bucketeer/evaluation/go"
"github.com/bucketeer-io/bucketeer/pkg/api/api"
autoopsdomain "github.com/bucketeer-io/bucketeer/pkg/autoops/domain"
v2ao "github.com/bucketeer-io/bucketeer/pkg/autoops/storage/v2"
domainevent "github.com/bucketeer-io/bucketeer/pkg/domainevent/domain"
Expand Down Expand Up @@ -104,14 +105,7 @@ func (s *FeatureService) GetFeature(
zap.String("environmentId", req.EnvironmentId),
)...,
)
dt, err := statusInternal.WithDetails(&errdetails.LocalizedMessage{
Locale: localizer.GetLocale(),
Message: localizer.MustLocalize(locale.InternalServerError),
})
if err != nil {
return nil, statusInternal.Err()
}
return nil, dt.Err()
return nil, api.NewGRPCStatus(err).Err()
}

// TEMPORARY: Clean up any orphaned variation references before returning to UI
Expand Down Expand Up @@ -213,14 +207,7 @@ func (s *FeatureService) GetFeatures(
zap.String("environmentId", req.EnvironmentId),
)...,
)
dt, err := statusInternal.WithDetails(&errdetails.LocalizedMessage{
Locale: localizer.GetLocale(),
Message: localizer.MustLocalize(locale.InternalServerError),
})
if err != nil {
return nil, statusInternal.Err()
}
return nil, dt.Err()
return nil, api.NewGRPCStatus(err).Err()
}

// TEMPORARY: Clean up any orphaned variation references before returning to UI
Expand Down Expand Up @@ -937,14 +924,7 @@ func (s *FeatureService) CreateFeature(
zap.String("environmentId", req.EnvironmentId),
)...,
)
dt, err := statusInternal.WithDetails(&errdetails.LocalizedMessage{
Locale: localizer.GetLocale(),
Message: localizer.MustLocalize(locale.InternalServerError),
})
if err != nil {
return nil, statusInternal.Err()
}
return nil, dt.Err()
return nil, api.NewGRPCStatus(err).Err()
}
if errs := s.publishDomainEvents(ctx, handler.Events); len(errs) > 0 {
s.logger.Error(
Expand Down Expand Up @@ -1049,14 +1029,7 @@ func (s *FeatureService) createFeatureNoCommand(
zap.String("environmentId", req.EnvironmentId),
)...,
)
dt, err := statusInternal.WithDetails(&errdetails.LocalizedMessage{
Locale: localizer.GetLocale(),
Message: localizer.MustLocalize(locale.InternalServerError),
})
if err != nil {
return nil, statusInternal.Err()
}
return nil, dt.Err()
return nil, api.NewGRPCStatus(err).Err()
}
err = s.domainPublisher.Publish(ctx, event)
if err != nil {
Expand All @@ -1067,14 +1040,7 @@ func (s *FeatureService) createFeatureNoCommand(
zap.String("environmentId", req.EnvironmentId),
)...,
)
dt, err := statusInternal.WithDetails(&errdetails.LocalizedMessage{
Locale: localizer.GetLocale(),
Message: localizer.MustLocalize(locale.InternalServerError),
})
if err != nil {
return nil, statusInternal.Err()
}
return nil, dt.Err()
return nil, api.NewGRPCStatus(err).Err()
}
s.updateFeatureFlagCache(ctx)
return &featureproto.CreateFeatureResponse{Feature: feature.Feature}, nil
Expand Down Expand Up @@ -1978,14 +1944,7 @@ func (s *FeatureService) convUpdateFeatureError(err error, localizer locale.Loca
}
return dt.Err()
default:
dt, err := statusInternal.WithDetails(&errdetails.LocalizedMessage{
Locale: localizer.GetLocale(),
Message: localizer.MustLocalize(locale.InternalServerError),
})
if err != nil {
return statusInternal.Err()
}
return dt.Err()
return api.NewGRPCStatus(err).Err()
}
}

Expand Down Expand Up @@ -2502,14 +2461,7 @@ func (s *FeatureService) evaluateFeatures(
zap.String("tag", tag),
)...,
)
dt, err := statusInternal.WithDetails(&errdetails.LocalizedMessage{
Locale: localizer.GetLocale(),
Message: localizer.MustLocalize(locale.InternalServerError),
})
if err != nil {
return nil, statusInternal.Err()
}
return nil, dt.Err()
return nil, api.NewGRPCStatus(err).Err()
}
return userEvaluations, nil
}
Expand Down Expand Up @@ -2607,12 +2559,12 @@ func (s *FeatureService) getSegmentUsers(
SegmentId: segmentID,
EnvironmentId: EnvironmentId,
}
res, err := s.ListSegmentUsers(ctx, req)
if err != nil {
res, storageErr := s.ListSegmentUsers(ctx, req)
if storageErr != nil {
s.logger.Error(
"Failed to retrieve segment users from storage",
log.FieldsFromIncomingContext(ctx).AddFields(
zap.Error(err),
zap.Error(storageErr),
zap.String("environmentId", EnvironmentId),
zap.String("segmentId", segmentID),
)...,
Expand Down Expand Up @@ -2659,14 +2611,7 @@ func (s *FeatureService) setLastUsedInfosToFeature(
zap.String("environmentId", EnvironmentId),
)...,
)
dt, err := statusInternal.WithDetails(&errdetails.LocalizedMessage{
Locale: localizer.GetLocale(),
Message: localizer.MustLocalize(locale.InternalServerError),
})
if err != nil {
return statusInternal.Err()
}
return dt.Err()
return api.NewGRPCStatus(err).Err()
}
for _, f := range fluiList {
for _, feature := range features {
Expand Down Expand Up @@ -2714,14 +2659,7 @@ func (s *FeatureService) EvaluateFeatures(
zap.String("environmentId", req.EnvironmentId),
)...,
)
dt, err := statusInternal.WithDetails(&errdetails.LocalizedMessage{
Locale: localizer.GetLocale(),
Message: localizer.MustLocalize(locale.InternalServerError),
})
if err != nil {
return nil, statusInternal.Err()
}
return nil, dt.Err()
return nil, api.NewGRPCStatus(err).Err()
}
// If the feature ID is set in the request, it will evaluate a single feature.
features, err := s.getTargetFeatures(fs.([]*featureproto.Feature), req.FeatureId, localizer)
Expand All @@ -2733,14 +2671,7 @@ func (s *FeatureService) EvaluateFeatures(
zap.String("environmentId", req.EnvironmentId),
)...,
)
dt, err := statusInternal.WithDetails(&errdetails.LocalizedMessage{
Locale: localizer.GetLocale(),
Message: localizer.MustLocalize(locale.InternalServerError),
})
if err != nil {
return nil, statusInternal.Err()
}
return nil, dt.Err()
return nil, api.NewGRPCStatus(err).Err()
}
userEvaluations, err := s.evaluateFeatures(ctx, features, req.User, req.EnvironmentId, req.Tag, localizer)
if err != nil {
Expand All @@ -2751,14 +2682,7 @@ func (s *FeatureService) EvaluateFeatures(
zap.String("environmentId", req.EnvironmentId),
)...,
)
dt, err := statusInternal.WithDetails(&errdetails.LocalizedMessage{
Locale: localizer.GetLocale(),
Message: localizer.MustLocalize(locale.InternalServerError),
})
if err != nil {
return nil, statusInternal.Err()
}
return nil, dt.Err()
return nil, api.NewGRPCStatus(err).Err()
}
// If the feature ID is set, it will return a single evaluation
if req.FeatureId != "" {
Expand All @@ -2771,14 +2695,7 @@ func (s *FeatureService) EvaluateFeatures(
zap.String("environmentId", req.EnvironmentId),
)...,
)
dt, err := statusInternal.WithDetails(&errdetails.LocalizedMessage{
Locale: localizer.GetLocale(),
Message: localizer.MustLocalize(locale.InternalServerError),
})
if err != nil {
return nil, statusInternal.Err()
}
return nil, dt.Err()
return nil, api.NewGRPCStatus(err).Err()
}
return &featureproto.EvaluateFeaturesResponse{
UserEvaluations: &featureproto.UserEvaluations{
Expand Down Expand Up @@ -2826,14 +2743,7 @@ func (s *FeatureService) DebugEvaluateFeatures(
zap.String("environmentId", req.EnvironmentId),
)...,
)
dt, err := statusInternal.WithDetails(&errdetails.LocalizedMessage{
Locale: localizer.GetLocale(),
Message: localizer.MustLocalize(locale.InternalServerError),
})
if err != nil {
return nil, statusInternal.Err()
}
return nil, dt.Err()
return nil, api.NewGRPCStatus(err).Err()
}

features := fs.([]*featureproto.Feature)
Expand All @@ -2850,14 +2760,7 @@ func (s *FeatureService) DebugEvaluateFeatures(
zap.String("environmentId", req.EnvironmentId),
)...,
)
dt, err := statusInternal.WithDetails(&errdetails.LocalizedMessage{
Locale: localizer.GetLocale(),
Message: localizer.MustLocalize(locale.InternalServerError),
})
if err != nil {
return nil, statusInternal.Err()
}
return nil, dt.Err()
return nil, api.NewGRPCStatus(err).Err()
}
}

Expand All @@ -2873,14 +2776,7 @@ func (s *FeatureService) DebugEvaluateFeatures(
zap.String("environmentId", req.EnvironmentId),
)...,
)
dt, err := statusInternal.WithDetails(&errdetails.LocalizedMessage{
Locale: localizer.GetLocale(),
Message: localizer.MustLocalize(locale.InternalServerError),
})
if err != nil {
return nil, statusInternal.Err()
}
return nil, dt.Err()
return nil, api.NewGRPCStatus(err).Err()
}

evaluations = append(evaluations, userEvaluations.Evaluations...)
Expand Down Expand Up @@ -2995,14 +2891,7 @@ func (s *FeatureService) CloneFeature(
zap.String("environmentId", req.EnvironmentId),
)...,
)
dt, err := statusInternal.WithDetails(&errdetails.LocalizedMessage{
Locale: localizer.GetLocale(),
Message: localizer.MustLocalize(locale.InternalServerError),
})
if err != nil {
return nil, statusInternal.Err()
}
return nil, dt.Err()
return nil, api.NewGRPCStatus(err).Err()
}
domainFeature := &domain.Feature{
Feature: f.Feature,
Expand Down Expand Up @@ -3057,14 +2946,7 @@ func (s *FeatureService) CloneFeature(
zap.String("environmentId", req.Command.EnvironmentId),
)...,
)
dt, err := statusInternal.WithDetails(&errdetails.LocalizedMessage{
Locale: localizer.GetLocale(),
Message: localizer.MustLocalize(locale.InternalServerError),
})
if err != nil {
return nil, statusInternal.Err()
}
return nil, dt.Err()
return nil, api.NewGRPCStatus(err).Err()
}
if errs := s.publishDomainEvents(ctx, handler.Events); len(errs) > 0 {
s.logger.Error(
Expand Down Expand Up @@ -3125,14 +3007,7 @@ func (s *FeatureService) cloneFeatureNoCommand(
zap.String("targetEnvironmentId", req.TargetEnvironmentId),
)...,
)
dt, err := statusInternal.WithDetails(&errdetails.LocalizedMessage{
Locale: localizer.GetLocale(),
Message: localizer.MustLocalize(locale.InternalServerError),
})
if err != nil {
return nil, statusInternal.Err()
}
return nil, dt.Err()
return nil, api.NewGRPCStatus(err).Err()
}
domainFeature := &domain.Feature{
Feature: f.Feature,
Expand Down Expand Up @@ -3209,14 +3084,7 @@ func (s *FeatureService) cloneFeatureNoCommand(
zap.String("environmentId", req.Command.EnvironmentId),
)...,
)
dt, err := statusInternal.WithDetails(&errdetails.LocalizedMessage{
Locale: localizer.GetLocale(),
Message: localizer.MustLocalize(locale.InternalServerError),
})
if err != nil {
return nil, statusInternal.Err()
}
return nil, dt.Err()
return nil, api.NewGRPCStatus(err).Err()
}
if err = s.domainPublisher.Publish(ctx, event); err != nil {
s.logger.Error(
Expand All @@ -3227,14 +3095,7 @@ func (s *FeatureService) cloneFeatureNoCommand(
zap.String("targetEnvironmentId", req.TargetEnvironmentId),
)...,
)
dt, err := statusInternal.WithDetails(&errdetails.LocalizedMessage{
Locale: localizer.GetLocale(),
Message: localizer.MustLocalize(locale.InternalServerError),
})
if err != nil {
return nil, statusInternal.Err()
}
return nil, dt.Err()
return nil, api.NewGRPCStatus(err).Err()
}
s.updateFeatureFlagCache(ctx)
return &featureproto.CloneFeatureResponse{}, nil
Expand Down
Loading