Skip to content

Commit

Permalink
fix(cls): [118241302] add syntax_rule params for cls alarm resource (
Browse files Browse the repository at this point in the history
…#2699)

* add

* add
  • Loading branch information
SevenEarth authored Jun 28, 2024
1 parent 05c224a commit a401d48
Show file tree
Hide file tree
Showing 12 changed files with 3,702 additions and 2,369 deletions.
3 changes: 3 additions & 0 deletions .changelog/2699.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/tencentcloud_cls_alarm: supports set `syntax_rule`
```
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ require (
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ckafka v1.0.748
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.860
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cloudaudit v1.0.544
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.860
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.947
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.952
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.952
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.624
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cwp v1.0.762
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cynosdb v1.0.692
Expand Down
5 changes: 5 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -860,6 +860,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cloudaudit v1.0.544 h1:
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cloudaudit v1.0.544/go.mod h1:c37rIdL3LrJXYwrfp9c8L4MabTqKIZUe1xvnWhN75oc=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.860 h1:IU20AhNd0fEbgFzTTGB8cdMkUCrgB0FsLd0puC4QDzU=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.860/go.mod h1:RP3NkBvKio1dFmCNKozHX9qmef57sUCfsTcE0FnCvjk=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.952 h1:+4g+Wp3WKTf/QU814lF+kft4jP/NNUkggciB/n0joTM=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.952/go.mod h1:OW+FNkQgeQTesREQ7iPA4g9V81cEb/NcWSYO6bYe2Qo=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.414/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.486/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.524/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
Expand Down Expand Up @@ -930,10 +932,13 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.916 h1:30u2
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.916/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.920 h1:Kmm4rJrdI7D29IMOTT2oNp70h0TGsZ3obaekS8hvYkU=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.920/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.921/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.932 h1:MB1+Ll6JxWTpZw/v0dMRvMEJhlcDKxK/JMQ8O5owRVc=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.932/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.947 h1:obeD8UftWQ6XO1OlQQYMAJ2r6tqKPTQ/+8IrZAE0BMs=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.947/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.952 h1:fqO77A01ayOji0F0ovFKRlbatbvVsDhyjO7h0MXJsFk=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.952/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/csip v1.0.860 h1:F3esKBIT3HW9+7Gt8cVgf8X06VdGIczpgLBUECzSEzU=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/csip v1.0.860/go.mod h1:NZo1WplQcC314kMlCRUoy8NQju2BnolIJj7NAWgsuhY=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.624 h1:nEZqsoqt1pEoaP9JjkHQy3/H00suCfzlHW1qOm2nYD8=
Expand Down
97 changes: 75 additions & 22 deletions tencentcloud/services/cls/resource_tc_cls_alarm.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ func ResourceTencentCloudClsAlarm() *schema.Resource {
Required: true,
Description: "logset id.",
},
"syntax_rule": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
Description: "Retrieve grammar rules, 0: Lucene syntax, 1: CQL syntax, Default value is 0.",
},
},
},
},
Expand Down Expand Up @@ -221,13 +227,13 @@ func resourceTencentCloudClsAlarmCreate(d *schema.ResourceData, meta interface{}
defer tccommon.LogElapsed("resource.tencentcloud_cls_alarm.create")()
defer tccommon.InconsistentCheck(d, meta)()

logId := tccommon.GetLogId(tccommon.ContextNil)

var (
logId = tccommon.GetLogId(tccommon.ContextNil)
request = cls.NewCreateAlarmRequest()
response = cls.NewCreateAlarmResponse()
alarmId string
)

if v, ok := d.GetOk("name"); ok {
request.Name = helper.String(v.(string))
}
Expand All @@ -239,21 +245,31 @@ func resourceTencentCloudClsAlarmCreate(d *schema.ResourceData, meta interface{}
if v, ok := dMap["topic_id"]; ok {
alarmTarget.TopicId = helper.String(v.(string))
}

if v, ok := dMap["query"]; ok {
alarmTarget.Query = helper.String(v.(string))
}

if v, ok := dMap["number"]; ok {
alarmTarget.Number = helper.IntInt64(v.(int))
}

if v, ok := dMap["start_time_offset"]; ok {
alarmTarget.StartTimeOffset = helper.IntInt64(v.(int))
}

if v, ok := dMap["end_time_offset"]; ok {
alarmTarget.EndTimeOffset = helper.IntInt64(v.(int))
}

if v, ok := dMap["logset_id"]; ok {
alarmTarget.LogsetId = helper.String(v.(string))
}

if v, ok := dMap["syntax_rule"]; ok {
alarmTarget.SyntaxRule = helper.IntUint64(v.(int))
}

request.AlarmTargets = append(request.AlarmTargets, &alarmTarget)
}
}
Expand All @@ -263,9 +279,11 @@ func resourceTencentCloudClsAlarmCreate(d *schema.ResourceData, meta interface{}
if v, ok := dMap["type"]; ok {
monitorTime.Type = helper.String(v.(string))
}

if v, ok := dMap["time"]; ok {
monitorTime.Time = helper.IntInt64(v.(int))
}

request.MonitorTime = &monitorTime
}

Expand Down Expand Up @@ -307,13 +325,15 @@ func resourceTencentCloudClsAlarmCreate(d *schema.ResourceData, meta interface{}
if v, ok := dMap["body"]; ok {
callBackInfo.Body = helper.String(v.(string))
}

if v, ok := dMap["headers"]; ok {
headersSet := v.(*schema.Set).List()
for i := range headersSet {
headers := headersSet[i].(string)
callBackInfo.Headers = append(callBackInfo.Headers, &headers)
}
}

request.CallBack = &callBackInfo
}

Expand All @@ -324,25 +344,31 @@ func resourceTencentCloudClsAlarmCreate(d *schema.ResourceData, meta interface{}
if v, ok := dMap["name"]; ok {
analysisDimensional.Name = helper.String(v.(string))
}

if v, ok := dMap["type"]; ok {
analysisDimensional.Type = helper.String(v.(string))
}

if v, ok := dMap["content"]; ok {
analysisDimensional.Content = helper.String(v.(string))
}

if v, ok := dMap["config_info"]; ok {
for _, item := range v.([]interface{}) {
configInfoMap := item.(map[string]interface{})
alarmAnalysisConfig := cls.AlarmAnalysisConfig{}
if v, ok := configInfoMap["key"]; ok {
alarmAnalysisConfig.Key = helper.String(v.(string))
}

if v, ok := configInfoMap["value"]; ok {
alarmAnalysisConfig.Value = helper.String(v.(string))
}

analysisDimensional.ConfigInfo = append(analysisDimensional.ConfigInfo, &alarmAnalysisConfig)
}
}

request.Analysis = append(request.Analysis, &analysisDimensional)
}
}
Expand All @@ -354,9 +380,11 @@ func resourceTencentCloudClsAlarmCreate(d *schema.ResourceData, meta interface{}
} else {
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString())
}

response = result
return nil
})

if err != nil {
log.Printf("[CRITAL]%s create cls alarm failed, reason:%+v", logId, err)
return err
Expand All @@ -382,13 +410,12 @@ func resourceTencentCloudClsAlarmRead(d *schema.ResourceData, meta interface{})
defer tccommon.LogElapsed("resource.tencentcloud_cls_alarm.read")()
defer tccommon.InconsistentCheck(d, meta)()

logId := tccommon.GetLogId(tccommon.ContextNil)

ctx := context.WithValue(context.TODO(), tccommon.LogIdKey, logId)

service := ClsService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}

alarmId := d.Id()
var (
logId = tccommon.GetLogId(tccommon.ContextNil)
ctx = context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
service = ClsService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}
alarmId = d.Id()
)

alarm, err := service.DescribeClsAlarmById(ctx, alarmId)
if err != nil {
Expand Down Expand Up @@ -434,6 +461,10 @@ func resourceTencentCloudClsAlarmRead(d *schema.ResourceData, meta interface{})
alarmTargetsMap["logset_id"] = alarmTarget.LogsetId
}

if alarmTarget.SyntaxRule != nil {
alarmTargetsMap["syntax_rule"] = alarmTarget.SyntaxRule
}

alarmTargetsList = append(alarmTargetsList, alarmTargetsMap)
}

Expand Down Expand Up @@ -546,6 +577,7 @@ func resourceTencentCloudClsAlarmRead(d *schema.ResourceData, meta interface{})
if err != nil {
return err
}

_ = d.Set("tags", tags)

return nil
Expand All @@ -555,15 +587,14 @@ func resourceTencentCloudClsAlarmUpdate(d *schema.ResourceData, meta interface{}
defer tccommon.LogElapsed("resource.tencentcloud_cls_alarm.update")()
defer tccommon.InconsistentCheck(d, meta)()

logId := tccommon.GetLogId(tccommon.ContextNil)
needChange := false

request := cls.NewModifyAlarmRequest()

alarmId := d.Id()
var (
logId = tccommon.GetLogId(tccommon.ContextNil)
request = cls.NewModifyAlarmRequest()
alarmId = d.Id()
)

needChange := false
request.AlarmId = &alarmId

mutableArgs := []string{
"name", "alarm_targets", "monitor_time", "condition", "alarm_level",
"trigger_count", "alarm_period", "alarm_notice_ids",
Expand All @@ -578,7 +609,6 @@ func resourceTencentCloudClsAlarmUpdate(d *schema.ResourceData, meta interface{}
}

if needChange {

if v, ok := d.GetOk("name"); ok {
request.Name = helper.String(v.(string))
}
Expand All @@ -590,21 +620,31 @@ func resourceTencentCloudClsAlarmUpdate(d *schema.ResourceData, meta interface{}
if v, ok := dMap["topic_id"]; ok {
alarmTarget.TopicId = helper.String(v.(string))
}

if v, ok := dMap["query"]; ok {
alarmTarget.Query = helper.String(v.(string))
}

if v, ok := dMap["number"]; ok {
alarmTarget.Number = helper.IntInt64(v.(int))
}

if v, ok := dMap["start_time_offset"]; ok {
alarmTarget.StartTimeOffset = helper.IntInt64(v.(int))
}

if v, ok := dMap["end_time_offset"]; ok {
alarmTarget.EndTimeOffset = helper.IntInt64(v.(int))
}

if v, ok := dMap["logset_id"]; ok {
alarmTarget.LogsetId = helper.String(v.(string))
}

if v, ok := dMap["syntax_rule"]; ok {
alarmTarget.SyntaxRule = helper.IntUint64(v.(int))
}

request.AlarmTargets = append(request.AlarmTargets, &alarmTarget)
}
}
Expand All @@ -614,9 +654,11 @@ func resourceTencentCloudClsAlarmUpdate(d *schema.ResourceData, meta interface{}
if v, ok := dMap["type"]; ok {
monitorTime.Type = helper.String(v.(string))
}

if v, ok := dMap["time"]; ok {
monitorTime.Time = helper.IntInt64(v.(int))
}

request.MonitorTime = &monitorTime
}

Expand Down Expand Up @@ -658,13 +700,15 @@ func resourceTencentCloudClsAlarmUpdate(d *schema.ResourceData, meta interface{}
if v, ok := dMap["body"]; ok {
callBackInfo.Body = helper.String(v.(string))
}

if v, ok := dMap["headers"]; ok {
headersSet := v.(*schema.Set).List()
for i := range headersSet {
headers := headersSet[i].(string)
callBackInfo.Headers = append(callBackInfo.Headers, &headers)
}
}

request.CallBack = &callBackInfo
}

Expand All @@ -675,25 +719,31 @@ func resourceTencentCloudClsAlarmUpdate(d *schema.ResourceData, meta interface{}
if v, ok := dMap["name"]; ok {
analysisDimensional.Name = helper.String(v.(string))
}

if v, ok := dMap["type"]; ok {
analysisDimensional.Type = helper.String(v.(string))
}

if v, ok := dMap["content"]; ok {
analysisDimensional.Content = helper.String(v.(string))
}

if v, ok := dMap["config_info"]; ok {
for _, item := range v.([]interface{}) {
configInfoMap := item.(map[string]interface{})
alarmAnalysisConfig := cls.AlarmAnalysisConfig{}
if v, ok := configInfoMap["key"]; ok {
alarmAnalysisConfig.Key = helper.String(v.(string))
}

if v, ok := configInfoMap["value"]; ok {
alarmAnalysisConfig.Value = helper.String(v.(string))
}

analysisDimensional.ConfigInfo = append(analysisDimensional.ConfigInfo, &alarmAnalysisConfig)
}
}

request.Analysis = append(request.Analysis, &analysisDimensional)
}
}
Expand All @@ -705,8 +755,10 @@ func resourceTencentCloudClsAlarmUpdate(d *schema.ResourceData, meta interface{}
} else {
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString())
}

return nil
})

if err != nil {
log.Printf("[CRITAL]%s update cls alarm failed, reason:%+v", logId, err)
return err
Expand All @@ -732,11 +784,12 @@ func resourceTencentCloudClsAlarmDelete(d *schema.ResourceData, meta interface{}
defer tccommon.LogElapsed("resource.tencentcloud_cls_alarm.delete")()
defer tccommon.InconsistentCheck(d, meta)()

logId := tccommon.GetLogId(tccommon.ContextNil)
ctx := context.WithValue(context.TODO(), tccommon.LogIdKey, logId)

service := ClsService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}
alarmId := d.Id()
var (
logId = tccommon.GetLogId(tccommon.ContextNil)
ctx = context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
service = ClsService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}
alarmId = d.Id()
)

if err := service.DeleteClsAlarmById(ctx, alarmId); err != nil {
return err
Expand Down
1 change: 1 addition & 0 deletions tencentcloud/services/cls/resource_tc_cls_alarm.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ resource "tencentcloud_cls_alarm" "example" {
query = "status:>500 | select count(*) as errorCounts"
start_time_offset = -15
topic_id = "88735a07-bea4-4985-8763-e9deb6da4fad"
syntax_rule = 1
}
analysis {
Expand Down
2 changes: 2 additions & 0 deletions tencentcloud/services/cls/resource_tc_cls_alarm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ resource "tencentcloud_cls_alarm" "alarm" {
query = "status:>500 | select count(*) as errorCounts"
start_time_offset = -15
topic_id = "775c0bc2-2246-43a0-8eb2-f5bc248be183"
syntax_rule = 0
}
analysis {
Expand Down Expand Up @@ -108,6 +109,7 @@ resource "tencentcloud_cls_alarm" "alarm" {
query = "status:>500 | select count(*) as errorCounts"
start_time_offset = -15
topic_id = "775c0bc2-2246-43a0-8eb2-f5bc248be183"
syntax_rule = 1
}
analysis {
Expand Down
Loading

0 comments on commit a401d48

Please sign in to comment.