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: add connection type to goal, query connections when getting goal #1456

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
140 changes: 108 additions & 32 deletions api-description/web-api.swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4356,24 +4356,6 @@ definitions:
- WriteType_OVERRIDE
- WriteType_PATCH
default: WriteType_UNSPECIFIED
ClauseOperator:
type: string
enum:
- EQUALS
- IN
- ENDS_WITH
- STARTS_WITH
- SEGMENT
- GREATER
- GREATER_OR_EQUAL
- LESS
- LESS_OR_EQUAL
- BEFORE
- AFTER
- FEATURE_FLAG
- PARTIALLY_MATCH
default: EQUALS
description: ' - FEATURE_FLAG: Attribute is feature ID, and value is variation ID.'
FeatureVariationType:
type: string
enum:
Expand All @@ -4389,6 +4371,13 @@ definitions:
- Action_ON
- Action_OFF
default: Action_UNKNOWN
GoalConnectionType:
type: string
enum:
- UNKNOWN
- EXPERIMENT
- OPERATION
default: UNKNOWN
ListFlagTriggersResponseFlagTriggerWithUrl:
type: object
properties:
Expand Down Expand Up @@ -5184,6 +5173,61 @@ definitions:
expiry:
type: string
format: int64
autoopsActionType:
type: string
enum:
- UNKNOWN
- ENABLE
- DISABLE
default: UNKNOWN
autoopsAutoOpsRule:
type: object
properties:
id:
type: string
featureId:
type: string
opsType:
$ref: '#/definitions/autoopsOpsType'
clauses:
type: array
items:
type: object
$ref: '#/definitions/bucketeerautoopsClause'
createdAt:
type: string
format: int64
updatedAt:
type: string
format: int64
deleted:
type: boolean
autoOpsStatus:
$ref: '#/definitions/autoopsAutoOpsStatus'
autoopsAutoOpsStatus:
type: string
enum:
- WAITING
- RUNNING
- FINISHED
- STOPPED
default: WAITING
autoopsOpsType:
type: string
enum:
- TYPE_UNKNOWN
- SCHEDULE
- EVENT_RATE
default: TYPE_UNKNOWN
bucketeerautoopsClause:
type: object
properties:
id:
type: string
clause:
$ref: '#/definitions/protobufAny'
actionType:
$ref: '#/definitions/autoopsActionType'
bucketeerenvironmentOrganization:
type: object
properties:
Expand Down Expand Up @@ -5221,6 +5265,19 @@ definitions:
format: int32
ownerEmail:
type: string
bucketeerfeatureClause:
type: object
properties:
id:
type: string
attribute:
type: string
operator:
$ref: '#/definitions/featureClauseOperator'
values:
type: array
items:
type: string
bucketeerfeatureListTagsRequestOrderBy:
type: string
enum:
Expand Down Expand Up @@ -5897,6 +5954,8 @@ definitions:
type: string
description:
type: string
connectionType:
$ref: '#/definitions/GoalConnectionType'
required:
- environmentId
- id
Expand Down Expand Up @@ -6010,6 +6069,18 @@ definitions:
description: This field is set only when APIs return.
archived:
type: boolean
connectionType:
$ref: '#/definitions/GoalConnectionType'
experiments:
type: array
items:
type: object
$ref: '#/definitions/experimentExperiment'
autoOpsRules:
type: array
items:
type: object
$ref: '#/definitions/autoopsAutoOpsRule'
experimentListExperimentsRequestOrderBy:
type: string
enum:
Expand Down Expand Up @@ -6145,19 +6216,24 @@ definitions:
properties:
description:
type: string
featureClause:
type: object
properties:
id:
type: string
attribute:
type: string
operator:
$ref: '#/definitions/ClauseOperator'
values:
type: array
items:
type: string
featureClauseOperator:
type: string
enum:
- EQUALS
- IN
- ENDS_WITH
- STARTS_WITH
- SEGMENT
- GREATER
- GREATER_OR_EQUAL
- LESS
- LESS_OR_EQUAL
- BEFORE
- AFTER
- FEATURE_FLAG
- PARTIALLY_MATCH
default: EQUALS
description: ' - FEATURE_FLAG: Attribute is feature ID, and value is variation ID.'
featureCloneFeatureCommand:
type: object
properties:
Expand Down Expand Up @@ -6644,7 +6720,7 @@ definitions:
type: array
items:
type: object
$ref: '#/definitions/featureClause'
$ref: '#/definitions/bucketeerfeatureClause'
featureSegment:
type: object
properties:
Expand Down
2 changes: 1 addition & 1 deletion manifests/bucketeer/charts/web/values.yaml

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions migration/mysql/20250116060049_update_goal_table.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE `goal` ADD COLUMN `connection_type` INT NOT NULL DEFAULT 0 AFTER `description`;
3 changes: 2 additions & 1 deletion migration/mysql/atlas.sum
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
h1:ByERmIG4qrnBTy9Iu6SJWvS0WrGAx+McScOzEnkb+GU=
h1:1gFvYJwtEn7dAVsV68Nzh0bXhPLPHh6OHmeV2U7vjQU=
20240626022133_initialization.sql h1:u9qmPkwWX7PN92qEcDDfR92lrMpwadQSMxUJgv6LjQ0=
20240708065726_update_audit_log_table.sql h1:k7gK8Njv1yHMsYXAQtSgMaSbXy4lxyZ9MPzbJyMyyoM=
20240815043128_update_auto_ops_rule_table.sql h1:6ib+XfS1uu9AUO3qESvkpUfOu3qUsLwHm9KHcrGEz0E=
Expand All @@ -22,3 +22,4 @@ h1:ByERmIG4qrnBTy9Iu6SJWvS0WrGAx+McScOzEnkb+GU=
20250109061411_update_tag_table.sql h1:3QsxRDVjdv45SkOKTUFswaSFaXV2ViHoqjlr6XR5fmY=
20250115040347_update_account_v2_table.sql h1:nEzBj41mgpXbQGgbNaIZ9thMqvtfamLO9NHISpEwMm8=
20250116054703_remove_environment_namespace_column.sql h1:UNiN/syYAs8nUQOkMw3RRvDQBQU/kKYv7B3XBhL6qPM=
20250116060049_update_goal_table.sql h1:zEhXMf2hntdk2Im9klR76vx6PEAh+cJwk3fKgm2gGPs=
4 changes: 4 additions & 0 deletions pkg/experiment/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"google.golang.org/grpc/status"

