未验证 提交 59d47250 编写于 作者: wu-sheng's avatar wu-sheng 提交者: GitHub

Fix endpoint name rule package (#2405)

* Add more logs

* no message

* no message

* Exclude test file.
上级 9a09e962
......@@ -63,6 +63,12 @@ public class StringFormatGroup {
return new FormatResult(false, string);
}
@Override public String toString() {
return "StringFormatGroup{" +
"rules=" + rules +
'}';
}
public class FormatResult {
private boolean match;
private String name;
......@@ -97,5 +103,12 @@ public class StringFormatGroup {
public Pattern getPattern() {
return pattern;
}
@Override public String toString() {
return "PatternRule{" +
"name='" + name + '\'' +
", pattern=" + pattern +
'}';
}
}
}
......@@ -46,18 +46,21 @@ public class EndpointNameFormater {
}
if (stream == null) {
logger.info("endpoint_naming_rules.properties not found. No endpoint name setup.");
logger.info("endpoint_naming_rules.properties not found. No endpoint naming setup.");
} else {
properties.load(stream);
properties.forEach((key, value) -> {
endpointRule.addRule((String)key, (String)value);
logger.debug("endpoint naming rule of service {} found, name[{}] and rule[{}]", service, key, value);
});
}
} catch (IOException e) {
logger.info("{}_endpoint_rules.properties not found. No endpoint name setup.", service);
logger.info("{}_endpoint_rules.properties not found. No endpoint naming setup.", service);
}
ALL_RULES.put(service, endpointRule);
logger.debug("endpoint naming rules of service {} added. {}", service, endpointRule);
}
public static StringFormatGroup.FormatResult format(String service, String endpointName) {
......
......@@ -63,10 +63,16 @@ public class TelemetryDataDispatcher {
public static void preProcess(ServiceMeshMetric data) {
String service = data.getDestServiceId() == Const.NONE ? data.getDestServiceName() :
SERVICE_CACHE.get(data.getDestServiceId()).getName();
StringFormatGroup.FormatResult formatResult = EndpointNameFormater.format(service, data.getEndpoint());
String endpointName = data.getEndpoint();
StringFormatGroup.FormatResult formatResult = EndpointNameFormater.format(service, endpointName);
if (formatResult.isMatch()) {
data = data.toBuilder().setEndpoint(formatResult.getName()).build();
}
if (logger.isDebugEnabled()) {
if (formatResult.isMatch()) {
logger.debug("Endpoint {} is renamed to {}", endpointName, data.getEndpoint());
}
}
ServiceMeshMetricDataDecorator decorator = new ServiceMeshMetricDataDecorator(data);
if (decorator.tryMetaDataRegister()) {
......
......@@ -186,6 +186,7 @@
<exclude>alarm-settings.yml</exclude>
<exclude>component-libraries.yml</exclude>
<exclude>datasource-settings.properties</exclude>
<exclude>endpoint_naming_rules.properties</exclude>
</excludes>
</configuration>
</plugin>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册