diff --git a/client.go b/client.go index 39558ef..af276c4 100644 --- a/client.go +++ b/client.go @@ -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) } diff --git a/datadog-accessors.go b/datadog-accessors.go index a845434..68a6b74 100644 --- a/datadog-accessors.go +++ b/datadog-accessors.go @@ -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 { diff --git a/service_level_objectives.go b/service_level_objectives.go index 0301e40..3fad1ac 100644 --- a/service_level_objectives.go +++ b/service_level_objectives.go @@ -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 @@ -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. diff --git a/service_level_objectives_test.go b/service_level_objectives_test.go index 34ce864..49743bf 100644 --- a/service_level_objectives_test.go +++ b/service_level_objectives_test.go @@ -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("jane.doe@example.com"), + Email: sptr("jane.doe@example.com"), + 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) }) } diff --git a/tests/fixtures/service_level_objectives/get_history_monitor_response.json b/tests/fixtures/service_level_objectives/get_history_monitor_response.json index 8b9a997..4e6faf8 100644 --- a/tests/fixtures/service_level_objectives/get_history_monitor_response.json +++ b/tests/fixtures/service_level_objectives/get_history_monitor_response.json @@ -590,10 +590,626 @@ "sli_value": 6.765872955322266, "span_precision": 2, "name": "some:tag", - "precision": { - "7d": 2 + "precision": 1, + "preview": true, + "history": [ + [ + 1571139968, + 1 + ], + [ + 1571185988, + 0 + ], + [ + 1571187248, + 1 + ], + [ + 1571200628, + 0 + ], + [ + 1571201408, + 1 + ], + [ + 1571242748, + 0 + ], + [ + 1571242868, + 1 + ], + [ + 1571315828, + 0 + ], + [ + 1571316548, + 1 + ], + [ + 1571330108, + 0 + ], + [ + 1571331008, + 1 + ], + [ + 1571344388, + 0 + ], + [ + 1571345408, + 1 + ], + [ + 1571358968, + 0 + ], + [ + 1571359748, + 1 + ], + [ + 1571369588, + 0 + ], + [ + 1571369708, + 1 + ], + [ + 1571370788, + 0 + ], + [ + 1571370908, + 1 + ], + [ + 1571371688, + 0 + ], + [ + 1571371988, + 1 + ], + [ + 1571376188, + 0 + ], + [ + 1571378408, + 1 + ], + [ + 1571382428, + 0 + ], + [ + 1571382548, + 1 + ], + [ + 1571383868, + 0 + ], + [ + 1571384228, + 1 + ], + [ + 1571385848, + 0 + ], + [ + 1571386508, + 1 + ], + [ + 1571387768, + 0 + ], + [ + 1571388488, + 1 + ], + [ + 1571389328, + 0 + ], + [ + 1571389988, + 1 + ], + [ + 1571390468, + 0 + ], + [ + 1571390528, + 1 + ], + [ + 1571392508, + 0 + ], + [ + 1571393348, + 1 + ], + [ + 1571393528, + 0 + ], + [ + 1571393828, + 1 + ], + [ + 1571394608, + 0 + ], + [ + 1571395868, + 1 + ], + [ + 1571396408, + 0 + ], + [ + 1571396648, + 1 + ], + [ + 1571398028, + 0 + ], + [ + 1571400848, + 1 + ], + [ + 1571402348, + 0 + ], + [ + 1571402588, + 1 + ], + [ + 1571416688, + 0 + ], + [ + 1571417228, + 1 + ], + [ + 1571445368, + 0 + ], + [ + 1571446208, + 1 + ], + [ + 1571457908, + 0 + ], + [ + 1571458448, + 1 + ], + [ + 1571465588, + 0 + ], + [ + 1571465768, + 1 + ], + [ + 1571468828, + 0 + ], + [ + 1571468948, + 1 + ], + [ + 1571470088, + 0 + ], + [ + 1571470628, + 1 + ], + [ + 1571472128, + 0 + ], + [ + 1571472848, + 1 + ], + [ + 1571473988, + 0 + ], + [ + 1571474408, + 1 + ], + [ + 1571477528, + 0 + ], + [ + 1571477768, + 1 + ], + [ + 1571479748, + 0 + ], + [ + 1571480048, + 1 + ], + [ + 1571481008, + 0 + ], + [ + 1571481188, + 1 + ], + [ + 1571481968, + 0 + ], + [ + 1571482448, + 1 + ], + [ + 1571483048, + 0 + ], + [ + 1571483588, + 1 + ], + [ + 1571485208, + 0 + ], + [ + 1571485748, + 1 + ], + [ + 1571486288, + 0 + ], + [ + 1571487128, + 1 + ], + [ + 1571487548, + 0 + ], + [ + 1571487908, + 1 + ], + [ + 1571490848, + 0 + ], + [ + 1571491028, + 1 + ], + [ + 1571502848, + 0 + ], + [ + 1571502908, + 1 + ], + [ + 1571544188, + 0 + ], + [ + 1571544788, + 1 + ], + [ + 1571546228, + 0 + ], + [ + 1571546408, + 1 + ], + [ + 1571550728, + 0 + ], + [ + 1571552048, + 1 + ], + [ + 1571555108, + 0 + ], + [ + 1571555288, + 1 + ], + [ + 1571558588, + 0 + ], + [ + 1571559248, + 1 + ], + [ + 1571560388, + 0 + ], + [ + 1571561468, + 1 + ], + [ + 1571562668, + 0 + ], + [ + 1571562908, + 1 + ], + [ + 1571563928, + 0 + ], + [ + 1571564048, + 1 + ], + [ + 1571565248, + 0 + ], + [ + 1571566328, + 1 + ], + [ + 1571568188, + 0 + ], + [ + 1571569388, + 1 + ], + [ + 1571570348, + 0 + ], + [ + 1571571068, + 1 + ], + [ + 1571572628, + 0 + ], + [ + 1571573588, + 1 + ], + [ + 1571573888, + 0 + ], + [ + 1571574068, + 1 + ], + [ + 1571574788, + 0 + ], + [ + 1571575808, + 1 + ], + [ + 1571576948, + 0 + ], + [ + 1571577428, + 1 + ], + [ + 1571589428, + 0 + ], + [ + 1571589608, + 1 + ], + [ + 1571603768, + 0 + ], + [ + 1571604668, + 1 + ], + [ + 1571617988, + 0 + ], + [ + 1571619008, + 1 + ], + [ + 1571631068, + 0 + ], + [ + 1571631308, + 1 + ], + [ + 1571632448, + 0 + ], + [ + 1571632928, + 1 + ], + [ + 1571635148, + 0 + ], + [ + 1571635268, + 1 + ], + [ + 1571637068, + 0 + ], + [ + 1571638508, + 1 + ], + [ + 1571649188, + 0 + ], + [ + 1571649248, + 1 + ], + [ + 1571653328, + 0 + ], + [ + 1571653448, + 1 + ], + [ + 1571655728, + 0 + ], + [ + 1571655788, + 1 + ], + [ + 1571657948, + 0 + ], + [ + 1571659028, + 1 + ], + [ + 1571660228, + 0 + ], + [ + 1571660468, + 1 + ], + [ + 1571661128, + 0 + ], + [ + 1571661488, + 1 + ], + [ + 1571663408, + 0 + ], + [ + 1571663768, + 1 + ] + ] + } + ], + "slo": { + "id": "12345678901234567890123456789012", + "name": "Test SLO", + "tags": ["product:foo"], + "monitor_tags": ["service:bar", "team:a"], + "type": "monitor", + "type_id": 0, + "description": "test slo description", + "monitor_ids": [1], + "thresholds": [ + { + "timeframe": "7d", + "target": 99.0, + "target_display": "99.0", + "warning": 99.5, + "warning_display": "99.5" }, + { + "timeframe": "30d", + "target": 98, + "target_display": "98.0", + "warning": 99, + "warning_display": "99.0" + } + ], + "creator": { + "handle": "jane.doe@example.com", + "email": "jane.doe@example.com", + "name": "Jane Doe" + }, + "created_at": 1563283800, + "modified_at": 1563283800 + }, + "type": "monitor", + "monitors": [ + { + "sli_value": 6.765872955322266, + "span_precision": 2, + "id": 12345678, + "name": "some:tag", + "precision": 1, "preview": true, + "monitor_type": "query alert", + "errors": [ + { + "error_type": "ERROR_TYPE", + "error_message": "error message" + } + ], + "monitor_modified": 1563283800, "history": [ [ 1571139968,