accountclient "github.com/bucketeer-io/bucketeer/pkg/account/client"
autoopsclient "github.com/bucketeer-io/bucketeer/pkg/autoops/client"
featureclient "github.com/bucketeer-io/bucketeer/pkg/feature/client"
"github.com/bucketeer-io/bucketeer/pkg/locale"
"github.com/bucketeer-io/bucketeer/pkg/log"
Expand Down Expand Up @@ -51,6 +52,7 @@ func WithLogger(l *zap.Logger) Option {
type experimentService struct {
featureClient featureclient.Client
accountClient accountclient.Client
autoOpsClient autoopsclient.Client
mysqlClient mysql.Client
publisher publisher.Publisher
opts *options
Expand All @@ -60,6 +62,7 @@ type experimentService struct {
func NewExperimentService(
featureClient featureclient.Client,
accountClient accountclient.Client,
autoOpsClient autoopsclient.Client,
mysqlClient mysql.Client,
publisher publisher.Publisher,
opts ...Option,
Expand All @@ -73,6 +76,7 @@ func NewExperimentService(
return &experimentService{
featureClient: featureClient,
accountClient: accountClient,
autoOpsClient: autoOpsClient,
mysqlClient: mysqlClient,
publisher: publisher,
opts: dopts,
Expand Down
6 changes: 5 additions & 1 deletion pkg/experiment/api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
md "google.golang.org/grpc/metadata"

accountclientmock "github.com/bucketeer-io/bucketeer/pkg/account/client/mock"
autoopsclientmock "github.com/bucketeer-io/bucketeer/pkg/autoops/client/mock"
featureclientmock "github.com/bucketeer-io/bucketeer/pkg/feature/client/mock"
publishermock "github.com/bucketeer-io/bucketeer/pkg/pubsub/publisher/mock"
"github.com/bucketeer-io/bucketeer/pkg/rpc"
Expand All @@ -40,12 +41,14 @@ func TestNewExperimentService(t *testing.T) {
defer mockController.Finish()
featureClientMock := featureclientmock.NewMockClient(mockController)
accountClientMock := accountclientmock.NewMockClient(mockController)
autoOpsClientMock := autoopsclientmock.NewMockClient(mockController)
mysqlClient := mysqlmock.NewMockClient(mockController)
p := publishermock.NewMockPublisher(mockController)
logger := zap.NewNop()
s := NewExperimentService(
featureClientMock,
accountClientMock,
autoOpsClientMock,
mysqlClient,
p,
WithLogger(logger),
Expand Down Expand Up @@ -104,10 +107,11 @@ func createExperimentService(c *gomock.Controller, specifiedEnvironmentId *strin
},
}
accountClientMock.EXPECT().GetAccountV2ByEnvironmentID(gomock.Any(), gomock.Any()).Return(ar, nil).AnyTimes()
autoOpsClientMock := autoopsclientmock.NewMockClient(c)
mysqlClient := mysqlmock.NewMockClient(c)
p := publishermock.NewMockPublisher(c)
p.EXPECT().Publish(gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
es := NewExperimentService(featureClientMock, accountClientMock, mysqlClient, p)
es := NewExperimentService(featureClientMock, accountClientMock, autoOpsClientMock, mysqlClient, p)
return es.(*experimentService)
}

Expand Down
65 changes: 63 additions & 2 deletions pkg/experiment/api/goal.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/bucketeer-io/bucketeer/pkg/log"
"github.com/bucketeer-io/bucketeer/pkg/storage/v2/mysql"
accountproto "github.com/bucketeer-io/bucketeer/proto/account"
autoopsproto "github.com/bucketeer-io/bucketeer/proto/autoops"
eventproto "github.com/bucketeer-io/bucketeer/proto/event/domain"
proto "github.com/bucketeer-io/bucketeer/proto/experiment"
)
Expand Down Expand Up @@ -76,6 +77,18 @@ func (s *experimentService) GetGoal(ctx context.Context, req *proto.GetGoalReque
}
return nil, dt.Err()
}
err = s.mapConnectedOperations(ctx, []*proto.Goal{goal.Goal}, req.EnvironmentId)
if err != nil {
s.logger.Error("Failed to map connected operations", zap.Error(err))
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 &proto.GetGoalResponse{Goal: goal.Goal}, nil
}

Expand Down Expand Up @@ -174,6 +187,19 @@ func (s *experimentService) ListGoals(
}
return nil, dt.Err()
}
err = s.mapConnectedOperations(ctx, goals, req.EnvironmentId)
if err != nil {
s.logger.Error("Failed to map connected operations", zap.Error(err))
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 &proto.ListGoalsResponse{
Goals: goals,
Cursor: strconv.Itoa(nextCursor),
Expand Down Expand Up @@ -212,6 +238,41 @@ func (s *experimentService) newGoalListOrders(
return []*mysql.Order{mysql.NewOrder(column, direction)}, nil
}

func (s *experimentService) mapConnectedOperations(
ctx context.Context,
goals []*proto.Goal,
environmentID string,
) error {
listAutoOpRulesResp, err := s.autoOpsClient.ListAutoOpsRules(ctx, &autoopsproto.ListAutoOpsRulesRequest{
EnvironmentId: environmentID,
})
if err != nil {
return err
}
autoOpsRules := listAutoOpRulesResp.AutoOpsRules
goalOpsMap := make(map[string][]*autoopsproto.AutoOpsRule)
for _, rule := range autoOpsRules {
for _, clause := range rule.Clauses {
if clause.Clause.MessageIs(&autoopsproto.OpsEventRateClause{}) {
c := &autoopsproto.OpsEventRateClause{}
if err := clause.Clause.UnmarshalTo(c); err != nil {
return err
}
if c.GoalId == "" {
continue
}
goalOpsMap[c.GoalId] = append(goalOpsMap[c.GoalId], rule)
}
}
}
for _, goal := range goals {
if ops, ok := goalOpsMap[goal.Id]; ok {
goal.AutoOpsRules = ops
}
}
return nil
}

func (s *experimentService) CreateGoal(
ctx context.Context,
req *proto.CreateGoalRequest,
Expand All @@ -229,7 +290,7 @@ func (s *experimentService) CreateGoal(
if err := validateCreateGoalRequest(req, localizer); err != nil {
return nil, err
}
goal, err := domain.NewGoal(req.Command.Id, req.Command.Name, req.Command.Description)
goal, err := domain.NewGoal(req.Command.Id, req.Command.Name, req.Command.Description, proto.Goal_UNKNOWN)
if err != nil {
s.logger.Error(
"Failed to create a new goal",
Expand Down Expand Up @@ -316,7 +377,7 @@ func (s *experimentService) createGoalNoCommand(
if err := validateCreateGoalNoCommandRequest(req, localizer); err != nil {
return nil, err
}
goal, err := domain.NewGoal(req.Id, req.Name, req.Description)
goal, err := domain.NewGoal(req.Id, req.Name, req.Description, req.ConnectionType)
if err != nil {
s.logger.Error(
"Failed to create a new goal",
Expand Down
Loading
Loading