Skip to content

Commit 1e5cfbe

Browse files
authored
Merge pull request #252 from LalitDeore/workflow-slowdown
Added child org workflow execution statistics and licensing feature to support workflow slowdown
2 parents 785c5a2 + 86890dd commit 1e5cfbe

File tree

4 files changed

+126
-26
lines changed

4 files changed

+126
-26
lines changed

db-connector.go

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13493,7 +13493,23 @@ func GetEsConfig(defaultCreds bool) *opensearch.Client {
1349313493

1349413494
func checkNoInternet() OnpremLicense {
1349513495

13496-
license := OnpremLicense{}
13496+
license := OnpremLicense{
13497+
Valid: false,
13498+
Tenant: OnpremLimits{
13499+
Active: false,
13500+
Limit: 3,
13501+
},
13502+
Environment: OnpremLimits{
13503+
Active: false,
13504+
Limit: 1,
13505+
},
13506+
WorkflowExecutions: OnpremLimits{
13507+
Active: false,
13508+
Limit: 10000,
13509+
},
13510+
Timeout: "",
13511+
Branding: false,
13512+
}
1349713513
licenseKey := os.Getenv("SHUFFLE_LICENSE")
1349813514
if len(licenseKey) == 0 {
1349913515
return license
@@ -13519,29 +13535,36 @@ func checkNoInternet() OnpremLicense {
1351913535
sum := sha256.Sum256([]byte(licenseKeyPart))
1352013536
encodedString := hex.EncodeToString(sum[:])
1352113537

13522-
tenantKey := ""
13538+
workflowLimitKey := ""
1352313539
if len(licenseParts) > 1 {
13524-
tenantKey = licenseParts[1]
13540+
workflowLimitKey = licenseParts[1]
13541+
}
13542+
13543+
workflowLimitHash := sha256.Sum256([]byte(workflowLimitKey))
13544+
encodedWorkflowLimit := hex.EncodeToString(workflowLimitHash[:])
13545+
13546+
tenantKey := ""
13547+
if len(licenseParts) > 2 {
13548+
tenantKey = licenseParts[2]
1352513549
}
1352613550

1352713551
tenantHash := sha256.Sum256([]byte(tenantKey))
1352813552
encodedTenant := hex.EncodeToString(tenantHash[:])
1352913553
environmentKey := ""
13530-
if len(licenseParts) > 2 {
13531-
environmentKey = licenseParts[2]
13554+
if len(licenseParts) > 3 {
13555+
environmentKey = licenseParts[3]
1353213556
}
1353313557

1353413558
environmentHash := sha256.Sum256([]byte(environmentKey))
1353513559
encodedEnvironment := hex.EncodeToString(environmentHash[:])
1353613560

1353713561
branding := ""
13538-
if len(licenseParts) > 3 {
13539-
branding = licenseParts[3]
13562+
if len(licenseParts) > 4 {
13563+
branding = licenseParts[4]
1354013564
}
1354113565

1354213566
brandingHash := sha256.Sum256([]byte(branding))
1354313567
encodedBranding := hex.EncodeToString(brandingHash[:])
13544-
1354513568
// Returns a map[sha256]timeout string
1354613569
onpremKeys := GetOnpremKeys()
1354713570
if timeout, ok := onpremKeys[encodedString]; ok {
@@ -13594,6 +13617,17 @@ func checkNoInternet() OnpremLicense {
1359413617
license.Branding = false
1359513618
}
1359613619

13620+
//check workflow limit
13621+
if len(workflowLimitKey) > 0 && len(encodedWorkflowLimit) > 0 {
13622+
amount := GetWorkflowRunAmount(encodedWorkflowLimit)
13623+
license.WorkflowExecutions.Limit = int64(amount)
13624+
if amount > 10000 {
13625+
license.WorkflowExecutions.Active = true
13626+
} else {
13627+
license.WorkflowExecutions.Active = false
13628+
}
13629+
}
13630+
1359713631
return license
1359813632
} else {
1359913633
log.Printf("[ERROR] License key has expired on %s", timeout)

shared.go

Lines changed: 55 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2651,7 +2651,7 @@ func HandleSetEnvironments(resp http.ResponseWriter, request *http.Request) {
26512651
}
26522652

26532653
licenseOrg := HandleCheckLicense(ctx, *parentOrg)
2654-
if !licenseOrg.SyncFeatures.MultiEnv.Active && int64(len(envs)) > licenseOrg.SyncFeatures.MultiEnv.Limit {
2654+
if int64(len(envs)) > licenseOrg.SyncFeatures.MultiEnv.Limit {
26552655
resp.WriteHeader(401)
26562656
resp.Write([]byte(fmt.Sprintf(`{"success": false, "reason": "You have reached the limit of %d environments for your subscription. Upgrade to an enterprise plan or contact [email protected] for more info."}`, licenseOrg.SyncFeatures.MultiEnv.Limit)))
26572657
return
@@ -30822,6 +30822,10 @@ func HandleCheckLicense(ctx context.Context, org Org) Org {
3082230822

3082330823
org.SyncFeatures.Branding.Active = false
3082430824
org.Licensed = false
30825+
30826+
org.SyncFeatures.WorkflowExecutions.Limit = 10000
30827+
org.SyncFeatures.WorkflowExecutions.Active = false
30828+
3082530829
return org
3082630830
}
3082730831
features := SyncFeatures{}
@@ -30835,20 +30839,43 @@ func HandleCheckLicense(ctx context.Context, org Org) Org {
3083530839
licenseData := string(data)
3083630840
if licenseData == "true" {
3083730841
org.Licensed = true
30842+
org.SyncFeatures.MultiEnv.Active = features.MultiEnv.Active
30843+
org.SyncFeatures.MultiEnv.Limit = features.MultiEnv.Limit
30844+
30845+
org.SyncFeatures.MultiTenant.Active = features.MultiTenant.Active
30846+
org.SyncFeatures.MultiTenant.Limit = features.MultiTenant.Limit
30847+
30848+
org.SyncFeatures.Branding.Active = features.Branding.Active
30849+
30850+
org.SyncFeatures.WorkflowExecutions.Active = features.WorkflowExecutions.Active
30851+
if features.WorkflowExecutions.Limit < 10000 {
30852+
org.SyncFeatures.WorkflowExecutions.Limit = 10000
30853+
} else {
30854+
org.SyncFeatures.WorkflowExecutions.Limit = features.WorkflowExecutions.Limit
30855+
}
3083830856
} else {
30839-
org.Licensed = false
30857+
org.SyncFeatures.MultiEnv.Active = false
30858+
org.SyncFeatures.MultiEnv.Limit = 1
30859+
30860+
org.SyncFeatures.MultiTenant.Active = false
30861+
org.SyncFeatures.MultiTenant.Limit = 3
30862+
30863+
org.SyncFeatures.Branding.Active = features.Branding.Active
30864+
org.SyncFeatures.WorkflowExecutions.Limit = 10000
30865+
org.SyncFeatures.WorkflowExecutions.Active = false
3084030866
}
3084130867
} else {
3084230868
org.Licensed = false
30843-
}
30869+
org.SyncFeatures.MultiEnv.Active = false
30870+
org.SyncFeatures.MultiEnv.Limit = 1
3084430871

30845-
org.SyncFeatures.MultiEnv.Active = features.MultiEnv.Active
30846-
org.SyncFeatures.MultiEnv.Limit = features.MultiEnv.Limit
30847-
30848-
org.SyncFeatures.MultiTenant.Active = features.MultiTenant.Active
30849-
org.SyncFeatures.MultiTenant.Limit = features.MultiTenant.Limit
30872+
org.SyncFeatures.MultiTenant.Active = false
30873+
org.SyncFeatures.MultiTenant.Limit = 3
3085030874

30851-
org.SyncFeatures.Branding.Active = features.Branding.Active
30875+
org.SyncFeatures.Branding.Active = features.Branding.Active
30876+
org.SyncFeatures.WorkflowExecutions.Limit = 10000
30877+
org.SyncFeatures.WorkflowExecutions.Active = false
30878+
}
3085230879

3085330880
org.SyncFeatures.AppExecutions.Active = features.AppExecutions.Active
3085430881
org.SyncFeatures.AppExecutions.Limit = features.AppExecutions.Limit
@@ -30883,9 +30910,6 @@ func HandleCheckLicense(ctx context.Context, org Org) Org {
3088330910
org.SyncFeatures.Autocomplete.Active = features.Autocomplete.Active
3088430911
org.SyncFeatures.Autocomplete.Limit = features.Autocomplete.Limit
3088530912

30886-
org.SyncFeatures.WorkflowExecutions.Active = features.WorkflowExecutions.Active
30887-
org.SyncFeatures.WorkflowExecutions.Limit = features.WorkflowExecutions.Limit
30888-
3088930913
org.SyncFeatures.Authentication.Active = features.Authentication.Active
3089030914
org.SyncFeatures.Authentication.Limit = features.Authentication.Limit
3089130915

@@ -30902,6 +30926,17 @@ func HandleCheckLicense(ctx context.Context, org Org) Org {
3090230926
org.SyncFeatures.MultiTenant.Limit = 3
3090330927
}
3090430928
}
30929+
} else {
30930+
org.Licensed = false
30931+
org.SyncFeatures.MultiEnv.Active = false
30932+
org.SyncFeatures.MultiEnv.Limit = 1
30933+
30934+
org.SyncFeatures.MultiTenant.Active = false
30935+
org.SyncFeatures.MultiTenant.Limit = 3
30936+
30937+
org.SyncFeatures.Branding.Active = false
30938+
org.SyncFeatures.WorkflowExecutions.Limit = 10000
30939+
org.SyncFeatures.WorkflowExecutions.Active = false
3090530940
}
3090630941

3090730942
// For the subsctiption
@@ -30932,6 +30967,8 @@ func HandleCheckLicense(ctx context.Context, org Org) Org {
3093230967
org.SyncFeatures.MultiTenant.Limit = license.Tenant.Limit
3093330968
org.SyncFeatures.MultiTenant.Active = license.Tenant.Active
3093430969
org.SyncFeatures.Branding.Active = license.Branding
30970+
org.SyncFeatures.WorkflowExecutions.Active = license.WorkflowExecutions.Active
30971+
org.SyncFeatures.WorkflowExecutions.Limit = license.WorkflowExecutions.Limit
3093530972

3093630973
org.SyncFeatures.AppExecutions.Active = true
3093730974
org.SyncFeatures.Webhook.Active = true
@@ -30944,7 +30981,6 @@ func HandleCheckLicense(ctx context.Context, org Org) Org {
3094430981
org.SyncFeatures.Notifications.Active = true
3094530982
org.SyncFeatures.Workflows.Active = true
3094630983
org.SyncFeatures.Autocomplete.Active = true
30947-
org.SyncFeatures.WorkflowExecutions.Active = true
3094830984
org.SyncFeatures.Authentication.Active = true
3094930985
org.SyncFeatures.Schedule.Active = true
3095030986
org.SyncFeatures.Apps.Active = true
@@ -30958,6 +30994,9 @@ func HandleCheckLicense(ctx context.Context, org Org) Org {
3095830994
org.SyncFeatures.MultiTenant.Active = false
3095930995

3096030996
org.SyncFeatures.Branding.Active = false
30997+
30998+
org.SyncFeatures.WorkflowExecutions.Active = false
30999+
org.SyncFeatures.WorkflowExecutions.Limit = 10000
3096131000
}
3096231001

3096331002
parsedEula := GetOnpremPaidEula()
@@ -31029,6 +31068,9 @@ func HandleCheckLicense(ctx context.Context, org Org) Org {
3102931068
org.SyncFeatures.MultiTenant.Active = false
3103031069

3103131070
org.SyncFeatures.Branding.Active = false
31071+
31072+
org.SyncFeatures.WorkflowExecutions.Active = false
31073+
org.SyncFeatures.WorkflowExecutions.Limit = 10000
3103231074
}
3103331075

3103431076
return org

stats.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -810,6 +810,14 @@ func IncrementCacheDump(ctx context.Context, orgId, dataType string, amount ...i
810810
}
811811
}
812812

813+
if len(tmpOrgDetail.ManagerOrgs) > 0 && (dataType == "workflow_executions") {
814+
for _, managerOrg := range tmpOrgDetail.ManagerOrgs {
815+
if len(managerOrg.Id) == 36 {
816+
IncrementCache(ctx, managerOrg.Id, "childorg_workflow_executions", int(dbDumpInterval))
817+
}
818+
}
819+
}
820+
813821
concurrentTxn := false
814822
errMsg := ""
815823

@@ -1382,6 +1390,7 @@ func handleDailyCacheUpdate(executionInfo *ExecutionInfo) *ExecutionInfo {
13821390
executionInfo.HourlySubflowExecutions = 0
13831391
executionInfo.HourlyWorkflowExecutions = 0
13841392
executionInfo.HourlyWorkflowExecutionsFinished = 0
1393+
executionInfo.HourlyChildWorkflowExecutions = 0
13851394
executionInfo.HourlyWorkflowExecutionsFailed = 0
13861395
executionInfo.HourlyOrgSyncActions = 0
13871396
executionInfo.HourlyCloudExecutions = 0
@@ -1394,6 +1403,7 @@ func handleDailyCacheUpdate(executionInfo *ExecutionInfo) *ExecutionInfo {
13941403
executionInfo.DailySubflowExecutions = 0
13951404
executionInfo.DailyWorkflowExecutions = 0
13961405
executionInfo.DailyWorkflowExecutionsFinished = 0
1406+
executionInfo.DailyChildWorkflowExecutions = 0
13971407
executionInfo.DailyWorkflowExecutionsFailed = 0
13981408
executionInfo.DailyOrgSyncActions = 0
13991409
executionInfo.DailyCloudExecutions = 0
@@ -1412,6 +1422,7 @@ func handleDailyCacheUpdate(executionInfo *ExecutionInfo) *ExecutionInfo {
14121422
executionInfo.WeeklyOrgSyncActions = 0
14131423
executionInfo.WeeklyCloudExecutions = 0
14141424
executionInfo.WeeklyOnpremExecutions = 0
1425+
executionInfo.WeeklyChildWorkflowExecutions = 0
14151426

14161427
// Cleans up "random" stats as well
14171428
for additionIndex, _ := range executionInfo.Additions {
@@ -1430,6 +1441,7 @@ func handleDailyCacheUpdate(executionInfo *ExecutionInfo) *ExecutionInfo {
14301441
executionInfo.MonthlySubflowExecutions = 0
14311442
executionInfo.MonthlyWorkflowExecutions = 0
14321443
executionInfo.MonthlyWorkflowExecutionsFinished = 0
1444+
executionInfo.MonthlyChildWorkflowExecutions = 0
14331445
executionInfo.MonthlyWorkflowExecutionsFailed = 0
14341446
executionInfo.MonthlyOrgSyncActions = 0
14351447
executionInfo.MonthlyCloudExecutions = 0
@@ -1504,6 +1516,12 @@ func HandleIncrement(dataType string, orgStatistics *ExecutionInfo, increment ui
15041516
orgStatistics.DailyWorkflowExecutions += int64(increment)
15051517
orgStatistics.HourlyWorkflowExecutions += int64(increment)
15061518

1519+
} else if dataType == "childorg_workflow_executions" {
1520+
orgStatistics.TotalChildWorkflowExecutions += int64(increment)
1521+
orgStatistics.MonthlyChildWorkflowExecutions += int64(increment)
1522+
orgStatistics.WeeklyChildWorkflowExecutions += int64(increment)
1523+
orgStatistics.DailyChildWorkflowExecutions += int64(increment)
1524+
orgStatistics.HourlyChildWorkflowExecutions += int64(increment)
15071525
} else if dataType == "workflow_executions_finished" {
15081526
orgStatistics.TotalWorkflowExecutionsFinished += int64(increment)
15091527
orgStatistics.MonthlyWorkflowExecutionsFinished += int64(increment)

structs.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -413,13 +413,15 @@ type ExecutionInfo struct {
413413
TotalCloudExecutions int64 `json:"total_cloud_executions" datastore:"total_cloud_executions"`
414414
TotalOnpremExecutions int64 `json:"total_onprem_executions" datastore:"total_onprem_executions"`
415415
TotalAIUsage int64 `json:"total_ai_executions" datastore:"total_ai_executions"`
416+
TotalChildWorkflowExecutions int64 `json:"total_child_workflow_executions" datastore:"total_child_workflow_executions"`
416417

417418
MonthlyApiUsage int64 `json:"monthly_api_usage,omitempty" datastore:"monthly_api_usage"`
418419
MonthlyChildAppExecutions int64 `json:"monthly_child_app_executions,omitempty" datastore:"monthly_child_app_executions"`
419420
MonthlyAppExecutions int64 `json:"monthly_app_executions,omitempty" datastore:"monthly_app_executions"`
420421
MonthlyAppExecutionsFailed int64 `json:"monthly_app_executions_failed,omitempty" datastore:"monthly_app_executions_failed"`
421422
MonthlySubflowExecutions int64 `json:"monthly_subflow_executions,omitempty" datastore:"monthly_subflow_executions"`
422423
MonthlyWorkflowExecutions int64 `json:"monthly_workflow_executions,omitempty" datastore:"monthly_workflow_executions"`
424+
MonthlyChildWorkflowExecutions int64 `json:"monthly_child_workflow_executions,omitempty" datastore:"monthly_child_workflow_executions"`
423425
MonthlyWorkflowExecutionsFinished int64 `json:"monthly_workflow_executions_finished,omitempty" datastore:"monthly_workflow_executions_finished"`
424426
MonthlyWorkflowExecutionsFailed int64 `json:"monthly_workflow_executions_failed,omitempty" datastore:"monthly_workflow_executions_failed"`
425427
MonthlyOrgSyncActions int64 `json:"monthly_org_sync_actions,omitempty" datastore:"monthly_org_sync_actions"`
@@ -432,6 +434,7 @@ type ExecutionInfo struct {
432434
WeeklyAppExecutionsFailed int64 `json:"weekly_app_executions_failed,omitempty" datastore:"weekly_app_executions_failed"`
433435
WeeklySubflowExecutions int64 `json:"weekly_subflow_executions,omitempty" datastore:"weekly_subflow_executions"`
434436
WeeklyWorkflowExecutions int64 `json:"weekly_workflow_executions,omitempty" datastore:"weekly_workflow_executions"`
437+
WeeklyChildWorkflowExecutions int64 `json:"weekly_child_workflow_executions,omitempty" datastore:"weekly_child_workflow_executions"`
435438
WeeklyWorkflowExecutionsFinished int64 `json:"weekly_workflow_executions_finished,omitempty" datastore:"weekly_workflow_executions_finished"`
436439
WeeklyWorkflowExecutionsFailed int64 `json:"weekly_workflow_executions_failed,omitempty" datastore:"weekly_workflow_executions_failed"`
437440
WeeklyOrgSyncActions int64 `json:"weekly_org_sync_actions,omitempty" datastore:"weekly_org_sync_actions"`
@@ -444,6 +447,7 @@ type ExecutionInfo struct {
444447
DailyAppExecutionsFailed int64 `json:"daily_app_executions_failed" datastore:"daily_app_executions_failed"`
445448
DailySubflowExecutions int64 `json:"daily_subflow_executions" datastore:"daily_subflow_executions"`
446449
DailyWorkflowExecutions int64 `json:"daily_workflow_executions" datastore:"daily_workflow_executions"`
450+
DailyChildWorkflowExecutions int64 `json:"daily_child_workflow_executions" datastore:"daily_child_workflow_executions"`
447451
DailyWorkflowExecutionsFinished int64 `json:"daily_workflow_executions_finished" datastore:"daily_workflow_executions_finished"`
448452
DailyWorkflowExecutionsFailed int64 `json:"daily_workflow_executions_failed" datastore:"daily_workflow_executions_failed"`
449453
DailyOrgSyncActions int64 `json:"daily_org_sync_actions" datastore:"daily_org_sync_actions"`
@@ -456,6 +460,7 @@ type ExecutionInfo struct {
456460
HourlyAppExecutionsFailed int64 `json:"hourly_app_executions_failed,omitempty" datastore:"hourly_app_executions_failed"`
457461
HourlySubflowExecutions int64 `json:"hourly_subflow_executions,omitempty" datastore:"hourly_subflow_executions"`
458462
HourlyWorkflowExecutions int64 `json:"hourly_workflow_executions,omitempty" datastore:"hourly_workflow_executions"`
463+
HourlyChildWorkflowExecutions int64 `json:"hourly_child_workflow_executions,omitempty" datastore:"hourly_child_workflow_executions"`
459464
HourlyWorkflowExecutionsFinished int64 `json:"hourly_workflow_executions_finished,omitempty" datastore:"hourly_workflow_executions_finished"`
460465
HourlyWorkflowExecutionsFailed int64 `json:"hourly_workflow_executions_failed,omitempty" datastore:"hourly_workflow_executions_failed"`
461466
HourlyOrgSyncActions int64 `json:"hourly_org_sync_actions,omitempty" datastore:"hourly_org_sync_actions"`
@@ -1003,11 +1008,12 @@ type OnpremLimits struct {
10031008
}
10041009

10051010
type OnpremLicense struct {
1006-
Valid bool `json:"valid" datastore:"valid"`
1007-
Tenant OnpremLimits `json:"tenant" datastore:"tenant"`
1008-
Environment OnpremLimits `json:"environment" datastore:"environment"`
1009-
Timeout string `json:"timeout" datastore:"timeout"`
1010-
Branding bool `json:"branding" datastore:"branding"`
1011+
Valid bool `json:"valid" datastore:"valid"`
1012+
Tenant OnpremLimits `json:"tenant" datastore:"tenant"`
1013+
Environment OnpremLimits `json:"environment" datastore:"environment"`
1014+
WorkflowExecutions OnpremLimits `json:"workflow_executions" datastore:"workflow_executions"`
1015+
Timeout string `json:"timeout" datastore:"timeout"`
1016+
Branding bool `json:"branding" datastore:"branding"`
10111017
}
10121018

10131019
type Org struct {

0 commit comments

Comments
 (0)