Skip to content

Commit f0d67c2

Browse files
vimalmeena238jotruon
authored andcommitted
Added concurrecy control for discovery
1 parent 4de77a0 commit f0d67c2

10 files changed

+80
-37
lines changed

internal/resourcediscovery/export_compartment.go

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ type ResourceDiscoveryStage int
4545
const (
4646
Discovery ResourceDiscoveryStage = 1
4747
GeneratingState = 2
48+
// maximum goroutines for finding resources in a step at base level.
49+
// Value of MaxParallelFindResources is decided based on perf analysis and experiments.
50+
// Note: SubResources will be discovered sequentially.
51+
MaxParallelFindResource = 16
4852
)
4953

5054
var (
@@ -315,7 +319,6 @@ func RunExportCommand(args *tf_export.ExportCommandArgs) (err error, status Stat
315319
if len(ctx.ErrorList.Errors) > 0 {
316320
// If the errors were from discovery of resources return partial success status
317321
error, status := getListOfNotDiscoveredResources(ctx)
318-
319322
return error, status
320323
}
321324
return nil, StatusSuccess
@@ -616,15 +619,15 @@ func generateStateParallel(ctx *tf_export.ResourceDiscoveryContext, steps []reso
616619

617620
// Write temp state file for each service, this step will import resources into a separate state file for each service in parallel
618621
// If writing temp configuration thrown error, won't attempt to write temp state
619-
// Write temp state file for each service, this step will import resources into a separate state file for each service in parallel
620-
if err := step.writeTmpState(); err != nil {
621-
var tfError tf_export.ResourceDiscoveryCustomError
622-
tfError = tf_export.ResourceDiscoveryCustomError{
623-
TypeOfError: tf_export.WriteTmpStateError,
624-
Message: errors.New(tf_export.WriteTmpStateErrorMessage),
625-
Suggestion: tf_export.WriteTmpStateErrorSuggestion,
622+
if err == nil {
623+
if err = step.writeTmpState(); err != nil {
624+
tfError := tf_export.ResourceDiscoveryCustomError{
625+
TypeOfError: tf_export.WriteTmpStateError,
626+
Message: errors.New(tf_export.WriteTmpStateErrorMessage),
627+
Suggestion: tf_export.WriteTmpStateErrorSuggestion}
628+
629+
errorChannel <- tfError.Error()
626630
}
627-
errorChannel <- tfError.Error()
628631
}
629632

630633
utils.Debugf("writing temp config and state: Completed step %d", i)
@@ -886,7 +889,7 @@ func getDiscoverResourceWithGraphSteps(ctx *tf_export.ResourceDiscoveryContext)
886889
return result, nil
887890
}
888891

889-
func findResources(ctx *tf_export.ResourceDiscoveryContext, root *tf_export.OCIResource, resourceGraph tf_export.TerraformResourceGraph) (foundResources []*tf_export.OCIResource, err error) {
892+
func findResources(ctx *tf_export.ResourceDiscoveryContext, root *tf_export.OCIResource, resourceGraph tf_export.TerraformResourceGraph, discoveryParallelism bool) (foundResources []*tf_export.OCIResource, err error) {
890893
// findResources will never return error, it will add the errors encountered to the errorList and print those after the discovery finishes
891894
// If find resources needs to fail in some scenario, this func needs to be modified to return error instead of continuing discovery
892895
// Errors so far are API errors or the errors when service/feature is not available
@@ -901,22 +904,31 @@ func findResources(ctx *tf_export.ResourceDiscoveryContext, root *tf_export.OCIR
901904
utils.Logf("[INFO] resource discovery: visiting %s\n", root.GetTerraformReference())
902905
utils.Debugf("[DEBUG] resource discovery: visiting %s\n", root.GetTerraformReference())
903906

904-
utils.Logf("[INFO] number of child resource types for %s: %d\n", root.getTerraformReference(), len(childResourceTypes))
907+
utils.Logf("[INFO] number of child resource types for %s: %d\n", root.GetTerraformReference(), len(childResourceTypes))
905908

906909
findResourcesStart := time.Now()
907910
var findResourcesWg sync.WaitGroup
908911
findResourcesWg.Add(len(childResourceTypes))
909912

910-
ch := make(chan struct{}, len(childResourceTypes))
913+
// setting parallelism argument false for subResources to control concurrency and thrashing
914+
var ch chan struct{}
915+
if discoveryParallelism == true {
916+
ch = make(chan struct{}, MaxParallelFindResource)
917+
// setting parallelism argument false for subResources to control concurrency and thrashing
918+
discoveryParallelism = false
919+
} else {
920+
ch = make(chan struct{}, 1)
921+
}
911922

912923
for i, childType := range childResourceTypes {
913924

914925
ch <- struct{}{}
915926

916-
go func(i int, childType TerraformResourceAssociation) {
927+
go func(i int, childType tf_export.TerraformResourceAssociation) {
917928
utils.Debugf("[DEBUG] findResources: finding resources for resource type index: %d", i)
918929

919930
defer func(tfMeta *tf_export.TerraformResourceAssociation, err *error) {
931+
<-ch
920932
if r := recover(); r != nil {
921933
utils.Logf("[WARN] recovered from panic in findResourcesGeneric for resource: %s \n continuing discovery...", tfMeta.ResourceClass)
922934
returnErr := fmt.Errorf("panic in findResourcesGeneric for resource %s", tfMeta.ResourceClass)
@@ -928,8 +940,8 @@ func findResources(ctx *tf_export.ResourceDiscoveryContext, root *tf_export.OCIR
928940
}(&childType, &err)
929941

930942
findResourceFn := tf_export.FindResourcesGeneric
931-
if childType.findResourcesOverrideFn != nil {
932-
findResourceFn = childType.findResourcesOverrideFn
943+
if childType.FindResourcesOverrideFn != nil {
944+
findResourceFn = childType.FindResourcesOverrideFn
933945
}
934946
results, err := findResourceFn(ctx, &childType, root, &resourceGraph)
935947
if err != nil {
@@ -976,7 +988,7 @@ func findResources(ctx *tf_export.ResourceDiscoveryContext, root *tf_export.OCIR
976988

977989
}
978990

979-
subResources, err := findResources(ctx, resource, resourceGraph)
991+
subResources, err := findResources(ctx, resource, resourceGraph, discoveryParallelism)
980992
if err != nil {
981993
continue
982994
}
@@ -985,14 +997,13 @@ func findResources(ctx *tf_export.ResourceDiscoveryContext, root *tf_export.OCIR
985997
foundResourcesLock.Unlock()
986998
}
987999
utils.Debugf("[DEBUG] findResources: Completed for resource type index %d", i)
988-
<-ch
9891000
}(i, childType)
9901001
}
9911002

9921003
// Wait for all steps to complete findResources
9931004
findResourcesWg.Wait()
9941005
totalFindResourcesTime := time.Since(findResourcesStart)
995-
utils.Debugf("finding resources for %s took %v\n", root.getTerraformReference(), totalFindResourcesTime)
1006+
utils.Debugf("finding resources for %s took %v\n", root.GetTerraformReference(), totalFindResourcesTime)
9961007

9971008
return foundResources, nil
9981009
}

internal/resourcediscovery/export_compartment_test.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,7 +1124,7 @@ func TestUnitFindResources_basic(t *testing.T) {
11241124
ctx := &tf_export.ResourceDiscoveryContext{
11251125
ErrorList: tf_export.ErrorList{},
11261126
}
1127-
results, err := findResources(ctx, rootResource, compartmentTestingResourceGraph)
1127+
results, err := findResources(ctx, rootResource, compartmentTestingResourceGraph, true)
11281128
if err != nil {
11291129
t.Logf("got error from findResources: %v", err)
11301130
t.Fail()
@@ -1164,7 +1164,7 @@ func TestUnitFindResources_404Error(t *testing.T) {
11641164
ctx := &tf_export.ResourceDiscoveryContext{
11651165
ErrorList: tf_export.ErrorList{},
11661166
}
1167-
results, err := findResources(ctx, rootResource, compartmentTestingResourceGraphWith404ErrorResource)
1167+
results, err := findResources(ctx, rootResource, compartmentTestingResourceGraphWith404ErrorResource, true)
11681168
if err != nil {
11691169
t.Logf("got error from findResources: %v", err)
11701170
t.Fail()
@@ -1198,7 +1198,7 @@ func TestUnitFindResources_panic(t *testing.T) {
11981198
ctx := &tf_export.ResourceDiscoveryContext{
11991199
ErrorList: tf_export.ErrorList{},
12001200
}
1201-
results, err := findResources(ctx, rootResource, compartmentTestingResourceGraphWithPanicResource)
1201+
results, err := findResources(ctx, rootResource, compartmentTestingResourceGraphWithPanicResource, true)
12021202
if err != nil {
12031203
t.Logf("got error from findResources: %v", err)
12041204
t.Fail()
@@ -1222,7 +1222,7 @@ func TestUnitFindResources_errorList(t *testing.T) {
12221222
ctx := &tf_export.ResourceDiscoveryContext{
12231223
ErrorList: tf_export.ErrorList{},
12241224
}
1225-
_, err := findResources(ctx, rootResource, compartmentTestingResourceGraphWithFaultyChildResource)
1225+
_, err := findResources(ctx, rootResource, compartmentTestingResourceGraphWithFaultyChildResource, true)
12261226
if err != nil {
12271227
t.Logf("got error from findResources: %v", err)
12281228
t.Fail()
@@ -1272,7 +1272,7 @@ func TestUnitFindResources_restrictedOcids(t *testing.T) {
12721272
ErrorList: tf_export.ErrorList{},
12731273
}
12741274

1275-
results, err := findResources(ctx, rootResource, compartmentTestingResourceGraph)
1275+
results, err := findResources(ctx, rootResource, compartmentTestingResourceGraph, true)
12761276
if err != nil {
12771277
t.Logf("got error from findResources: %v", err)
12781278
t.Fail()
@@ -1308,7 +1308,7 @@ func TestUnitFindResources_overrideFn(t *testing.T) {
13081308
ctx := &tf_export.ResourceDiscoveryContext{
13091309
ErrorList: tf_export.ErrorList{},
13101310
}
1311-
results, err := findResources(ctx, rootResource, compartmentTestingResourceGraph)
1311+
results, err := findResources(ctx, rootResource, compartmentTestingResourceGraph, true)
13121312
if err != nil {
13131313
t.Logf("got error from findResources: %v", err)
13141314
t.Fail()
@@ -1348,7 +1348,7 @@ func TestUnitFindResources_processResourceFn(t *testing.T) {
13481348
ErrorList: tf_export.ErrorList{},
13491349
}
13501350

1351-
results, err := findResources(ctx, rootResource, compartmentTestingResourceGraph)
1351+
results, err := findResources(ctx, rootResource, compartmentTestingResourceGraph, true)
13521352
if err != nil {
13531353
t.Logf("got error from findResources: %v", err)
13541354
t.Fail()
@@ -1437,7 +1437,7 @@ func TestUnitGetHCLString_basic(t *testing.T) {
14371437
ctx := &tf_export.ResourceDiscoveryContext{
14381438
ErrorList: tf_export.ErrorList{},
14391439
}
1440-
results, err := findResources(ctx, rootResource, compartmentTestingResourceGraph)
1440+
results, err := findResources(ctx, rootResource, compartmentTestingResourceGraph, true)
14411441
if err != nil {
14421442
t.Logf("got error from findResources: %v", err)
14431443
t.Fail()
@@ -1513,7 +1513,7 @@ func TestUnitGetHCLStringFromMap(t *testing.T) {
15131513
rootResource := getRootCompartmentResource()
15141514

15151515
ctx := &tf_export.ResourceDiscoveryContext{}
1516-
results, err := findResources(ctx, rootResource, compartmentTestingResourceGraph)
1516+
results, err := findResources(ctx, rootResource, compartmentTestingResourceGraph, true)
15171517
if err != nil {
15181518
t.Logf("got error from findResources: %v", err)
15191519
t.Fail()
@@ -1545,7 +1545,7 @@ func TestUnitGetHCLString_missingFields(t *testing.T) {
15451545
ctx := &tf_export.ResourceDiscoveryContext{
15461546
ErrorList: tf_export.ErrorList{},
15471547
}
1548-
results, err := findResources(ctx, rootResource, compartmentTestingResourceGraph)
1548+
results, err := findResources(ctx, rootResource, compartmentTestingResourceGraph, true)
15491549
if err != nil {
15501550
t.Logf("got error from findResources: %v", err)
15511551
t.Fail()
@@ -1591,7 +1591,7 @@ func TestUnitGetHCLString_interpolationMap(t *testing.T) {
15911591
ctx := &tf_export.ResourceDiscoveryContext{
15921592
ErrorList: tf_export.ErrorList{},
15931593
}
1594-
results, err := findResources(ctx, rootResource, compartmentTestingResourceGraph)
1594+
results, err := findResources(ctx, rootResource, compartmentTestingResourceGraph, true)
15951595
if err != nil {
15961596
t.Logf("got error from findResources: %v", err)
15971597
t.Fail()
@@ -1641,7 +1641,7 @@ func TestUnitGetHCLString_tfSyntaxVersion(t *testing.T) {
16411641
rootResource := getRootCompartmentResource()
16421642

16431643
ctx := &tf_export.ResourceDiscoveryContext{}
1644-
results, err := findResources(ctx, rootResource, compartmentTestingResourceGraph)
1644+
results, err := findResources(ctx, rootResource, compartmentTestingResourceGraph, true)
16451645
if err != nil {
16461646
t.Logf("got error from findResources: %v", err)
16471647
t.Fail()
@@ -2012,7 +2012,7 @@ func TestUnitGetHCLString_logging(t *testing.T) {
20122012
ctx := &tf_export.ResourceDiscoveryContext{
20132013
ErrorList: tf_export.ErrorList{},
20142014
}
2015-
_, err = findResources(ctx, rootResource, compartmentTestingResourceGraph)
2015+
_, err = findResources(ctx, rootResource, compartmentTestingResourceGraph, true)
20162016
if err != nil {
20172017
t.Logf("got error from findResources: %v", err)
20182018
t.Fail()

internal/resourcediscovery/export_resource_helpers.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ type resourceDiscoveryBaseStep struct {
124124
discoveredResources []*tf_export.OCIResource
125125
omittedResources []*tf_export.OCIResource
126126
tempState interface{}
127+
discoveryParallelism bool
127128
timeTakenForDiscovery time.Duration
128129
timeTakenForGeneratingState time.Duration
129130
}
@@ -408,7 +409,11 @@ func (r *resourceDiscoveryWithGraph) discover() error {
408409
var err error
409410
var ociResources []*tf_export.OCIResource
410411

411-
ociResources, err = findResources(r.ctx, r.root, r.resourceGraph)
412+
// for root step, setting discovery parallelism on
413+
// turn it off for further levels
414+
r.discoveryParallelism = true
415+
416+
ociResources, err = findResources(r.ctx, r.root, r.resourceGraph, r.discoveryParallelism)
412417
if err != nil {
413418
return err
414419
}
@@ -534,7 +539,7 @@ func (r *resourceDiscoveryWithTargetIds) discover() error {
534539

535540
if _, hasRelatedResources := tf_export.ExportRelatedResourcesGraph[resourceHint.ResourceClass]; hasRelatedResources && r.ctx.IsExportWithRelatedResources {
536541
utils.Logf("[INFO] resource discovery: finding related resources for %s\n", resourceHint.ResourceClass)
537-
ociResources, err := findResources(r.ctx, ociResource, tf_export.ExportRelatedResourcesGraph)
542+
ociResources, err := findResources(r.ctx, ociResource, tf_export.ExportRelatedResourcesGraph, r.discoveryParallelism)
538543
if err != nil {
539544
return err
540545
}

website/docs/d/core_volume.html.markdown

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ The following attributes are exported:
4646
* `display_name` - A user-friendly name. Does not have to be unique, and it's changeable. Avoid entering confidential information.
4747
* `freeform_tags` - Free-form tags for this resource. Each tag is a simple key-value pair with no predefined name, type, or namespace. For more information, see [Resource Tags](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/resourcetags.htm). Example: `{"Department": "Finance"}`
4848
* `id` - The OCID of the volume.
49+
<<<<<<< ours
50+
* `is_auto_tune_enabled` - Specifies whether the auto-tune performance is enabled for this volume. This field is deprecated. Use the `DetachedVolumeAutotunePolicy` instead to enable the volume for detached autotune.
51+
=======
4952
* `is_auto_tune_enabled` - Specifies whether the auto-tune performance is enabled for this boot volume.
53+
>>>>>>> theirs
5054
* `is_hydrated` - Specifies whether the cloned volume's data has finished copying from the source volume or backup.
5155
* `kms_key_id` - The OCID of the Key Management key which is the master encryption key for the volume.
5256
* `size_in_gbs` - The size of the volume in GBs.

website/docs/d/datascience_model_deployment.html.markdown

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,13 @@ The following attributes are exported:
5454
* `instance_configuration` - The model deployment instance configuration
5555
* `instance_shape_name` - The shape used to launch the model deployment instances.
5656
* `model_deployment_instance_shape_config_details` - Details for the model-deployment instance shape configuration.
57+
<<<<<<< ours
58+
* `memory_in_gbs` - A model-deployment instance of type VM.Standard.E3.Flex or VM.Standard.E4.Flex allows the memory to be specified with in the range of 6 to 1024 GB. VM.Standard3.Flex memory range is between 6 to 512 GB and VM.Optimized3.Flex memory range is between 6 to 256 GB.
59+
* `ocpus` - A model-deployment instance of type VM.Standard.E3.Flex or VM.Standard.E4.Flex allows the ocpu count to be specified with in the range of 1 to 64 ocpu. VM.Standard3.Flex OCPU range is between 1 to 32 ocpu and for VM.Optimized3.Flex OCPU range is 1 to 18 ocpu.
60+
=======
5761
* `memory_in_gbs` - A model-deployment instance of type VM.Standard.E3.Flex or VM.Standard.E4.Flex allows the memory to be specified with in the range of 6 to 1024 GB. VM.Standard3.Flex memory range is between 6 and 512 GB and VM.Optimized3.Flex memory range is between 6 and 256 GB.
5862
* `ocpus` - A model-deployment instance of type VM.Standard.E3.Flex or VM.Standard.E4.Flex allows the ocpu count to be specified with in the range of 1 to 64 ocpu. VM.Standard3.Flex OCPU range is between 1 and 32 ocpu and for VM.Optimized3.Flex OCPU range is 1 to 18 ocpu.
63+
>>>>>>> theirs
5964
* `model_id` - The OCID of the model you want to deploy.
6065
* `scaling_policy` - The scaling policy to apply to each model of the deployment.
6166
* `instance_count` - The number of instances for the model deployment.

website/docs/d/datascience_model_deployments.html.markdown

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,13 @@ The following attributes are exported:
7373
* `instance_configuration` - The model deployment instance configuration
7474
* `instance_shape_name` - The shape used to launch the model deployment instances.
7575
* `model_deployment_instance_shape_config_details` - Details for the model-deployment instance shape configuration.
76+
<<<<<<< ours
77+
* `memory_in_gbs` - A model-deployment instance of type VM.Standard.E3.Flex or VM.Standard.E4.Flex allows the memory to be specified with in the range of 6 to 1024 GB. VM.Standard3.Flex memory range is between 6 to 512 GB and VM.Optimized3.Flex memory range is between 6 to 256 GB.
78+
* `ocpus` - A model-deployment instance of type VM.Standard.E3.Flex or VM.Standard.E4.Flex allows the ocpu count to be specified with in the range of 1 to 64 ocpu. VM.Standard3.Flex OCPU range is between 1 to 32 ocpu and for VM.Optimized3.Flex OCPU range is 1 to 18 ocpu.
79+
=======
7680
* `memory_in_gbs` - A model-deployment instance of type VM.Standard.E3.Flex or VM.Standard.E4.Flex allows the memory to be specified with in the range of 6 to 1024 GB. VM.Standard3.Flex memory range is between 6 and 512 GB and VM.Optimized3.Flex memory range is between 6 and 256 GB.
7781
* `ocpus` - A model-deployment instance of type VM.Standard.E3.Flex or VM.Standard.E4.Flex allows the ocpu count to be specified with in the range of 1 to 64 ocpu. VM.Standard3.Flex OCPU range is between 1 and 32 ocpu and for VM.Optimized3.Flex OCPU range is 1 to 18 ocpu.
82+
>>>>>>> theirs
7883
* `model_id` - The OCID of the model you want to deploy.
7984
* `scaling_policy` - The scaling policy to apply to each model of the deployment.
8085
* `instance_count` - The number of instances for the model deployment.

website/docs/d/opsi_host_insight.html.markdown

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ The following arguments are supported:
3333
The following attributes are exported:
3434

3535
* `compartment_id` - The [OCID](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm) of the compartment.
36+
<<<<<<< ours
37+
* `compute_id` - The [OCID](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm) of the Compute Instance
38+
* `defined_tags` - Defined tags for this resource. Each key is predefined and scoped to a namespace. Example: `{"foo-namespace.bar-key": "value"}`
39+
=======
40+
>>>>>>> theirs
3641
* `enterprise_manager_bridge_id` - OPSI Enterprise Manager Bridge OCID
3742
* `enterprise_manager_entity_display_name` - Enterprise Manager Entity Display Name
3843
* `enterprise_manager_entity_identifier` - Enterprise Manager Entity Unique Identifier

website/docs/d/opsi_host_insights.html.markdown

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ The following arguments are supported:
3939
* `compartment_id_in_subtree` - (Optional) A flag to search all resources within a given compartment and all sub-compartments.
4040
* `enterprise_manager_bridge_id` - (Applicable when entity_source=EM_MANAGED_EXTERNAL_HOST) Unique Enterprise Manager bridge identifier
4141
* `exadata_insight_id` - (Applicable when entity_source=EM_MANAGED_EXTERNAL_HOST) [OCID](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm) of exadata insight resource.
42+
<<<<<<< ours
43+
* `host_type` - (Optional) Filter by one or more host types. Possible values are CLOUD-HOST, EXTERNAL-HOST
44+
=======
4245
* `host_type` - (Optional) Filter by one or more host types. Possible value is EXTERNAL-HOST.
46+
>>>>>>> theirs
4347
* `id` - (Optional) Optional list of host insight resource [OCIDs](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm).
4448
* `platform_type` - (Optional) Filter by one or more platform types. Supported platformType(s) for MACS-managed external host insight: [LINUX, SOLARIS, WINDOWS]. Supported platformType(s) for MACS-managed cloud host insight: [LINUX]. Supported platformType(s) for EM-managed external host insight: [LINUX, SOLARIS, SUNOS, ZLINUX, WINDOWS].
4549
* `state` - (Optional) Lifecycle states

0 commit comments

Comments
 (0)