Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
Shardingsphere
提交
2225e0e1
Shardingsphere
项目概览
apache
/
Shardingsphere
通知
56
Star
3
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Shardingsphere
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
2225e0e1
编写于
5月 12, 2020
作者:
kimmking
提交者:
GitHub
5月 12, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #5555 from yu199195/metrics-point-1
Add sharding and transaction counter metrics.
上级
3d32d8a2
c1dbc5a5
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
258 addition
and
7 deletion
+258
-7
sharding-metrics/sharding-metrics-facade/src/main/java/org/apache/shardingsphere/metrics/facade/MetricsTrackerFacade.java
...e/shardingsphere/metrics/facade/MetricsTrackerFacade.java
+6
-2
sharding-metrics/sharding-metrics-facade/src/main/java/org/apache/shardingsphere/metrics/facade/handler/MetricsTrackerHandler.java
...gsphere/metrics/facade/handler/MetricsTrackerHandler.java
+10
-2
sharding-metrics/sharding-metrics-facade/src/test/java/org/apache/shardingsphere/metrics/facade/handler/MetricsTrackerHandlerTest.java
...ere/metrics/facade/handler/MetricsTrackerHandlerTest.java
+10
-2
sharding-metrics/sharding-metrics-prometheus/src/main/java/org/apache/shardingsphere/metrics/prometheus/PrometheusMetricsTrackerFactory.java
...e/metrics/prometheus/PrometheusMetricsTrackerFactory.java
+4
-0
sharding-metrics/sharding-metrics-prometheus/src/main/java/org/apache/shardingsphere/metrics/prometheus/impl/counter/ShardingCounterMetricsTracker.java
...rometheus/impl/counter/ShardingCounterMetricsTracker.java
+44
-0
sharding-metrics/sharding-metrics-prometheus/src/main/java/org/apache/shardingsphere/metrics/prometheus/impl/counter/TransactionCounterMetricsTracker.java
...etheus/impl/counter/TransactionCounterMetricsTracker.java
+44
-0
sharding-metrics/sharding-metrics-prometheus/src/test/java/org/apache/shardingsphere/metrics/prometheus/impl/counter/ShardingCounterMetricsTrackerTest.java
...theus/impl/counter/ShardingCounterMetricsTrackerTest.java
+59
-0
sharding-metrics/sharding-metrics-prometheus/src/test/java/org/apache/shardingsphere/metrics/prometheus/impl/counter/TransactionCounterMetricsTrackerTest.java
...us/impl/counter/TransactionCounterMetricsTrackerTest.java
+70
-0
sharding-metrics/sharding-metrics-spi/src/main/java/org/apache/shardingsphere/metrics/enums/MetricsLabelEnum.java
...apache/shardingsphere/metrics/enums/MetricsLabelEnum.java
+11
-1
未找到文件。
sharding-metrics/sharding-metrics-facade/src/main/java/org/apache/shardingsphere/metrics/facade/MetricsTrackerFacade.java
浏览文件 @
2225e0e1
...
...
@@ -137,7 +137,9 @@ public final class MetricsTrackerFacade {
* @param delegate histogram metrics tracker delegate
*/
public
void
histogramObserveDuration
(
final
HistogramMetricsTrackerDelegate
delegate
)
{
MetricsTrackerHandler
.
getInstance
().
histogramObserveDuration
(
delegate
);
if
(
enabled
)
{
MetricsTrackerHandler
.
getInstance
().
histogramObserveDuration
(
delegate
);
}
}
/**
...
...
@@ -160,7 +162,9 @@ public final class MetricsTrackerFacade {
* @param delegate summary metrics tracker delegate
*/
public
void
summaryObserveDuration
(
final
SummaryMetricsTrackerDelegate
delegate
)
{
MetricsTrackerHandler
.
getInstance
().
summaryObserveDuration
(
delegate
);
if
(
enabled
)
{
MetricsTrackerHandler
.
getInstance
().
summaryObserveDuration
(
delegate
);
}
}
private
void
loadMetricsManager
()
{
...
...
sharding-metrics/sharding-metrics-facade/src/main/java/org/apache/shardingsphere/metrics/facade/handler/MetricsTrackerHandler.java
浏览文件 @
2225e0e1
...
...
@@ -150,7 +150,11 @@ public final class MetricsTrackerHandler {
* @param delegate histogram metrics tracker delegate
*/
public
void
histogramObserveDuration
(
final
HistogramMetricsTrackerDelegate
delegate
)
{
delegate
.
observeDuration
();
if
(
async
)
{
executorService
.
execute
(
delegate:
:
observeDuration
);
}
else
{
delegate
.
observeDuration
();
}
}
/**
...
...
@@ -178,7 +182,11 @@ public final class MetricsTrackerHandler {
* @param delegate summary metrics tracker delegate
*/
public
void
summaryObserveDuration
(
final
SummaryMetricsTrackerDelegate
delegate
)
{
delegate
.
observeDuration
();
if
(
async
)
{
executorService
.
execute
(
delegate:
:
observeDuration
);
}
else
{
delegate
.
observeDuration
();
}
}
/**
...
...
sharding-metrics/sharding-metrics-facade/src/test/java/org/apache/shardingsphere/metrics/facade/handler/MetricsTrackerHandlerTest.java
浏览文件 @
2225e0e1
...
...
@@ -71,11 +71,15 @@ public final class MetricsTrackerHandlerTest {
histogramDelegate
.
ifPresent
(
delegate
->
{
handler
.
histogramObserveDuration
(
delegate
);
assertThat
(
delegate
.
getClass
().
getName
(),
is
(
NoneHistogramMetricsTrackerDelegate
.
class
.
getName
()));
handler
.
histogramObserveDuration
(
delegate
);
});
FieldUtil
.
setField
(
handler
,
"async"
,
false
);
Optional
<
HistogramMetricsTrackerDelegate
>
syncHistogram
=
handler
.
histogramStartTimer
(
METRICS_LABEL
);
assertThat
(
syncHistogram
.
isPresent
(),
is
(
true
));
syncHistogram
.
ifPresent
(
delegate
->
assertThat
(
delegate
.
getClass
().
getName
(),
is
(
NoneHistogramMetricsTrackerDelegate
.
class
.
getName
())));
syncHistogram
.
ifPresent
(
delegate
->
{
assertThat
(
delegate
.
getClass
().
getName
(),
is
(
NoneHistogramMetricsTrackerDelegate
.
class
.
getName
()));
handler
.
histogramObserveDuration
(
delegate
);
});
}
@Test
...
...
@@ -85,12 +89,16 @@ public final class MetricsTrackerHandlerTest {
summaryDelegate
.
ifPresent
(
delegate
->
{
handler
.
summaryObserveDuration
(
delegate
);
assertThat
(
delegate
.
getClass
().
getName
(),
is
(
NoneSummaryMetricsTrackerDelegate
.
class
.
getName
()));
handler
.
summaryObserveDuration
(
delegate
);
});
FieldUtil
.
setField
(
handler
,
"async"
,
false
);
Optional
<
SummaryMetricsTrackerDelegate
>
syncSummary
=
handler
.
summaryStartTimer
(
METRICS_LABEL
);
assertThat
(
syncSummary
.
isPresent
(),
is
(
true
));
syncSummary
.
ifPresent
(
delegate
->
assertThat
(
delegate
.
getClass
().
getName
(),
is
(
NoneSummaryMetricsTrackerDelegate
.
class
.
getName
())));
syncSummary
.
ifPresent
(
delegate
->
{
assertThat
(
delegate
.
getClass
().
getName
(),
is
(
NoneSummaryMetricsTrackerDelegate
.
class
.
getName
()));
handler
.
summaryObserveDuration
(
delegate
);
});
}
@After
...
...
sharding-metrics/sharding-metrics-prometheus/src/main/java/org/apache/shardingsphere/metrics/prometheus/PrometheusMetricsTrackerFactory.java
浏览文件 @
2225e0e1
...
...
@@ -21,6 +21,8 @@ import org.apache.shardingsphere.metrics.api.MetricsTracker;
import
org.apache.shardingsphere.metrics.api.MetricsTrackerFactory
;
import
org.apache.shardingsphere.metrics.prometheus.impl.counter.RequestTotalCounterMetricsTracker
;
import
org.apache.shardingsphere.metrics.prometheus.impl.counter.SQLStatementCounterMetricsTracker
;
import
org.apache.shardingsphere.metrics.prometheus.impl.counter.ShardingCounterMetricsTracker
;
import
org.apache.shardingsphere.metrics.prometheus.impl.counter.TransactionCounterMetricsTracker
;
import
org.apache.shardingsphere.metrics.prometheus.impl.gauge.ChannelCountGaugeMetricsTracker
;
import
org.apache.shardingsphere.metrics.prometheus.impl.histogram.RequestLatencyHistogramMetricsTracker
;
import
org.apache.shardingsphere.metrics.prometheus.impl.summary.RequestLatencySummaryMetricsTracker
;
...
...
@@ -42,6 +44,8 @@ public final class PrometheusMetricsTrackerFactory implements MetricsTrackerFact
REGISTER
.
add
(
new
ChannelCountGaugeMetricsTracker
());
REGISTER
.
add
(
new
RequestLatencyHistogramMetricsTracker
());
REGISTER
.
add
(
new
RequestLatencySummaryMetricsTracker
());
REGISTER
.
add
(
new
ShardingCounterMetricsTracker
());
REGISTER
.
add
(
new
TransactionCounterMetricsTracker
());
}
@Override
...
...
sharding-metrics/sharding-metrics-prometheus/src/main/java/org/apache/shardingsphere/metrics/prometheus/impl/counter/ShardingCounterMetricsTracker.java
0 → 100644
浏览文件 @
2225e0e1
/*
* 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.shardingsphere.metrics.prometheus.impl.counter
;
import
io.prometheus.client.Counter
;
import
org.apache.shardingsphere.metrics.api.CounterMetricsTracker
;
import
org.apache.shardingsphere.metrics.enums.MetricsLabelEnum
;
/**
* Sharding counter metrics tracker.
*/
public
final
class
ShardingCounterMetricsTracker
implements
CounterMetricsTracker
{
private
static
final
Counter
SHARDING
=
Counter
.
build
()
.
name
(
"sharding"
)
.
labelNames
(
"datasource"
,
"table"
)
.
help
(
"collect sharding datasource and table count"
)
.
register
();
@Override
public
void
inc
(
final
double
amount
,
final
String
...
labelValues
)
{
SHARDING
.
labels
(
labelValues
).
inc
(
amount
);
}
@Override
public
String
metricsLabel
()
{
return
MetricsLabelEnum
.
SHARDING
.
getName
();
}
}
sharding-metrics/sharding-metrics-prometheus/src/main/java/org/apache/shardingsphere/metrics/prometheus/impl/counter/TransactionCounterMetricsTracker.java
0 → 100644
浏览文件 @
2225e0e1
/*
* 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.shardingsphere.metrics.prometheus.impl.counter
;
import
io.prometheus.client.Counter
;
import
org.apache.shardingsphere.metrics.api.CounterMetricsTracker
;
import
org.apache.shardingsphere.metrics.enums.MetricsLabelEnum
;
/**
* Transaction counter metrics tracker.
*/
public
final
class
TransactionCounterMetricsTracker
implements
CounterMetricsTracker
{
private
static
final
Counter
TRANSACTION
=
Counter
.
build
()
.
name
(
"transaction"
)
.
labelNames
(
"status"
)
.
help
(
"collect sharding datasource and table count"
)
.
register
();
@Override
public
void
inc
(
final
double
amount
,
final
String
...
labelValues
)
{
TRANSACTION
.
labels
(
labelValues
).
inc
(
amount
);
}
@Override
public
String
metricsLabel
()
{
return
MetricsLabelEnum
.
TRANSACTION
.
getName
();
}
}
sharding-metrics/sharding-metrics-prometheus/src/test/java/org/apache/shardingsphere/metrics/prometheus/impl/counter/ShardingCounterMetricsTrackerTest.java
0 → 100644
浏览文件 @
2225e0e1
/*
* 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.shardingsphere.metrics.prometheus.impl.counter
;
import
org.apache.shardingsphere.metrics.enums.MetricsLabelEnum
;
import
org.apache.shardingsphere.metrics.enums.MetricsTypeEnum
;
import
org.apache.shardingsphere.metrics.prometheus.impl.AbstractPrometheusCollectorRegistry
;
import
org.junit.Test
;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
import
static
org
.
junit
.
Assert
.
assertThat
;
public
final
class
ShardingCounterMetricsTrackerTest
extends
AbstractPrometheusCollectorRegistry
{
@Test
public
void
assertShardingCounter
()
{
ShardingCounterMetricsTracker
tracker
=
new
ShardingCounterMetricsTracker
();
assertThat
(
tracker
.
metricsLabel
(),
is
(
MetricsLabelEnum
.
SHARDING
.
getName
()));
assertThat
(
tracker
.
metricsType
(),
is
(
MetricsTypeEnum
.
COUNTER
.
name
()));
String
name
=
"sharding"
;
String
[]
labelNames
=
{
"datasource"
,
"table"
};
String
[]
labelValues0
=
{
"ds0"
,
"t_order_0"
};
tracker
.
inc
(
1.0
,
labelValues0
);
Double
ds0
=
getCollectorRegistry
().
getSampleValue
(
name
,
labelNames
,
labelValues0
);
assertThat
(
ds0
,
is
(
1.0
));
String
[]
labelValues1
=
{
"ds1"
,
"t_order_1"
};
tracker
.
inc
(
2.0
,
labelValues1
);
Double
ds1
=
getCollectorRegistry
().
getSampleValue
(
name
,
labelNames
,
labelValues1
);
assertThat
(
ds1
,
is
(
2.0
));
}
@Test
(
expected
=
IllegalArgumentException
.
class
)
public
void
assertNoLabels
()
{
ShardingCounterMetricsTracker
tracker
=
new
ShardingCounterMetricsTracker
();
tracker
.
inc
(
1.0
);
}
@Test
(
expected
=
IllegalArgumentException
.
class
)
public
void
assertMoreLabels
()
{
ShardingCounterMetricsTracker
tracker
=
new
ShardingCounterMetricsTracker
();
tracker
.
inc
(
1.0
,
"ds0"
,
"t_order_0"
,
" t_order_1"
);
}
}
sharding-metrics/sharding-metrics-prometheus/src/test/java/org/apache/shardingsphere/metrics/prometheus/impl/counter/TransactionCounterMetricsTrackerTest.java
0 → 100644
浏览文件 @
2225e0e1
/*
* 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.shardingsphere.metrics.prometheus.impl.counter
;
import
org.apache.shardingsphere.metrics.enums.MetricsLabelEnum
;
import
org.apache.shardingsphere.metrics.enums.MetricsTypeEnum
;
import
org.apache.shardingsphere.metrics.prometheus.impl.AbstractPrometheusCollectorRegistry
;
import
org.junit.Test
;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
import
static
org
.
junit
.
Assert
.
assertThat
;
public
final
class
TransactionCounterMetricsTrackerTest
extends
AbstractPrometheusCollectorRegistry
{
@Test
public
void
assertShardingCounter
()
{
TransactionCounterMetricsTracker
tracker
=
new
TransactionCounterMetricsTracker
();
assertThat
(
tracker
.
metricsLabel
(),
is
(
MetricsLabelEnum
.
TRANSACTION
.
getName
()));
assertThat
(
tracker
.
metricsType
(),
is
(
MetricsTypeEnum
.
COUNTER
.
name
()));
String
name
=
"transaction"
;
String
[]
labelNames
=
{
"status"
};
String
[]
beginValues
=
{
"begin"
};
tracker
.
inc
(
1.0
,
beginValues
);
Double
beginValue
=
getValue
(
name
,
labelNames
,
beginValues
);
assertThat
(
beginValue
,
is
(
1.0
));
String
[]
commitValues
=
{
"commit"
};
tracker
.
inc
(
2.0
,
commitValues
);
Double
commitValue
=
getValue
(
name
,
labelNames
,
commitValues
);
assertThat
(
commitValue
,
is
(
2.0
));
String
[]
rollbackValues
=
{
"rollback"
};
tracker
.
inc
(
3.0
,
rollbackValues
);
Double
rollbackValue
=
getValue
(
name
,
labelNames
,
rollbackValues
);
assertThat
(
rollbackValue
,
is
(
3.0
));
}
@Test
(
expected
=
IllegalArgumentException
.
class
)
public
void
assertNoLabels
()
{
TransactionCounterMetricsTracker
tracker
=
new
TransactionCounterMetricsTracker
();
tracker
.
inc
(
1.0
);
}
@Test
(
expected
=
IllegalArgumentException
.
class
)
public
void
assertModeLabels
()
{
TransactionCounterMetricsTracker
tracker
=
new
TransactionCounterMetricsTracker
();
String
[]
labelValues
=
{
"begin"
,
"rollback"
};
tracker
.
inc
(
1.0
,
labelValues
);
}
private
Double
getValue
(
final
String
name
,
final
String
[]
labelNames
,
final
String
[]
labelValue
)
{
return
getCollectorRegistry
().
getSampleValue
(
name
,
labelNames
,
labelValue
);
}
}
sharding-metrics/sharding-metrics-spi/src/main/java/org/apache/shardingsphere/metrics/enums/MetricsLabelEnum.java
浏览文件 @
2225e0e1
...
...
@@ -45,7 +45,17 @@ public enum MetricsLabelEnum {
/**
* Request latency metrics label.
*/
REQUEST_LATENCY
(
"request_latency"
);
REQUEST_LATENCY
(
"request_latency"
),
/**
* Sharding metrics label.
*/
SHARDING
(
"sharding"
),
/**
* Transaction metrics label.
*/
TRANSACTION
(
"transaction"
);
private
final
String
name
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录