Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/merge release 4 into dev #898

Merged
merged 11 commits into from
Jun 26, 2023
419 changes: 109 additions & 310 deletions backend/packages/Upgrade/package-lock.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ import { env } from '../../env';
import { MonitoredDecisionPointLog } from '../models/MonitoredDecisionPointLog';
import { MarkExperimentValidatorv4 } from './validators/MarkExperimentValidator.v4';
import { Log } from '../models/Log';
import { flatten } from '@nestjs/common';
import { CaliperLogEnvelope } from './validators/CaliperLogEnvelope';

interface IMonitoredDecisionPoint {
id: string;
Expand Down Expand Up @@ -633,6 +635,53 @@ export class ExperimentClientController {
});
}

/**
* @swagger
* /log/caliper:
* post:
* description: Post Caliper format log data
* consumes:
* - application/json
* parameters:
* - in: body
* name: data
* required: true
* description: User Document
* tags:
* - Client Side SDK
* produces:
* - application/json
* responses:
* '200':
* description: Log data
* '500':
* description: null value in column "id\" of relation \"experiment_user\" violates not-null constraint
*/
@Post('log/caliper')
public async caliperLog(
@Body({ validate: { validationError: { target: false, value: false } } })
@Req()
request: AppRequest,
envelope: CaliperLogEnvelope
): Promise<Log[]> {
const result = envelope.data.map(async (log) => {
// getOriginalUserDoc call for alias
const experimentUserDoc = await this.getUserDoc(log.object.assignee.id, request.logger);
if (experimentUserDoc) {
// append userDoc in logger
request.logger.child({ userDoc: experimentUserDoc });
request.logger.info({ message: 'Got the original user doc' });
}
return this.experimentAssignmentService.caliperDataLog(log, {
logger: request.logger,
userDoc: experimentUserDoc,
});
});

const logsToReturn = await Promise.all(result);
return flatten(logsToReturn);
}

