This repository has been archived by the owner on Aug 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
types.go
122 lines (106 loc) · 3.83 KB
/
types.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package client
import (
"net/url"
"time"
log "github.com/sirupsen/logrus"
)
const (
insightsInsertURL = "https://insights-collector.newrelic.com/v1/accounts"
insightsQueryURL = "https://insights-api.newrelic.com/v1/accounts"
// Minimum length check for a valid NRQL statement
minValidNRQLLength = 8 // "SELECT 1"
// DefaultBatchTimeout is the amount of time to submit batches even if the event count hasn't been hit
DefaultBatchTimeout = 1 * time.Minute
// DefaultBatchEventCount is the maximum number of events before sending a batch (fuzzy)
DefaultBatchEventCount = 950
// DefaultWorkerCount is the number of background workers consuming and sending events
DefaultWorkerCount = 1
// DefaultInsertRequestTimeout is the amount of seconds to wait for a insert response
DefaultInsertRequestTimeout = 10 * time.Second
// DefaultQueryRequestTimeout is the amount of seconds to wait for a query response
DefaultQueryRequestTimeout = 20 * time.Second
// DefaultRetries is how many times to attempt the query
DefaultRetries = 3
// DefaultRetryWaitTime is the amount of seconds between query attempts
DefaultRetryWaitTime = 5 * time.Second
)
// Compression to use during transport.
type Compression int32
// Supported / recognized types of compression
const (
None Compression = iota
Deflate Compression = iota
Gzip Compression = iota
Zlib Compression = iota
)
// Client is the building block of the insert and query clients
type Client struct {
URL *url.URL
Logger *log.Logger
RequestTimeout time.Duration
RetryCount int
RetryWait time.Duration
}
// InsertClient contains all of the configuration required for inserts
type InsertClient struct {
InsertKey string
eventQueue chan []byte
eventTimer *time.Timer
flushQueue chan bool
WorkerCount int
BatchSize int
BatchTime time.Duration
Compression Compression
Client
Statistics
}
// Statistics about the inserted data
type Statistics struct {
// the number of events added using EnqueueEvent
EventCount int64
// the number of events that finished processing (both successfully and not) in batch mode
ProcessedEventCount int64
// the number of times a Flush has been requested
FlushCount int64
// the number of bytes that have been attempted to be written to the insights API
ByteCount int64
// the number of times a flush has occurred with a full batch of events
FullFlushCount int64
// the number of times a flush has occurred with a partial batch of events
PartialFlushCount int64
// the number of times flush has been called because the BatchTime timer expired
TimerExpiredCount int64
// the number of times failed batches have been retried
InsightsRetryCount int64
// not used
HTTPErrorCount int64
}
// Assumption here that responses from insights are either success or error.
type insertResponse struct {
Error string `json:"error,omitempty"`
Success bool `json:"success,omitempty"`
}
// QueryClient contains all of the configuration required for queries
type QueryClient struct {
QueryKey string
Client
}
// QueryResponse used to decode the JSON response from Insights
type QueryResponse struct {
Results []map[string]interface{} `json:"results"`
Facets []map[string]interface{} `json:"facets"`
Metadata QueryMetadata `json:"metadata"`
}
// QueryMetadata used to decode the JSON response metadata from Insights
type QueryMetadata struct {
Contents interface{} `json:"contents"`
EventType string `json:"eventType"`
OpenEnded bool `json:"openEnded"`
BeginTime time.Time `json:"beginTime"`
EndTime time.Time `json:"endTime"`
BeginTimeMillis int64 `json:"beginTimeMillis"`
EndTimeMillis int64 `json:"endTimeMillis"`
RawSince string `json:"rawSince"`
RawUntil string `json:"rawUntil"`
RawCompareWith string `json:"rawCompareWith"`
}