-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: support cat * faet: support task * fix: Modify the interface DescribeProbeNodes to DescribeNodes * fix: modify sdk * fix: modify sdk * fix: modify test * fix: modify test * fix: modify test * fix: modify test * fix: modify test * fix: modify provider * fix: modify provider * fix: modify provider * fix: modify provider * fix: modify provider * fix: modify go mod * fix: modify go mod * fix: add doc * fix: add changelog * Update 2143.txt changelog update --------- Co-authored-by: andrewjiang <[email protected]>
- Loading branch information
Showing
19 changed files
with
1,028 additions
and
225 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
```release-note:new-data-source | ||
tencentcloud_cat_metric_data | ||
``` | ||
|
||
```release-note:enhancement | ||
datasource/tencentcloud_cat_node: Add computed `task_types` | ||
``` | ||
|
||
```release-note:enhancement | ||
resource/tencentcloud_cat_task_set: Support `suspend` and `resume` for dial test tasks | ||
``` |
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 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,154 @@ | ||
/* | ||
Use this data source to query detailed information of cat metric_data | ||
Example Usage | ||
```hcl | ||
data "tencentcloud_cat_metric_data" "metric_data" { | ||
analyze_task_type = "AnalyzeTaskType_Network" | ||
metric_type = "gauge" | ||
field = "avg(\"ping_time\")" | ||
filters = [ | ||
"\"host\" = 'www.qq.com'", | ||
"time >= now()-1h", | ||
] | ||
} | ||
``` | ||
*/ | ||
package tencentcloud | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
cat "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cat/v20180409" | ||
sdkErrors "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors" | ||
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" | ||
) | ||
|
||
func dataSourceTencentCloudCatMetricData() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceTencentCloudCatMetricDataRead, | ||
Schema: map[string]*schema.Schema{ | ||
"analyze_task_type": { | ||
Required: true, | ||
Type: schema.TypeString, | ||
Description: "Analysis of task type, supported types: `AnalyzeTaskType_Network`: network quality, `AnalyzeTaskType_Browse`: page performance, `AnalyzeTaskType_Transport`: port performance, `AnalyzeTaskType_UploadDownload`: file transport, `AnalyzeTaskType_MediaStream`: audiovisual experience.", | ||
}, | ||
|
||
"metric_type": { | ||
Required: true, | ||
Type: schema.TypeString, | ||
Description: "Metric type, metrics queries are passed with gauge by default.", | ||
}, | ||
|
||
"field": { | ||
Required: true, | ||
Type: schema.TypeString, | ||
Description: "Detailed fields of metrics, specified metrics can be passed or aggregate metrics, such as avg(ping_time) means entire delay.", | ||
}, | ||
|
||
"filter": { | ||
Optional: true, | ||
Type: schema.TypeString, | ||
Description: "Filter conditions can be passed as a single filter or multiple parameters concatenated together.", | ||
}, | ||
|
||
"group_by": { | ||
Optional: true, | ||
Type: schema.TypeString, | ||
Description: "Aggregation time, such as 1m, 1d, 30d, and so on.", | ||
}, | ||
|
||
"filters": { | ||
Required: true, | ||
Type: schema.TypeSet, | ||
Elem: &schema.Schema{ | ||
Type: schema.TypeString, | ||
}, | ||
Description: "Multiple condition filtering, supports combining multiple filtering conditions for query.", | ||
}, | ||
|
||
"metric_set": { | ||
Computed: true, | ||
Type: schema.TypeString, | ||
Description: "Return JSON string.", | ||
}, | ||
|
||
"result_output_file": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Description: "Used to save results.", | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceTencentCloudCatMetricDataRead(d *schema.ResourceData, meta interface{}) error { | ||
defer logElapsed("data_source.tencentcloud_cat_metric_data.read")() | ||
defer inconsistentCheck(d, meta)() | ||
|
||
logId := getLogId(contextNil) | ||
|
||
ctx := context.WithValue(context.TODO(), logIdKey, logId) | ||
|
||
paramMap := make(map[string]interface{}) | ||
if v, ok := d.GetOk("analyze_task_type"); ok { | ||
paramMap["AnalyzeTaskType"] = helper.String(v.(string)) | ||
} | ||
|
||
if v, ok := d.GetOk("metric_type"); ok { | ||
paramMap["MetricType"] = helper.String(v.(string)) | ||
} | ||
|
||
if v, ok := d.GetOk("field"); ok { | ||
paramMap["Field"] = helper.String(v.(string)) | ||
} | ||
|
||
if v, ok := d.GetOk("filter"); ok { | ||
paramMap["Filter"] = helper.String(v.(string)) | ||
} | ||
|
||
if v, ok := d.GetOk("group_by"); ok { | ||
paramMap["GroupBy"] = helper.String(v.(string)) | ||
} | ||
|
||
if v, ok := d.GetOk("filters"); ok { | ||
filtersSet := v.(*schema.Set).List() | ||
paramMap["Filters"] = helper.InterfacesStringsPoint(filtersSet) | ||
} | ||
|
||
service := CatService{client: meta.(*TencentCloudClient).apiV3Conn} | ||
|
||
var metric *cat.DescribeProbeMetricDataResponseParams | ||
err := resource.Retry(readRetryTimeout, func() *resource.RetryError { | ||
result, e := service.DescribeCatMetricDataByFilter(ctx, paramMap) | ||
if e != nil { | ||
if sdkError, ok := e.(*sdkErrors.TencentCloudSDKError); ok { | ||
if sdkError.Code == "FailedOperation.DbQueryFailed" { | ||
return resource.NonRetryableError(e) | ||
} | ||
} | ||
return retryError(e) | ||
} | ||
metric = result | ||
return nil | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
var metricSet string | ||
if metric != nil && metric.MetricSet != nil { | ||
metricSet = *metric.MetricSet | ||
_ = d.Set("metric_set", metric.MetricSet) | ||
} | ||
|
||
d.SetId(helper.DataResourceIdsHash([]string{metricSet})) | ||
output, ok := d.GetOk("result_output_file") | ||
if ok && output.(string) != "" { | ||
if e := writeToFile(output.(string), metricSet); e != nil { | ||
return e | ||
} | ||
} | ||
return nil | ||
} |
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,83 @@ | ||
package tencentcloud | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
) | ||
|
||
// go test -test.run TestAccTencentCloudCatMetricDataDataSource_basic -v | ||
func TestAccTencentCloudCatMetricDataDataSource_basic(t *testing.T) { | ||
t.Parallel() | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { | ||
testAccPreCheck(t) | ||
}, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccCatMetricDataDataSource, | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckTencentCloudDataSourceID("data.tencentcloud_cat_metric_data.metric_data"), | ||
resource.TestCheckResourceAttrSet("data.tencentcloud_cat_metric_data.metric_data", "metric_set"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
const testAccCatMetricDataDataSource = ` | ||
resource "tencentcloud_cat_task_set" "task_set" { | ||
interval = 1 | ||
nodes = [ | ||
"12136", | ||
"12137", | ||
] | ||
parameters = jsonencode( | ||
{ | ||
blackList = "" | ||
filterIp = 0 | ||
grabBag = 0 | ||
ipType = 0 | ||
netDigOn = 1 | ||
netDnsNs = "" | ||
netDnsOn = 1 | ||
netDnsQuerymethod = 1 | ||
netDnsServer = 2 | ||
netDnsTimeout = 5 | ||
netIcmpActivex = 0 | ||
netIcmpActivexStr = "" | ||
netIcmpDataCut = 1 | ||
netIcmpInterval = 0.5 | ||
netIcmpNum = 20 | ||
netIcmpOn = 1 | ||
netIcmpSize = 32 | ||
netIcmpTimeout = 20 | ||
netTracertNum = 30 | ||
netTracertOn = 1 | ||
netTracertTimeout = 60 | ||
whiteList = "" | ||
} | ||
) | ||
tags = {} | ||
task_category = 1 | ||
task_type = 5 | ||
batch_tasks { | ||
name = "terraform-test" | ||
target_address = "www.baidu.com" | ||
} | ||
} | ||
data "tencentcloud_cat_metric_data" "metric_data" { | ||
analyze_task_type = "AnalyzeTaskType_Network" | ||
metric_type = "gauge" | ||
field = "avg(\"ping_time\")" | ||
filters = [ | ||
"\"host\" = 'www.baidu.com'", | ||
"time >= now()-1h", | ||
] | ||
depends_on = [ tencentcloud_cat_task_set.task_set ] | ||
} | ||
` |
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.