diff --git a/datadog-accessors.go b/datadog-accessors.go index 5555abc..c8beac7 100644 --- a/datadog-accessors.go +++ b/datadog-accessors.go @@ -13964,6 +13964,99 @@ func (s *ServiceLevelObjective) SetTypeID(v int) { s.TypeID = &v } +// GetID returns the ID field if non-nil, zero value otherwise. +func (s *ServiceLevelObjectiveDeleteTimeFramesError) GetID() string { + if s == nil || s.ID == nil { + return "" + } + return *s.ID +} + +// GetIDOk returns a tuple with the ID field if it's non-nil, zero value otherwise +// and a boolean to check if the value has been set. +func (s *ServiceLevelObjectiveDeleteTimeFramesError) GetIDOk() (string, bool) { + if s == nil || s.ID == nil { + return "", false + } + return *s.ID, true +} + +// HasID returns a boolean if a field has been set. +func (s *ServiceLevelObjectiveDeleteTimeFramesError) HasID() bool { + if s != nil && s.ID != nil { + return true + } + + return false +} + +// SetID allocates a new s.ID and returns the pointer to it. +func (s *ServiceLevelObjectiveDeleteTimeFramesError) SetID(v string) { + s.ID = &v +} + +// GetMessage returns the Message field if non-nil, zero value otherwise. +func (s *ServiceLevelObjectiveDeleteTimeFramesError) GetMessage() string { + if s == nil || s.Message == nil { + return "" + } + return *s.Message +} + +// GetMessageOk returns a tuple with the Message field if it's non-nil, zero value otherwise +// and a boolean to check if the value has been set. +func (s *ServiceLevelObjectiveDeleteTimeFramesError) GetMessageOk() (string, bool) { + if s == nil || s.Message == nil { + return "", false + } + return *s.Message, true +} + +// HasMessage returns a boolean if a field has been set. +func (s *ServiceLevelObjectiveDeleteTimeFramesError) HasMessage() bool { + if s != nil && s.Message != nil { + return true + } + + return false +} + +// SetMessage allocates a new s.Message and returns the pointer to it. +func (s *ServiceLevelObjectiveDeleteTimeFramesError) SetMessage(v string) { + s.Message = &v +} + +// GetTimeFrame returns the TimeFrame field if non-nil, zero value otherwise. +func (s *ServiceLevelObjectiveDeleteTimeFramesError) GetTimeFrame() string { + if s == nil || s.TimeFrame == nil { + return "" + } + return *s.TimeFrame +} + +// GetTimeFrameOk returns a tuple with the TimeFrame field if it's non-nil, zero value otherwise +// and a boolean to check if the value has been set. +func (s *ServiceLevelObjectiveDeleteTimeFramesError) GetTimeFrameOk() (string, bool) { + if s == nil || s.TimeFrame == nil { + return "", false + } + return *s.TimeFrame, true +} + +// HasTimeFrame returns a boolean if a field has been set. +func (s *ServiceLevelObjectiveDeleteTimeFramesError) HasTimeFrame() bool { + if s != nil && s.TimeFrame != nil { + return true + } + + return false +} + +// SetTimeFrame allocates a new s.TimeFrame and returns the pointer to it. +func (s *ServiceLevelObjectiveDeleteTimeFramesError) SetTimeFrame(v string) { + s.TimeFrame = &v +} + // GetDenominator returns the Denominator field if non-nil, zero value otherwise. func (s *ServiceLevelObjectiveMetricQuery) GetDenominator() string { if s == nil || s.Denominator == nil { diff --git a/service_level_objectives.go b/service_level_objectives.go index ad3d649..a257ac4 100644 --- a/service_level_objectives.go +++ b/service_level_objectives.go @@ -1,7 +1,6 @@ package datadog import ( - "encoding/json" "fmt" "net/url" "strings" @@ -49,16 +48,33 @@ type ServiceLevelObjectiveMetricQuery struct { Denominator *string `json:"denominator,omitempty"` } +type ServiceLevelObjectiveThresholds []*ServiceLevelObjectiveThreshold + +// Len implements sort.Interface length +func (t ServiceLevelObjectiveThresholds) Len() int { + return len(t) +} + +// Less implements sort.Interface less comparator +func (t ServiceLevelObjectiveThresholds) Less(i, j int) bool { + return strings.Compare(t[i].GetTimeFrame(), t[j].GetTimeFrame()) == -1 +} + +// Swap implements sort.Interface swap method +func (t ServiceLevelObjectiveThresholds) Swap(i, j int) { + t[i], t[j] = t[j], t[i] +} + // ServiceLevelObjective defines the Service Level Objective entity type ServiceLevelObjective struct { // Common - ID *string `json:"id,omitempty"` - Name *string `json:"name,omitempty"` - Description *string `json:"description,omitempty"` - Tags []string `json:"tags,omitempty"` - Thresholds []*ServiceLevelObjectiveThreshold `json:"thresholds,omitempty"` - Type *string `json:"type,omitempty"` - TypeID *int `json:"type_id,omitempty"` // Read-Only + ID *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Description *string `json:"description,omitempty"` + Tags []string `json:"tags,omitempty"` + Thresholds ServiceLevelObjectiveThresholds `json:"thresholds,omitempty"` + Type *string `json:"type,omitempty"` + TypeID *int `json:"type_id,omitempty"` // Read-Only // SLI definition Query *ServiceLevelObjectiveMetricQuery `json:"query,omitempty"` MonitorIDs []int `json:"monitor_ids,omitempty"` @@ -253,9 +269,22 @@ type ServiceLevelObjectiveDeleteTimeFramesResponse struct { UpdatedIDs []string `json:"updated"` } +// ServiceLevelObjectiveDeleteTimeFramesError is the error specific to deleting individual time frames. +// It contains more detailed information than the standard error. +type ServiceLevelObjectiveDeleteTimeFramesError struct { + ID *string `json:"id"` + TimeFrame *string `json:"timeframe"` + Message *string `json:"message"` +} + +// Error computes the human readable error +func (e ServiceLevelObjectiveDeleteTimeFramesError) Error() string { + return fmt.Sprintf("error=%s id=%s for timeframe=%s", e.GetMessage(), e.GetID(), e.GetTimeFrame()) +} + type timeframesDeleteResp struct { Data *ServiceLevelObjectiveDeleteTimeFramesResponse `json:"data"` - Errors []map[string]interface{} `json:"errors"` + Errors []*ServiceLevelObjectiveDeleteTimeFramesError `json:"errors"` } // DeleteServiceLevelObjectiveTimeFrames will delete SLO timeframes individually. @@ -275,10 +304,7 @@ func (client *Client) DeleteServiceLevelObjectiveTimeFrames(timeframeByID map[st if out.Errors != nil && len(out.Errors) > 0 { errMsgs := make([]string, 0) for _, e := range out.Errors { - if len(e) > 0 { - b, _ := json.Marshal(e) - errMsgs = append(errMsgs, string(b)) - } + errMsgs = append(errMsgs, e.Error()) } return nil, fmt.Errorf("errors deleting timeframes: %s", strings.Join(errMsgs, ",")) } diff --git a/tests/fixtures/service_level_objectives/delete_by_timeframe_response.json b/tests/fixtures/service_level_objectives/delete_by_timeframe_response.json index 4484bc2..8f866df 100644 --- a/tests/fixtures/service_level_objectives/delete_by_timeframe_response.json +++ b/tests/fixtures/service_level_objectives/delete_by_timeframe_response.json @@ -3,5 +3,5 @@ "deleted": ["abcdefabcdefabcdefabcdefabcdefab"], "updated": ["12345678901234567890123456789012"] }, - "error": null + "errors": null } \ No newline at end of file