Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
killuaz丶x
SkyWalking
提交
6d92bc66
S
SkyWalking
项目概览
killuaz丶x
/
SkyWalking
与 Fork 源项目一致
Fork自
apache / SkyWalking
通知
1
Star
0
Fork
0
代码
文件
提交
分支
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,发现更多精彩内容 >>
未验证
提交
6d92bc66
编写于
2月 19, 2021
作者:
静夜思朝颜
提交者:
GitHub
2月 19, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Meter system enhancement (#6398)
上级
1adea8a1
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
110 addition
and
10 deletion
+110
-10
CHANGES.md
CHANGES.md
+1
-0
oap-server/analyzer/meter-analyzer/src/main/java/org/apache/skywalking/oap/meter/analyzer/Analyzer.java
...va/org/apache/skywalking/oap/meter/analyzer/Analyzer.java
+3
-4
oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/meter/MeterSystem.java
...kywalking/oap/server/core/analysis/meter/MeterSystem.java
+17
-6
oap-server/server-core/src/test/java/org/apache/skywalking/oap/server/core/analysis/meter/MeterSystemTest.java
...lking/oap/server/core/analysis/meter/MeterSystemTest.java
+89
-0
未找到文件。
CHANGES.md
浏览文件 @
6d92bc66
...
@@ -20,6 +20,7 @@ Release Notes.
...
@@ -20,6 +20,7 @@ Release Notes.
*
Update the
`timestamp`
field type for
`LogQuery`
.
*
Update the
`timestamp`
field type for
`LogQuery`
.
*
Support Zabbix protocol to receive agent metrics.
*
Support Zabbix protocol to receive agent metrics.
*
Update the Apdex metric combine calculator.
*
Update the Apdex metric combine calculator.
*
Enhance
`MeterSystem`
to allow creating metrics with same
`metricName`
/
`function`
/
`scope`
.
#### UI
#### UI
*
Update selector scroller to show in all pages.
*
Update selector scroller to show in all pages.
...
...
oap-server/analyzer/meter-analyzer/src/main/java/org/apache/skywalking/oap/meter/analyzer/Analyzer.java
浏览文件 @
6d92bc66
...
@@ -18,7 +18,6 @@
...
@@ -18,7 +18,6 @@
package
org.apache.skywalking.oap.meter.analyzer
;
package
org.apache.skywalking.oap.meter.analyzer
;
import
com.google.common.base.Preconditions
;
import
com.google.common.collect.ImmutableMap
;
import
com.google.common.collect.ImmutableMap
;
import
io.vavr.Tuple
;
import
io.vavr.Tuple
;
import
io.vavr.Tuple2
;
import
io.vavr.Tuple2
;
...
@@ -208,12 +207,12 @@ public class Analyzer {
...
@@ -208,12 +207,12 @@ public class Analyzer {
metricType
=
MetricType
.
labeled
;
metricType
=
MetricType
.
labeled
;
}
}
}
}
Preconditions
.
checkState
(
createMetric
(
ctx
.
getScopeType
(),
metricType
.
literal
,
ctx
.
getDownsampling
()
));
createMetric
(
ctx
.
getScopeType
(),
metricType
.
literal
,
ctx
.
getDownsampling
(
));
}
}
private
boolean
createMetric
(
final
ScopeType
scopeType
,
final
String
dataType
,
final
DownsamplingType
downsamplingType
)
{
private
void
createMetric
(
final
ScopeType
scopeType
,
final
String
dataType
,
final
DownsamplingType
downsamplingType
)
{
String
functionName
=
String
.
format
(
FUNCTION_NAME_TEMP
,
downsamplingType
.
toString
().
toLowerCase
(),
Strings
.
capitalize
(
dataType
));
String
functionName
=
String
.
format
(
FUNCTION_NAME_TEMP
,
downsamplingType
.
toString
().
toLowerCase
(),
Strings
.
capitalize
(
dataType
));
return
meterSystem
.
create
(
metricName
,
functionName
,
scopeType
);
meterSystem
.
create
(
metricName
,
functionName
,
scopeType
);
}
}
private
void
send
(
final
AcceptableValue
<?>
v
,
final
long
time
)
{
private
void
send
(
final
AcceptableValue
<?>
v
,
final
long
time
)
{
...
...
oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/meter/MeterSystem.java
浏览文件 @
6d92bc66
...
@@ -99,11 +99,10 @@ public class MeterSystem implements Service {
...
@@ -99,11 +99,10 @@ public class MeterSystem implements Service {
*
*
* @param metricsName The name used as the storage eneity and in the query stage.
* @param metricsName The name used as the storage eneity and in the query stage.
* @param functionName The function provided through {@link MeterFunction}.
* @param functionName The function provided through {@link MeterFunction}.
* @return true if created, false if it exists.
* @throws IllegalArgumentException if the parameter can't match the expectation.
* @throws IllegalArgumentException if the parameter can't match the expectation.
* @throws UnexpectedException if binary code manipulation fails or stream core failure.
* @throws UnexpectedException if binary code manipulation fails or stream core failure.
*/
*/
public
synchronized
<
T
>
boolean
create
(
String
metricsName
,
public
synchronized
<
T
>
void
create
(
String
metricsName
,
String
functionName
,
String
functionName
,
ScopeType
type
)
throws
IllegalArgumentException
{
ScopeType
type
)
throws
IllegalArgumentException
{
final
Class
<?
extends
MeterFunction
>
meterFunction
=
functionRegister
.
get
(
functionName
);
final
Class
<?
extends
MeterFunction
>
meterFunction
=
functionRegister
.
get
(
functionName
);
...
@@ -123,7 +122,7 @@ public class MeterSystem implements Service {
...
@@ -123,7 +122,7 @@ public class MeterSystem implements Service {
}
}
}
}
try
{
try
{
return
create
(
metricsName
,
functionName
,
type
,
Class
.
forName
(
Objects
.
requireNonNull
(
acceptance
).
getTypeName
()));
create
(
metricsName
,
functionName
,
type
,
Class
.
forName
(
Objects
.
requireNonNull
(
acceptance
).
getTypeName
()));
}
catch
(
ClassNotFoundException
e
)
{
}
catch
(
ClassNotFoundException
e
)
{
throw
new
IllegalArgumentException
(
e
);
throw
new
IllegalArgumentException
(
e
);
}
}
...
@@ -135,11 +134,10 @@ public class MeterSystem implements Service {
...
@@ -135,11 +134,10 @@ public class MeterSystem implements Service {
*
*
* @param metricsName The name used as the storage eneity and in the query stage.
* @param metricsName The name used as the storage eneity and in the query stage.
* @param functionName The function provided through {@link MeterFunction}.
* @param functionName The function provided through {@link MeterFunction}.
* @return true if created, false if it exists.
* @throws IllegalArgumentException if the parameter can't match the expectation.
* @throws IllegalArgumentException if the parameter can't match the expectation.
* @throws UnexpectedException if binary code manipulation fails or stream core failure.
* @throws UnexpectedException if binary code manipulation fails or stream core failure.
*/
*/
public
synchronized
<
T
>
boolean
create
(
String
metricsName
,
public
synchronized
<
T
>
void
create
(
String
metricsName
,
String
functionName
,
String
functionName
,
ScopeType
type
,
ScopeType
type
,
Class
<
T
>
dataType
)
throws
IllegalArgumentException
{
Class
<
T
>
dataType
)
throws
IllegalArgumentException
{
...
@@ -187,6 +185,20 @@ public class MeterSystem implements Service {
...
@@ -187,6 +185,20 @@ public class MeterSystem implements Service {
throw
new
IllegalArgumentException
(
"Function "
+
functionName
+
" can't be found by javaassist."
);
throw
new
IllegalArgumentException
(
"Function "
+
functionName
+
" can't be found by javaassist."
);
}
}
final
String
className
=
formatName
(
metricsName
);
final
String
className
=
formatName
(
metricsName
);
/**
* Check whether the metrics class is already defined or not
*/
try
{
CtClass
existingMetric
=
classPool
.
get
(
METER_CLASS_PACKAGE
+
className
);
if
(
existingMetric
.
getSuperclass
()
!=
parentClass
||
type
!=
meterPrototypes
.
get
(
metricsName
).
getScopeType
())
{
throw
new
IllegalArgumentException
(
metricsName
+
" has been defined, but calculate function or/are scope type is/are different."
);
}
log
.
info
(
"Metric {} is already defined, so skip the metric creation."
,
metricsName
);
return
;
}
catch
(
NotFoundException
e
)
{
}
CtClass
metricsClass
=
classPool
.
makeClass
(
METER_CLASS_PACKAGE
+
className
,
parentClass
);
CtClass
metricsClass
=
classPool
.
makeClass
(
METER_CLASS_PACKAGE
+
className
,
parentClass
);
/**
/**
...
@@ -234,7 +246,6 @@ public class MeterSystem implements Service {
...
@@ -234,7 +246,6 @@ public class MeterSystem implements Service {
log
.
error
(
"Can't compile/load/init "
+
className
+
"."
,
e
);
log
.
error
(
"Can't compile/load/init "
+
className
+
"."
,
e
);
throw
new
UnexpectedException
(
e
.
getMessage
(),
e
);
throw
new
UnexpectedException
(
e
.
getMessage
(),
e
);
}
}
return
true
;
}
}
/**
/**
...
...
oap-server/server-core/src/test/java/org/apache/skywalking/oap/server/core/analysis/meter/MeterSystemTest.java
0 → 100644
浏览文件 @
6d92bc66
/*
* 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
org.apache.skywalking.oap.server.core.analysis.meter
;
import
java.util.Map
;
import
org.apache.skywalking.oap.server.core.analysis.StreamDefinition
;
import
org.apache.skywalking.oap.server.core.analysis.worker.MetricsStreamProcessor
;
import
org.apache.skywalking.oap.server.core.storage.StorageException
;
import
org.apache.skywalking.oap.server.library.module.ModuleManager
;
import
org.junit.Assert
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.mockito.Mock
;
import
org.mockito.Mockito
;
import
org.mockito.junit.MockitoJUnitRunner
;
import
org.powermock.reflect.Whitebox
;
import
static
org
.
mockito
.
ArgumentMatchers
.
any
;
import
static
org
.
mockito
.
Mockito
.
doNothing
;
import
static
org
.
mockito
.
Mockito
.
spy
;
@RunWith
(
MockitoJUnitRunner
.
Silent
.
class
)
public
class
MeterSystemTest
{
@Mock
private
ModuleManager
moduleManager
;
private
MeterSystem
meterSystem
;
@Before
public
void
setup
()
throws
StorageException
{
meterSystem
=
spy
(
new
MeterSystem
(
moduleManager
));
Whitebox
.
setInternalState
(
MetricsStreamProcessor
.
class
,
"PROCESSOR"
,
Mockito
.
spy
(
MetricsStreamProcessor
.
getInstance
()));
doNothing
().
when
(
MetricsStreamProcessor
.
getInstance
()).
create
(
any
(),
(
StreamDefinition
)
any
(),
any
());
}
@Test
public
void
testCreate
()
{
// validate with same name, function and scope types
meterSystem
.
create
(
"test_meter"
,
"avg"
,
ScopeType
.
SERVICE
);
validateMeterDefinition
(
"test_meter"
,
Long
.
class
,
ScopeType
.
SERVICE
);
meterSystem
.
create
(
"test_meter"
,
"avg"
,
ScopeType
.
SERVICE
);
validateMeterDefinition
(
"test_meter"
,
Long
.
class
,
ScopeType
.
SERVICE
);
// validate with same name, difference scope type
try
{
meterSystem
.
create
(
"test_meter"
,
"avg"
,
ScopeType
.
SERVICE_INSTANCE
);
throw
new
IllegalStateException
();
}
catch
(
IllegalArgumentException
e
)
{
// If wrong arguments is means right
}
// validate with same name, difference function
try
{
meterSystem
.
create
(
"test_meter"
,
"avgLabeled"
,
ScopeType
.
SERVICE
);
throw
new
IllegalStateException
();
}
catch
(
IllegalArgumentException
e
)
{
// If wrong arguments is means right
}
}
private
void
validateMeterDefinition
(
String
meterName
,
Class
<?>
dataType
,
ScopeType
type
)
{
Map
<
String
,
?>
meterPrototypes
=
Whitebox
.
getInternalState
(
meterSystem
,
"meterPrototypes"
);
Object
meterDefinition
=
meterPrototypes
.
get
(
meterName
);
Class
<?>
realDataType
=
Whitebox
.
getInternalState
(
meterDefinition
,
"dataType"
);
ScopeType
realScopeTypes
=
Whitebox
.
getInternalState
(
meterDefinition
,
"scopeType"
);
Assert
.
assertEquals
(
dataType
,
realDataType
);
Assert
.
assertEquals
(
type
,
realScopeTypes
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录