/**
* @swagger
* /bloblog:
Expand Down
1 change: 0 additions & 1 deletion clientlibs/java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
<artifactId>jersey-media-json-jackson</artifactId>
<version>2.30.1</version>
</dependency>

<dependency>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
Expand Down
139 changes: 65 additions & 74 deletions clientlibs/java/src/main/java/org/upgradeplatform/client/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,110 +11,101 @@

import org.eclipse.jdt.annotation.NonNull;
import org.upgradeplatform.interfaces.ResponseCallback;
import org.upgradeplatform.requestbeans.MarkExperimentRequestData;
import org.upgradeplatform.responsebeans.UserAliasResponse;
import org.upgradeplatform.responsebeans.Condition;
import org.upgradeplatform.responsebeans.ErrorResponse;
import org.upgradeplatform.responsebeans.ExperimentUser;
import org.upgradeplatform.responsebeans.ExperimentsResponse;
import org.upgradeplatform.responsebeans.InitializeUser;
import org.upgradeplatform.responsebeans.MarkExperimentPoint;
import org.upgradeplatform.responsebeans.UserAliasResponse;
import org.upgradeplatform.utils.Utils.MarkedDecisionPointStatus;

public class Main {
public static void main(String[] args) throws InterruptedException, ExecutionException
{
final String baseUrl = "http://localhost:3030";
final String userId = UUID.randomUUID().toString();
final String site = "SelectSection";
public static void main(String[] args) throws InterruptedException, ExecutionException
{
final String baseUrl = "https://upgradeapi.qa-cli.net";
final String userId = UUID.randomUUID().toString();
final String site = "SelectSection";

String target = args.length > 0 ? args[0] : "absolute_value_plot_equality";
String target = args.length > 0 ? args[0] : "volume_surface_area_cone_vol";

try(ExperimentClient experimentClient = new ExperimentClient(userId, "BearerToken", baseUrl, Collections.emptyMap())){
CompletableFuture<String> result = new CompletableFuture<>();
try(ExperimentClient experimentClient = new ExperimentClient(userId, "BearerToken", baseUrl, Collections.emptyMap())){
CompletableFuture<String> result = new CompletableFuture<>();

System.out.println(prefix() + "initiating requests");
experimentClient.init(new ResponseCallback<InitializeUser>() {
@Override
public void onSuccess(@NonNull InitializeUser t){
System.out.println("init " + t);
List<String> schools = new ArrayList<String>();

List<String> schools = new ArrayList<>();
schools.add("school1");
Map<String, List<String>> group = new HashMap<String, List<String>>();
Map<String, List<String>> group = new HashMap<>();
group.put("schoolid", schools);

System.out.println(prefix() + "setting group membership");
experimentClient.setGroupMembership(group, new ResponseCallback<ExperimentUser>(){
@Override
public void onSuccess(@NonNull ExperimentUser expResult){
System.out.println("group membership " + expResult);
System.out.println("success updating groups");
}
@Override
public void onError(@NonNull ErrorResponse error){
System.out.println("error updating groups " + error);
}
});


System.out.println(prefix() + "setting working group");
Map<String, String> workingGroup = new HashMap<String, String>();
workingGroup.put("schoolId", "school1");
experimentClient.setWorkingGroup(workingGroup, new ResponseCallback<ExperimentUser>(){
@Override
public void onSuccess(@NonNull ExperimentUser expResult){
System.out.println("working group " + expResult);
System.out.println("success updating working groups");
}
@Override
public void onError(@NonNull ErrorResponse error){
System.out.println("error updating working groups " + error);
}
});
System.out.println(prefix() + "success updating groups; setting working group");


System.out.println(prefix() + "setting user aliases");
List<String> altIds = new ArrayList<String>();
altIds.add(UUID.randomUUID().toString());
experimentClient.setAltUserIds(altIds, new ResponseCallback<UserAliasResponse>(){
@Override
public void onSuccess(@NonNull UserAliasResponse t) {
System.out.println("aliases " + t);
System.out.println("success updating user aliases");
}
@Override
public void onError(@NonNull ErrorResponse error){
System.out.println("error updating user aliases " + error);
}

});

System.out.println(prefix() + "getting conditions");
experimentClient.getExperimentCondition("assign-prog", site, target, new ResponseCallback<ExperimentsResponse>(){
@Override
public void onSuccess(@NonNull ExperimentsResponse expResult){
System.out.println("condition " + expResult);
Condition condition = expResult.getAssignedCondition();
String code = condition == null ? null : condition.getConditionCode();
MarkExperimentRequestData data = new MarkExperimentRequestData(site, target, condition);
experimentClient.markExperimentPoint(MarkedDecisionPointStatus.CONDITION_APPLIED, data, new ResponseCallback<MarkExperimentPoint>(){
Map<String, String> workingGroup = new HashMap<>();
workingGroup.put("schoolId", "school1");
experimentClient.setWorkingGroup(workingGroup, new ResponseCallback<ExperimentUser>(){
@Override
public void onSuccess(@NonNull MarkExperimentPoint markResult){
result.complete("marked " + code + ": " + markResult.toString());
public void onSuccess(@NonNull ExperimentUser expResult){
System.out.println(prefix() + "success updating working groups; setting user aliases");

List<String> altIds = new ArrayList<>();
altIds.add(UUID.randomUUID().toString());
experimentClient.setAltUserIds(altIds, new ResponseCallback<UserAliasResponse>(){
@Override
public void onSuccess(@NonNull UserAliasResponse uar) {
System.out.println(prefix() + "success updating user aliases; getting conditions");

experimentClient.getExperimentCondition("assign-prog", site, target, new ResponseCallback<ExperimentsResponse>(){
@Override
public void onSuccess(@NonNull ExperimentsResponse expResult){
System.out.println(prefix() + "success getting condition; marking");

Condition condition = expResult.getAssignedCondition();
String code = condition == null ? null : condition.getConditionCode();
experimentClient.markExperimentPoint(site, target, code, MarkedDecisionPointStatus.CONDITION_APPLIED, new ResponseCallback<MarkExperimentPoint>(){
@Override
public void onSuccess(@NonNull MarkExperimentPoint markResult){
result.complete("marked " + code + ": " + markResult.toString());
}

@Override
public void onError(@NonNull ErrorResponse error){
result.complete("error marking " + code + ": " + error.toString());
}
});
}

@Override
public void onError(@NonNull ErrorResponse error){
result.complete(error.toString());
}

});
}
@Override
public void onError(@NonNull ErrorResponse error){
result.complete(error.toString());
}

});
}

@Override
public void onError(@NonNull ErrorResponse error){
result.complete("error marking " + code + ": " + error.toString());
result.complete(error.toString());
}
});
}

@Override
public void onError(@NonNull ErrorResponse error){
result.complete(error.toString());
}

});
}

Expand All @@ -127,10 +118,10 @@ public void onError(@NonNull ErrorResponse error){
System.out.println(prefix() + result.getNow("not complete yet"));
String rs = result.get();
System.out.println(prefix() + rs);
}
}
}
}

private static final String prefix() {
return "on thread " + Thread.currentThread().getName() + " at " + System.currentTimeMillis() + ": ";
}
private static final String prefix() {
return "on thread " + Thread.currentThread().getName() + " at " + System.currentTimeMillis() + ": ";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,4 @@ public AsyncInvoker prepareRequest(String apiPath) {
public void close() {
client.close();
}
}
}
2 changes: 1 addition & 1 deletion clientlibs/js/src/UpgradeClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export default class UpgradeClient {
failedExperimentPoint: `${hostUrl}/api/v4/failed`,
getAllFeatureFlag: `${hostUrl}/api/v4/featureflag`,
log: `${hostUrl}/api/v4/log`,
logCaliper: `${hostUrl}/api/v4/logCaliper`,
logCaliper: `${hostUrl}/api/v4/log/caliper`,
altUserIds: `${hostUrl}/api/v4/useraliases`,
addMetrics: `${hostUrl}/api/v4/metric`,
};
Expand Down
21 changes: 17 additions & 4 deletions clientlibs/js/src/functions/markExperimentPoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ import { IExperimentAssignmentv4, MARKED_DECISION_POINT_STATUS } from 'upgrade_t
interface markData {
userId: string;
status: MARKED_DECISION_POINT_STATUS;
data: IExperimentAssignmentv4;
data: {
site: string;
assignedCondition: { conditionCode: string; experimentId?: string };
target?: string;
};
clientError?: string;
}

Expand All @@ -21,13 +25,22 @@ export default async function markExperimentPoint(
getAllData: IExperimentAssignmentv4[],
clientError?: string
): Promise<Interfaces.IMarkExperimentPoint> {
const data = getAllData.find((data) => data.site === site && data.target === target);
data.assignedCondition.conditionCode = condition;
let requestBody: markData = {
userId,
status,
data,
data: {
site: site,
assignedCondition: {
conditionCode: condition,
},
},
};
if (target) {
requestBody.data = {
...requestBody.data,
target,
};
}
if (clientError) {
requestBody = {
...requestBody,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,10 @@ export class ExperimentParticipantsComponent implements OnInit {
this.members2.push(this.addMembers2(MemberTypes.SEGMENT, id.name));
});
}
}

this.members1.removeAt(0);
this.members2.removeAt(0);
} else {
this.members1.removeAt(0);
this.members2.removeAt(0);
}

this.updateView1();
this.updateView2();
Expand Down