Skip to content

feat: add parse record rule config #562

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
Expand Up @@ -6,6 +6,7 @@
import io.arex.inst.runtime.context.RecordLimiter;
import io.arex.inst.runtime.listener.EventProcessor;
import io.arex.inst.runtime.model.DynamicClassEntity;
import io.arex.inst.runtime.model.RecordRuleEntity;

import java.util.ArrayList;
import java.util.Collections;
Expand All @@ -24,10 +25,11 @@ public class Config {

static void update(boolean enableDebug, String serviceName, List<DynamicClassEntity> dynamicClassList,
Map<String, String> properties, Set<String> excludeServiceOperations,
int dubboStreamReplayThreshold, int recordRate) {
int dubboStreamReplayThreshold, int recordRate,
List<RecordRuleEntity> recordRuleList, boolean existUrlParamRule, boolean existBodyParamRule) {
INSTANCE = new Config(enableDebug, serviceName, dynamicClassList, properties,
excludeServiceOperations,
dubboStreamReplayThreshold, recordRate);
excludeServiceOperations, dubboStreamReplayThreshold, recordRate,
recordRuleList, existUrlParamRule, existBodyParamRule);
}

public static Config get() {
Expand All @@ -46,10 +48,14 @@ public static Config get() {
private final String recordVersion;
private final Set<String> includeServiceOperations;
private final String[] coveragePackages;
private final List<RecordRuleEntity> recordRuleList;
private final boolean existUrlParamRule;
private final boolean existBodyParamRule;

Config(boolean enableDebug, String serviceName, List<DynamicClassEntity> dynamicClassList,
Map<String, String> properties,
Set<String> excludeServiceOperations, int dubboStreamReplayThreshold, int recordRate) {
Set<String> excludeServiceOperations, int dubboStreamReplayThreshold, int recordRate,
List<RecordRuleEntity> recordRuleList, boolean existUrlParamRule, boolean existBodyParamRule) {
this.enableDebug = enableDebug;
this.serviceName = serviceName;
this.dynamicClassList = dynamicClassList;
Expand All @@ -60,6 +66,9 @@ public static Config get() {
this.recordVersion = properties.get("arex.agent.version");
this.includeServiceOperations = StringUtil.splitToSet(properties.get("includeServiceOperations"), ',');
this.coveragePackages = StringUtil.split(properties.get(ConfigConstants.COVERAGE_PACKAGES), ',');
this.recordRuleList = recordRuleList;
this.existUrlParamRule = existUrlParamRule;
this.existBodyParamRule = existBodyParamRule;
buildDynamicClassInfo();
}

Expand Down Expand Up @@ -187,6 +196,18 @@ public boolean isLocalStorage() {
return STORAGE_MODE.equalsIgnoreCase(getString(STORAGE_SERVICE_MODE));
}

public List<RecordRuleEntity> getRecordRuleList() {
return recordRuleList;
}

public boolean isExistUrlParamRule() {
return existUrlParamRule;
}

public boolean isExistBodyParamRule() {
return existBodyParamRule;
}

/**
* Conditions for determining invalid recording configuration:<br/>
* 1. rate <= 0 <br/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.arex.inst.runtime.config;

import io.arex.inst.runtime.model.DynamicClassEntity;
import io.arex.inst.runtime.model.RecordRuleEntity;

import java.util.*;

Expand All @@ -12,6 +13,9 @@ public class ConfigBuilder {
private Set<String> excludeServiceOperations;
private int dubboStreamReplayThreshold;
private int recordRate;
private List<RecordRuleEntity> recordRuleList;
private boolean existUrlParamRule;
private boolean existBodyParamRule;

public static ConfigBuilder create(String serviceName) {
return new ConfigBuilder(serviceName);
Expand Down Expand Up @@ -69,8 +73,23 @@ public ConfigBuilder recordRate(int recordRate) {
return this;
}

public ConfigBuilder recordRuleList(List<RecordRuleEntity> recordRuleList) {
this.recordRuleList = recordRuleList;
return this;
}

public ConfigBuilder existUrlParamRule(boolean existUrlParamRule) {
this.existUrlParamRule = existUrlParamRule;
return this;
}

public ConfigBuilder existBodyParamRule(boolean existBodyParamRule) {
this.existBodyParamRule = existBodyParamRule;
return this;
}

public void build() {
Config.update(enableDebug, serviceName, dynamicClassList, Collections.unmodifiableMap(new HashMap<>(properties)),
excludeServiceOperations, dubboStreamReplayThreshold, recordRate);
excludeServiceOperations, dubboStreamReplayThreshold, recordRate, recordRuleList, existUrlParamRule, existBodyParamRule);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package io.arex.inst.runtime.model;

import java.util.List;

public class ParamRuleEntity {
private String id;
private String appId;
private String urlRuleId;
private String paramType;
private List<ValueRuleEntity> valueRuleEntityList;

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public String getAppId() {
return appId;
}

public void setAppId(String appId) {
this.appId = appId;
}

public String getUrlRuleId() {
return urlRuleId;
}

public void setUrlRuleId(String urlRuleId) {
this.urlRuleId = urlRuleId;
}

public String getParamType() {
return paramType;
}

public void setParamType(String paramType) {
this.paramType = paramType;
}

public List<ValueRuleEntity> getValueRuleEntityList() {
return valueRuleEntityList;
}

public void setValueRuleEntityList(List<ValueRuleEntity> valueRuleEntityList) {
this.valueRuleEntityList = valueRuleEntityList;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package io.arex.inst.runtime.model;

import java.util.List;

public class RecordRuleEntity {
private String id;
private String appId;
private String httpPath;
private List<ParamRuleEntity> paramRuleEntityList;

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public String getAppId() {
return appId;
}

public void setAppId(String appId) {
this.appId = appId;
}

public String getHttpPath() {
return httpPath;
}

public void setHttpPath(String httpPath) {
this.httpPath = httpPath;
}

public List<ParamRuleEntity> getParamRuleEntityList() {
return paramRuleEntityList;
}

public void setParamRuleEntityList(List<ParamRuleEntity> paramRuleEntityList) {
this.paramRuleEntityList = paramRuleEntityList;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package io.arex.inst.runtime.model;

public class ValueRuleEntity {
private String key;
private String value;

public String getKey() {
return key;
}

public void setKey(String key) {
this.key = key;
}

public String getValue() {
return value;
}

public void setValue(String value) {
this.value = value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ public class IgnoreUtils {
*/
private static final Set<Integer> INVALID_OPERATION_HASH_CACHE = new ConcurrentHashSet<>();

public static final String PARAM_TYPE_QUERY_STRING = "QUERY_STRING";
public static final String PARAM_TYPE_JSON_BODY = "JSON_BODY";

public static boolean ignoreMockResult(String serviceKey, String operationKey) {
if (StringUtil.isEmpty(serviceKey)) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
import io.arex.inst.runtime.listener.EventProcessor;
import io.arex.inst.runtime.model.ArexConstants;
import io.arex.inst.runtime.model.DynamicClassEntity;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;

import java.util.*;

import io.arex.inst.runtime.model.ParamRuleEntity;
import io.arex.inst.runtime.model.RecordRuleEntity;
import io.arex.inst.runtime.util.IgnoreUtils;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
Expand Down Expand Up @@ -139,4 +141,40 @@ void buildCoveragePackages() {
assertEquals(1, Config.get().getCoveragePackages().length);
assertEquals("io.arex.inst", Config.get().getCoveragePackages()[0]);
}

@Test
void testBuildRecordRule() {
ConfigBuilder.create("mock").recordRuleList(null).build();
assertNull(Config.get().getRecordRuleList());

ConfigBuilder config = ConfigBuilder.create("mock");
List<RecordRuleEntity> recordRuleList = new ArrayList<>();
recordRuleList.add(getRecordRuleEntity());
config.recordRuleList(recordRuleList).build();
Assertions.assertEquals(1, Config.get().getRecordRuleList().size());
}

private RecordRuleEntity getRecordRuleEntity() {
RecordRuleEntity recordRule = new RecordRuleEntity();
recordRule.setId("mock-record-rule-id");
recordRule.setAppId("mock");
recordRule.setHttpPath("/unitTestHttpPath");
return recordRule;
}

@Test
void testBuildExistUrlParamRule() {
ConfigBuilder.create("mock").build();
assertFalse(Config.get().isExistUrlParamRule());
ConfigBuilder.create("mock").existUrlParamRule(true).build();
assertTrue(Config.get().isExistUrlParamRule());
}

@Test
void testBuildExistBodyParamRule() {
ConfigBuilder.create("mock").build();
assertFalse(Config.get().isExistBodyParamRule());
ConfigBuilder.create("mock").existBodyParamRule(true).build();
assertTrue(Config.get().isExistBodyParamRule());
}
}
Loading