Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: aliyun/aliyun-log-go-sdk
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.1.97
Choose a base ref
...
head repository: aliyun/aliyun-log-go-sdk
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.1.98
Choose a head ref
  • 1 commit
  • 3 files changed
  • 1 contributor

Commits on Mar 14, 2025

  1. Deprecate alert state (#328)

    * feat: make state of alert deprecated, use status instead
    crimson-gao authored Mar 14, 2025
    Copy the full SHA
    65e8a32 View commit details
Showing with 20 additions and 15 deletions.
  1. +16 −7 client_alert.go
  2. +4 −6 client_alert_test.go
  3. +0 −2 example/alert/alert_example.go
23 changes: 16 additions & 7 deletions client_alert.go
Original file line number Diff line number Diff line change
@@ -155,28 +155,37 @@ type SinkAlerthubConfiguration struct {
}

type Alert struct {
Name string `json:"name"`
DisplayName string `json:"displayName"`
Description string `json:"description"`
State string `json:"state"`
Status string `json:"status"`
Name string `json:"name"`
DisplayName string `json:"displayName"`
Description string `json:"description"`
// Deprecated: use `alert.IsEnabled()` to get the status, use api EnableAlert and DisableAlert to enable/disable the alert
State string `json:"state,omitempty"`
Status string `json:"status,omitempty"`
Configuration *AlertConfiguration `json:"configuration"`
Schedule *Schedule `json:"schedule"`
CreateTime int64 `json:"createTime,omitempty"`
LastModifiedTime int64 `json:"lastModifiedTime,omitempty"`
}

func (alert *Alert) IsEnabled() bool {
return alert.Status == "ENABLED"
}

func (alert *Alert) MarshalJSON() ([]byte, error) {
body := map[string]interface{}{
"name": alert.Name,
"displayName": alert.DisplayName,
"description": alert.Description,
"state": alert.State,
"status": alert.Status,
"configuration": alert.Configuration,
"schedule": alert.Schedule,
"type": "Alert",
}
if alert.State != "" {
body["state"] = alert.State
}
if alert.Status != "" {
body["status"] = alert.Status
}
return json.Marshal(body)
}

10 changes: 4 additions & 6 deletions client_alert_test.go
Original file line number Diff line number Diff line change
@@ -74,7 +74,6 @@ func (s *AlertTestSuite) createAlert() error {
}
alert := &Alert{
Name: s.alertName,
State: "Enabled",
DisplayName: "AlertTest By GO SDK",
Description: "Description for alert",
Schedule: &Schedule{
@@ -130,7 +129,6 @@ func (s *AlertTestSuite) createAlert2() error {
}
alert := &Alert{
Name: s.alertName,
State: "Enabled",
DisplayName: "AlertTest By GO SDK ",
Description: "Description for alert by go sdk",
Schedule: &Schedule{
@@ -303,12 +301,12 @@ func (s *AlertTestSuite) TestClient_DisableAndEnableAlert() {
s.Require().Nil(err)
alert, err := s.client.GetAlert(s.projectName, s.alertName)
s.Require().Nil(err)
s.Require().Equal("Disabled", alert.State, "disable alert failed")
s.Require().False(alert.IsEnabled(), "disable alert failed")
err = s.client.EnableAlert(s.projectName, s.alertName)
s.Require().Nil(err)
alert, err = s.client.GetAlert(s.projectName, s.alertName)
s.Require().Nil(err)
s.Require().Equal("Enabled", alert.State, "enable alert failed")
s.Require().True(alert.IsEnabled(), "enable alert failed")
err = s.client.DeleteAlert(s.projectName, s.alertName)
s.Require().Nil(err)
}
@@ -320,12 +318,12 @@ func (s *AlertTestSuite) TestClient_DisableAndEnableAlert2() {
s.Require().Nil(err)
alert, err := s.client.GetAlert(s.projectName, s.alertName)
s.Require().Nil(err)
s.Require().Equal("Disabled", alert.State, "disable alert failed")
s.Require().False(alert.IsEnabled(), "disable alert failed")
err = s.client.EnableAlert(s.projectName, s.alertName)
s.Require().Nil(err)
alert, err = s.client.GetAlert(s.projectName, s.alertName)
s.Require().Nil(err)
s.Require().Equal("Enabled", alert.State, "enable alert failed")
s.Require().True(alert.IsEnabled(), "enable alert failed")
err = s.client.DeleteAlert(s.projectName, s.alertName)
s.Require().Nil(err)
}
2 changes: 0 additions & 2 deletions example/alert/alert_example.go
Original file line number Diff line number Diff line change
@@ -53,8 +53,6 @@ func main() {
Name: alertName,
DisplayName: "count monitoring",
Description: "",
State: "Enabled",
Status: "",
Configuration: &sls.AlertConfiguration{
Condition: "count > 0",
Dashboard: dashboardName,