Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
9e3536e
Use Micrometer to monitor the metrics previously detected by Prometheus
FAWC438 Jul 3, 2023
4bbc318
Replace all Prometheus implement to Micrometer
FAWC438 Jul 4, 2023
d61992d
Merge branch 'alibaba:develop' into develop-issue#10377
FAWC438 Jul 6, 2023
d6554e3
Add unit test
FAWC438 Jul 6, 2023
c5dcb08
Merge branch 'alibaba:develop' into develop-issue#10377
FAWC438 Jul 7, 2023
0c501c0
Merge branch 'alibaba:develop' into develop-issue#10377
FAWC438 Jul 11, 2023
64a7189
Define unit test case
FAWC438 Jul 11, 2023
88beb24
Remove unnecessary dependencies
FAWC438 Jul 11, 2023
6aa4cf4
Remove unnecessary dependencies
FAWC438 Jul 11, 2023
61db466
Fix magic value
FAWC438 Jul 11, 2023
e50b2ac
Optimize code architecture
FAWC438 Jul 26, 2023
f1a916c
Use a new CompositeMeterRegistry instead of the globalRegistry
FAWC438 Jul 26, 2023
2681739
Use `NacosClientProperties` to get the env value
FAWC438 Jul 30, 2023
52e1557
Finish `configNotifyCostDuration` metric
FAWC438 Jul 31, 2023
54ee6f4
Finish all config metric
FAWC438 Aug 1, 2023
248d406
Finish record naming rpc request duration
FAWC438 Aug 2, 2023
b515014
Finish all naming meters
FAWC438 Aug 10, 2023
d971376
Fix meter names
FAWC438 Aug 10, 2023
d3d9226
Add unit tests
FAWC438 Aug 25, 2023
72fdf26
Add Config trace spans
FAWC438 Aug 26, 2023
877cc12
Add Naming trace spans
FAWC438 Aug 27, 2023
b82af66
Add trace unit test
FAWC438 Aug 29, 2023
1c14f87
Inject trace context with request headers
FAWC438 Aug 30, 2023
c3ee3a5
Test trace to Jaeger
FAWC438 Aug 31, 2023
656d7e5
Add config trace nested spans
FAWC438 Aug 31, 2023
51e6809
Add naming trace nested spans
FAWC438 Sep 1, 2023
58587df
Add naming trace namespace attr and fix unit tests
FAWC438 Sep 2, 2023
6cfe500
Fix Jaeger test case
FAWC438 Sep 3, 2023
b8aeb1a
Update author info
FAWC438 Sep 4, 2023
11b66fd
Add config serverNumber metric
FAWC438 Sep 9, 2023
456fd6d
Add server request handle meters
FAWC438 Sep 12, 2023
6a4d914
Fix metric/trace tests
FAWC438 Sep 12, 2023
73a895c
Set grpc attr to lower case
FAWC438 Sep 12, 2023
292de2d
Set span name "nacos" to upper case
FAWC438 Sep 12, 2023
7fc120c
Fix trace tests assert
FAWC438 Sep 12, 2023
4bb7f87
Add server request handler traces
FAWC438 Sep 13, 2023
ec5aeac
Fix config magic values and make sure config trace attributes are set…
FAWC438 Sep 18, 2023
c99aa7d
Fix naming magic values and make sure naming trace attributes are set…
FAWC438 Sep 18, 2023
e0a120f
Add trace about EncryptDataKey
FAWC438 Sep 19, 2023
d679112
Roll back enhanced subclass
FAWC438 Sep 21, 2023
2f0724f
Roll back enhanced subclass
FAWC438 Sep 21, 2023
88e9ce1
Nacos common no longer depends on opentelemetry-api
FAWC438 Sep 21, 2023
cd9d73c
Add spanProxy
FAWC438 Sep 25, 2023
74b0e44
Set spanProxy params type to SpanBuilder
FAWC438 Sep 25, 2023
d238d46
Set the span kind of outgoing spans to `SpanKind.CLIENT`
FAWC438 Sep 27, 2023
5fbe8ab
Call `getTracer()` every time when acquiring spans to follow OpenTele…
FAWC438 Oct 4, 2023
eb77bd3
Fix a null pointer issue
FAWC438 Oct 5, 2023
9ebd64f
Using dynamic proxy to tracing ClientWorker
FAWC438 Oct 5, 2023
80ea766
Using dynamic proxy to tracing all config module, except some static …
FAWC438 Oct 5, 2023
e27e0d1
Using dynamic proxy to tracing Service level naming spans
FAWC438 Oct 6, 2023
03df79e
Using dynamic proxy to tracing naming redo service
FAWC438 Oct 6, 2023
d6e0ade
Almost all trace spans are refactored by JDK dynamic proxy
FAWC438 Oct 6, 2023
b78d68d
Add unit tests for `TraceDynamicProxy`
FAWC438 Oct 9, 2023
6426151
Merge branch 'summer-ospp#10377' into trace
FAWC438 Oct 30, 2023
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
33 changes: 33 additions & 0 deletions client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,19 @@
<url>https://nacos.io</url>
<description>Nacos client pom.xml file</description>

