-
-
Notifications
You must be signed in to change notification settings - Fork 163
/
Copy pathtracking_event.go
73 lines (59 loc) · 2.82 KB
/
tracking_event.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
package exporter
import (
"bytes"
"encoding/json"
"text/template"
"time"
)
type TrackingEventDetails = map[string]interface{}
// TrackingEvent represent an Event that we store in the data storage
// nolint:lll
type TrackingEvent struct {
// Kind for a feature event is feature.
// A feature event will only be generated if the trackEvents attribute of the flag is set to true.
Kind string `json:"kind" example:"feature" parquet:"name=kind, type=BYTE_ARRAY, convertedtype=UTF8"`
// ContextKind is the kind of context which generated an event. This will only be "anonymousUser" for events generated
// on behalf of an anonymous user or the reserved word "user" for events generated on behalf of a non-anonymous user
ContextKind string `json:"contextKind,omitempty" example:"user" parquet:"name=contextKind, type=BYTE_ARRAY, convertedtype=UTF8"`
// UserKey The key of the user object used in a feature flag evaluation. Details for the user object used in a feature
// flag evaluation as reported by the "feature" event are transmitted periodically with a separate index event.
UserKey string `json:"userKey" example:"94a25909-20d8-40cc-8500-fee99b569345" parquet:"name=userKey, type=BYTE_ARRAY, convertedtype=UTF8"`
// CreationDate When the feature flag was requested at Unix epoch time in milliseconds.
CreationDate int64 `json:"creationDate" example:"1680246000011" parquet:"name=creationDate, type=INT64"`
// Key of the event.
Key string `json:"key" example:"my-feature-flag" parquet:"name=key, type=BYTE_ARRAY, convertedtype=UTF8"`
// EvaluationContext contains the evaluation context used for the tracking
EvaluationContext map[string]any `json:"evaluationContext" parquet:"name=evaluationContext, type=MAP, keytype=BYTE_ARRAY, keyconvertedtype=UTF8, valuetype=BYTE_ARRAY, valueconvertedtype=UTF8"`
// TrackingDetails contains the details of the tracking event
TrackingDetails TrackingEventDetails `json:"trackingEventDetails" parquet:"name=trackingEventDetails, type=MAP, keytype=BYTE_ARRAY, keyconvertedtype=UTF8, valuetype=BYTE_ARRAY, valueconvertedtype=UTF8"`
}
func (f TrackingEvent) GetKey() string {
return f.Key
}
// GetUserKey returns the user key of the event
func (f TrackingEvent) GetUserKey() string {
return f.UserKey
}
// GetCreationDate returns the creationDate of the event.
func (f TrackingEvent) GetCreationDate() int64 {
return f.CreationDate
}
func (f TrackingEvent) FormatInCSV(csvTemplate *template.Template) ([]byte, error) {
var buf bytes.Buffer
err := csvTemplate.Execute(&buf, struct {
TrackingEvent
FormattedDate string
}{
TrackingEvent: f,
FormattedDate: time.Unix(f.GetCreationDate(), 0).Format(time.RFC3339),
})
if err != nil {
return nil, err
}
return buf.Bytes(), nil
}
func (f TrackingEvent) FormatInJSON() ([]byte, error) {
b, err := json.Marshal(f)
b = append(b, []byte("\n")...)
return b, err
}