Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change service level objective history response structs #330

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func (client *Client) Validate() (bool, error) {
return false, err
}
req.Header.Set("DD-API-KEY", client.apiKey)
if (client.appKey != "") {
if client.appKey != "" {
req.Header.Set("DD-APPLICATION-KEY", client.appKey)
}

Expand Down
31 changes: 31 additions & 0 deletions datadog-accessors.go
Original file line number Diff line number Diff line change
Expand Up @@ -19358,6 +19358,37 @@ func (s *ServiceLevelObjectiveHistoryResponseData) SetOverall(v ServiceLevelObje
s.Overall = &v
}

// GetSlo returns the Slo field if non-nil, zero value otherwise.
func (s *ServiceLevelObjectiveHistoryResponseData) GetSlo() ServiceLevelObjective {
if s == nil || s.Slo == nil {
return ServiceLevelObjective{}
}
return *s.Slo
}

// GetSloOk returns a tuple with the Slo field if it's non-nil, zero value otherwise
// and a boolean to check if the value has been set.
func (s *ServiceLevelObjectiveHistoryResponseData) GetSloOk() (ServiceLevelObjective, bool) {
if s == nil || s.Slo == nil {
return ServiceLevelObjective{}, false
}
return *s.Slo, true
}

// HasSlo returns a boolean if a field has been set.
func (s *ServiceLevelObjectiveHistoryResponseData) HasSlo() bool {
if s != nil && s.Slo != nil {
return true
}

return false
}

// SetSlo allocates a new s.Slo and returns the pointer to it.
func (s *ServiceLevelObjectiveHistoryResponseData) SetSlo(v ServiceLevelObjective) {
s.Slo = &v
}

// GetDenominator returns the Denominator field if non-nil, zero value otherwise.
func (s *ServiceLevelObjectiveMetricQuery) GetDenominator() string {
if s == nil || s.Denominator == nil {
Expand Down
27 changes: 20 additions & 7 deletions service_level_objectives.go
Original file line number Diff line number Diff line change
Expand Up @@ -525,12 +525,22 @@ type ServiceLevelObjectiveHistoryMetricSeries struct {

// ServiceLevelObjectiveHistoryMonitorSeries defines the SLO history data response for `monitor` type SLOs
type ServiceLevelObjectiveHistoryMonitorSeries struct {
SliValue float32 `json:"sli_value"`
SpanPrecision json.Number `json:"span_precision"`
Name string `json:"name"`
Precision map[string]json.Number `json:"precision"`
Preview bool `json:"preview"`
History []ServiceLevelObjectiveHistorySeriesPoint `json:"history"`
SliValue float32 `json:"sli_value"`
SpanPrecision json.Number `json:"span_precision"`
Name string `json:"name"`
Precision json.Number `json:"precision"`
Preview bool `json:"preview"`
History []ServiceLevelObjectiveHistorySeriesPoint `json:"history"`
ID int64 `json:"id"`
MonitorType string `json:"monitor_type"`
MonitorModified int64 `json:"monitor_modified"`
Errors []ServiceLevelObjectiveHistoryMonitorSeriesError `json:"errors"`
}

// ServiceLevelObjectiveHistoryMonitorSeriesError is the error specific to monitors.
type ServiceLevelObjectiveHistoryMonitorSeriesError struct {
ErrorType string `json:"error_type"`
ErrorMessage string `json:"error_message"`
}

// ServiceLevelObjectiveHistoryOverall defines the overall SLO history data response
Expand All @@ -556,12 +566,15 @@ type ServiceLevelObjectiveHistoryResponseData struct {
FromTs int64 `json:"from_ts"`
Thresholds map[string]ServiceLevelObjectiveThreshold `json:"thresholds"`
Overall *ServiceLevelObjectiveHistoryOverall `json:"overall"`
Slo *ServiceLevelObjective `json:"slo"`
Type string `json:"type"`

// metric based SLO
Metrics *ServiceLevelObjectiveHistoryMetricSeries `json:"series"`

// monitor based SLO
Groups []*ServiceLevelObjectiveHistoryMonitorSeries `json:"groups"`
Groups []*ServiceLevelObjectiveHistoryMonitorSeries `json:"groups"`
Monitors []*ServiceLevelObjectiveHistoryMonitorSeries `json:"monitors"`
}

// ServiceLevelObjectiveHistoryResponse is the canonical response for SLO history data.
Expand Down
53 changes: 53 additions & 0 deletions service_level_objectives_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,9 +351,62 @@ func TestServiceLevelObjectiveIntegration(t *testing.T) {
assert.NoError(t2, err)
assert.Nil(t2, resp.Error)
assert.Equal(t2, float32(6.765872955322266), resp.Data.Overall.SliValue)

typeID := 0
createdAt := 1563283800
modifiedAt := 1563283800
slo := &ServiceLevelObjective{
ID: sptr("12345678901234567890123456789012"),
Name: sptr("Test SLO"),
Description: sptr("test slo description"),
Tags: []string{"product:foo"},
Thresholds: []*ServiceLevelObjectiveThreshold{
{
TimeFrame: String("7d"),
Target: Float64(99),
TargetDisplay: String("99.0"),
Warning: Float64(99.5),
WarningDisplay: String("99.5"),
},
{
TimeFrame: String("30d"),
Target: Float64(98),
TargetDisplay: String("98.0"),
Warning: Float64(99),
WarningDisplay: String("99.0"),
},
},
Type: sptr("monitor"),
TypeID: &typeID,
MonitorIDs: []int{1},
MonitorTags: []string{"service:bar", "team:a"},
Creator: &Creator{
Handle: sptr("[email protected]"),
Email: sptr("[email protected]"),
Name: sptr("Jane Doe"),
},
CreatedAt: &createdAt,
ModifiedAt: &modifiedAt,
}
assert.Equal(t2, slo, resp.Data.Slo)
assert.Equal(t2, "monitor", resp.Data.Type)

assert.Len(t2, resp.Data.Groups, 1)
assert.Equal(t2, float32(6.765872955322266), resp.Data.Groups[0].SliValue)
assert.Equal(t2, "some:tag", resp.Data.Groups[0].Name)
group_precision, _ := resp.Data.Groups[0].Precision.Int64()
assert.Equal(t2, int64(1), group_precision)

assert.Len(t2, resp.Data.Monitors, 1)
assert.Equal(t2, int64(12345678), resp.Data.Monitors[0].ID)
assert.Equal(t2, float32(6.765872955322266), resp.Data.Monitors[0].SliValue)
assert.Equal(t2, "some:tag", resp.Data.Monitors[0].Name)
assert.Equal(t2, "query alert", resp.Data.Monitors[0].MonitorType)
assert.Equal(t2, int64(1563283800), resp.Data.Monitors[0].MonitorModified)
monitor_precision, _ := resp.Data.Monitors[0].Precision.Int64()
assert.Equal(t2, int64(1), monitor_precision)
assert.Equal(t2, "ERROR_TYPE", resp.Data.Monitors[0].Errors[0].ErrorType)
assert.Equal(t2, "error message", resp.Data.Monitors[0].Errors[0].ErrorMessage)
})

}
Loading