Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature : add TC exception log appender metric #5396

Merged
merged 8 commits into from
Mar 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/en-us/2.0.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ The version is updated as follows:
- [[#5165](https://github.com/seata/seata/pull/5165)] optimize TCC structure, supporting API access. add integration layer module(seata-integration-tx-api) for transaction process definition and proxy enhancement.
- [[#5352](https://github.com/seata/seata/pull/5352)] add jackson json parser and gson json parser for tcc business action context
- [[#5377](https://github.com/seata/seata/pull/5377)] make AbstractHttpExecutor.class support http put
- [[#5396](https://github.com/seata/seata/pull/5396)] TC log appender metric

### bugfix:
- [[#5194](https://github.com/seata/seata/pull/5194)] fix wrong keyword order for oracle when creating a table
Expand Down
1 change: 1 addition & 0 deletions changes/zh-cn/2.0.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Seata 是一款开源的分布式事务解决方案,提供高性能和简单
- [[#5165](https://github.com/seata/seata/pull/5165)] TCC结构拆分,支持API方式接入。增加集成层模块(seata-integration-tx-api),对事务流程定义以及代理部分增强。
- [[#5352](https://github.com/seata/seata/pull/5352)] 在TCC Business Action Context中集成jackson和gson序列化功能
- [[#5377](https://github.com/seata/seata/pull/5377)] 使AbstractHttpExecutor类支持PUT方式的请求
- [[#5396](https://github.com/seata/seata/pull/5396)] TC 异常日志指标采集

### bugfix:
- [[#5194](https://github.com/seata/seata/pull/5194)] 修复使用Oracle作为服务端DB存储时的建表失败问题
Expand Down
31 changes: 31 additions & 0 deletions core/src/main/java/io/seata/core/event/ExceptionEvent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright 1999-2019 Seata.io Group.
*
* 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.seata.core.event;

/**
* Event data for exception.
*
* @author Bughue
*/
public class ExceptionEvent implements Event {

private String name;

public ExceptionEvent(String code) {
this.name = code;
}

public String getName() {
return name;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
public interface IdConstants {
String SEATA_TRANSACTION = "seata.transaction";

String SEATA_EXCEPTION = "seata.exception";

String APP_ID_KEY = "applicationId";

String GROUP_KEY = "group";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright 1999-2019 Seata.io Group.
*
* 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.seata.server.logging.logback.appender;


import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.classic.spi.ThrowableProxy;
import ch.qos.logback.core.AppenderBase;
import ch.qos.logback.core.LogbackException;
import io.seata.core.event.EventBus;
import io.seata.core.event.ExceptionEvent;
import io.seata.server.event.EventBusManager;

/**
* The type metric logback appender
*
* @author Bughue
*/
public class MetricLogbackAppender extends AppenderBase<ILoggingEvent> {

private EventBus eventBus = EventBusManager.get();

@Override
protected void append(ILoggingEvent event) {
try {
Level level = event.getLevel();

if (level.isGreaterOrEqual(Level.ERROR)) {
ThrowableProxy info = (ThrowableProxy)event.getThrowableProxy();

if (info != null) {
Throwable throwable = info.getThrowable();
eventBus.post(new ExceptionEvent(throwable.getClass().getName()));
}
}
} catch (Exception ex) {
throw new LogbackException(event.getFormattedMessage(), ex);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,8 @@ public interface MeterIdConstants {
.withTag(IdConstants.METER_KEY, IdConstants.METER_VALUE_TIMER)
.withTag(IdConstants.STATUS_KEY, IdConstants.STATUS_VALUE_AFTER_COMMITTED_KEY);


Id SUMMARY_EXP = new Id(IdConstants.SEATA_EXCEPTION)
.withTag(IdConstants.ROLE_KEY, IdConstants.ROLE_VALUE_TC)
.withTag(IdConstants.METER_KEY, IdConstants.METER_VALUE_SUMMARY);
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.function.Consumer;

import com.google.common.eventbus.Subscribe;
import io.seata.core.event.ExceptionEvent;
import io.seata.core.event.GlobalTransactionEvent;
import io.seata.core.model.GlobalStatus;
import io.seata.metrics.registry.Registry;
Expand Down Expand Up @@ -200,6 +201,13 @@ public void recordGlobalTransactionEventForMetrics(GlobalTransactionEvent event)
}
}


@Subscribe
public void exceptionEventForMetrics(ExceptionEvent event) {
registry.getSummary(MeterIdConstants.SUMMARY_EXP
.withTag(APP_ID_KEY, event.getName())).increase(1);
}

@Override
public boolean equals(Object obj) {
return this.getClass().getName().equals(obj.getClass().getName());
Expand Down
6 changes: 6 additions & 0 deletions server/src/main/resources/logback-spring.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
<!-- kafka-appender: off by default -->
<!--<include resource="logback/kafka-appender.xml"/>-->

<!-- metric-appender: off by default -->
<!--<include resource="logback/metric-appender.xml"/>-->

<root level="INFO">
<!-- console-appender -->
<appender-ref ref="CONSOLE"/>
Expand All @@ -57,5 +60,8 @@

<!-- kafka-appender: off by default -->
<!--<appender-ref ref="KAFKA"/>-->

<!-- metric-appender: off by default -->
<!--<appender-ref ref="METRIC"/>-->
</root>
</configuration>
21 changes: 21 additions & 0 deletions server/src/main/resources/logback/metric-appender.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 1999-2019 Seata.io Group.
~
~ 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.
-->

<included>
<!-- metric-appender properties -->
<appender name="METRIC" class="io.seata.server.logging.logback.appender.MetricLogbackAppender"/>
</included>