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

feat: exclude replay noise #216

Merged
merged 2 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.arextest.schedule.beans;

import com.arextest.schedule.model.CommonResponse;
import java.util.List;
import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.ObjectError;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice
public class ControllerException {

@ExceptionHandler(MethodArgumentNotValidException.class)
public ResponseEntity<CommonResponse> handleValidException(MethodArgumentNotValidException e) {
// setting application/json;charset=UTF-8
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON_UTF8);

List<ObjectError> allErrors = e.getBindingResult().getAllErrors();
String message = allErrors.stream().map(s -> s.getDefaultMessage())
.collect(Collectors.joining(";"));

return new ResponseEntity<>(CommonResponse.badResponse(message), headers,
HttpStatus.BAD_REQUEST);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
import com.arextest.schedule.dao.mongodb.util.MongoHelper;
import com.arextest.schedule.model.converter.ReplayNoiseConverter;
import com.arextest.schedule.model.dao.mongodb.ReplayNoiseCollection;
import com.arextest.schedule.model.dao.mongodb.ReplayNoiseCollection.ReplayNoiseItemDao;
import com.arextest.schedule.model.noiseidentify.ReplayNoiseDto;
import com.arextest.schedule.model.noiseidentify.UpdateNoiseItem;
import com.arextest.schedule.utils.MapUtils;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -101,6 +104,44 @@ public List<ReplayNoiseDto> queryReplayNoise(@NotBlank String planId, String pla
.collect(Collectors.toList());
}

public boolean updateReplayNoiseStatus(List<UpdateNoiseItem> updateNoiseItems) {

try {
BulkOperations bulkOperations =
mongoTemplate.bulkOps(BulkOperations.BulkMode.UNORDERED, ReplayNoiseCollection.class);
for (UpdateNoiseItem updateNoiseItem : updateNoiseItems) {
Map<String, Object> queryFields = updateNoiseItem.getQueryFields();
Map<String, Object> updateFields = updateNoiseItem.getUpdateFields();
if (MapUtils.isEmpty(queryFields) || MapUtils.isEmpty(updateFields)) {
continue;
}

List<Criteria> criteriaList = new ArrayList<>();
for (Map.Entry<String, Object> entry : queryFields.entrySet()) {
if (entry.getKey() == null) {
continue;
}
criteriaList.add(Criteria.where(entry.getKey()).is(entry.getValue()));
}
if (CollectionUtils.isEmpty(criteriaList)) {
continue;
}
Query query = new Query().addCriteria(new Criteria().andOperator(criteriaList));

Update update = MongoHelper.getUpdate();
for (Map.Entry<String, Object> entry : updateFields.entrySet()) {
update.set(entry.getKey(), entry.getValue());
}
bulkOperations.updateMulti(query, update);
}
bulkOperations.execute();
} catch (RuntimeException e) {
LOGGER.error("ReplayNoiseRepository.updateReplayNoiseStatus error", e);
return false;
}
return true;
}

private void appendUpdate(Update update,
Map<String, ReplayNoiseCollection.ReplayNoiseItemDao> needUpdateContent,
String updateKey) {
Expand All @@ -120,6 +161,11 @@ private void appendUpdate(Update update,
MongoHelper.appendDot(updateKey, path,
ReplayNoiseCollection.ReplayNoiseItemDao.FIELD_LOG_INDEXES),
replayNoiseItemDao.getLogIndexes());
if (replayNoiseItemDao.getStatus() != null) {
update.set(
MongoHelper.appendDot(updateKey, path, ReplayNoiseItemDao.FIELD_STATUS),
replayNoiseItemDao.getStatus());
}
update.inc(
MongoHelper.appendDot(updateKey, path,
ReplayNoiseCollection.ReplayNoiseItemDao.FIELD_PATH_COUNT),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.arextest.schedule.model.converter;

import com.arextest.schedule.model.dao.mongodb.ReplayNoiseCollection;
import com.arextest.schedule.model.noiseidentify.QueryNoiseResponseType;
import com.arextest.schedule.model.noiseidentify.ReplayNoiseDto;
import com.arextest.schedule.model.noiseidentify.ReplayNoiseItemDto;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;

/**
Expand All @@ -25,5 +27,8 @@ public interface ReplayNoiseConverter {

ReplayNoiseItemDto dtoFromDao(ReplayNoiseCollection.ReplayNoiseItemDao dao);

// ReplayNoiseDto.ReplayNoiseItemDto toReplayNoiseItemDto(ReplayNoiseItemDto dao);
@Mappings(
@Mapping(target = "nodeEntity", source = "nodePath")
)
QueryNoiseResponseType.NoiseItem toNoiseItem(ReplayNoiseItemDto dto);
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,7 @@ public static class ReplayNoiseItemDao {

private Integer caseCount;

private Integer status;

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.arextest.schedule.model.noiseidentify;

import com.arextest.diff.model.log.NodeEntity;
import com.arextest.model.mock.MockCategoryType;
import com.arextest.schedule.model.noiseidentify.QueryNoiseResponseType.InterfaceNoiseItem;
import java.util.List;
import javax.validation.constraints.NotBlank;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
public class ExcludeNoiseRequestType {

@NotBlank(message = "appId cannot be blank")
private String appId;
@NotBlank(message = "planId cannot be blank")
private String planId;

private List<InterfaceNoiseItem> interfaceNoiseItemList;

@Data
@NoArgsConstructor
@AllArgsConstructor
public static class InterfaceExcludeNoiseItem {
private String operationId;
private List<QueryNoiseResponseType.MockerNoiseItem> randomNoise;
}

@Data
@NoArgsConstructor
@AllArgsConstructor
public static class MockerExcludeNoiseItem {

private MockCategoryType mockCategoryType;
private String operationName;
private String operationType;
private List<QueryNoiseResponseType.NoiseItem> noiseItemList;
}

@Data
public static class ExcludeNoiseItem {

private String identifier;

private List<NodeEntity> nodeEntity;

}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.arextest.schedule.model.report;
package com.arextest.schedule.model.noiseidentify;

import com.arextest.diff.model.log.NodeEntity;
import com.arextest.model.mock.MockCategoryType;
Expand Down Expand Up @@ -39,12 +39,19 @@ public static class MockerNoiseItem {
@Data
public static class NoiseItem {

private String identifier;

private List<NodeEntity> nodeEntity;

private List<Integer> logIndexes;

private String compareResultId;

/**
* @see ReplayNoiseStatus
*/
private Integer status;

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@ public class ReplayNoiseItemDto {
public int getPathCount() {
return subPaths.size();
}

private Integer status;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.arextest.schedule.model.noiseidentify;

public interface ReplayNoiseStatus {

int STATUS_NORMAL = 0;

int STATUS_EXCLUDE = 1;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.arextest.schedule.model.noiseidentify;

import java.util.Map;
import lombok.Data;

@Data
public class UpdateNoiseItem {

private Map<String, Object> queryFields;

private Map<String, Object> updateFields;

}
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ protected void doWithTracedRunning() {
List<NodeEntity> nodePath = nodeEntry.getKey();
ReplayNoiseItemDto replayNoiseItemDto = nodeEntry.getValue();
replayNoiseItemDto.setNodePath(nodePath);
mayIgnoreItems.put(ListUtils.getFuzzyPathStr(nodePath), replayNoiseItemDto);
mayIgnoreItems.put(ListUtils.getFuzzyPathStrWithBase64(nodePath), replayNoiseItemDto);
}
replayNoiseDto.setMayIgnoreItems(mayIgnoreItems);
}
Expand All @@ -146,7 +146,7 @@ protected void doWithTracedRunning() {
List<NodeEntity> nodePath = nodeEntry.getKey();
ReplayNoiseItemDto replayNoiseItemDto = nodeEntry.getValue();
replayNoiseItemDto.setNodePath(nodePath);
mayDisorderItems.put(ListUtils.getFuzzyPathStr(nodePath), replayNoiseItemDto);
mayDisorderItems.put(ListUtils.getFuzzyPathStrWithBase64(nodePath), replayNoiseItemDto);
}
replayNoiseDto.setMayDisorderItems(mayDisorderItems);
}
Expand Down Expand Up @@ -275,7 +275,7 @@ private void getAnalysisOfSingleCompareResult(
LogEntity logEntity,
int logIndex) {
ReplayNoiseItemDto replayNoiseItemDto = singleAggContent.get(upperArrayNodePath);
String fuzzyPathStr = ListUtils.getFuzzyPathStr(logEntity.getPathPair().getLeftUnmatchedPath());
String fuzzyPathStr = ListUtils.getFuzzyPathStrWithBase64(logEntity.getPathPair().getLeftUnmatchedPath());
if (replayNoiseItemDto == null) {
replayNoiseItemDto = new ReplayNoiseItemDto();
replayNoiseItemDto.setCompareResult(replayCompareResult);
Expand Down
Loading