Skip to content

Commit

Permalink
Merge pull request alibaba#364 from alibaba/1.3.1
Browse files Browse the repository at this point in the history
Merge 1.3.1 release
  • Loading branch information
sczyh30 authored Dec 29, 2018
2 parents f4b5fae + 97d5b9a commit 52475fc
Show file tree
Hide file tree
Showing 76 changed files with 1,122 additions and 353 deletions.
10 changes: 8 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@ language: java
sudo: required
dist: trusty

jdk:
- oraclejdk8
matrix:
include:
- jdk: oraclejdk8
env: BUILD_JDK=ORACLE_JDK_8
- jdk: oraclejdk11
env: BUILD_JDK=ORACLE_JDK_11
allow_failures:
- env: BUILD_JDK=ORACLE_JDK_11

after_success:
- bash <(curl -s https://codecov.io/bash)
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-parent</artifactId>
<version>1.3.0-GA</version>
<version>1.3.1</version>
<packaging>pom</packaging>

<name>${project.artifactId}</name>
Expand Down Expand Up @@ -41,7 +41,7 @@

<properties>
<!-- Compile libs -->
<fastjson.version>1.2.51</fastjson.version>
<fastjson.version>1.2.54</fastjson.version>

<!-- Test libs -->
<junit.version>4.12</junit.version>
Expand Down Expand Up @@ -169,7 +169,7 @@
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<!-- CircleCI build workaround -->
<argLine>-Xms1024m -Xmx2048m</argLine>
<argLine>@{argLine} -Xms1024m -Xmx2048m</argLine>
<useSystemClassLoader>false</useSystemClassLoader>
</configuration>
</plugin>
Expand Down
2 changes: 1 addition & 1 deletion sentinel-adapter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-parent</artifactId>
<version>1.3.0-GA</version>
<version>1.3.1</version>
</parent>
<artifactId>sentinel-adapter</artifactId>
<packaging>pom</packaging>
Expand Down
2 changes: 1 addition & 1 deletion sentinel-adapter/sentinel-dubbo-adapter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-adapter</artifactId>
<version>1.3.0-GA</version>
<version>1.3.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>sentinel-dubbo-adapter</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcExcept
Entry methodEntry = null;
try {
String resourceName = getResourceName(invoker, invocation);
ContextUtil.enter(resourceName);
interfaceEntry = SphU.entry(invoker.getInterface().getName(), EntryType.OUT);
methodEntry = SphU.entry(resourceName, EntryType.OUT);

Expand All @@ -76,7 +75,6 @@ public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcExcept
if (interfaceEntry != null) {
interfaceEntry.exit();
}
ContextUtil.exit();
}
}
}
9 changes: 8 additions & 1 deletion sentinel-adapter/sentinel-grpc-adapter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>sentinel-adapter</artifactId>
<groupId>com.alibaba.csp</groupId>
<version>1.3.0-GA</version>
<version>1.3.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>sentinel-grpc-adapter</artifactId>
Expand Down Expand Up @@ -39,6 +39,13 @@
<version>${grpc.version}</version>
<scope>provided</scope>
</dependency>
<!-- workaround for compile in JDK 11 -->
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>1.2</version>
</dependency>


