-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(GaussDBforMySQL): add gaussdb mysql slow logs data source (#5777)
- Loading branch information
Showing
5 changed files
with
427 additions
and
0 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,84 @@ | ||
--- | ||
subcategory: "GaussDB(for MySQL)" | ||
layout: "huaweicloud" | ||
page_title: "HuaweiCloud: huaweicloud_gaussdb_mysql_slow_logs" | ||
description: |- | ||
Use this data source to get the list of GaussDB MySQL slow logs. | ||
--- | ||
|
||
# huaweicloud_gaussdb_mysql_slow_logs | ||
|
||
Use this data source to get the list of GaussDB MySQL slow logs. | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
variable "instance_id" {} | ||
variable "node_id" {} | ||
variable "start_time" {} | ||
variable "end_time" {} | ||
data "huaweicloud_gaussdb_mysql_slow_logs" "test" { | ||
instance_id = var.instance_id | ||
node_id = var.node_id | ||
start_time = var.start_time | ||
end_time = var.end_time | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are supported: | ||
|
||
* `region` - (Optional, String) Specifies the region in which to query the resource. | ||
If omitted, the provider-level region will be used. | ||
|
||
* `instance_id` - (Required, String) Specifies the ID of the GaussDB MySQL instance. | ||
|
||
* `node_id` - (Required, String) Specifies the ID of the instance node. | ||
|
||
* `start_time` - (Required, String) Specifies the start time in the **yyyy-mm-ddThh:mm:ssZ** format. | ||
|
||
* `end_time` - (Required, String) Specifies the end time in the **yyyy-mm-ddThh:mm:ssZ** format. | ||
|
||
* `operate_type` - (Optional, String) Specifies the SQL statement type. Value options: **INSERT**, **UPDATE**, **SELECT**, | ||
**DELETE**, **CREATE**, **ALTER**, **DROP**. | ||
|
||
* `database` - (Optional, String) Specifies the name of the database. | ||
|
||
## Attribute Reference | ||
|
||
In addition to all arguments above, the following attributes are exported: | ||
|
||
* `id` - The data source ID. | ||
|
||
* `slow_log_list` - Indicates the list of the slow logs. | ||
|
||
The [slow_log_list](#slow_log_list_struct) structure is documented below. | ||
|
||
<a name="slow_log_list_struct"></a> | ||
The `slow_log_list` block supports: | ||
|
||
* `count` - Indicates the ID of the instance node. | ||
|
||
* `count` - Indicates the number of executions. | ||
|
||
* `time` - Indicates the execution time. | ||
|
||
* `lock_time` - Indicates the lock wait time. | ||
|
||
* `rows_sent` - Indicates the number of sent rows. | ||
|
||
* `rows_examined` - Indicates the number of scanned rows. | ||
|
||
* `database` - Indicates the database that slow query logs belong to. | ||
|
||
* `users` - Indicates the name of the account. | ||
|
||
* `query_sample` - Indicates the execution syntax. | ||
|
||
* `type` - Indicates the statement type. | ||
|
||
* `start_time` - Indicates the start time in the **yyyy-mm-ddThh:mm:ssZ** format. | ||
|
||
* `client_ip` - Indicates the IP address of the client. |
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
93 changes: 93 additions & 0 deletions
93
...cloud/services/acceptance/gaussdb/data_source_huaweicloud_gaussdb_mysql_slow_logs_test.go
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,93 @@ | ||
package gaussdb | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
|
||
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance" | ||
) | ||
|
||
func TestAccDataSourceGaussDBMysqlSlowLogs_basic(t *testing.T) { | ||
dataSource := "data.huaweicloud_gaussdb_mysql_slow_logs.test" | ||
dc := acceptance.InitDataSourceCheck(dataSource) | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { | ||
acceptance.TestAccPreCheck(t) | ||
acceptance.TestAccPreCheckGaussDBMysqlInstanceId(t) | ||
acceptance.TestAccPreCheckGaussDBMysqlNodeId(t) | ||
acceptance.TestAccPreCheckGaussDBMysqlTimeRange(t) | ||
}, | ||
ProviderFactories: acceptance.TestAccProviderFactories, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testDataSourceGaussDBMysqlSlowLogs_basic(), | ||
Check: resource.ComposeTestCheckFunc( | ||
dc.CheckResourceExists(), | ||
resource.TestCheckResourceAttrSet(dataSource, "slow_log_list.#"), | ||
resource.TestCheckResourceAttrSet(dataSource, "slow_log_list.0.node_id"), | ||
resource.TestCheckResourceAttrSet(dataSource, "slow_log_list.0.count"), | ||
resource.TestCheckResourceAttrSet(dataSource, "slow_log_list.0.time"), | ||
resource.TestCheckResourceAttrSet(dataSource, "slow_log_list.0.lock_time"), | ||
resource.TestCheckResourceAttrSet(dataSource, "slow_log_list.0.rows_sent"), | ||
resource.TestCheckResourceAttrSet(dataSource, "slow_log_list.0.rows_examined"), | ||
resource.TestCheckResourceAttrSet(dataSource, "slow_log_list.0.database"), | ||
resource.TestCheckResourceAttrSet(dataSource, "slow_log_list.0.users"), | ||
resource.TestCheckResourceAttrSet(dataSource, "slow_log_list.0.query_sample"), | ||
resource.TestCheckResourceAttrSet(dataSource, "slow_log_list.0.type"), | ||
resource.TestCheckResourceAttrSet(dataSource, "slow_log_list.0.start_time"), | ||
resource.TestCheckResourceAttrSet(dataSource, "slow_log_list.0.client_ip"), | ||
|
||
resource.TestCheckOutput("operate_type_filter_is_useful", "true"), | ||
resource.TestCheckOutput("database_filter_is_useful", "true"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testDataSourceGaussDBMysqlSlowLogs_basic() string { | ||
return fmt.Sprintf(` | ||
data "huaweicloud_gaussdb_mysql_slow_logs" "test" { | ||
instance_id = "%[1]s" | ||
node_id = "%[2]s" | ||
start_time = "%[3]s" | ||
end_time = "%[4]s" | ||
} | ||
locals { | ||
operate_type = "UPDATE" | ||
} | ||
data "huaweicloud_gaussdb_mysql_slow_logs" "operate_type_filter" { | ||
instance_id = "%[1]s" | ||
node_id = "%[2]s" | ||
start_time = "%[3]s" | ||
end_time = "%[4]s" | ||
operate_type = "UPDATE" | ||
} | ||
output "operate_type_filter_is_useful" { | ||
value = length(data.huaweicloud_gaussdb_mysql_slow_logs.operate_type_filter.slow_log_list) > 0 && alltrue( | ||
[for v in data.huaweicloud_gaussdb_mysql_slow_logs.operate_type_filter.slow_log_list[*].type : v == local.operate_type] | ||
) | ||
} | ||
locals { | ||
database = "test_db_1" | ||
} | ||
data "huaweicloud_gaussdb_mysql_slow_logs" "database_filter" { | ||
instance_id = "%[1]s" | ||
node_id = "%[2]s" | ||
start_time = "%[3]s" | ||
end_time = "%[4]s" | ||
database = "test_db_1" | ||
} | ||
output "database_filter_is_useful" { | ||
value = length(data.huaweicloud_gaussdb_mysql_slow_logs.database_filter.slow_log_list) > 0 && alltrue( | ||
[for v in data.huaweicloud_gaussdb_mysql_slow_logs.database_filter.slow_log_list[*].database : v == local.database] | ||
) | ||
} | ||
`, acceptance.HW_GAUSSDB_MYSQL_INSTANCE_ID, acceptance.HW_GAUSSDB_MYSQL_NODE_ID, acceptance.HW_GAUSSDB_MYSQL_START_TIME, | ||
acceptance.HW_GAUSSDB_MYSQL_END_TIME) | ||
} |
Oops, something went wrong.