/
types.go
77 lines (62 loc) · 2.23 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
package ingester
import (
"context"
"github.com/airdeploy/flagger-go/core"
"sync"
)
type Ingester struct {
entity *core.Entity
strategy *GroupStrategy
mux sync.Mutex
}
type GroupStrategy struct {
// the responsibility of the WaitGroup here is to ensure that all ingestion data
// is sent when ShutdownWithTimeout is called
wg sync.WaitGroup
ingestionWg sync.WaitGroup
ctx context.Context
cancel context.CancelFunc
lock sync.RWMutex
isActive bool
httpRequest HttpRequest // readonly
sdkInfo *core.SDKInfo // readonly
retryPolicy *RetryPolicy // readonly
// channels to update ingester config
updateSDKConfigChannel chan *core.SDKConfig
ingestionURLChannel chan string
// inner channels to prevent synchronization
ingestionDataChannel chan *IngestionDataRequest
retryPolicyChannel chan *RetryPolicyRequest
// ingestion data
callCount int
accumulator []*IngestionDataRequest
}
type RetryPolicy struct {
maxMemorySizeInBytes int64
queue []*QueueElement
currentMemorySize int64
}
type QueueElement struct {
data []byte
callback RetryPolicyCallback
}
type HttpRequest func(data []byte, ingestionURL string) error
type RetryPolicyRequest struct {
data []byte // data to be sent to the server
ingestionURL string // URL
httpRequest HttpRequest // function to be executed to send data
callback RetryPolicyCallback // callback
}
// This callback is called when retry policy finishes the processing of the ingestion data httpRequest
// There are 2 possible scenarios:
// 1) ingestion is successfully sent to the server
// 2) new ingestion arrive, so the current ingestion is shift from the queue(not enough memory)
type RetryPolicyCallback func(err error)
type IngestionDataRequest struct {
Id string `json:"id"`
Entities []*core.Entity `json:"entities"`
Exposures []*core.Exposure `json:"exposures"` // the output of every single API call
Events []*core.Event `json:"events"` // user generated event
SDKInfo *core.SDKInfo `json:"sdkInfo"` // Dictionary holding info about the Flagger version that's sending data back
DetectedFlags []string `json:"detectedFlags"`
}