-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add metric collection function in router plugin
Signed-off-by: hanbingleixue <[email protected]>
- Loading branch information
1 parent
2cc3bcb
commit 9022abb
Showing
28 changed files
with
769 additions
and
18 deletions.
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
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
48 changes: 48 additions & 0 deletions
48
...gin/src/main/java/io/sermant/router/dubbo/declarer/AlibabaDubboMonitorFilterDeclarer.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,48 @@ | ||
/* | ||
* Copyright (C) 2024-2024 Sermant Authors. 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 io.sermant.router.dubbo.declarer; | ||
|
||
import io.sermant.core.plugin.agent.declarer.AbstractPluginDeclarer; | ||
import io.sermant.core.plugin.agent.declarer.InterceptDeclarer; | ||
import io.sermant.core.plugin.agent.matcher.ClassMatcher; | ||
import io.sermant.core.plugin.agent.matcher.MethodMatcher; | ||
import io.sermant.router.dubbo.interceptor.AlibabaDubboMonitorFilterInterceptor; | ||
|
||
/** | ||
* Enhanced Declarer of the MonitorFilter | ||
* | ||
* @author zhp | ||
* @since 2024-10-23 | ||
*/ | ||
public class AlibabaDubboMonitorFilterDeclarer extends AbstractPluginDeclarer { | ||
private static final String ENHANCE_CLASS = "com.alibaba.dubbo.monitor.support.MonitorFilter"; | ||
|
||
private static final String METHOD_NAME = "invoke"; | ||
|
||
@Override | ||
public ClassMatcher getClassMatcher() { | ||
return ClassMatcher.nameEquals(ENHANCE_CLASS); | ||
} | ||
|
||
@Override | ||
public InterceptDeclarer[] getInterceptDeclarers(ClassLoader classLoader) { | ||
return new InterceptDeclarer[]{ | ||
InterceptDeclarer.build(MethodMatcher.nameEquals(METHOD_NAME), | ||
new AlibabaDubboMonitorFilterInterceptor()) | ||
}; | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
...ugin/src/main/java/io/sermant/router/dubbo/declarer/ApacheDubboMonitorFilterDeclarer.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,48 @@ | ||
/* | ||
* Copyright (C) 2024-2024 Sermant Authors. 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 io.sermant.router.dubbo.declarer; | ||
|
||
import io.sermant.core.plugin.agent.declarer.AbstractPluginDeclarer; | ||
import io.sermant.core.plugin.agent.declarer.InterceptDeclarer; | ||
import io.sermant.core.plugin.agent.matcher.ClassMatcher; | ||
import io.sermant.core.plugin.agent.matcher.MethodMatcher; | ||
import io.sermant.router.dubbo.interceptor.ApacheDubboMonitorFilterInterceptor; | ||
|
||
/** | ||
* Enhanced Declarer of the MonitorFilter | ||
* | ||
* @author zhp | ||
* @since 2024-10-23 | ||
*/ | ||
public class ApacheDubboMonitorFilterDeclarer extends AbstractPluginDeclarer { | ||
private static final String ENHANCE_CLASS = "org.apache.dubbo.monitor.support.MonitorFilter"; | ||
|
||
private static final String METHOD_NAME = "invoke"; | ||
|
||
@Override | ||
public ClassMatcher getClassMatcher() { | ||
return ClassMatcher.nameEquals(ENHANCE_CLASS); | ||
} | ||
|
||
@Override | ||
public InterceptDeclarer[] getInterceptDeclarers(ClassLoader classLoader) { | ||
return new InterceptDeclarer[]{ | ||
InterceptDeclarer.build(MethodMatcher.nameEquals(METHOD_NAME), | ||
new ApacheDubboMonitorFilterInterceptor()) | ||
}; | ||
} | ||
} |
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
54 changes: 54 additions & 0 deletions
54
...c/main/java/io/sermant/router/dubbo/interceptor/AlibabaDubboMonitorFilterInterceptor.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,54 @@ | ||
/* | ||
* Copyright (C) 2024-2024 Sermant Authors. 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 io.sermant.router.dubbo.interceptor; | ||
|
||
import com.alibaba.dubbo.common.URL; | ||
import com.alibaba.dubbo.rpc.Invoker; | ||
|
||
import io.sermant.core.plugin.agent.entity.ExecuteContext; | ||
import io.sermant.core.plugin.agent.interceptor.AbstractInterceptor; | ||
import io.sermant.router.common.constants.RouterConstant; | ||
import io.sermant.router.common.metric.MetricsManager; | ||
|
||
/** | ||
* Interceptor of the MonitorFilter, Collecting Metric Information | ||
* | ||
* @author zhp | ||
* @since 2024-10-23 | ||
*/ | ||
public class AlibabaDubboMonitorFilterInterceptor extends AbstractInterceptor { | ||
@Override | ||
public ExecuteContext before(ExecuteContext context) throws Exception { | ||
return context; | ||
} | ||
|
||
@Override | ||
public ExecuteContext after(ExecuteContext context) throws Exception { | ||
Object[] arguments = context.getArguments(); | ||
if (arguments == null || arguments.length == 0) { | ||
return context; | ||
} | ||
if (arguments[0] instanceof Invoker) { | ||
Invoker<?> invoker = (Invoker<?>) arguments[0]; | ||
URL url = invoker.getUrl(); | ||
String address = url.getHost() + RouterConstant.URL_CONNECTOR + url.getPort(); | ||
MetricsManager.addOrUpdateMetricValue(RouterConstant.REQUEST_COUNT, RouterConstant.REQUEST_COUNT_TAG_NAME, | ||
address, 1); | ||
} | ||
return context; | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
...rc/main/java/io/sermant/router/dubbo/interceptor/ApacheDubboMonitorFilterInterceptor.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,54 @@ | ||
/* | ||
* Copyright (C) 2024-2024 Sermant Authors. 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 io.sermant.router.dubbo.interceptor; | ||
|
||
import io.sermant.core.plugin.agent.entity.ExecuteContext; | ||
import io.sermant.core.plugin.agent.interceptor.AbstractInterceptor; | ||
import io.sermant.router.common.constants.RouterConstant; | ||
import io.sermant.router.common.metric.MetricsManager; | ||
|
||
import org.apache.dubbo.common.URL; | ||
import org.apache.dubbo.rpc.Invoker; | ||
|
||
/** | ||
* Interceptor of the MonitorFilter, Collecting Metric Information | ||
* | ||
* @author zhp | ||
* @since 2024-10-23 | ||
*/ | ||
public class ApacheDubboMonitorFilterInterceptor extends AbstractInterceptor { | ||
@Override | ||
public ExecuteContext before(ExecuteContext context) throws Exception { | ||
return context; | ||
} | ||
|
||
@Override | ||
public ExecuteContext after(ExecuteContext context) throws Exception { | ||
Object[] arguments = context.getArguments(); | ||
if (arguments == null || arguments.length == 0) { | ||
return context; | ||
} | ||
if (arguments[0] instanceof Invoker) { | ||
Invoker<?> invoker = (Invoker<?>) arguments[0]; | ||
URL url = invoker.getUrl(); | ||
String address = url.getHost() + RouterConstant.URL_CONNECTOR + url.getPort(); | ||
MetricsManager.addOrUpdateMetricValue(RouterConstant.ROUTE_COUNT_TAG_NAME, RouterConstant.REQUEST_COUNT, | ||
address, 1); | ||
} | ||
return context; | ||
} | ||
} |
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
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
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
Oops, something went wrong.