<!-- Manage the version of libraries in OpenTelemetry -->
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-bom</artifactId>
<version>${io.opentelemetry.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>

<dependency>
Expand Down Expand Up @@ -126,6 +139,26 @@
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-otlp</artifactId>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-api</artifactId>
</dependency>

<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-sdk</artifactId>
</dependency>

<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-exporter-otlp</artifactId>
</dependency>

<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-semconv</artifactId>
<version>${io.opentelemetry.version}-alpha</version>
</dependency>

</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.alibaba.nacos.client.config.filter.impl.ConfigFilterChainManager;
import com.alibaba.nacos.client.config.filter.impl.ConfigRequest;
import com.alibaba.nacos.client.config.filter.impl.ConfigResponse;
import com.alibaba.nacos.client.config.http.HttpAgent;
import com.alibaba.nacos.client.config.http.ServerHttpAgent;
import com.alibaba.nacos.client.config.impl.ClientWorker;
import com.alibaba.nacos.client.config.impl.LocalConfigInfoProcessor;
Expand All @@ -34,10 +35,19 @@
import com.alibaba.nacos.client.config.utils.ContentUtils;
import com.alibaba.nacos.client.config.utils.ParamUtils;
import com.alibaba.nacos.client.env.NacosClientProperties;
import com.alibaba.nacos.client.monitor.TraceDynamicProxy;
import com.alibaba.nacos.client.monitor.config.ClientWorkerTraceProxy;
import com.alibaba.nacos.common.constant.NacosSemanticAttributes;
import com.alibaba.nacos.client.monitor.config.ConfigTrace;
import com.alibaba.nacos.client.utils.LogUtils;
import com.alibaba.nacos.client.utils.ParamUtil;
import com.alibaba.nacos.client.utils.ValidatorUtils;
import com.alibaba.nacos.common.utils.StringUtils;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.SpanBuilder;
import io.opentelemetry.api.trace.StatusCode;
import io.opentelemetry.context.Scope;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import org.slf4j.Logger;

import java.util.Arrays;
Expand All @@ -61,12 +71,12 @@ public class NacosConfigService implements ConfigService {
* will be deleted in 2.0 later versions
*/
@Deprecated
ServerHttpAgent agent = null;
HttpAgent agent;

/**
* long polling.
*/
private final ClientWorker worker;
private final ClientWorkerTraceProxy worker;

private String namespace;

Expand All @@ -81,9 +91,10 @@ public NacosConfigService(Properties properties) throws NacosException {
ServerListManager serverListManager = new ServerListManager(clientProperties);
serverListManager.start();

this.worker = new ClientWorker(this.configFilterChainManager, serverListManager, clientProperties);
this.worker = TraceDynamicProxy.getClientWorkerTraceProxy(
new ClientWorker(this.configFilterChainManager, serverListManager, clientProperties));
// will be deleted in 2.0 later versions
agent = new ServerHttpAgent(serverListManager);
agent = TraceDynamicProxy.getHttpAgentTraceProxy(new ServerHttpAgent(serverListManager));

}

Expand All @@ -102,8 +113,8 @@ public String getConfigAndSignListener(String dataId, String group, long timeout
throws NacosException {
group = StringUtils.isBlank(group) ? Constants.DEFAULT_GROUP : group.trim();

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using an enhanced subclass of ClientWorker or AOP processing is a better way to wrap or decorate these methods.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, I will think about it carefully and discuss it with you

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An enhanced subclass may be better, since a span could include more than one method

ConfigResponse configResponse = worker.getAgent()
.queryConfig(dataId, group, worker.getAgent().getTenant(), timeoutMs, false);
ConfigResponse configResponse = worker.getServerConfig(dataId, group, worker.getAgentTenant(), timeoutMs,
false);

String content = configResponse.getContent();
String encryptedDataKey = configResponse.getEncryptedDataKey();
Expand Down Expand Up @@ -171,14 +182,15 @@ private String getConfigInner(String tenant, String dataId, String group, long t
// but is maintained by user.
// This is designed for certain scenario like client emergency reboot,
// changing config needed in the same time, while nacos server is down.
String content = LocalConfigInfoProcessor.getFailover(worker.getAgentName(), dataId, group, tenant);
String content = getFailoverWithTrace(worker.getAgentName(), dataId, group, tenant, false);

if (content != null) {
LOGGER.warn("[{}] [get-config] get failover ok, dataId={}, group={}, tenant={}, config={}",
worker.getAgentName(), dataId, group, tenant, ContentUtils.truncateContent(content));
cr.setContent(content);
String encryptedDataKey = LocalEncryptedDataKeyProcessor.getEncryptDataKeyFailover(agent.getName(), dataId,
group, tenant);

String encryptedDataKey = getFailoverWithTrace(agent.getName(), dataId, group, tenant, true);

cr.setEncryptedDataKey(encryptedDataKey);
configFilterChainManager.doFilter(null, cr);
content = cr.getContent();
Expand All @@ -203,21 +215,142 @@ private String getConfigInner(String tenant, String dataId, String group, long t
worker.getAgentName(), dataId, group, tenant, ioe.toString());
}

content = LocalConfigInfoProcessor.getSnapshot(worker.getAgentName(), dataId, group, tenant);
content = getSnapshotWithTrace(worker.getAgentName(), dataId, group, tenant, false);

if (content != null) {
LOGGER.warn("[{}] [get-config] get snapshot ok, dataId={}, group={}, tenant={}, config={}",
worker.getAgentName(), dataId, group, tenant, ContentUtils.truncateContent(content));
}
cr.setContent(content);
String encryptedDataKey = LocalEncryptedDataKeyProcessor.getEncryptDataKeySnapshot(agent.getName(), dataId,
group, tenant);

String encryptedDataKey = getSnapshotWithTrace(agent.getName(), dataId, group, tenant, true);

cr.setEncryptedDataKey(encryptedDataKey);
configFilterChainManager.doFilter(null, cr);
content = cr.getContent();
return content;
}

/**
* Get failover with trace.
*
* <p>Didn't use dynamic proxy here because of calling static method.
*
* @param envName env name
* @param dataId data id
* @param group group
* @param tenant tenant
* @param isEncrypted is encrypted
* @return content
*/
private String getFailoverWithTrace(String envName, String dataId, String group, String tenant,
boolean isEncrypted) {

SpanBuilder spanBuilder;
if (isEncrypted) {
spanBuilder = ConfigTrace.getClientConfigServiceSpanBuilder("getEncryptDataKeyFailover");
spanBuilder.setAttribute(SemanticAttributes.CODE_NAMESPACE, LocalEncryptedDataKeyProcessor.class.getName());
} else {
spanBuilder = ConfigTrace.getClientConfigServiceSpanBuilder("getFailover");
spanBuilder.setAttribute(SemanticAttributes.CODE_NAMESPACE, LocalConfigInfoProcessor.class.getName());
}

Span span = setSpanLocalConfigInfoAttributes(envName, dataId, group, tenant, spanBuilder);

String content;
try (Scope ignored = span.makeCurrent()) {

if (isEncrypted) {
content = LocalEncryptedDataKeyProcessor.getEncryptDataKeyFailover(envName, dataId, group, tenant);
} else {
content = LocalConfigInfoProcessor.getFailover(envName, dataId, group, tenant);
}

if (span.isRecording()) {
if (content == null) {
span.setStatus(StatusCode.ERROR, "Get failover failed");
} else {
span.setStatus(StatusCode.OK, "Get failover ok");
span.setAttribute(NacosSemanticAttributes.CONTENT, content);
}
}

} catch (Throwable e) {
span.recordException(e);
span.setStatus(StatusCode.ERROR, e.getClass().getSimpleName());
throw e;
} finally {
span.end();
}

return content;
}

/**
* Get snapshot with trace.
*
* <p>Didn't use dynamic proxy here because of calling static method.
*
* @param envName env name
* @param dataId data id
* @param group group
* @param tenant tenant
* @param isEncrypted is encrypted
* @return content
*/
private String getSnapshotWithTrace(String envName, String dataId, String group, String tenant,
boolean isEncrypted) {

SpanBuilder spanBuilder;
if (isEncrypted) {
spanBuilder = ConfigTrace.getClientConfigServiceSpanBuilder("getEncryptDataKeySnapshot");
spanBuilder.setAttribute(SemanticAttributes.CODE_NAMESPACE, LocalEncryptedDataKeyProcessor.class.getName());
} else {
spanBuilder = ConfigTrace.getClientConfigServiceSpanBuilder("getSnapshot");
spanBuilder.setAttribute(SemanticAttributes.CODE_NAMESPACE, LocalConfigInfoProcessor.class.getName());
}

Span span = setSpanLocalConfigInfoAttributes(envName, dataId, group, tenant, spanBuilder);

String content;
try (Scope ignored = span.makeCurrent()) {

if (isEncrypted) {
content = LocalEncryptedDataKeyProcessor.getEncryptDataKeySnapshot(envName, dataId, group, tenant);
} else {
content = LocalConfigInfoProcessor.getSnapshot(envName, dataId, group, tenant);
}

if (span.isRecording()) {
if (content == null) {
span.setStatus(StatusCode.ERROR, "Get snapshot failed");
} else {
span.setStatus(StatusCode.OK, "Get snapshot ok");
span.setAttribute(NacosSemanticAttributes.CONTENT, content);
}
}

} catch (Throwable e) {
span.recordException(e);
span.setStatus(StatusCode.ERROR, e.getClass().getSimpleName());
throw e;
} finally {
span.end();
}
return content;
}

private Span setSpanLocalConfigInfoAttributes(String envName, String dataId, String group, String tenant,
SpanBuilder spanBuilder) {
spanBuilder.setAttribute(NacosSemanticAttributes.AGENT_NAME, envName);
spanBuilder.setAttribute(NacosSemanticAttributes.DATA_ID, dataId);
spanBuilder.setAttribute(NacosSemanticAttributes.GROUP, group);
spanBuilder.setAttribute(NacosSemanticAttributes.TENANT, tenant);
spanBuilder.setAttribute(NacosSemanticAttributes.NAMESPACE, namespace);

return spanBuilder.startSpan();
}

private String blank2defaultGroup(String group) {
return (StringUtils.isBlank(group)) ? Constants.DEFAULT_GROUP : group.trim();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.alibaba.nacos.client.monitor.config.ConfigMetrics;
import com.alibaba.nacos.common.http.HttpRestResult;

import java.net.HttpURLConnection;
import java.util.Date;
import java.util.Map;

Expand Down Expand Up @@ -124,5 +125,13 @@ public String getEncode() {
public void shutdown() throws NacosException {
httpAgent.shutdown();
}

private boolean isFail(HttpRestResult<String> result) {
return result.getCode() == HttpURLConnection.HTTP_INTERNAL_ERROR
|| result.getCode() == HttpURLConnection.HTTP_BAD_GATEWAY
|| result.getCode() == HttpURLConnection.HTTP_UNAVAILABLE
|| result.getCode() == HttpURLConnection.HTTP_NOT_FOUND;
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ private boolean isFail(HttpRestResult<String> result) {
|| result.getCode() == HttpURLConnection.HTTP_NOT_FOUND;
}

public static String getAppname() {
public static String getAppName() {
return ParamUtil.getAppName();
}

Expand Down
Loading