-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathstatsig_options.go
186 lines (164 loc) · 5.6 KB
/
statsig_options.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
package statsig
import (
"net/http"
"reflect"
"time"
)
// Advanced options for configuring the Statsig SDK
type Options struct {
API string `json:"api"`
APIOverrides APIOverrides `json:"api_overrides"`
FallbackToStatsigAPI bool
Transport http.RoundTripper
Environment Environment `json:"environment"`
LocalMode bool `json:"localMode"`
ConfigSyncInterval time.Duration
IDListSyncInterval time.Duration
LoggingInterval time.Duration
LoggingMaxBufferSize int
BootstrapValues string
RulesUpdatedCallback func(rules string, time int64)
InitTimeout time.Duration
DataAdapter IDataAdapter
OutputLoggerOptions OutputLoggerOptions
StatsigLoggerOptions StatsigLoggerOptions
EvaluationCallbacks EvaluationCallbacks
DisableCDN bool // Disables use of CDN for downloading config specs
UserPersistentStorage IUserPersistentStorage
IPCountryOptions IPCountryOptions
UAParserOptions UAParserOptions
}
func (o *Options) GetSDKEnvironmentTier() string {
if o.Environment.Tier != "" {
return o.Environment.Tier
}
return "production"
}
func GetOptionLoggingCopy(options Options) map[string]interface{} {
loggingCopy := make(map[string]interface{})
val := reflect.ValueOf(options)
for i := 0; i < val.NumField(); i++ {
field := val.Type().Field(i)
fieldValue := val.Field(i)
switch fieldValue.Kind() {
case reflect.String:
if fieldValue.String() != "" {
if fieldValue.Len() < 50 {
loggingCopy[field.Name] = fieldValue.String()
} else {
loggingCopy[field.Name] = "set"
}
}
case reflect.Bool:
if fieldValue.Bool() {
loggingCopy[field.Name] = true
}
case reflect.Int, reflect.Int64, reflect.Int32:
if fieldValue.Int() != 0 {
loggingCopy[field.Name] = fieldValue.Int()
}
case reflect.Float64, reflect.Float32:
if fieldValue.Float() != 0 {
loggingCopy[field.Name] = fieldValue.Float()
}
case reflect.Struct:
if fieldValue.Type().Name() == "Duration" {
loggingCopy[field.Name] = fieldValue.Interface().(time.Duration).String()
break
}
if field.Name == "StatsigLoggerOptions" && !fieldValue.IsZero() {
statsigLoggerOptions := map[string]interface{}{
"DisableInitDiagnostics": fieldValue.Interface().(StatsigLoggerOptions).DisableInitDiagnostics,
"DisableSyncDiagnostics": fieldValue.Interface().(StatsigLoggerOptions).DisableSyncDiagnostics,
"DisableApiDiagnostics": fieldValue.Interface().(StatsigLoggerOptions).DisableApiDiagnostics,
"DisableAllLogging": fieldValue.Interface().(StatsigLoggerOptions).DisableAllLogging,
}
loggingCopy[field.Name] = statsigLoggerOptions
break
}
if field.Name == "APIOverrides" && !fieldValue.IsZero() {
APIOptionOverrides := map[string]interface{}{
"DownloadConfigSpecs": fieldValue.Interface().(APIOverrides).DownloadConfigSpecs,
"GetIDLists": fieldValue.Interface().(APIOverrides).GetIDLists,
"LogEvent": fieldValue.Interface().(APIOverrides).LogEvent,
}
loggingCopy[field.Name] = APIOptionOverrides
break
}
if !fieldValue.IsZero() {
loggingCopy[field.Name] = "set"
}
case reflect.Func:
if !fieldValue.IsNil() {
loggingCopy[field.Name] = "set"
}
case reflect.Interface:
if !fieldValue.IsNil() {
loggingCopy[field.Name] = "set"
}
default:
// ignore other fields
}
}
return loggingCopy
}
type APIOverrides struct {
DownloadConfigSpecs string `json:"download_config_specs"`
GetIDLists string `json:"get_id_lists"`
LogEvent string `json:"log_event"`
}
type EvaluationCallbacks struct {
GateEvaluationCallback func(name string, result bool, exposure *ExposureEvent)
ConfigEvaluationCallback func(name string, result DynamicConfig, exposure *ExposureEvent)
ExperimentEvaluationCallback func(name string, result DynamicConfig, exposure *ExposureEvent)
LayerEvaluationCallback func(name string, param string, result DynamicConfig, exposure *ExposureEvent)
ExposureCallback func(name string, exposure *ExposureEvent)
IncludeDisabledExposures bool
}
type OutputLoggerOptions struct {
LogCallback func(message string, err error)
EnableDebug bool
DisableInitDiagnostics bool
DisableSyncDiagnostics bool
}
type StatsigLoggerOptions struct {
DisableInitDiagnostics bool
DisableSyncDiagnostics bool
DisableApiDiagnostics bool
DisableAllLogging bool
}
type IPCountryOptions struct {
Disabled bool // Fully disable IP to country lookup
LazyLoad bool // Load in background
EnsureLoaded bool // Wait until loaded when needed
}
type UAParserOptions struct {
Disabled bool // Fully disable UA parser
LazyLoad bool // Load in background
EnsureLoaded bool // Wait until loaded when needed
}
// See https://docs.statsig.com/guides/usingEnvironments
type Environment struct {
Tier string `json:"tier"`
Params map[string]string `json:"params"`
}
// options for getClientInitializeResponse
type GCIROptions struct {
IncludeLocalOverrides bool
ClientKey string
TargetAppID string
HashAlgorithm string
IncludeConfigType bool
ConfigTypesToInclude []ConfigType
}
type ConfigType = string
const (
FeatureGateType ConfigType = "feature_gate"
HoldoutType ConfigType = "holdout"
SegmentType ConfigType = "segment"
DynamicConfigType ConfigType = "dynamic_config"
ExperimentType ConfigType = "experiment"
AutotuneType ConfigType = "autotune"
LayerType ConfigType = "layer"
UnknownType ConfigType = "unknown"
)