17
17
18
18
import com .optimizely .ab .annotations .VisibleForTesting ;
19
19
import com .optimizely .ab .config .*;
20
-
20
+ import org .slf4j .Logger ;
21
+ import org .slf4j .LoggerFactory ;
21
22
import java .util .*;
22
23
import java .util .function .Function ;
23
24
import java .util .stream .Collectors ;
24
25
25
26
public class OptimizelyConfigService {
26
27
28
+ private static final Logger logger = LoggerFactory .getLogger (OptimizelyConfigService .class );
27
29
private ProjectConfig projectConfig ;
28
30
private OptimizelyConfig optimizelyConfig ;
29
31
@@ -34,7 +36,9 @@ public OptimizelyConfigService(ProjectConfig projectConfig) {
34
36
this .projectConfig = projectConfig ;
35
37
this .featureKeyToVariablesMap = generateFeatureKeyToVariablesMap ();
36
38
39
+ logger .info ("Getting experiment map for project config" );
37
40
Map <String , OptimizelyExperiment > experimentsMap = getExperimentsMap ();
41
+ logger .info ("Creating the complete optimizely config" );
38
42
optimizelyConfig = new OptimizelyConfig (
39
43
experimentsMap ,
40
44
getFeaturesMap (experimentsMap ),
@@ -59,6 +63,7 @@ public OptimizelyConfig getConfig() {
59
63
Map <String , List <FeatureVariable >> generateFeatureKeyToVariablesMap () {
60
64
List <FeatureFlag > featureFlags = projectConfig .getFeatureFlags ();
61
65
if (featureFlags == null ) {
66
+ logger .warn ("Returning empty map because there are no feature flags in project config" );
62
67
return Collections .emptyMap ();
63
68
}
64
69
return featureFlags .stream ().collect (Collectors .toMap (FeatureFlag ::getKey , featureFlag -> featureFlag .getVariables ()));
@@ -67,13 +72,15 @@ Map<String, List<FeatureVariable>> generateFeatureKeyToVariablesMap() {
67
72
@ VisibleForTesting
68
73
String getExperimentFeatureKey (String experimentId ) {
69
74
List <String > featureKeys = projectConfig .getExperimentFeatureKeyMapping ().get (experimentId );
75
+ logger .info ("Keys for feature experiment is null {}" , featureKeys == null );
70
76
return featureKeys != null ? featureKeys .get (0 ) : null ;
71
77
}
72
78
73
79
@ VisibleForTesting
74
80
Map <String , OptimizelyExperiment > getExperimentsMap () {
75
81
List <Experiment > experiments = projectConfig .getExperiments ();
76
82
if (experiments == null ) {
83
+ logger .warn ("Returning empty map because there are no experiments in project config" );
77
84
return Collections .emptyMap ();
78
85
}
79
86
return experiments .stream ().collect (Collectors .toMap (Experiment ::getKey , experiment -> new OptimizelyExperiment (
@@ -86,9 +93,11 @@ Map<String, OptimizelyExperiment> getExperimentsMap() {
86
93
@ VisibleForTesting
87
94
Map <String , OptimizelyVariation > getVariationsMap (List <Variation > variations , String experimentId ) {
88
95
if (variations == null ) {
96
+ logger .warn ("Returning empty map because there variations provided are null" );
89
97
return Collections .emptyMap ();
90
98
}
91
99
Boolean isFeatureExperiment = this .getExperimentFeatureKey (experimentId ) != null ;
100
+ logger .debug ("Experiment id {} is a feature experiment: {}" , experimentId , isFeatureExperiment );
92
101
return variations .stream ().collect (Collectors .toMap (Variation ::getKey , variation -> new OptimizelyVariation (
93
102
variation .getId (),
94
103
variation .getKey (),
@@ -106,15 +115,16 @@ Map<String, OptimizelyVariation> getVariationsMap(List<Variation> variations, St
106
115
@ VisibleForTesting
107
116
Map <String , OptimizelyVariable > getMergedVariablesMap (Variation variation , String experimentId ) {
108
117
String featureKey = this .getExperimentFeatureKey (experimentId );
109
-
110
118
if (featureKey != null ) {
119
+ logger .info ("Merging the variables as feature key is available" );
111
120
// Generate temp map of all the available variable values from variation.
112
121
Map <String , OptimizelyVariable > tempVariableIdMap = getFeatureVariableUsageInstanceMap (variation .getFeatureVariableUsageInstances ());
113
122
114
123
// Iterate over all the variables available in associated feature.
115
124
// Use value from variation variable if variable is available in variation and feature is enabled, otherwise use defaultValue from feature variable.
116
125
List <FeatureVariable > featureVariables = featureKeyToVariablesMap .get (featureKey );
117
126
if (featureVariables == null ) {
127
+ logger .warn ("Returning empty map as featureKeyToVariablesMap is null" );
118
128
return Collections .emptyMap ();
119
129
}
120
130
@@ -133,6 +143,7 @@ Map<String, OptimizelyVariable> getMergedVariablesMap(Variation variation, Strin
133
143
@ VisibleForTesting
134
144
Map <String , OptimizelyVariable > getFeatureVariableUsageInstanceMap (List <FeatureVariableUsageInstance > featureVariableUsageInstances ) {
135
145
if (featureVariableUsageInstances == null ) {
146
+ logger .warn ("Returning empty map because there FeatureVariableUsageInstance provided are null" );
136
147
return Collections .emptyMap ();
137
148
}
138
149
return featureVariableUsageInstances .stream ().collect (Collectors .toMap (FeatureVariableUsageInstance ::getId , variable -> new OptimizelyVariable (
@@ -147,6 +158,7 @@ Map<String, OptimizelyVariable> getFeatureVariableUsageInstanceMap(List<FeatureV
147
158
Map <String , OptimizelyFeature > getFeaturesMap (Map <String , OptimizelyExperiment > allExperimentsMap ) {
148
159
List <FeatureFlag > featureFlags = projectConfig .getFeatureFlags ();
149
160
if (featureFlags == null ) {
161
+ logger .warn ("Returning empty map because there are no feature flags in project config" );
150
162
return Collections .emptyMap ();
151
163
}
152
164
return featureFlags .stream ().collect (Collectors .toMap (FeatureFlag ::getKey , featureFlag -> new OptimizelyFeature (
@@ -160,6 +172,7 @@ Map<String, OptimizelyFeature> getFeaturesMap(Map<String, OptimizelyExperiment>
160
172
@ VisibleForTesting
161
173
Map <String , OptimizelyExperiment > getExperimentsMapForFeature (List <String > experimentIds , Map <String , OptimizelyExperiment > allExperimentsMap ) {
162
174
if (experimentIds == null ) {
175
+ logger .warn ("Returning empty map because the experiment id list is null" );
163
176
return Collections .emptyMap ();
164
177
}
165
178
@@ -173,6 +186,7 @@ Map<String, OptimizelyExperiment> getExperimentsMapForFeature(List<String> exper
173
186
@ VisibleForTesting
174
187
Map <String , OptimizelyVariable > getFeatureVariablesMap (List <FeatureVariable > featureVariables ) {
175
188
if (featureVariables == null ) {
189
+ logger .warn ("Returning empty map because the feature variables list is null" );
176
190
return Collections .emptyMap ();
177
191
}
178
192
return featureVariables .stream ().collect (Collectors .toMap (FeatureVariable ::getKey , featureVariable -> new OptimizelyVariable (
0 commit comments