Skip to content

Commit 2dada92

Browse files
authored
Feature Management - API View Changes (#46738)
* APIView comments * Feature to FeatureDefinition * Renaming a few things * mroe review items * review changes + safety check
1 parent 94e188d commit 2dada92

File tree

8 files changed

+27
-25
lines changed

8 files changed

+27
-25
lines changed

sdk/spring/spring-cloud-azure-feature-management/src/main/java/com/azure/spring/cloud/feature/management/FeatureManager.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ private void publishTelemetryIfEnabled(EvaluationEvent event) {
227227
if (telemetryPublisher != null && event.getFeature() != null
228228
&& event.getFeature().getTelemetry() != null
229229
&& event.getFeature().getTelemetry().isEnabled()) {
230-
telemetryPublisher.publishTelemetry(event);
230+
telemetryPublisher.publish(event);
231231
}
232232
}
233233

@@ -292,7 +292,7 @@ private void assignVariant(EvaluationEvent event) {
292292
List<String> groups = targetingContext.getGroups();
293293
String variantName = null;
294294

295-
if (StringUtils.hasText(targetingContext.getUserId())) {
295+
if (StringUtils.hasText(targetingContext.getUserId()) && allocation.getUser() != null) {
296296
// Loop through all user allocations
297297
for (UserAllocation userAllocation : allocation.getUser()) {
298298
if (!evaluationOptions.isIgnoreCase()
@@ -308,7 +308,7 @@ private void assignVariant(EvaluationEvent event) {
308308
}
309309
}
310310
}
311-
if (variantName == null) {
311+
if (variantName == null && allocation.getGroup() != null) {
312312
for (GroupAllocation groupAllocation : allocation.getGroup()) {
313313
for (String allocationGroup : groupAllocation.getGroups()) {
314314
if (!evaluationOptions.isIgnoreCase() && groups.contains(allocationGroup)) {

sdk/spring/spring-cloud-azure-feature-management/src/main/java/com/azure/spring/cloud/feature/management/models/Allocation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public List<GroupAllocation> getGroup() {
109109
* @param group the list of group allocations
110110
* @return the updated Allocation object
111111
*/
112-
public Allocation setGroups(List<GroupAllocation> group) {
112+
public Allocation setGroup(List<GroupAllocation> group) {
113113
this.group = group;
114114
return this;
115115
}

sdk/spring/spring-cloud-azure-feature-management/src/main/java/com/azure/spring/cloud/feature/management/models/VariantAssignmentReason.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,24 +39,24 @@ public enum VariantAssignmentReason {
3939
*/
4040
PERCENTILE("Percentile");
4141

42-
private final String type;
42+
private final String value;
4343

4444
/**
45-
* Creates a new instance of the VariantAssignmentReason enum with the specified type.
45+
* Creates a new instance of the VariantAssignmentReason enum with the specified value.
4646
*
47-
* @param type The string representation of the variant assignment reason
47+
* @param value The string representation of the variant assignment reason
4848
*/
49-
VariantAssignmentReason(final String type) {
50-
this.type = type;
49+
VariantAssignmentReason(final String value) {
50+
this.value = value;
5151
}
5252

5353
/**
5454
* Gets the string representation of this variant assignment reason.
5555
*
5656
* @return the string representation of this variant assignment reason
5757
*/
58-
public String getType() {
59-
return type;
58+
public String getValue() {
59+
return value;
6060
}
6161

6262
}

sdk/spring/spring-cloud-azure-feature-management/src/main/java/com/azure/spring/cloud/feature/management/models/VariantReference.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
package com.azure.spring.cloud.feature.management.models;
44

55
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
6+
import com.fasterxml.jackson.annotation.JsonProperty;
67

78
/**
89
* Reference to a Variant containing the Variant name, configuration value, and possible status override.
@@ -20,6 +21,7 @@ public class VariantReference {
2021
* The configuration value associated with this variant reference.
2122
* This can be any type of object depending on the feature configuration.
2223
*/
24+
@JsonProperty("configuration_value")
2325
private Object configurationValue;
2426

2527
/**

sdk/spring/spring-cloud-azure-feature-management/src/main/java/com/azure/spring/cloud/feature/management/telemetry/LoggerTelemetryPublisher.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public LoggerTelemetryPublisher() {
5353
*
5454
* @param evaluationEvent The evaluation event to be published.
5555
*/
56-
public void publishTelemetry(EvaluationEvent evaluationEvent) {
56+
public void publish(EvaluationEvent evaluationEvent) {
5757
if (evaluationEvent == null || evaluationEvent.getFeature() == null) {
5858
return;
5959
}
@@ -65,7 +65,7 @@ public void publishTelemetry(EvaluationEvent evaluationEvent) {
6565
Map<String, String> eventProperties = new HashMap<>(Map.of(
6666
FEATURE_NAME, feature.getId(),
6767
ENABLED, String.valueOf(evaluationEvent.isEnabled()),
68-
REASON, evaluationEvent.getReason().getType(),
68+
REASON, evaluationEvent.getReason().getValue(),
6969
VERSION, EVALUATION_EVENT_VERSION));
7070

7171
if (variant != null) {

sdk/spring/spring-cloud-azure-feature-management/src/main/java/com/azure/spring/cloud/feature/management/telemetry/TelemetryPublisher.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ public interface TelemetryPublisher {
1717
*
1818
* @param evaluationEvent The evaluation event to be published.
1919
*/
20-
void publishTelemetry(EvaluationEvent evaluationEvent);
20+
void publish(EvaluationEvent evaluationEvent);
2121

2222
}

sdk/spring/spring-cloud-azure-feature-management/src/test/java/com/azure/spring/cloud/feature/management/FeatureManagerTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ public void telemetryPublisherCalledWhenFeatureEnabledWithTelemetry() {
248248
when(featureManagementPropertiesMock.getFeatureFlags()).thenReturn(features);
249249

250250
assertTrue(featureManager.isEnabled("EnabledFeatureWithTelemetry"));
251-
verify(telemetryPublisher, times(1)).publishTelemetry(Mockito.any(EvaluationEvent.class));
251+
verify(telemetryPublisher, times(1)).publish(Mockito.any(EvaluationEvent.class));
252252
}
253253

254254
@Test
@@ -258,7 +258,7 @@ public void telemetryPublisherNotCalledWhenTelemetryDisabled() {
258258
when(featureManagementPropertiesMock.getFeatureFlags()).thenReturn(features);
259259

260260
assertTrue(featureManager.isEnabled("FeatureWithTelemetryDisabled"));
261-
verify(telemetryPublisher, times(0)).publishTelemetry(Mockito.any(EvaluationEvent.class));
261+
verify(telemetryPublisher, times(0)).publish(Mockito.any(EvaluationEvent.class));
262262
}
263263

264264
@Test
@@ -268,7 +268,7 @@ public void telemetryPublisherCalledWhenFeatureDisabledWithTelemetry() {
268268
when(featureManagementPropertiesMock.getFeatureFlags()).thenReturn(features);
269269

270270
assertFalse(featureManager.isEnabled("DisabledFeatureWithTelemetry"));
271-
verify(telemetryPublisher, times(1)).publishTelemetry(Mockito.any(EvaluationEvent.class));
271+
verify(telemetryPublisher, times(1)).publish(Mockito.any(EvaluationEvent.class));
272272
}
273273

274274
class AlwaysOnFilter implements FeatureFilter {

sdk/spring/spring-cloud-azure-feature-management/src/test/java/com/azure/spring/cloud/feature/management/telemetry/LoggerTelemetryPublisherTest.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ void featureFlagTest(TestInfo testInfo) throws Exception {
103103
EvaluationEvent evaluationEvent = new EvaluationEvent(featureMock);
104104

105105
LoggerTelemetryPublisher publisher = new LoggerTelemetryPublisher();
106-
publisher.publishTelemetry(evaluationEvent);
106+
publisher.publish(evaluationEvent);
107107

108108
logEvent = getEvent(listAppender.list, testInfo.getDisplayName());
109109
Map<String, String> mdcMap = logEvent.getMDCPropertyMap();
@@ -127,7 +127,7 @@ void featureVariantTest(TestInfo testInfo) throws Exception {
127127
when(variantMock.getName()).thenReturn("fake-variant");
128128

129129
LoggerTelemetryPublisher publisher = new LoggerTelemetryPublisher();
130-
publisher.publishTelemetry(evaluationEvent);
130+
publisher.publish(evaluationEvent);
131131

132132
logEvent = getEvent(listAppender.list, testInfo.getDisplayName());
133133
Map<String, String> mdcMap = logEvent.getMDCPropertyMap();
@@ -150,7 +150,7 @@ void featureFlagDisabledTest(TestInfo testInfo) throws Exception {
150150
EvaluationEvent evaluationEvent = new EvaluationEvent(featureMock);
151151

152152
LoggerTelemetryPublisher publisher = new LoggerTelemetryPublisher();
153-
publisher.publishTelemetry(evaluationEvent);
153+
publisher.publish(evaluationEvent);
154154

155155
logEvent = getEvent(listAppender.list, testInfo.getDisplayName());
156156
Map<String, String> mdcMap = logEvent.getMDCPropertyMap();
@@ -181,7 +181,7 @@ void featureVariantWithPercentageTest(TestInfo testInfo) throws Exception {
181181
when(variantMock.getName()).thenReturn("fake-variant");
182182

183183
LoggerTelemetryPublisher publisher = new LoggerTelemetryPublisher();
184-
publisher.publishTelemetry(evaluationEvent);
184+
publisher.publish(evaluationEvent);
185185

186186
logEvent = getEvent(listAppender.list, testInfo.getDisplayName());
187187
Map<String, String> mdcMap = logEvent.getMDCPropertyMap();
@@ -202,7 +202,7 @@ void featureVariantWithPercentageTest(TestInfo testInfo) throws Exception {
202202
void nullEvaluationEventTest(TestInfo testInfo) {
203203
when(featureMock.getId()).thenReturn(testInfo.getDisplayName());
204204
LoggerTelemetryPublisher publisher = new LoggerTelemetryPublisher();
205-
publisher.publishTelemetry(null);
205+
publisher.publish(null);
206206

207207
// Ensure no logs are generated
208208
assertEquals(0, listAppender.list.size());
@@ -214,7 +214,7 @@ void nullFeatureInEvaluationEventTest(TestInfo testInfo) {
214214
EvaluationEvent evaluationEvent = new EvaluationEvent(null);
215215

216216
LoggerTelemetryPublisher publisher = new LoggerTelemetryPublisher();
217-
publisher.publishTelemetry(evaluationEvent);
217+
publisher.publish(evaluationEvent);
218218

219219
// Ensure no logs are generated
220220
assertEquals(0, listAppender.list.size());
@@ -228,7 +228,7 @@ void nullVariantInEvaluationEventTest(TestInfo testInfo) {
228228
evaluationEvent.setReason(VariantAssignmentReason.DEFAULT_WHEN_ENABLED);
229229

230230
LoggerTelemetryPublisher publisher = new LoggerTelemetryPublisher();
231-
publisher.publishTelemetry(evaluationEvent);
231+
publisher.publish(evaluationEvent);
232232

233233
logEvent = getEvent(listAppender.list, testInfo.getDisplayName());
234234
Map<String, String> mdcMap = logEvent.getMDCPropertyMap();
@@ -255,7 +255,7 @@ void emptyPercentileAllocationTest(TestInfo testInfo) {
255255
when(variantMock.getName()).thenReturn("fake-variant");
256256

257257
LoggerTelemetryPublisher publisher = new LoggerTelemetryPublisher();
258-
publisher.publishTelemetry(evaluationEvent);
258+
publisher.publish(evaluationEvent);
259259

260260
logEvent = getEvent(listAppender.list, testInfo.getDisplayName());
261261
Map<String, String> mdcMap = logEvent.getMDCPropertyMap();

0 commit comments

Comments
 (0)