Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
SkyWalking
提交
47fde7eb
S
SkyWalking
项目概览
apache
/
SkyWalking
上一次同步 1 年多
通知
302
Star
21345
Fork
6091
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
SkyWalking
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
47fde7eb
编写于
3月 11, 2016
作者:
wu-sheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
增加部分代码,提供新的应用程序入口,用于增强类实现。#36
上级
852aec98
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
249 addition
and
10 deletion
+249
-10
skywalking-api/src/main/java/com/ai/cloud/skywalking/conf/ConfigInitializer.java
.../java/com/ai/cloud/skywalking/conf/ConfigInitializer.java
+11
-9
skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/PluginBootstrap.java
.../java/com/ai/cloud/skywalking/plugin/PluginBootstrap.java
+40
-0
skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/PluginCfg.java
...c/main/java/com/ai/cloud/skywalking/plugin/PluginCfg.java
+36
-0
skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/PluginResourcesResolver.java
...m/ai/cloud/skywalking/plugin/PluginResourcesResolver.java
+49
-0
skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/TracingBootstrap.java
...java/com/ai/cloud/skywalking/plugin/TracingBootstrap.java
+33
-0
skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/EnhanceClazz4Interceptor.java
...ywalking/plugin/interceptor/EnhanceClazz4Interceptor.java
+52
-0
skywalking-api/src/main/java/com/ai/cloud/skywalking/selfexamination/SDKHealthCollector.java
.../cloud/skywalking/selfexamination/SDKHealthCollector.java
+1
-1
skywalking-api/src/test/java/test/ai/cloud/plugin/PluginResourceResoverTest.java
.../java/test/ai/cloud/plugin/PluginResourceResoverTest.java
+14
-0
skywalking-api/src/test/resources/log4j2.xml
skywalking-api/src/test/resources/log4j2.xml
+13
-0
skywalking-api/src/test/resources/skywalking-plugin.properties
...lking-api/src/test/resources/skywalking-plugin.properties
+0
-0
未找到文件。
skywalking-api/src/main/java/com/ai/cloud/skywalking/conf/ConfigInitializer.java
浏览文件 @
47fde7eb
package
com.ai.cloud.skywalking.conf
;
import
static
com
.
ai
.
cloud
.
skywalking
.
conf
.
Config
.
SkyWalking
.
AUTH_OVERRIDE
;
import
static
com
.
ai
.
cloud
.
skywalking
.
conf
.
Config
.
SkyWalking
.
AUTH_SYSTEM_ENV_NAME
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.lang.reflect.Field
;
import
java.lang.reflect.Modifier
;
import
java.util.LinkedList
;
import
java.util.Properties
;
import
java.util.logging.Level
;
import
java.util.logging.Logger
;
import
static
com
.
ai
.
cloud
.
skywalking
.
conf
.
Config
.
SkyWalking
.*;
import
org.apache.logging.log4j.LogManager
;
import
org.apache.logging.log4j.Logger
;
public
class
ConfigInitializer
{
private
static
Logger
logger
=
Logger
.
getLogger
(
ConfigInitializer
.
class
.
getName
()
);
private
static
Logger
logger
=
LogManager
.
getLogger
(
ConfigInitializer
.
class
);
public
static
void
initialize
()
{
InputStream
inputStream
=
ConfigInitializer
.
class
.
getResourceAsStream
(
"/sky-walking.auth"
);
if
(
inputStream
==
null
)
{
logger
.
log
(
Level
.
ALL
,
"No provider sky-walking certification documents, sky-walking api auto shutdown."
);
logger
.
info
(
"No provider sky-walking certification documents, sky-walking api auto shutdown."
);
}
else
{
try
{
Properties
properties
=
new
Properties
();
properties
.
load
(
inputStream
);
initNextLevel
(
properties
,
Config
.
class
,
new
ConfigDesc
());
AuthDesc
.
isAuth
=
Boolean
.
valueOf
(
System
.
getenv
(
AUTH_SYSTEM_ENV_NAME
));
logger
.
log
(
Level
.
ALL
,
"sky-walking auth check : "
+
AuthDesc
.
isAuth
);
logger
.
info
(
"sky-walking auth check : "
+
AuthDesc
.
isAuth
);
if
(!
AuthDesc
.
isAuth
&&
AUTH_OVERRIDE
){
AuthDesc
.
isAuth
=
AUTH_OVERRIDE
;
logger
.
log
(
Level
.
ALL
,
"sky-walking auth override: "
+
AuthDesc
.
isAuth
);
logger
.
info
(
"sky-walking auth override: "
+
AuthDesc
.
isAuth
);
}
}
catch
(
IllegalAccessException
e
)
{
logger
.
log
(
Level
.
ALL
,
"Parsing certification file failed, sky-walking api auto shutdown."
);
logger
.
error
(
"Parsing certification file failed, sky-walking api auto shutdown."
,
e
);
}
catch
(
IOException
e
)
{
logger
.
log
(
Level
.
ALL
,
"Failed to read the certification file, sky-walking api auto shutdown."
);
logger
.
error
(
"Failed to read the certification file, sky-walking api auto shutdown."
,
e
);
}
}
}
...
...
skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/PluginBootstrap.java
0 → 100644
浏览文件 @
47fde7eb
package
com.ai.cloud.skywalking.plugin
;
import
java.net.URL
;
import
java.util.Enumeration
;
import
org.apache.logging.log4j.LogManager
;
import
org.apache.logging.log4j.Logger
;
import
com.ai.cloud.skywalking.conf.AuthDesc
;
import
com.ai.cloud.skywalking.plugin.interceptor.EnhanceClazz4Interceptor
;
public
class
PluginBootstrap
{
private
static
Logger
logger
=
LogManager
.
getLogger
(
PluginBootstrap
.
class
);
public
void
start
()
{
if
(!
AuthDesc
.
isAuth
())
{
return
;
}
PluginResourcesResolver
resolver
=
new
PluginResourcesResolver
();
Enumeration
<
URL
>
resources
=
resolver
.
getResources
();
if
(
resources
==
null
||
!
resources
.
hasMoreElements
())
{
logger
.
info
(
"no plugin files (skywalking-plugin.properties) found, continue to start application."
);
return
;
}
while
(
resources
.
hasMoreElements
())
{
URL
pluginUrl
=
resources
.
nextElement
();
try
{
PluginCfg
.
CFG
.
load
(
pluginUrl
.
openStream
());
}
catch
(
Throwable
t
)
{
logger
.
error
(
"plugin [{}] init failure."
,
pluginUrl
,
t
);
}
}
EnhanceClazz4Interceptor
enhanceClazz4Interceptor
=
new
EnhanceClazz4Interceptor
();
enhanceClazz4Interceptor
.
enhance
();
}
}
skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/PluginCfg.java
0 → 100644
浏览文件 @
47fde7eb
package
com.ai.cloud.skywalking.plugin
;
import
java.io.BufferedReader
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStreamReader
;
import
java.util.HashSet
;
import
java.util.Set
;
import
com.ai.cloud.skywalking.util.StringUtil
;
public
class
PluginCfg
{
public
final
static
PluginCfg
CFG
=
new
PluginCfg
();
private
Set
<
String
>
interceptorClassList
=
new
HashSet
<
String
>();
private
PluginCfg
(){}
void
load
(
InputStream
input
)
throws
IOException
{
try
{
BufferedReader
reader
=
new
BufferedReader
(
new
InputStreamReader
(
input
));
String
nhanceOriginClassName
=
null
;
while
((
nhanceOriginClassName
=
reader
.
readLine
())
!=
null
){
if
(!
StringUtil
.
isEmpty
(
nhanceOriginClassName
)){
interceptorClassList
.
add
(
nhanceOriginClassName
.
trim
());
}
}
}
finally
{
input
.
close
();
}
}
public
Set
<
String
>
getInterceptorClassList
(){
return
interceptorClassList
;
}
}
skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/PluginResourcesResolver.java
0 → 100644
浏览文件 @
47fde7eb
package
com.ai.cloud.skywalking.plugin
;
import
java.io.IOException
;
import
java.net.URL
;
import
java.util.Enumeration
;
import
org.apache.logging.log4j.LogManager
;
import
org.apache.logging.log4j.Logger
;
public
class
PluginResourcesResolver
{
private
static
Logger
logger
=
LogManager
.
getLogger
(
PluginResourcesResolver
.
class
);
public
Enumeration
<
URL
>
getResources
(){
Enumeration
<
URL
>
urls
;
try
{
urls
=
getDefaultClassLoader
().
getResources
(
"skywalking-plugin.properties"
);
if
(!
urls
.
hasMoreElements
()){
logger
.
info
(
"no plugin files (skywalking-plugin.properties) found"
);
}
while
(
urls
.
hasMoreElements
()){
URL
pluginUrl
=
urls
.
nextElement
();
logger
.
info
(
"find skywalking plugin define in {}"
,
pluginUrl
);
}
return
urls
;
}
catch
(
IOException
e
)
{
logger
.
error
(
"read resources failure."
,
e
);
}
return
null
;
}
private
ClassLoader
getDefaultClassLoader
()
{
ClassLoader
cl
=
null
;
try
{
cl
=
Thread
.
currentThread
().
getContextClassLoader
();
}
catch
(
Throwable
ex
)
{
// Cannot access thread context ClassLoader - falling back to system class loader...
}
if
(
cl
==
null
)
{
// No thread context class loader -> use class loader of this class.
cl
=
PluginResourcesResolver
.
class
.
getClassLoader
();
}
return
cl
;
}
}
skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/TracingBootstrap.java
0 → 100644
浏览文件 @
47fde7eb
package
com.ai.cloud.skywalking.plugin
;
import
org.apache.logging.log4j.LogManager
;
import
org.apache.logging.log4j.Logger
;
/**
* 替代应用函数的main函数入口,确保在程序入口处运行 <br/>
* 用于替代-javaagent的另一种模式 <br/>
*
* @author wusheng
*
*/
public
class
TracingBootstrap
{
private
static
Logger
logger
=
LogManager
.
getLogger
(
TracingBootstrap
.
class
);
private
TracingBootstrap
()
{
}
public
static
void
main
(
String
[]
args
)
{
if
(
args
.
length
==
0
)
{
throw
new
RuntimeException
(
"bootstrap failure. need args[0] to be main class."
);
}
try
{
PluginBootstrap
bootstrap
=
new
PluginBootstrap
();
bootstrap
.
start
();
}
catch
(
Throwable
t
)
{
logger
.
error
(
"PluginBootstrap start failure."
,
t
);
}
}
}
skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/EnhanceClazz4Interceptor.java
0 → 100644
浏览文件 @
47fde7eb
package
com.ai.cloud.skywalking.plugin.interceptor
;
import
java.util.Set
;
import
net.bytebuddy.ByteBuddy
;
import
net.bytebuddy.dynamic.ClassFileLocator
;
import
net.bytebuddy.dynamic.loading.ClassLoadingStrategy
;
import
net.bytebuddy.pool.TypePool
;
import
org.apache.logging.log4j.LogManager
;
import
org.apache.logging.log4j.Logger
;
import
com.ai.cloud.skywalking.plugin.PluginCfg
;
public
class
EnhanceClazz4Interceptor
{
private
static
Logger
logger
=
LogManager
.
getLogger
(
EnhanceClazz4Interceptor
.
class
);
private
TypePool
typePool
;
public
EnhanceClazz4Interceptor
()
{
typePool
=
TypePool
.
Default
.
ofClassPath
();
}
public
void
enhance
()
{
Set
<
String
>
interceptorClassList
=
PluginCfg
.
CFG
.
getInterceptorClassList
();
for
(
String
interceptorClassName
:
interceptorClassList
)
{
try
{
enhance0
(
interceptorClassName
);
}
catch
(
Throwable
t
)
{
logger
.
error
(
"enhance class [{}] for intercept failure."
,
interceptorClassName
,
t
);
}
}
}
private
void
enhance0
(
String
enhanceOriginClassName
)
{
/**
* add '$$Origin' at the end of be enhanced classname <br/>
* such as: class com.ai.cloud.TestClass to class com.ai.cloud.TestClass$$Origin
*/
new
ByteBuddy
()
.
redefine
(
typePool
.
describe
(
enhanceOriginClassName
).
resolve
(),
ClassFileLocator
.
ForClassLoader
.
ofClassPath
())
.
name
(
enhanceOriginClassName
+
"$$Origin"
)
.
make
()
.
load
(
ClassLoader
.
getSystemClassLoader
(),
ClassLoadingStrategy
.
Default
.
INJECTION
).
getLoaded
();
}
}
skywalking-api/src/main/java/com/ai/cloud/skywalking/selfexamination/SDKHealthCollector.java
浏览文件 @
47fde7eb
...
...
@@ -12,7 +12,7 @@ import com.ai.cloud.skywalking.conf.Config;
import
com.ai.cloud.skywalking.util.BuriedPointMachineUtil
;
public
class
SDKHealthCollector
extends
Thread
{
private
Logger
logger
=
LogManager
.
getLogger
(
SDKHealthCollector
.
class
);
private
static
Logger
logger
=
LogManager
.
getLogger
(
SDKHealthCollector
.
class
);
private
static
Map
<
String
,
HeathReading
>
heathReadings
=
new
ConcurrentHashMap
<
String
,
HeathReading
>();
...
...
skywalking-api/src/test/java/test/ai/cloud/plugin/PluginResourceResoverTest.java
0 → 100644
浏览文件 @
47fde7eb
package
test.ai.cloud.plugin
;
import
java.io.IOException
;
import
com.ai.cloud.skywalking.plugin.PluginResourcesResolver
;
public
class
PluginResourceResoverTest
{
public
static
void
main
(
String
[]
args
)
throws
IOException
{
PluginResourcesResolver
resolver
=
new
PluginResourcesResolver
();
resolver
.
getResources
();
}
}
skywalking-api/src/test/resources/log4j2.xml
0 → 100644
浏览文件 @
47fde7eb
<?xml version="1.0" encoding="UTF-8"?>
<Configuration
status=
"debug"
>
<Appenders>
<Console
name=
"Console"
target=
"SYSTEM_OUT"
>
<PatternLayout
pattern=
"%d [%t](%F:%L) %-5level %logger{36} - %msg%n"
/>
</Console>
</Appenders>
<Loggers>
<Root
level=
"debug"
>
<AppenderRef
ref=
"Console"
/>
</Root>
</Loggers>
</Configuration>
\ No newline at end of file
skywalking-api/src/test/resources/skywalking-plugin.properties
0 → 100644
浏览文件 @
47fde7eb
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录