-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright (C) 2023-2023 Huawei Technologies Co., Ltd. All rights reserved. | ||
* | ||
* Licensed 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.huawei.metrics.common; | ||
|
||
/** | ||
* 结果类型 | ||
* | ||
* @author zhp | ||
* @since 2023-12-15 | ||
*/ | ||
public enum ResultType { | ||
SUCCESS(0), | ||
Check failure on line 26 in sermant-plugins/sermant-metrics/metrics-plugin/src/main/java/com/huawei/metrics/common/ResultType.java
|
||
CLIENT_ERROR(1), | ||
Check failure on line 27 in sermant-plugins/sermant-metrics/metrics-plugin/src/main/java/com/huawei/metrics/common/ResultType.java
|
||
SERVER_ERROR(2), | ||
Check failure on line 28 in sermant-plugins/sermant-metrics/metrics-plugin/src/main/java/com/huawei/metrics/common/ResultType.java
|
||
ERROR(3); | ||
Check failure on line 29 in sermant-plugins/sermant-metrics/metrics-plugin/src/main/java/com/huawei/metrics/common/ResultType.java
|
||
|
||
private final int value; | ||
|
||
ResultType(int value) { | ||
this.value = value; | ||
} | ||
|
||
public int getValue() { | ||
return value; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright (C) 2023-2023 Huawei Technologies Co., Ltd. All rights reserved. | ||
* | ||
* Licensed 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.huawei.metrics.declarer.httpclient; | ||
|
||
import com.huawei.metrics.declarer.AbstractDeclarer; | ||
import com.huawei.metrics.interceptor.httpclient.HttpClientInterceptor; | ||
|
||
import com.huaweicloud.sermant.core.plugin.agent.declarer.InterceptDeclarer; | ||
import com.huaweicloud.sermant.core.plugin.agent.matcher.ClassMatcher; | ||
import com.huaweicloud.sermant.core.plugin.agent.matcher.MethodMatcher; | ||
|
||
/** | ||
* HttpClient4.x请求方法拦截声明 | ||
* | ||
* @author zhp | ||
* @since 2023-12-15 | ||
*/ | ||
public class HttpClientDeclarer extends AbstractDeclarer { | ||
/** | ||
* 增强类的全限定名 http请求 | ||
*/ | ||
private static final String[] ENHANCE_CLASSES = { | ||
"org.apache.http.impl.client.AbstractHttpClient", | ||
"org.apache.http.impl.client.DefaultRequestDirector", | ||
"org.apache.http.impl.client.InternalHttpClient", | ||
"org.apache.http.impl.client.MinimalHttpClient" | ||
}; | ||
|
||
@Override | ||
public ClassMatcher getClassMatcher() { | ||
return ClassMatcher.nameContains(ENHANCE_CLASSES); | ||
} | ||
|
||
@Override | ||
public InterceptDeclarer[] getInterceptDeclarers(ClassLoader classLoader) { | ||
return new InterceptDeclarer[]{ | ||
InterceptDeclarer.build(MethodMatcher.nameContains("doExecute", "execute") | ||
.and(MethodMatcher.paramTypesEqual( | ||
"org.apache.http.HttpHost", | ||
"org.apache.http.HttpRequest", | ||
"org.apache.http.protocol.HttpContext")), | ||
new HttpClientInterceptor()) | ||
}; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright (C) 2023-2023 Huawei Technologies Co., Ltd. All rights reserved. | ||
* | ||
* Licensed 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.huawei.metrics.declarer.httpurlconnection; | ||
|
||
import com.huawei.metrics.declarer.AbstractDeclarer; | ||
import com.huawei.metrics.interceptor.httpurlconnection.ConnectorInterceptor; | ||
|
||
import com.huaweicloud.sermant.core.plugin.agent.declarer.InterceptDeclarer; | ||
import com.huaweicloud.sermant.core.plugin.agent.matcher.ClassMatcher; | ||
import com.huaweicloud.sermant.core.plugin.agent.matcher.MethodMatcher; | ||
|
||
/** | ||
* HttpURLConnection1.7.x+链接方法拦截声明 | ||
* | ||
* @author zhp | ||
* @since 2023-12-15 | ||
*/ | ||
public class ConnectDeclarer extends AbstractDeclarer { | ||
private static final String ENHANCE_CLASS = "sun.net.www.protocol.http.HttpURLConnection"; | ||
|
||
@Override | ||
public ClassMatcher getClassMatcher() { | ||
return ClassMatcher.nameEquals(ENHANCE_CLASS); | ||
} | ||
|
||
@Override | ||
public InterceptDeclarer[] getInterceptDeclarers(ClassLoader classLoader) { | ||
return new InterceptDeclarer[]{ | ||
InterceptDeclarer.build(MethodMatcher.nameEquals("connect"), | ||
new ConnectorInterceptor()) | ||
}; | ||
} | ||
} |