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

resource/alicloud_ess_scaling_rule: optimize query rule #7827

Open
wants to merge 1 commit into
base: master
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
14 changes: 6 additions & 8 deletions alicloud/resource_alicloud_ess_scaling_rule.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package alicloud

import (
"fmt"
"strconv"
"strings"

Expand Down Expand Up @@ -202,19 +203,16 @@ func resourceAliyunEssScalingRuleCreate(d *schema.ResourceData, meta interface{}
}
addDebug(request.GetActionName(), raw, request.RpcRequest, request)
response, _ := raw.(*ess.CreateScalingRuleResponse)
d.SetId(response.ScalingRuleId)

_, ok := d.GetOk("alarm_dimension")
d.SetId(fmt.Sprint("false", ":", response.ScalingRuleId))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里为什么需要拼接上一个bool值

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

因为在查询伸缩规则的时候,因为当前后端和CMS之间请求方式的原因 如果查询伸缩规则的时候,同时查询报警任务
可能会出现超时的情况;而目前伸缩规则只有当资源设置了AlarmDimension的时候,才必须查报警任务,而其他场景则不需要查报警任务;查询伸缩规则时,只有请求的AlarmRule设置了True 才查报警任务,否则就不查报警任务,避免绝大多数场景因查伸缩规则的时候同时查报警任务导致查询超时的异常,临时解决绝大部分TF用户查询伸缩组的超时异常。当然这块后续还需要ESS后端和CMS共同优化查询时间太长这个问题。

if ok {
d.SetId(fmt.Sprint("true", ":", response.ScalingRuleId))
}
return resourceAliyunEssScalingRuleRead(d, meta)
}

func resourceAliyunEssScalingRuleRead(d *schema.ResourceData, meta interface{}) error {

//Compatible with older versions id
if strings.Contains(d.Id(), COLON_SEPARATED) {
parts, _ := ParseResourceId(d.Id(), 2)
d.SetId(parts[1])
}

client := meta.(*connectivity.AliyunClient)
essService := EssService{client}

Expand Down
8 changes: 7 additions & 1 deletion alicloud/service_alicloud_ess.go
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,13 @@ func (s *EssService) flattenVserverGroupList(vServerGroups []ess.VServerGroup) [
func (s *EssService) DescribeEssScalingRule(id string) (rule ess.ScalingRule, err error) {
request := ess.CreateDescribeScalingRulesRequest()
request.ScalingRuleId = &[]string{id}
request.ShowAlarmRules = "true"
request.ShowAlarmRules = "false"
if strings.Contains(id, COLON_SEPARATED) {
parts, _ := ParseResourceId(id, 2)
request.ScalingRuleId = &[]string{parts[1]}
request.ShowAlarmRules = requests.Boolean(parts[0])
id = parts[1]
}
request.RegionId = s.client.RegionId
raw, err := s.client.WithEssClient(func(essClient *ess.Client) (interface{}, error) {
return essClient.DescribeScalingRules(request)
Expand Down
Loading