-
Notifications
You must be signed in to change notification settings - Fork 307
/
reporting_types.go
211 lines (181 loc) · 5.49 KB
/
reporting_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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
package types
import (
"database/sql"
"encoding/json"
)
type Config struct {
ClientName string
ConnInfo string
}
const (
CoreReportingClient = "core"
WarehouseReportingClient = "warehouse"
SupportedTransformerApiVersion = 2
DefaultReportingEnabled = true
DefaultReplayEnabled = false
)
var (
DiffStatus = "diff"
// Module names
GATEWAY = "gateway"
DESTINATION_FILTER = "destination_filter"
TRACKINGPLAN_VALIDATOR = "tracking_plan_validator"
USER_TRANSFORMER = "user_transformer"
EVENT_FILTER = "event_filter"
DEST_TRANSFORMER = "dest_transformer"
ROUTER = "router"
BATCH_ROUTER = "batch_router"
WAREHOUSE = "warehouse"
)
var (
// Tracking plan validation states
SUCCEEDED_WITHOUT_VIOLATIONS = "succeeded_without_violations"
SUCCEEDED_WITH_VIOLATIONS = "succeeded_with_violations"
)
type Client struct {
Config
DbHandle *sql.DB
}
type StatusDetail struct {
Status string `json:"state"`
Count int64 `json:"count"`
StatusCode int `json:"statusCode"`
SampleResponse string `json:"sampleResponse"`
SampleEvent json.RawMessage `json:"sampleEvent"`
EventName string `json:"eventName"`
EventType string `json:"eventType"`
ErrorType string `json:"errorType"`
ViolationCount int64 `json:"violationCount"`
}
type ReportByStatus struct {
InstanceDetails
ConnectionDetails
PUDetails
ReportMetadata
StatusDetail *StatusDetail
}
type InstanceDetails struct {
WorkspaceID string `json:"workspaceId"`
Namespace string `json:"namespace"`
InstanceID string `json:"instanceId"`
}
type ReportMetadata struct {
ReportedAt int64 `json:"reportedAt"`
}
type Metric struct {
InstanceDetails
ConnectionDetails
PUDetails
ReportMetadata
StatusDetails []*StatusDetail `json:"reports"`
}
// EDMetric => ErrorDetailMetric
type EDConnectionDetails struct {
SourceID string `json:"sourceId"`
DestinationID string `json:"destinationId"`
SourceDefinitionId string `json:"sourceDefinitionId"`
DestinationDefinitionId string `json:"destinationDefinitionId"`
DestType string `json:"destinationDefinitionName"`
}
type EDInstanceDetails struct {
WorkspaceID string `json:"workspaceId"`
Namespace string `json:"namespace"`
InstanceID string `json:"-"`
}
type EDErrorDetails struct {
StatusCode int `json:"statusCode"`
ErrorCode string `json:"errorCode"`
ErrorMessage string `json:"errorMessage"`
// TODO: need to check with team if this makes sense ?
EventType string `json:"-"`
Count int `json:"count"`
}
type EDReportsDB struct {
EDErrorDetails
EDInstanceDetails
EDConnectionDetails
ReportMetadata
PU string `json:"reportedBy"`
Count int64 `json:"-"`
}
// The structure in which the error detail data is being sent to reporting service
type EDMetric struct {
EDInstanceDetails
PU string `json:"reportedBy"`
ReportMetadata
EDConnectionDetails
Errors []EDErrorDetails `json:"errors"`
Count int64 `json:"-"`
}
type ConnectionDetails struct {
SourceID string `json:"sourceId"`
DestinationID string `json:"destinationId"`
SourceTaskRunID string `json:"sourceTaskRunId"`
SourceJobID string `json:"sourceJobId"`
SourceJobRunID string `json:"sourceJobRunId"`
SourceDefinitionId string `json:"sourceDefinitionId"`
DestinationDefinitionId string `string:"destinationDefinitionId"`
SourceCategory string `json:"sourceCategory"`
TransformationID string `json:"transformationId"`
TransformationVersionID string `json:"transformationVersionId"`
TrackingPlanID string `json:"trackingPlanId"`
TrackingPlanVersion int `json:"trackingPlanVersion"`
}
type PUDetails struct {
InPU string `json:"inReportedBy"`
PU string `json:"reportedBy"`
TerminalPU bool `json:"terminalState"`
InitialPU bool `json:"initialState"`
}
type PUReportedMetric struct {
ConnectionDetails
PUDetails
StatusDetail *StatusDetail
}
func CreateConnectionDetail(sid, did, strid, sjid, sjrid, sdid, ddid, sc, trid, trvid, tpid string, tpv int) *ConnectionDetails {
return &ConnectionDetails{
SourceID: sid,
DestinationID: did,
SourceTaskRunID: strid,
SourceJobID: sjid,
SourceJobRunID: sjrid,
SourceDefinitionId: sdid,
DestinationDefinitionId: ddid,
SourceCategory: sc,
TransformationID: trid,
TransformationVersionID: trvid,
TrackingPlanID: tpid,
TrackingPlanVersion: tpv,
}
}
func CreateStatusDetail(status string, count, violationCount int64, code int, resp string, event json.RawMessage, eventName, eventType, errorType string) *StatusDetail {
return &StatusDetail{
Status: status,
Count: count,
ViolationCount: violationCount,
StatusCode: code,
SampleResponse: resp,
SampleEvent: event,
EventName: eventName,
EventType: eventType,
ErrorType: errorType,
}
}
func CreatePUDetails(inPU, pu string, terminalPU, initialPU bool) *PUDetails {
return &PUDetails{
InPU: inPU,
PU: pu,
TerminalPU: terminalPU,
InitialPU: initialPU,
}
}
func AssertSameKeys[V1, V2 any](m1 map[string]V1, m2 map[string]V2) {
if len(m1) != len(m2) {
panic("maps length don't match") // TODO improve msg
}
for k := range m1 {
if _, ok := m2[k]; !ok {
panic("key in map1 not found in map2") // TODO improve msg
}
}
}