<dependency>
<groupId>junit</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(MethodDescriptor<ReqT
String resourceName = methodDescriptor.getFullMethodName();
Entry entry = null;
try {
ContextUtil.enter(resourceName);
entry = SphU.entry(resourceName, EntryType.OUT);
// Allow access, forward the call.
return new ForwardingClientCall.SimpleForwardingClientCall<ReqT, RespT>(
Expand Down Expand Up @@ -131,7 +130,6 @@ public void sendMessage(ReqT message) {
if (entry != null) {
entry.exit();
}
ContextUtil.exit();
}
}

Expand Down
2 changes: 1 addition & 1 deletion sentinel-adapter/sentinel-web-servlet/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-adapter</artifactId>
<version>1.3.0-GA</version>
<version>1.3.1</version>
</parent>

<artifactId>sentinel-web-servlet</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion sentinel-benchmark/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>sentinel-parent</artifactId>
<groupId>com.alibaba.csp</groupId>
<version>1.3.0-GA</version>
<version>1.3.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion sentinel-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-parent</artifactId>
<version>1.3.0-GA</version>
<version>1.3.1</version>
</parent>
<artifactId>sentinel-core</artifactId>
<packaging>jar</packaging>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
*/
public final class Constants {

public static final String SENTINEL_VERSION = VersionUtil.getVersion("1.3.0");
public static final String SENTINEL_VERSION = VersionUtil.getVersion("1.3.1");

public final static int MAX_CONTEXT_NAME_SIZE = 2000;
public final static int MAX_SLOT_CHAIN_SIZE = 6000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
/**
* @return name of the Sentinel resource
*/
String value() default "";;
String value() default "";

/**
* @return the entry type (inbound or outbound), outbound by default
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,21 @@ public static void doInit() {
ServiceLoader<InitFunc> loader = ServiceLoader.load(InitFunc.class);
List<OrderWrapper> initList = new ArrayList<OrderWrapper>();
for (InitFunc initFunc : loader) {
RecordLog.info("[Sentinel InitExecutor] Found init func: " + initFunc.getClass().getCanonicalName());
RecordLog.info("[InitExecutor] Found init func: " + initFunc.getClass().getCanonicalName());
insertSorted(initList, initFunc);
}
for (OrderWrapper w : initList) {
w.func.init();
RecordLog.info(String.format("[Sentinel InitExecutor] Initialized: %s with order %d",
RecordLog.info(String.format("[InitExecutor] Initialized: %s with order %d",
w.func.getClass().getCanonicalName(), w.order));
}
} catch (Exception ex) {
RecordLog.info("[Sentinel InitExecutor] Init failed", ex);
RecordLog.warn("[InitExecutor] Init failed", ex);
ex.printStackTrace();
} catch (Error error) {
RecordLog.warn("[InitExecutor] Init failed with fatal error", error);
error.printStackTrace();
throw error;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public synchronized List<MetricNode> findByTimeAndResource(long beginTimeMs, lon
MetricWriter.formIndexFileName(fileName), offsetInIndex);
offsetInIndex = 0;
if (offset != -1) {
return metricsReader.readMetricsByEndTime(fileNames, i, offset, endTimeMs, identity);
return metricsReader.readMetricsByEndTime(fileNames, i, offset, beginTimeMs, endTimeMs, identity);
}
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,24 +194,26 @@ private String nextFileNameOfDay(long time) {
File baseFile = new File(baseDir);
DateFormat fileNameDf = new SimpleDateFormat("yyyy-MM-dd");
String dateStr = fileNameDf.format(new Date(time));
String fileNameModel = baseFileName + "." + dateStr;
for (File file : baseFile.listFiles()) {
if (file.getName().contains(baseFileName + "." + dateStr)
&& !file.getName().endsWith(METRIC_FILE_INDEX_SUFFIX)
&& !file.getName().endsWith(".lck")) {
String fileName = file.getName();
if (fileName.contains(fileNameModel)
&& !fileName.endsWith(METRIC_FILE_INDEX_SUFFIX)
&& !fileName.endsWith(".lck")) {
list.add(file.getAbsolutePath());
}
}
Collections.sort(list, METRIC_FILE_NAME_CMP);
if (list.isEmpty()) {
return baseDir + baseFileName + "." + dateStr;
return baseDir + fileNameModel;
}
String last = list.get(list.size() - 1);
int n = 0;
String[] strs = last.split("\\.");
if (strs.length > 0 && strs[strs.length - 1].matches("[0-9]{1,10}")) {
n = Integer.parseInt(strs[strs.length - 1]);
}
return baseDir + baseFileName + "." + dateStr + "." + (n + 1);
return baseDir + fileNameModel + "." + (n + 1);
}

/**
Expand Down Expand Up @@ -244,7 +246,7 @@ public int compare(String o1, String o2) {
String name2 = new File(o2).getName();
String dateStr1 = name1.split("\\.")[2];
String dateStr2 = name2.split("\\.")[2];
// in case of file name contains pid, skip it
// in case of file name contains pid, skip it, like Sentinel-Admin-metrics.log.pid22568.2018-12-24
if (dateStr1.startsWith(pid)) {
dateStr1 = name1.split("\\.")[3];
dateStr2 = name2.split("\\.")[3];
Expand All @@ -266,7 +268,10 @@ public int compare(String o1, String o2) {
}

/**
* Get all metric files' name in {@code baseDir}. The file name must contain {@code baseFileName}
* Get all metric files' name in {@code baseDir}. The file name must like
* <pre>
* baseFileName + ".yyyy-MM-dd.number"
* </pre>
* and not endsWith {@link #METRIC_FILE_INDEX_SUFFIX} or ".lck".
*
* @param baseDir the directory to search.
Expand All @@ -282,17 +287,38 @@ static List<String> listMetricFiles(String baseDir, String baseFileName) throws
return list;
}
for (File file : files) {
String fileName = file.getName();
if (file.isFile()
&& file.getName().contains(baseFileName)
&& !file.getName().endsWith(MetricWriter.METRIC_FILE_INDEX_SUFFIX)
&& !file.getName().endsWith(".lck")) {
&& fileNameMatches(fileName, baseFileName)
&& !fileName.endsWith(MetricWriter.METRIC_FILE_INDEX_SUFFIX)
&& !fileName.endsWith(".lck")) {
list.add(file.getAbsolutePath());
}
}
Collections.sort(list, MetricWriter.METRIC_FILE_NAME_CMP);
return list;
}

/**
* Test whether fileName matches baseFileName. fileName matches baseFileName when
* <pre>
* fileName = baseFileName + ".yyyy-MM-dd.number"
* </pre>
*
* @param fileName file name
* @param baseFileName base file name.
* @return if fileName matches baseFileName return true, else return false.
*/
public static boolean fileNameMatches(String fileName, String baseFileName) {
if (fileName.startsWith(baseFileName)) {
String part = fileName.substring(baseFileName.length());
// part is like: ".yyyy-MM-dd.number", eg. ".2018-12-24.11"
return part.matches("\\.[0-9]{4}-[0-9]{2}-[0-9]{2}(\\.[0-9]*)?");
} else {
return false;
}
}

private void removeMoreFiles() throws Exception {
List<String> list = listMetricFiles(baseDir, baseFileName);
if (list == null || list.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ public MetricsReader(Charset charset) {
/**
* @return if should continue read, return true, else false.
*/
boolean readMetricsInOneFileByEndTime(List<MetricNode> list, String fileName,
long offset, long endTimeMs, String identity) throws Exception {
boolean readMetricsInOneFileByEndTime(List<MetricNode> list, String fileName, long offset,
long beginTimeMs, long endTimeMs, String identity) throws Exception {
FileInputStream in = null;
long beginSecond = beginTimeMs / 1000;
long endSecond = endTimeMs / 1000;
try {
in = new FileInputStream(fileName);
Expand All @@ -48,6 +49,10 @@ boolean readMetricsInOneFileByEndTime(List<MetricNode> list, String fileName,
while ((line = reader.readLine()) != null) {
MetricNode node = MetricNode.fromFatString(line);
long currentSecond = node.getTimestamp() / 1000;
// currentSecond should >= beginSecond, otherwise a wrong metric file must occur
if (currentSecond < beginSecond) {
return false;
}
if (currentSecond <= endSecond) {
// read all
if (identity == null) {
Expand Down Expand Up @@ -109,12 +114,12 @@ void readMetricsInOneFile(List<MetricNode> list, String fileName,
* When identity is null, all metric between the time intervalMs will be read, otherwise, only the specific
* identity will be read.
*/
List<MetricNode> readMetricsByEndTime(List<String> fileNames, int pos,
long offset, long endTimeMs, String identity) throws Exception {
List<MetricNode> readMetricsByEndTime(List<String> fileNames, int pos, long offset,
long beginTimeMs, long endTimeMs, String identity) throws Exception {
List<MetricNode> list = new ArrayList<MetricNode>(1024);
if (readMetricsInOneFileByEndTime(list, fileNames.get(pos++), offset, endTimeMs, identity)) {
if (readMetricsInOneFileByEndTime(list, fileNames.get(pos++), offset, beginTimeMs, endTimeMs, identity)) {
while (pos < fileNames.size()
&& readMetricsInOneFileByEndTime(list, fileNames.get(pos++), 0, endTimeMs, identity)) {
&& readMetricsInOneFileByEndTime(list, fileNames.get(pos++), 0, beginTimeMs, endTimeMs, identity)) {
}
}
return list;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
*/
package com.alibaba.csp.sentinel.slots.block;

/***
/**
* Abstract rule entity.
*
* @author youji.zj
* @author Eric Zhao
*/
Expand All @@ -29,10 +31,11 @@ public abstract class AbstractRule implements Rule {
/**
* <p>
* Application name that will be limited by origin.
* Multiple application name can be separated with comma (',').
* The default limitApp is {@code default}, which means allowing all origin apps.
* </p>
* <p>
* For authority rules, multiple origin name can be separated with comma (',').
* </p>
* <p>The default limitApp is `default`, which means allowing all origin apps.</p>
* <p>For example: limitApp = `appA,appB` will limit requests from appA and appB.</p>
*/
private String limitApp;

Expand Down Expand Up @@ -68,8 +71,6 @@ public boolean equals(Object o) {
if (resource != null ? !resource.equals(that.resource) : that.resource != null) {
return false;
}
// if (limitApp != null ? !limitApp.equals(that.limitApp) :
// that.limitApp != null) { return false; }
if (!limitAppEquals(limitApp, that.limitApp)) {
return false;
}
Expand All @@ -78,12 +79,12 @@ public boolean equals(Object o) {

private boolean limitAppEquals(String str1, String str2) {
if ("".equals(str1)) {
return "default".equals(str2);
} else if ("default".equals(str1)) {
return RuleConstant.LIMIT_APP_DEFAULT.equals(str2);
} else if (RuleConstant.LIMIT_APP_DEFAULT.equals(str1)) {
return "".equals(str2) || str2 == null || str1.equals(str2);
}
if (str1 == null) {
return str2 == null || "default".equals(str2);
return str2 == null || RuleConstant.LIMIT_APP_DEFAULT.equals(str2);
}
return str1.equals(str2);
}
Expand All @@ -95,8 +96,7 @@ public <T extends AbstractRule> T as(Class<T> clazz) {
@Override
public int hashCode() {
int result = resource != null ? resource.hashCode() : 0;
// result = 31 * result + (limitApp != null ? limitApp.hashCode() : 0);
if (!("".equals(limitApp) || "default".equals(limitApp) || limitApp == null)) {
if (!("".equals(limitApp) || RuleConstant.LIMIT_APP_DEFAULT.equals(limitApp) || limitApp == null)) {
result = 31 * result + limitApp.hashCode();
}
return result;
Expand Down
Loading

0 comments on commit 52475fc

Please sign in to comment.