-
Notifications
You must be signed in to change notification settings - Fork 94
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
Add recorder support #203
Merged
Merged
Add recorder support #203
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/main/java/com/alipay/sofa/common/insight/NoopRecorder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.alipay.sofa.common.insight; | ||
|
||
/** | ||
* @author muqingcai | ||
* @version 2024年4月19日 上午9:54:51 | ||
*/ | ||
public class NoopRecorder implements Recorder { | ||
public static final NoopRecorder INSTANCE = new NoopRecorder(); | ||
|
||
private NoopRecorder() { | ||
} | ||
|
||
@Override | ||
public void start(RecordScene scene, RecordContext context) { | ||
|
||
} | ||
|
||
@Override | ||
public void stop(RecordScene scene, RecordContext context) { | ||
|
||
} | ||
} |
222 changes: 222 additions & 0 deletions
222
src/main/java/com/alipay/sofa/common/insight/RecordContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,222 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.alipay.sofa.common.insight; | ||
|
||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
/** | ||
* @author muqingcai | ||
* @version 2024年4月19日 上午9:54:59 | ||
*/ | ||
public class RecordContext { | ||
private int requestId; | ||
private String traceId; | ||
private String rpcId; | ||
private String targetServiceUniqueName; | ||
private String methodName; | ||
private String moduleName; | ||
private String beanName; | ||
private Map<String, Object> extraInfo; | ||
|
||
/** | ||
* Constructor. | ||
*/ | ||
public RecordContext() { | ||
this.extraInfo = new ConcurrentHashMap<>(); | ||
} | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param requestId the request id | ||
*/ | ||
public RecordContext(int requestId) { | ||
this.requestId = requestId; | ||
this.extraInfo = new ConcurrentHashMap<>(); | ||
} | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param moduleName the module name | ||
* @param beanName the bean name | ||
*/ | ||
public RecordContext(String moduleName, String beanName) { | ||
this.extraInfo = new ConcurrentHashMap<>(); | ||
this.moduleName = moduleName; | ||
this.beanName = beanName; | ||
} | ||
|
||
/** | ||
* Gets get request id. | ||
* | ||
* @return the get request id | ||
*/ | ||
public int getRequestId() { | ||
return requestId; | ||
} | ||
|
||
/** | ||
* Sets set request id. | ||
* | ||
* @param requestId the request id | ||
*/ | ||
public void setRequestId(int requestId) { | ||
this.requestId = requestId; | ||
} | ||
|
||
/** | ||
* Gets get trace id. | ||
* | ||
* @return the get trace id | ||
*/ | ||
public String getTraceId() { | ||
return traceId; | ||
} | ||
|
||
/** | ||
* Sets set trace id. | ||
* | ||
* @param traceId the trace id | ||
*/ | ||
public void setTraceId(String traceId) { | ||
this.traceId = traceId; | ||
} | ||
|
||
/** | ||
* Gets get rpc id. | ||
* | ||
* @return the get rpc id | ||
*/ | ||
public String getRpcId() { | ||
return rpcId; | ||
} | ||
|
||
/** | ||
* Sets set rpc id. | ||
* | ||
* @param rpcId the rpc id | ||
*/ | ||
public void setRpcId(String rpcId) { | ||
this.rpcId = rpcId; | ||
} | ||
|
||
/** | ||
* Gets get target service unique name. | ||
* | ||
* @return the get target service unique name | ||
*/ | ||
public String getTargetServiceUniqueName() { | ||
return targetServiceUniqueName; | ||
} | ||
|
||
/** | ||
* Sets set target service unique name. | ||
* | ||
* @param targetServiceUniqueName the target service unique name | ||
*/ | ||
public void setTargetServiceUniqueName(String targetServiceUniqueName) { | ||
this.targetServiceUniqueName = targetServiceUniqueName; | ||
} | ||
|
||
/** | ||
* Gets get method name. | ||
* | ||
* @return the get method name | ||
*/ | ||
public String getMethodName() { | ||
return methodName; | ||
} | ||
|
||
/** | ||
* Sets set method name. | ||
* | ||
* @param methodName the method name | ||
*/ | ||
public void setMethodName(String methodName) { | ||
this.methodName = methodName; | ||
} | ||
|
||
/** | ||
* Gets get module name. | ||
* | ||
* @return the get module name | ||
*/ | ||
public String getModuleName() { | ||
return moduleName; | ||
} | ||
|
||
/** | ||
* Sets set module name. | ||
* | ||
* @param moduleName the module name | ||
*/ | ||
public void setModuleName(String moduleName) { | ||
this.moduleName = moduleName; | ||
} | ||
|
||
/** | ||
* Gets get bean name. | ||
* | ||
* @return the get bean name | ||
*/ | ||
public String getBeanName() { | ||
return beanName; | ||
} | ||
|
||
/** | ||
* Sets set bean name. | ||
* | ||
* @param beanName the bean name | ||
*/ | ||
public void setBeanName(String beanName) { | ||
this.beanName = beanName; | ||
} | ||
|
||
/** | ||
* Gets get extra info. | ||
* | ||
* @return the get extra info | ||
*/ | ||
public Map<String, Object> getExtraInfo() { | ||
return extraInfo; | ||
} | ||
|
||
/** | ||
* Sets set extra info. | ||
* | ||
* @param extraInfo the extra info | ||
*/ | ||
public void setExtraInfo(Map<String, Object> extraInfo) { | ||
this.extraInfo = extraInfo; | ||
} | ||
|
||
/** | ||
* To string string. | ||
* | ||
* @return the string | ||
*/ | ||
@Override | ||
public String toString() { | ||
return "RecordContext{" + "requestId=" + requestId + ", traceId='" + traceId + '\'' | ||
+ ", rpcId='" + rpcId + '\'' + ", targetServiceUniqueName='" | ||
+ targetServiceUniqueName + '\'' + ", methodName='" + methodName + '\'' | ||
+ ", moduleName='" + moduleName + '\'' + ", beanName='" + beanName + '\'' | ||
+ ", extraInfo=" + extraInfo + '}'; | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
src/main/java/com/alipay/sofa/common/insight/RecordScene.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.alipay.sofa.common.insight; | ||
|
||
/** | ||
* @author muqingcai | ||
* @version 2024年4月19日 上午9:55:54 | ||
*/ | ||
public enum RecordScene { | ||
/** | ||
* record 场景 | ||
*/ | ||
BOLT_REQUEST_HANDLE("boltRequestHandle", "bolt 协议 RPC 请求处理"), | ||
|
||
TR_REQUEST_HANDLE("trRequestHandle", "tr 协议 RPC 请求处理"), | ||
|
||
SOFA_STARTUP("sofaStartup", "应用启动"), | ||
|
||
SPRING_BEAN_REFRESH("springBeanRefresh", "应用 bean 刷新"); | ||
|
||
private final String scene; | ||
private final String desc; | ||
|
||
RecordScene(String scene, String desc) { | ||
this.scene = scene; | ||
this.desc = desc; | ||
} | ||
|
||
/** | ||
* Gets get scene. | ||
* | ||
* @return the get scene | ||
*/ | ||
public String getScene() { | ||
return scene; | ||
} | ||
|
||
/** | ||
* Gets get desc. | ||
* | ||
* @return the get desc | ||
*/ | ||
public String getDesc() { | ||
return desc; | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/main/java/com/alipay/sofa/common/insight/Recorder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.alipay.sofa.common.insight; | ||
|
||
/** | ||
* @author muqingcai | ||
* @version 2024年4月11日 下午9:56:03 | ||
*/ | ||
public interface Recorder { | ||
|
||
/** | ||
* Start record | ||
* | ||
* @param scene the scene | ||
* @param context the context | ||
*/ | ||
void start(RecordScene scene, RecordContext context); | ||
|
||
/** | ||
* Stop record | ||
* | ||
* @param scene the scene | ||
* @param context the context | ||
*/ | ||
void stop(RecordScene scene, RecordContext context); | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ensure thread safety for
extraInfo
initialization in all constructors.Consider initializing
extraInfo
in the field declaration to ensure it's always initialized properly, regardless of the constructor used:Then, remove the initialization from all constructors.
Also applies to: 48-51, 59-63
Committable suggestion