mirror of
https://github.com/wahyd4/pinpoint.git
synced 2026-08-24 20:26:16 +10:00
Merge pull request #895 from minwoo-jung/issue-762
[#762] standardize the error message format when exception occured.
This commit is contained in:
@@ -45,91 +45,91 @@ import com.navercorp.pinpoint.web.alarm.vo.Rule;
|
||||
*/
|
||||
public enum CheckerCategory {
|
||||
|
||||
SLOW_COUNT("SLOW_COUNT", DataCollectorCategory.RESPONSE_TIME) {
|
||||
SLOW_COUNT("SLOW COUNT", DataCollectorCategory.RESPONSE_TIME) {
|
||||
@Override
|
||||
public AlarmChecker createChecker(DataCollector dataCollector, Rule rule) {
|
||||
return new SlowCountChecker((ResponseTimeDataCollector)dataCollector, rule);
|
||||
}
|
||||
},
|
||||
|
||||
SLOW_RATE("SLOW_RATE", DataCollectorCategory.RESPONSE_TIME) {
|
||||
SLOW_RATE("SLOW RATE", DataCollectorCategory.RESPONSE_TIME) {
|
||||
@Override
|
||||
public AlarmChecker createChecker(DataCollector dataCollector, Rule rule) {
|
||||
return new SlowRateChecker((ResponseTimeDataCollector)dataCollector, rule);
|
||||
}
|
||||
},
|
||||
|
||||
ERROR_COUNT("ERROR_COUNT", DataCollectorCategory.RESPONSE_TIME) {
|
||||
ERROR_COUNT("ERROR COUNT", DataCollectorCategory.RESPONSE_TIME) {
|
||||
@Override
|
||||
public AlarmChecker createChecker(DataCollector dataCollector, Rule rule) {
|
||||
return new ErrorCountChecker((ResponseTimeDataCollector)dataCollector, rule);
|
||||
}
|
||||
},
|
||||
|
||||
ERROR_RATE("ERROR_RATE", DataCollectorCategory.RESPONSE_TIME) {
|
||||
ERROR_RATE("ERROR RATE", DataCollectorCategory.RESPONSE_TIME) {
|
||||
@Override
|
||||
public AlarmChecker createChecker(DataCollector dataCollector, Rule rule) {
|
||||
return new ErrorRateChecker((ResponseTimeDataCollector)dataCollector, rule);
|
||||
}
|
||||
},
|
||||
|
||||
TOTAL_COUNT("TOTAL_COUNT", DataCollectorCategory.RESPONSE_TIME) {
|
||||
TOTAL_COUNT("TOTAL COUNT", DataCollectorCategory.RESPONSE_TIME) {
|
||||
@Override
|
||||
public AlarmChecker createChecker(DataCollector dataCollector, Rule rule) {
|
||||
return new ResponseCountChecker((ResponseTimeDataCollector)dataCollector, rule);
|
||||
}
|
||||
},
|
||||
|
||||
SLOW_COUNT_TO_CALLEE("SLOW_COUNT_TO_CALLEE", DataCollectorCategory.CALLER_STAT) {
|
||||
SLOW_COUNT_TO_CALLEE("SLOW COUNT TO CALLEE", DataCollectorCategory.CALLER_STAT) {
|
||||
@Override
|
||||
public AlarmChecker createChecker(DataCollector dataCollector, Rule rule) {
|
||||
return new SlowCountToCalleeChecker((MapStatisticsCallerDataCollector)dataCollector, rule);
|
||||
}
|
||||
},
|
||||
|
||||
SLOW_RATE_TO_CALLEE("SLOW_RATE_TO_CALLEE", DataCollectorCategory.CALLER_STAT) {
|
||||
SLOW_RATE_TO_CALLEE("SLOW RATE TO CALLEE", DataCollectorCategory.CALLER_STAT) {
|
||||
@Override
|
||||
public AlarmChecker createChecker(DataCollector dataCollector, Rule rule) {
|
||||
return new SlowRateToCalleeChecker((MapStatisticsCallerDataCollector)dataCollector, rule);
|
||||
}
|
||||
},
|
||||
|
||||
ERROR_COUNT_TO_CALLEE("ERROR_COUNT_TO_CALLEE", DataCollectorCategory.CALLER_STAT) {
|
||||
ERROR_COUNT_TO_CALLEE("ERROR COUNT TO CALLEE", DataCollectorCategory.CALLER_STAT) {
|
||||
@Override
|
||||
public AlarmChecker createChecker(DataCollector dataCollector, Rule rule) {
|
||||
return new ErrorCountToCalleeChecker((MapStatisticsCallerDataCollector)dataCollector, rule);
|
||||
}
|
||||
},
|
||||
|
||||
ERROR_RATE_TO_CALLEE("ERROR_RATE_TO_CALLEE", DataCollectorCategory.CALLER_STAT) {
|
||||
ERROR_RATE_TO_CALLEE("ERROR RATE TO CALLEE", DataCollectorCategory.CALLER_STAT) {
|
||||
@Override
|
||||
public AlarmChecker createChecker(DataCollector dataCollector, Rule rule) {
|
||||
return new ErrorRateToCalleeChecker((MapStatisticsCallerDataCollector)dataCollector, rule);
|
||||
}
|
||||
},
|
||||
|
||||
TOTAL_COUNT_TO_CALLEE("TOTAL_COUNT_TO_CALLEE", DataCollectorCategory.CALLER_STAT) {
|
||||
TOTAL_COUNT_TO_CALLEE("TOTAL COUNT TO CALLEE", DataCollectorCategory.CALLER_STAT) {
|
||||
@Override
|
||||
public AlarmChecker createChecker(DataCollector dataCollector, Rule rule) {
|
||||
return new TotalCountToCalleeChecker((MapStatisticsCallerDataCollector)dataCollector, rule);
|
||||
}
|
||||
},
|
||||
|
||||
HEAP_USAGE_RATE("HEAP_USAGE_RATE", DataCollectorCategory.AGENT_STAT) {
|
||||
HEAP_USAGE_RATE("HEAP USAGE RATE", DataCollectorCategory.AGENT_STAT) {
|
||||
@Override
|
||||
public AlarmChecker createChecker(DataCollector dataCollector, Rule rule) {
|
||||
return new HeapUsageRateChecker((AgentStatDataCollector)dataCollector, rule);
|
||||
}
|
||||
},
|
||||
|
||||
GC_COUNT("GC_COUNT", DataCollectorCategory.AGENT_STAT) {
|
||||
GC_COUNT("GC COUNT", DataCollectorCategory.AGENT_STAT) {
|
||||
@Override
|
||||
public AlarmChecker createChecker(DataCollector dataCollector, Rule rule) {
|
||||
return new GcCountChecker((AgentStatDataCollector)dataCollector, rule);
|
||||
}
|
||||
},
|
||||
|
||||
JVM_CPU_USAGE_RATE("JVM_CPU_USAGE_RATE", DataCollectorCategory.AGENT_STAT) {
|
||||
JVM_CPU_USAGE_RATE("JVM CPU USAGE RATE", DataCollectorCategory.AGENT_STAT) {
|
||||
@Override
|
||||
public AlarmChecker createChecker(DataCollector dataCollector, Rule rule) {
|
||||
return new JvmCpuUsageRateChecker((AgentStatDataCollector)dataCollector, rule);
|
||||
|
||||
@@ -20,9 +20,12 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
@@ -39,6 +42,8 @@ import com.navercorp.pinpoint.web.service.AlarmService;
|
||||
@Controller
|
||||
@RequestMapping(value="/alarmRule")
|
||||
public class AlarmController {
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
public final static String USER_GROUP_ID = "userGroupId";
|
||||
|
||||
@Autowired
|
||||
@@ -115,4 +120,15 @@ public class AlarmController {
|
||||
return CheckerCategory.getNames();
|
||||
}
|
||||
|
||||
@ExceptionHandler(Exception.class)
|
||||
@ResponseBody
|
||||
public Map<String, String> handleException(Exception e) {
|
||||
logger.error(" Exception occured while trying to CRUD Alarm Rule information", e);
|
||||
|
||||
Map<String, String> result = new HashMap<String, String>();
|
||||
result.put("errorCode", "500");
|
||||
result.put("errorMessage", "Exception occured while trying to Alarm Rule information");
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
@@ -125,5 +126,15 @@ public class UserController {
|
||||
return result;
|
||||
}
|
||||
|
||||
@ExceptionHandler(Exception.class)
|
||||
@ResponseBody
|
||||
public Map<String, String> handleException(Exception e) {
|
||||
logger.error(" Exception occured while trying to CRUD user information", e);
|
||||
|
||||
Map<String, String> result = new HashMap<String, String>();
|
||||
result.put("errorCode", "500");
|
||||
result.put("errorMessage", "Exception occured while trying to CRUD user information");
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,9 +19,12 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
@@ -39,6 +42,8 @@ import com.navercorp.pinpoint.web.vo.UserGroupMember;
|
||||
@RequestMapping(value = "/userGroup")
|
||||
public class UserGroupController {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
public static final String USER_GROUP_ID = "userGroupId";
|
||||
|
||||
@Autowired
|
||||
@@ -163,4 +168,15 @@ public class UserGroupController {
|
||||
// result.put("result", "SUCCESS");
|
||||
// return result;
|
||||
// }
|
||||
|
||||
@ExceptionHandler(Exception.class)
|
||||
@ResponseBody
|
||||
public Map<String, String> handleException(Exception e) {
|
||||
logger.error(" Exception occured while trying to CRUD userGroup information", e);
|
||||
|
||||
Map<String, String> result = new HashMap<String, String>();
|
||||
result.put("errorCode", "500");
|
||||
result.put("errorMessage", "Exception occured while trying to CRUD userGroup information");
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.navercorp.pinpoint.web.vo;
|
||||
|
||||
public class User {
|
||||
private String number;
|
||||
private String userId;
|
||||
private String name;
|
||||
private String department;
|
||||
@@ -18,6 +19,14 @@ public class User {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public String getNumber() {
|
||||
return number;
|
||||
}
|
||||
|
||||
public void setNumber(String number) {
|
||||
this.number = number;
|
||||
}
|
||||
|
||||
public String getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@ package com.navercorp.pinpoint.web.vo;
|
||||
|
||||
public class UserGroupMember {
|
||||
|
||||
private String number;
|
||||
|
||||
private String userGroupId;
|
||||
private String memberId;
|
||||
private String name;
|
||||
@@ -12,6 +14,15 @@ public class UserGroupMember {
|
||||
|
||||
public UserGroupMember(String userGroupId, String memberId) {
|
||||
this.userGroupId = userGroupId;
|
||||
this.memberId = memberId;
|
||||
}
|
||||
|
||||
public String getNumber() {
|
||||
return number;
|
||||
}
|
||||
|
||||
public void setNumber(String number) {
|
||||
this.number = number;
|
||||
}
|
||||
|
||||
public String getUserGroupId() {
|
||||
|
||||
@@ -5,12 +5,12 @@
|
||||
<mapper namespace="com.navercorp.pinpoint.web.dao.UserDao">
|
||||
|
||||
<insert id="insertUser" parameterType="User">
|
||||
INSERT INTO user
|
||||
INSERT INTO user (user_id, name, department, phonenumber, email)
|
||||
VALUES (#{userId}, #{name}, #{department}, #{phoneNumber}, #{email})
|
||||
</insert>
|
||||
|
||||
<insert id="insertUserList">
|
||||
INSERT INTO user
|
||||
INSERT INTO user (user_id, name, department, phonenumber, email)
|
||||
VALUES
|
||||
<foreach collection="list" item="User" separator=",">
|
||||
(#{User.userId}, #{User.name}, #{User.department}, #{User.phoneNumber}, #{User.email})
|
||||
|
||||
@@ -4,37 +4,41 @@ DROP TABLE user;
|
||||
DROP TABLE alarm_rule;
|
||||
|
||||
CREATE TABLE `user_group` (
|
||||
`number` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`number` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`id` VARCHAR(30) NOT NULL,
|
||||
PRIMARY KEY (`number`)
|
||||
);
|
||||
ALTER TABLE user_group ADD UNIQUE KEY id_idx (id);
|
||||
|
||||
CREATE TABLE `user_group_member` (
|
||||
`user_group_id` varchar(30) NOT NULL,
|
||||
`member_id` varchar(30) NOT NULL,
|
||||
PRIMARY KEY (`user_group_id`,`member_id`)
|
||||
`number` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`user_group_id` VARCHAR(30) NOT NULL,
|
||||
`member_id` VARCHAR(30) NOT NULL,
|
||||
PRIMARY KEY (`number`)
|
||||
);
|
||||
ALTER TABLE user_group_member ADD UNIQUE KEY user_group_id_member_id_idx (`user_group_id`,`member_id`);
|
||||
|
||||
CREATE TABLE `user` (
|
||||
`number` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`user_id` VARCHAR(30) NOT NULL,
|
||||
`name` VARCHAR(30) NOT NULL,
|
||||
`department` VARCHAR(100) NOT NULL,
|
||||
`phonenumber` VARCHAR(30) NOT NULL,
|
||||
`email` VARCHAR(30) NOT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
`name` VARCHAR(150) NOT NULL,
|
||||
`department` VARCHAR(150) NOT NULL,
|
||||
`phonenumber` VARCHAR(100),
|
||||
`email` VARCHAR(100),
|
||||
PRIMARY KEY (`number`)
|
||||
);
|
||||
ALTER TABLE USER ADD UNIQUE KEY user_id_idx (`user_id`);
|
||||
|
||||
CREATE TABLE `alarm_rule` (
|
||||
`rule_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`application_id` VARCHAR(30) NOT NULL,
|
||||
`service_type` VARCHAR(30) NOT NULL,
|
||||
`checker_name` VARCHAR(30) NOT NULL,
|
||||
`checker_name` VARCHAR(50) NOT NULL,
|
||||
`threshold` INT(10) DEFAULT NULL,
|
||||
`user_group_id` VARCHAR(30) NOT NULL,
|
||||
`sms_send` CHAR(1) DEFAULT NULL,
|
||||
`email_send` CHAR(1) DEFAULT NULL,
|
||||
`notes` VARCHAR(50) DEFAULT NULL,
|
||||
`notes` VARCHAR(100) DEFAULT NULL,
|
||||
PRIMARY KEY (`rule_id`)
|
||||
);
|
||||
ALTER TABLE alarm_rule ADD UNIQUE KEY application_id_checker_name_user_group_id_idx (application_id, user_group_id, checker_name);
|
||||
|
||||
@@ -161,12 +161,12 @@ public class UserControllerTest {
|
||||
this.mockMvc.perform(get("/user.pinpoint?userId=" + USER_ID).contentType(MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType("application/json;charset=UTF-8"))
|
||||
.andExpect(jsonPath("$", hasKey("userId")))
|
||||
.andExpect(jsonPath("$.userId").value(USER_ID))
|
||||
.andExpect(jsonPath("$", hasKey("name")))
|
||||
.andExpect(jsonPath("$", hasKey("department")))
|
||||
.andExpect(jsonPath("$", hasKey("phoneNumber")))
|
||||
.andExpect(jsonPath("$", hasKey("email")))
|
||||
.andExpect(jsonPath("$[0]", hasKey("userId")))
|
||||
.andExpect(jsonPath("$[0].userId").value(USER_ID))
|
||||
.andExpect(jsonPath("$[0]", hasKey("name")))
|
||||
.andExpect(jsonPath("$[0]", hasKey("department")))
|
||||
.andExpect(jsonPath("$[0]", hasKey("phoneNumber")))
|
||||
.andExpect(jsonPath("$[0]", hasKey("email")))
|
||||
.andReturn();
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user