-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
syncing up to d15c0957749f70fb6b18287b85bb6d65b9380136
Co-authored-by: Carl Noel <[email protected]>
- Loading branch information
1 parent
d21a094
commit af42a9e
Showing
31 changed files
with
1,066 additions
and
680 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
package flags | ||
|
||
import ( | ||
"github.com/superblocksteam/agent/internal/flags/options" | ||
"github.com/superblocksteam/agent/pkg/flagsclient" | ||
"github.com/superblocksteam/agent/pkg/observability" | ||
"github.com/superblocksteam/agent/pkg/utils" | ||
apiv1 "github.com/superblocksteam/agent/types/gen/go/api/v1" | ||
"go.uber.org/zap" | ||
) | ||
|
||
type launchdarkly struct { | ||
flagsclient.FlagsClient | ||
|
||
logger *zap.Logger | ||
options options.Options | ||
} | ||
|
||
func LaunchDarkly(client flagsclient.FlagsClient, ops ...options.Option) Client { | ||
settings := options.Apply(ops...) | ||
|
||
return &launchdarkly{ | ||
FlagsClient: client, | ||
logger: settings.Logger, | ||
options: settings, | ||
} | ||
} | ||
|
||
func (flags *launchdarkly) GetFlagSource() int { | ||
return SourceLaunchDarkly | ||
} | ||
|
||
func (flags *launchdarkly) GetStepSizeByOrg(orgId string) int { | ||
return flags.GetIntVariationByOrg("agent.quota.org.step.size.bytes", orgId, flags.options.DefaultStepSizeByOrg) | ||
} | ||
|
||
func (flags *launchdarkly) GetStepSizeV2(tier string, orgId string) int { | ||
return flags.GetIntVariation("agent.quota.step.size.bytes", tier, orgId, flags.options.DefaultStepSizeByOrg) | ||
} | ||
|
||
func (flags *launchdarkly) GetStepRateByOrg(orgId string) int { | ||
return flags.GetIntVariationByOrg("agent.quota.org.step.rate.seconds", orgId, flags.options.DefaultStepRateByOrg) | ||
} | ||
|
||
func (flags *launchdarkly) GetStepRateV2(tier string, orgId string) int { | ||
return flags.GetIntVariation("agent.quota.org.step.rate.seconds", tier, orgId, flags.options.DefaultStepRateByOrg) | ||
} | ||
|
||
func (flags *launchdarkly) GetStepRatePerApiByOrg(workflowId string) int { | ||
return flags.GetIntVariationByOrg("agent.quota.api.step.rate.seconds", workflowId, flags.options.DefaultStepRatePerApiByOrg) | ||
} | ||
|
||
func (flags *launchdarkly) GetStepRatePerApiV2(tier string, orgId string) int { | ||
return flags.GetIntVariation("agent.quota.api.step.rate.seconds", tier, orgId, flags.options.DefaultStepRatePerApiByOrg) | ||
} | ||
|
||
func (flags *launchdarkly) GetStepRatePerPluginV2(tier string, orgId string, pluginName string) int { | ||
return flags.GetIntVariationCustomDims("agent.quota.plugin.step.rate.seconds", orgId, map[string]string{"tier": tier, "plugin": pluginName}, flags.options.DefaultStepRatePerPluginByOrg) | ||
} | ||
|
||
func (flags *launchdarkly) GetStepRatePerUserByOrg(orgId string) int { | ||
return flags.GetIntVariationByOrg("agent.quota.user.step.rate.seconds", orgId, flags.options.DefaultStepRatePerUserByOrg) | ||
} | ||
|
||
func (flags *launchdarkly) GetStepRatePerUserV2(tier string, orgId string) int { | ||
return flags.GetIntVariation("agent.quota.user.step.rate.seconds", tier, orgId, flags.options.DefaultStepRatePerUserByOrg) | ||
} | ||
|
||
func (flags *launchdarkly) GetStepDurationByOrg(orgId string) int { | ||
return flags.GetIntVariationByOrg("agent.quota.org.step.duration.milliseconds", orgId, flags.options.DefaultStepDurationByOrg) | ||
} | ||
|
||
func (flags *launchdarkly) GetStepDurationV2(tier string, orgId string) int { | ||
return flags.GetIntVariation("agent.quota.org.step.duration.milliseconds", tier, orgId, flags.options.DefaultStepDurationByOrg) | ||
} | ||
|
||
func (flags *launchdarkly) GetMaxParallelPoolSizeByAPI(apiId string) int { | ||
return flags.GetIntVariationByOrg("agent.quota.api.parallel.pool.size.max", apiId, flags.options.DefaultMaxParallelPoolSizeByAPI) | ||
} | ||
|
||
func (flags *launchdarkly) GetMaxParallelPoolSizeV2(tier string, orgId string) int { | ||
return flags.GetIntVariation("agent.quota.api.parallel.pool.size.max", tier, orgId, flags.options.DefaultMaxParallelPoolSizeByAPI) | ||
} | ||
|
||
func (flags *launchdarkly) GetMaxStreamSendSizeByOrg(orgId string) int { | ||
return flags.GetIntVariationByOrg("agent.quota.org.stream.send.size.max", orgId, flags.options.DefaultMaxStreamSendSizeByOrg) | ||
} | ||
|
||
func (flags *launchdarkly) GetMaxStreamSendSizeV2(tier string, orgId string) int { | ||
return flags.GetIntVariation("agent.quota.org.stream.send.size.max", tier, orgId, flags.options.DefaultMaxStreamSendSizeByOrg) | ||
} | ||
|
||
func (flags *launchdarkly) GetComputeMinutesPerWeekV2(tier string, orgId string) float64 { | ||
return flags.GetFloatVariation("agent.quota.minutes.rate.week", tier, orgId, flags.options.DefaultMaxComputeMinutesPerWeek) | ||
} | ||
|
||
func (flags *launchdarkly) GetGoWorkerEnabled(tier string, orgId string) bool { | ||
return flags.GetBoolVariation("worker.go.enabled", tier, orgId, flags.options.DefaultGoWorkerEnabled) | ||
} | ||
|
||
func (flags *launchdarkly) GetWorkflowPluginInheritanceEnabled(orgId string) bool { | ||
return flags.GetBoolVariationByOrg("agent.plugins.workflow.inherit_parameters.enabled", orgId, flags.options.DefaultWorkflowPluginInheritanceEnabled) | ||
} | ||
|
||
func (flags *launchdarkly) GetApiTimeoutV2(api *apiv1.Api, tier string) float64 { | ||
fallback := flags.options.DefaultApiTimeout | ||
orgId := api.GetMetadata().GetOrganization() | ||
|
||
logger := flags.logger.With( | ||
zap.String(observability.OBS_TAG_ORG_ID, orgId), | ||
zap.String(observability.OBS_TAG_API_ID, api.GetMetadata().GetId()), | ||
zap.String(observability.OBS_TAG_ORG_TIER, tier), | ||
zap.String(observability.OBS_TAG_RESOURCE_TYPE, utils.ApiType(api)), | ||
) | ||
|
||
var flag string | ||
{ | ||
switch api.GetTrigger().GetConfig().(type) { | ||
case *apiv1.Trigger_Application_: | ||
flag = "agent.quota.api.timeout.trigger.application.milliseconds" | ||
case *apiv1.Trigger_Workflow_: | ||
flag = "agent.quota.api.timeout.trigger.workflow.milliseconds" | ||
case *apiv1.Trigger_Job_: | ||
flag = "agent.quota.api.timeout.trigger.job.milliseconds" | ||
default: | ||
logger.Warn("could not retrieve flag value: unknown trigger; returning default value") | ||
return fallback | ||
} | ||
} | ||
|
||
return flags.GetFloatVariation(flag, tier, orgId, fallback) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package flags | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/superblocksteam/agent/internal/flags/options" | ||
"github.com/superblocksteam/agent/pkg/flagsclient" | ||
apiv1 "github.com/superblocksteam/agent/types/gen/go/api/v1" | ||
commonv1 "github.com/superblocksteam/agent/types/gen/go/common/v1" | ||
) | ||
|
||
func TestGetApiTimeoutByOrgTier(t *testing.T) { | ||
t.Parallel() | ||
|
||
for _, test := range []struct { | ||
name string | ||
tier string | ||
api *apiv1.Api | ||
shouldCallLaunchDarkly bool | ||
expected float64 | ||
expectedOrg string | ||
expectedFlag string | ||
}{ | ||
{ | ||
name: "nil api", | ||
tier: "TRIAL", | ||
api: nil, | ||
expected: 500, | ||
}, | ||
{ | ||
name: "nil trigger", | ||
tier: "TRIAL", | ||
api: &apiv1.Api{}, | ||
expected: 500, | ||
}, | ||
{ | ||
name: "application", | ||
tier: "TRIAL", | ||
api: &apiv1.Api{ | ||
Trigger: &apiv1.Trigger{Config: &apiv1.Trigger_Application_{}}, | ||
Metadata: &commonv1.Metadata{Organization: "asdf"}, | ||
}, | ||
shouldCallLaunchDarkly: true, | ||
expected: 1000, | ||
expectedOrg: "asdf", | ||
expectedFlag: "agent.quota.api.timeout.trigger.application.milliseconds", | ||
}, | ||
{ | ||
name: "workflow", | ||
tier: "ENTERPRISE", | ||
api: &apiv1.Api{ | ||
Trigger: &apiv1.Trigger{Config: &apiv1.Trigger_Workflow_{}}, | ||
Metadata: &commonv1.Metadata{Organization: "asdf"}, | ||
}, | ||
shouldCallLaunchDarkly: true, | ||
expected: 4000, | ||
expectedOrg: "asdf", | ||
expectedFlag: "agent.quota.api.timeout.trigger.workflow.milliseconds", | ||
}, | ||
{ | ||
name: "job", | ||
tier: "FREE", | ||
api: &apiv1.Api{ | ||
Trigger: &apiv1.Trigger{Config: &apiv1.Trigger_Job_{}}, | ||
Metadata: &commonv1.Metadata{Organization: "asdf"}, | ||
}, | ||
shouldCallLaunchDarkly: true, | ||
expected: 6000, | ||
expectedOrg: "asdf", | ||
expectedFlag: "agent.quota.api.timeout.trigger.job.milliseconds", | ||
}, | ||
{ | ||
name: "malformed trigger", | ||
tier: "TRIAL", | ||
api: &apiv1.Api{Trigger: &apiv1.Trigger{}}, | ||
expected: 500, | ||
}, | ||
} { | ||
t.Run(test.name, func(t *testing.T) { | ||
anyDefaultTimeout := float64(500) | ||
|
||
mockFlagsClient := flagsclient.NewMockFlagsClient(t) | ||
if test.shouldCallLaunchDarkly { | ||
mockFlagsClient.On("GetFloatVariation", test.expectedFlag, test.tier, test.expectedOrg, anyDefaultTimeout).Return(test.expected).Once() | ||
} | ||
|
||
client := LaunchDarkly(mockFlagsClient, options.WithDefaultApiTimeout(anyDefaultTimeout)) | ||
|
||
assert.Equal(t, test.expected, client.GetApiTimeoutV2(test.api, test.tier), test.name) | ||
}) | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.