diff --git a/datadog-accessors.go b/datadog-accessors.go index 83353bc..ab8b845 100644 --- a/datadog-accessors.go +++ b/datadog-accessors.go @@ -3579,130 +3579,6 @@ func (c *ConditionalFormat) SetValue(v string) { c.Value = &v } -// GetHost returns the Host field if non-nil, zero value otherwise. -func (c *Content) GetHost() string { - if c == nil || c.Host == nil { - return "" - } - return *c.Host -} - -// GetHostOk returns a tuple with the Host field if it's non-nil, zero value otherwise -// and a boolean to check if the value has been set. -func (c *Content) GetHostOk() (string, bool) { - if c == nil || c.Host == nil { - return "", false - } - return *c.Host, true -} - -// HasHost returns a boolean if a field has been set. -func (c *Content) HasHost() bool { - if c != nil && c.Host != nil { - return true - } - - return false -} - -// SetHost allocates a new c.Host and returns the pointer to it. -func (c *Content) SetHost(v string) { - c.Host = &v -} - -// GetMessage returns the Message field if non-nil, zero value otherwise. -func (c *Content) GetMessage() string { - if c == nil || c.Message == nil { - return "" - } - return *c.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 (c *Content) GetMessageOk() (string, bool) { - if c == nil || c.Message == nil { - return "", false - } - return *c.Message, true -} - -// HasMessage returns a boolean if a field has been set. -func (c *Content) HasMessage() bool { - if c != nil && c.Message != nil { - return true - } - - return false -} - -// SetMessage allocates a new c.Message and returns the pointer to it. -func (c *Content) SetMessage(v string) { - c.Message = &v -} - -// GetService returns the Service field if non-nil, zero value otherwise. -func (c *Content) GetService() string { - if c == nil || c.Service == nil { - return "" - } - return *c.Service -} - -// GetServiceOk returns a tuple with the Service field if it's non-nil, zero value otherwise -// and a boolean to check if the value has been set. -func (c *Content) GetServiceOk() (string, bool) { - if c == nil || c.Service == nil { - return "", false - } - return *c.Service, true -} - -// HasService returns a boolean if a field has been set. -func (c *Content) HasService() bool { - if c != nil && c.Service != nil { - return true - } - - return false -} - -// SetService allocates a new c.Service and returns the pointer to it. -func (c *Content) SetService(v string) { - c.Service = &v -} - -// GetTimestamp returns the Timestamp field if non-nil, zero value otherwise. -func (c *Content) GetTimestamp() time.Time { - if c == nil || c.Timestamp == nil { - return time.Time{} - } - return *c.Timestamp -} - -// GetTimestampOk returns a tuple with the Timestamp field if it's non-nil, zero value otherwise -// and a boolean to check if the value has been set. -func (c *Content) GetTimestampOk() (time.Time, bool) { - if c == nil || c.Timestamp == nil { - return time.Time{}, false - } - return *c.Timestamp, true -} - -// HasTimestamp returns a boolean if a field has been set. -func (c *Content) HasTimestamp() bool { - if c != nil && c.Timestamp != nil { - return true - } - - return false -} - -// SetTimestamp allocates a new c.Timestamp and returns the pointer to it. -func (c *Content) SetTimestamp(v time.Time) { - c.Timestamp = &v -} - // GetAccessRole returns the AccessRole field if non-nil, zero value otherwise. func (c *CreatedBy) GetAccessRole() string { if c == nil || c.AccessRole == nil { @@ -11546,6 +11422,130 @@ func (l *Logs) SetID(v string) { l.ID = &v } +// GetHost returns the Host field if non-nil, zero value otherwise. +func (l *LogsContent) GetHost() string { + if l == nil || l.Host == nil { + return "" + } + return *l.Host +} + +// GetHostOk returns a tuple with the Host field if it's non-nil, zero value otherwise +// and a boolean to check if the value has been set. +func (l *LogsContent) GetHostOk() (string, bool) { + if l == nil || l.Host == nil { + return "", false + } + return *l.Host, true +} + +// HasHost returns a boolean if a field has been set. +func (l *LogsContent) HasHost() bool { + if l != nil && l.Host != nil { + return true + } + + return false +} + +// SetHost allocates a new l.Host and returns the pointer to it. +func (l *LogsContent) SetHost(v string) { + l.Host = &v +} + +// GetMessage returns the Message field if non-nil, zero value otherwise. +func (l *LogsContent) GetMessage() string { + if l == nil || l.Message == nil { + return "" + } + return *l.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 (l *LogsContent) GetMessageOk() (string, bool) { + if l == nil || l.Message == nil { + return "", false + } + return *l.Message, true +} + +// HasMessage returns a boolean if a field has been set. +func (l *LogsContent) HasMessage() bool { + if l != nil && l.Message != nil { + return true + } + + return false +} + +// SetMessage allocates a new l.Message and returns the pointer to it. +func (l *LogsContent) SetMessage(v string) { + l.Message = &v +} + +// GetService returns the Service field if non-nil, zero value otherwise. +func (l *LogsContent) GetService() string { + if l == nil || l.Service == nil { + return "" + } + return *l.Service +} + +// GetServiceOk returns a tuple with the Service field if it's non-nil, zero value otherwise +// and a boolean to check if the value has been set. +func (l *LogsContent) GetServiceOk() (string, bool) { + if l == nil || l.Service == nil { + return "", false + } + return *l.Service, true +} + +// HasService returns a boolean if a field has been set. +func (l *LogsContent) HasService() bool { + if l != nil && l.Service != nil { + return true + } + + return false +} + +// SetService allocates a new l.Service and returns the pointer to it. +func (l *LogsContent) SetService(v string) { + l.Service = &v +} + +// GetTimestamp returns the Timestamp field if non-nil, zero value otherwise. +func (l *LogsContent) GetTimestamp() time.Time { + if l == nil || l.Timestamp == nil { + return time.Time{} + } + return *l.Timestamp +} + +// GetTimestampOk returns a tuple with the Timestamp field if it's non-nil, zero value otherwise +// and a boolean to check if the value has been set. +func (l *LogsContent) GetTimestampOk() (time.Time, bool) { + if l == nil || l.Timestamp == nil { + return time.Time{}, false + } + return *l.Timestamp, true +} + +// HasTimestamp returns a boolean if a field has been set. +func (l *LogsContent) HasTimestamp() bool { + if l != nil && l.Timestamp != nil { + return true + } + + return false +} + +// SetTimestamp allocates a new l.Timestamp and returns the pointer to it. +func (l *LogsContent) SetTimestamp(v time.Time) { + l.Timestamp = &v +} + // GetID returns the ID field if non-nil, zero value otherwise. func (l *LogSet) GetID() json.Number { if l == nil || l.ID == nil { @@ -11981,18 +11981,18 @@ func (l *LogsListRequest) SetStartAt(v string) { } // GetTime returns the Time field if non-nil, zero value otherwise. -func (l *LogsListRequest) GetTime() QueryTime { +func (l *LogsListRequest) GetTime() LogsListRequestQueryTime { if l == nil || l.Time == nil { - return QueryTime{} + return LogsListRequestQueryTime{} } return *l.Time } // GetTimeOk returns a tuple with the Time field if it's non-nil, zero value otherwise // and a boolean to check if the value has been set. -func (l *LogsListRequest) GetTimeOk() (QueryTime, bool) { +func (l *LogsListRequest) GetTimeOk() (LogsListRequestQueryTime, bool) { if l == nil || l.Time == nil { - return QueryTime{}, false + return LogsListRequestQueryTime{}, false } return *l.Time, true } @@ -12007,10 +12007,134 @@ func (l *LogsListRequest) HasTime() bool { } // SetTime allocates a new l.Time and returns the pointer to it. -func (l *LogsListRequest) SetTime(v QueryTime) { +func (l *LogsListRequest) SetTime(v LogsListRequestQueryTime) { l.Time = &v } +// GetOffset returns the Offset field if non-nil, zero value otherwise. +func (l *LogsListRequestQueryTime) GetOffset() int { + if l == nil || l.Offset == nil { + return 0 + } + return *l.Offset +} + +// GetOffsetOk returns a tuple with the Offset field if it's non-nil, zero value otherwise +// and a boolean to check if the value has been set. +func (l *LogsListRequestQueryTime) GetOffsetOk() (int, bool) { + if l == nil || l.Offset == nil { + return 0, false + } + return *l.Offset, true +} + +// HasOffset returns a boolean if a field has been set. +func (l *LogsListRequestQueryTime) HasOffset() bool { + if l != nil && l.Offset != nil { + return true + } + + return false +} + +// SetOffset allocates a new l.Offset and returns the pointer to it. +func (l *LogsListRequestQueryTime) SetOffset(v int) { + l.Offset = &v +} + +// GetTimeFrom returns the TimeFrom field if non-nil, zero value otherwise. +func (l *LogsListRequestQueryTime) GetTimeFrom() string { + if l == nil || l.TimeFrom == nil { + return "" + } + return *l.TimeFrom +} + +// GetTimeFromOk returns a tuple with the TimeFrom field if it's non-nil, zero value otherwise +// and a boolean to check if the value has been set. +func (l *LogsListRequestQueryTime) GetTimeFromOk() (string, bool) { + if l == nil || l.TimeFrom == nil { + return "", false + } + return *l.TimeFrom, true +} + +// HasTimeFrom returns a boolean if a field has been set. +func (l *LogsListRequestQueryTime) HasTimeFrom() bool { + if l != nil && l.TimeFrom != nil { + return true + } + + return false +} + +// SetTimeFrom allocates a new l.TimeFrom and returns the pointer to it. +func (l *LogsListRequestQueryTime) SetTimeFrom(v string) { + l.TimeFrom = &v +} + +// GetTimeTo returns the TimeTo field if non-nil, zero value otherwise. +func (l *LogsListRequestQueryTime) GetTimeTo() string { + if l == nil || l.TimeTo == nil { + return "" + } + return *l.TimeTo +} + +// GetTimeToOk returns a tuple with the TimeTo field if it's non-nil, zero value otherwise +// and a boolean to check if the value has been set. +func (l *LogsListRequestQueryTime) GetTimeToOk() (string, bool) { + if l == nil || l.TimeTo == nil { + return "", false + } + return *l.TimeTo, true +} + +// HasTimeTo returns a boolean if a field has been set. +func (l *LogsListRequestQueryTime) HasTimeTo() bool { + if l != nil && l.TimeTo != nil { + return true + } + + return false +} + +// SetTimeTo allocates a new l.TimeTo and returns the pointer to it. +func (l *LogsListRequestQueryTime) SetTimeTo(v string) { + l.TimeTo = &v +} + +// GetTimeZone returns the TimeZone field if non-nil, zero value otherwise. +func (l *LogsListRequestQueryTime) GetTimeZone() string { + if l == nil || l.TimeZone == nil { + return "" + } + return *l.TimeZone +} + +// GetTimeZoneOk returns a tuple with the TimeZone field if it's non-nil, zero value otherwise +// and a boolean to check if the value has been set. +func (l *LogsListRequestQueryTime) GetTimeZoneOk() (string, bool) { + if l == nil || l.TimeZone == nil { + return "", false + } + return *l.TimeZone, true +} + +// HasTimeZone returns a boolean if a field has been set. +func (l *LogsListRequestQueryTime) HasTimeZone() bool { + if l != nil && l.TimeZone != nil { + return true + } + + return false +} + +// SetTimeZone allocates a new l.TimeZone and returns the pointer to it. +func (l *LogsListRequestQueryTime) SetTimeZone(v string) { + l.TimeZone = &v +} + // GetFilter returns the Filter field if non-nil, zero value otherwise. func (l *LogsPipeline) GetFilter() FilterConfiguration { if l == nil || l.Filter == nil { @@ -15173,130 +15297,6 @@ func (q *QueryTableRequest) SetProcessQuery(v WidgetProcessQuery) { q.ProcessQuery = &v } -// GetOffset returns the Offset field if non-nil, zero value otherwise. -func (q *QueryTime) GetOffset() int { - if q == nil || q.Offset == nil { - return 0 - } - return *q.Offset -} - -// GetOffsetOk returns a tuple with the Offset field if it's non-nil, zero value otherwise -// and a boolean to check if the value has been set. -func (q *QueryTime) GetOffsetOk() (int, bool) { - if q == nil || q.Offset == nil { - return 0, false - } - return *q.Offset, true -} - -// HasOffset returns a boolean if a field has been set. -func (q *QueryTime) HasOffset() bool { - if q != nil && q.Offset != nil { - return true - } - - return false -} - -// SetOffset allocates a new q.Offset and returns the pointer to it. -func (q *QueryTime) SetOffset(v int) { - q.Offset = &v -} - -// GetTimeFrom returns the TimeFrom field if non-nil, zero value otherwise. -func (q *QueryTime) GetTimeFrom() string { - if q == nil || q.TimeFrom == nil { - return "" - } - return *q.TimeFrom -} - -// GetTimeFromOk returns a tuple with the TimeFrom field if it's non-nil, zero value otherwise -// and a boolean to check if the value has been set. -func (q *QueryTime) GetTimeFromOk() (string, bool) { - if q == nil || q.TimeFrom == nil { - return "", false - } - return *q.TimeFrom, true -} - -// HasTimeFrom returns a boolean if a field has been set. -func (q *QueryTime) HasTimeFrom() bool { - if q != nil && q.TimeFrom != nil { - return true - } - - return false -} - -// SetTimeFrom allocates a new q.TimeFrom and returns the pointer to it. -func (q *QueryTime) SetTimeFrom(v string) { - q.TimeFrom = &v -} - -// GetTimeTo returns the TimeTo field if non-nil, zero value otherwise. -func (q *QueryTime) GetTimeTo() string { - if q == nil || q.TimeTo == nil { - return "" - } - return *q.TimeTo -} - -// GetTimeToOk returns a tuple with the TimeTo field if it's non-nil, zero value otherwise -// and a boolean to check if the value has been set. -func (q *QueryTime) GetTimeToOk() (string, bool) { - if q == nil || q.TimeTo == nil { - return "", false - } - return *q.TimeTo, true -} - -// HasTimeTo returns a boolean if a field has been set. -func (q *QueryTime) HasTimeTo() bool { - if q != nil && q.TimeTo != nil { - return true - } - - return false -} - -// SetTimeTo allocates a new q.TimeTo and returns the pointer to it. -func (q *QueryTime) SetTimeTo(v string) { - q.TimeTo = &v -} - -// GetTimeZone returns the TimeZone field if non-nil, zero value otherwise. -func (q *QueryTime) GetTimeZone() string { - if q == nil || q.TimeZone == nil { - return "" - } - return *q.TimeZone -} - -// GetTimeZoneOk returns a tuple with the TimeZone field if it's non-nil, zero value otherwise -// and a boolean to check if the value has been set. -func (q *QueryTime) GetTimeZoneOk() (string, bool) { - if q == nil || q.TimeZone == nil { - return "", false - } - return *q.TimeZone, true -} - -// HasTimeZone returns a boolean if a field has been set. -func (q *QueryTime) HasTimeZone() bool { - if q != nil && q.TimeZone != nil { - return true - } - - return false -} - -// SetTimeZone allocates a new q.TimeZone and returns the pointer to it. -func (q *QueryTime) SetTimeZone(v string) { - q.TimeZone = &v -} - // GetAutoscale returns the Autoscale field if non-nil, zero value otherwise. func (q *QueryValueDefinition) GetAutoscale() bool { if q == nil || q.Autoscale == nil { diff --git a/log_lists.go b/log_lists.go index d668f3e..a7971b6 100644 --- a/log_lists.go +++ b/log_lists.go @@ -8,16 +8,16 @@ const logsListPath = "/v1/logs-queries/list" // LogsListRequest represents the request body sent to the list API type LogsListRequest struct { - Index *string `json:"index,omitempty"` - Limit *int `json:"limit,omitempty"` - Query *string `json:"query"` - Sort *string `json:"sort,omitempty"` - StartAt *string `json:"startAt,omitempty"` - Time *QueryTime `json:"time"` + Index *string `json:"index,omitempty"` + Limit *int `json:"limit,omitempty"` + Query *string `json:"query"` + Sort *string `json:"sort,omitempty"` + StartAt *string `json:"startAt,omitempty"` + Time *LogsListRequestQueryTime `json:"time"` } -// QueryTime represents the time object for the request sent to the list API -type QueryTime struct { +// LogsListRequestQueryTime represents the time object for the request sent to the list API +type LogsListRequestQueryTime struct { TimeFrom *string `json:"from"` TimeTo *string `json:"to"` TimeZone *string `json:"timezone,omitempty"` @@ -32,7 +32,7 @@ type LogsList struct { } func (l *LogsList) next() bool { - if l.NextLogID != nil || l.Status == nil { + if l.NextLogID != nil { return true } @@ -42,22 +42,22 @@ func (l *LogsList) next() bool { // Logs represents the data of a log entry and contains the UUID of that entry (which // is used for the StartAt option in an API request) as well as the content of that log type Logs struct { - ID *string `json:"id"` - Content Content `json:"content"` + ID *string `json:"id"` + Content LogsContent `json:"content"` } -// Content respresents the actual log content returned by the list API -type Content struct { - Timestamp *time.Time `json:"timestamp"` - Tags []string `json:"tags,omitempty"` - Attributes Attributes `json:"attributes,omitempty"` - Host *string `json:"host"` - Service *string `json:"service"` - Message *string `json:"message"` +// LogsContent respresents the actual log content returned by the list API +type LogsContent struct { + Timestamp *time.Time `json:"timestamp"` + Tags []string `json:"tags,omitempty"` + Attributes LogsAttributes `json:"attributes,omitempty"` + Host *string `json:"host"` + Service *string `json:"service"` + Message *string `json:"message"` } -// Attributes represents the Content attribute object from the list API -type Attributes map[string]interface{} +// LogsAttributes represents the Content attribute object from the list API +type LogsAttributes map[string]interface{} // GetLogsList gets a page of log entries based on the values in the provided LogListRequest func (client *Client) GetLogsList(logsRequest *LogsListRequest) (logsList *LogsList, err error) { @@ -71,7 +71,12 @@ func (client *Client) GetLogsList(logsRequest *LogsListRequest) (logsList *LogsL } // GetLogsListPages calls GetLogsList and handles the pagination performed by the 'logs-queries/list' API -func (client *Client) GetLogsListPages(logsRequest *LogsListRequest) (logs []Logs, err error) { +func (client *Client) GetLogsListPages(logsRequest *LogsListRequest, maxResults int) (logs []Logs, err error) { + + // Reduce the number of results we have to fetch if the limit in our request body is greater than the value of maxResults + if maxResults < logsRequest.GetLimit() && maxResults > 0 { + logsRequest.SetLimit(maxResults) + } response, err := client.GetLogsList(logsRequest) if err != nil { @@ -79,12 +84,31 @@ func (client *Client) GetLogsListPages(logsRequest *LogsListRequest) (logs []Log } logs = append(logs, response.Logs...) - - for response.next() && err == nil { - logsRequest.StartAt = response.NextLogID - response, err = client.GetLogsList(logsRequest) - logs = append(logs, response.Logs...) + if maxResults < 0 { // Retrieve all results + for response.next() && err == nil { + logsRequest.StartAt = response.NextLogID + response, err = client.GetLogsList(logsRequest) + if err != nil { + return logs, err + } + + logs = append(logs, response.Logs...) + } + } else { + for response.next() && err == nil && len(logs) < maxResults { + logsRequest.StartAt = response.NextLogID + + if maxResults-len(logs) < logsRequest.GetLimit() { + logsRequest.SetLimit(maxResults - len(logs)) + } + + response, err = client.GetLogsList(logsRequest) + if err != nil { + return logs, err + } + + logs = append(logs, response.Logs...) + } } - return logs, err } diff --git a/log_lists_test.go b/log_lists_test.go index 64f15f8..4f21794 100644 --- a/log_lists_test.go +++ b/log_lists_test.go @@ -74,7 +74,7 @@ func TestGetLogsListPages(t *testing.T) { Limit: Int(50), } - logs, err := client.GetLogsListPages(req) + logs, err := client.GetLogsListPages(req, -1) assert.Nil(err) assert.Len(logs, 3)