Skip to content

Commit

Permalink
feat(GaussDBforMySQL): gaussdb mysql instance support slow log show o…
Browse files Browse the repository at this point in the history
…riginal switch (#5766)
  • Loading branch information
houpeng80 authored Oct 30, 2024
1 parent d1857c5 commit 1fa6b5a
Show file tree
Hide file tree
Showing 9 changed files with 127 additions and 4 deletions.
2 changes: 2 additions & 0 deletions docs/resources/gaussdb_mysql_instance.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ The following arguments are supported:

Defaults to **true**.

* `slow_log_show_original_switch` - (Optional, Bool) Specifies the slow log show original switch of the instance.

* `description` - (Optional, String) Specifies the description of the instance.

* `private_write_ip` - (Optional, String) Specifies the private IP address of the DB instance.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.18

require (
github.com/GehirnInc/crypt v0.0.0-20200316065508-bb7000b8a962
github.com/chnsz/golangsdk v0.0.0-20241024112204-a96c8484ffa3
github.com/chnsz/golangsdk v0.0.0-20241026031406-eeb6712069c7
github.com/hashicorp/go-cleanhttp v0.5.2
github.com/hashicorp/go-multierror v1.1.1
github.com/hashicorp/go-uuid v1.0.3
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ github.com/apparentlymart/go-textseg/v13 v13.0.0 h1:Y+KvPE1NYz0xl601PVImeQfFyEy6
github.com/apparentlymart/go-textseg/v13 v13.0.0/go.mod h1:ZK2fH7c4NqDTLtiYLvIkEghdlcqw7yxLeM89kiTRPUo=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/chnsz/golangsdk v0.0.0-20241024112204-a96c8484ffa3 h1:afaYCtfr7XhRkJQd2UupmTst+/ProhdVdp6tE616mdg=
github.com/chnsz/golangsdk v0.0.0-20241024112204-a96c8484ffa3/go.mod h1:Erm4hDWxXgAdbkG3+hhJFgRzEL1TvvcroWzw2Gax4uI=
github.com/chnsz/golangsdk v0.0.0-20241026031406-eeb6712069c7 h1:pjlmJMw0DC5orJnnPxHooMQpMCuKxRFn0ZpiC1EdrBI=
github.com/chnsz/golangsdk v0.0.0-20241026031406-eeb6712069c7/go.mod h1:Erm4hDWxXgAdbkG3+hhJFgRzEL1TvvcroWzw2Gax4uI=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func TestAccGaussDBInstance_basic(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "maintain_end", "11:00"),
resource.TestCheckResourceAttr(resourceName, "seconds_level_monitoring_enabled", "true"),
resource.TestCheckResourceAttr(resourceName, "seconds_level_monitoring_period", "1"),
resource.TestCheckResourceAttr(resourceName, "slow_log_show_original_switch", "true"),
resource.TestCheckResourceAttr(resourceName, "description", "test_description"),
resource.TestCheckResourceAttr(resourceName, "encryption_status", "ON"),
resource.TestCheckResourceAttr(resourceName, "tags.foo", "bar"),
Expand Down Expand Up @@ -111,6 +112,7 @@ func TestAccGaussDBInstance_basic(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "maintain_begin", "14:00"),
resource.TestCheckResourceAttr(resourceName, "maintain_end", "18:00"),
resource.TestCheckResourceAttr(resourceName, "seconds_level_monitoring_enabled", "false"),
resource.TestCheckResourceAttr(resourceName, "slow_log_show_original_switch", "false"),
resource.TestCheckResourceAttr(resourceName, "description", ""),
resource.TestCheckResourceAttr(resourceName, "encryption_status", "OFF"),
resource.TestCheckResourceAttr(resourceName, "tags.foo_update", "bar"),
Expand Down Expand Up @@ -325,6 +327,8 @@ resource "huaweicloud_gaussdb_mysql_instance" "test" {
seconds_level_monitoring_enabled = true
seconds_level_monitoring_period = 1
slow_log_show_original_switch = true
encryption_status = "ON"
encryption_type = "kms"
kms_key_id = huaweicloud_kms_key.test.id
Expand Down Expand Up @@ -392,6 +396,8 @@ resource "huaweicloud_gaussdb_mysql_instance" "test" {
seconds_level_monitoring_enabled = false
slow_log_show_original_switch = false
encryption_status = "OFF"
parameters {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,11 @@ func ResourceGaussDBInstance() *schema.Resource {
Optional: true,
ValidateFunc: validation.StringInSlice([]string{"true", "false"}, false),
},
"slow_log_show_original_switch": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
},
"description": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -819,6 +824,12 @@ func resourceGaussDBInstanceCreate(ctx context.Context, d *schema.ResourceData,
}
}

if _, ok := d.GetOk("slow_log_show_original_switch"); ok {
if err = updateSlowLogShowOriginalSwitch(client, d); err != nil {
return diag.FromErr(err)
}
}

if _, ok := d.GetOk("description"); ok {
if err = updateDescription(client, d); err != nil {
return diag.FromErr(err)
Expand Down Expand Up @@ -980,6 +991,8 @@ func resourceGaussDBInstanceRead(ctx context.Context, d *schema.ResourceData, me
mErr = multierror.Append(mErr, setEncryption(d, client, instanceID))
// set version
mErr = multierror.Append(mErr, setVersion(d, client, instanceID)...)
// set slow log show original
mErr = multierror.Append(mErr, setSlowLogShowOriginalSwitch(d, client, instanceID))

// save tags
if resourceTags, err := tags.Get(client, "instances", d.Id()).Extract(); err == nil {
Expand Down Expand Up @@ -1197,6 +1210,16 @@ func setVersion(d *schema.ResourceData, client *golangsdk.ServiceClient, instanc
return errs
}

func setSlowLogShowOriginalSwitch(d *schema.ResourceData, client *golangsdk.ServiceClient, instanceId string) error {
resp, err := instances.GetSlowLogShowOriginalSwitch(client, instanceId).Extract()
if err != nil {
log.Printf("[WARN] query instance %s slow log show original failed: %s", instanceId, err)
return nil
}
slowLogShowOriginalSwitch, _ := strconv.ParseBool(resp.OpenSlowLogSwitch)
return d.Set("slow_log_show_original_switch", slowLogShowOriginalSwitch)
}

func setGaussDBMySQLParameters(ctx context.Context, d *schema.ResourceData, client *golangsdk.ServiceClient) diag.Diagnostics {
parametersList, err := parameters.List(client, d.Id())
if err != nil {
Expand Down Expand Up @@ -1406,6 +1429,13 @@ func resourceGaussDBInstanceUpdate(ctx context.Context, d *schema.ResourceData,
}
}

if d.HasChange("slow_log_show_original_switch") {
err = updateSlowLogShowOriginalSwitch(client, d)
if err != nil {
return diag.FromErr(err)
}
}

if d.HasChange("description") {
err = updateDescription(client, d)
if err != nil {
Expand Down Expand Up @@ -2280,6 +2310,19 @@ func updateSslOption(ctx context.Context, client *golangsdk.ServiceClient, d *sc
return checkGaussDBMySQLJobFinish(ctx, client, job.JobID, d.Timeout(timeout))
}

func updateSlowLogShowOriginalSwitch(client *golangsdk.ServiceClient, d *schema.ResourceData) error {
opts := instances.UpdateSlowLogShowOriginalSwitchOpts{
OpenSlowLogSwitch: d.Get("slow_log_show_original_switch").(bool),
}

_, err := instances.UpdateSlowLogShowOriginalSwitch(client, d.Id(), opts).ExtractUpdateSlowLogShowOriginalSwitchResponse()
if err != nil {
return fmt.Errorf("error updating slow low show original switch for instance %s: %s ", d.Id(), err)
}

return nil
}

func updateDescription(client *golangsdk.ServiceClient, d *schema.ResourceData) error {
updateAliasOpts := instances.UpdateAliasOpts{
Alias: d.Get("description").(string),
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ github.com/apparentlymart/go-cidr/cidr
# github.com/apparentlymart/go-textseg/v13 v13.0.0
## explicit; go 1.16
github.com/apparentlymart/go-textseg/v13/textseg
# github.com/chnsz/golangsdk v0.0.0-20241024112204-a96c8484ffa3
# github.com/chnsz/golangsdk v0.0.0-20241026031406-eeb6712069c7
## explicit; go 1.14
github.com/chnsz/golangsdk
github.com/chnsz/golangsdk/auth
Expand Down

0 comments on commit 1fa6b5a

Please sign in to comment.