Repository: pinpoint-apm/pinpoint
Issue: Error in logs when using alarms on Mysql
Labels: bug

#### Description
I got some error logs when using alarms:

```
Error MySQL com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'date_time' in 'field list' (alarm)
```

I found in IBatis mapper /web/target/deploy/WEB-INF/classes/mapper/AgentStaticsMapper.xml:

```
INSERT INTO agent_statistics (date_time, agent_count)
```

Whereas in web/src/main/resources/sql/CreateTableStatement-mysql.sql there is:
```
CREATE TABLE `agent_statistics` (
        `agent_count` INT(10) UNSIGNED NOT NULL,
        `date_val`DATETIME NOT NULL,
        PRIMARY KEY (`date_val`)
);
```

Which of date_val ou date_time is the right value ?

I hope to find the fix for this before the coming great 1.6.0 release !

#### Environment
* Pinpoint version: 1.6.0-SNAPSHOT (current master)
* Linux CentOS
* Using alarms batch job on mysql


Issue comments:
@gitzalm Thanks for the bug report!
@gitzalm  I fixed bad field name which related to AgentStatics. 
Thanks for the bug report! :)
Great, that was a quick fix.

Pull request review comments:

Patch that resolved the issue:
diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/AgentCountStatistics.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/AgentCountStatistics.java
index e4dcd6f6dba4..c10b085b08f6 100644
--- a/web/src/main/java/com/navercorp/pinpoint/web/vo/AgentCountStatistics.java
+++ b/web/src/main/java/com/navercorp/pinpoint/web/vo/AgentCountStatistics.java
@@ -56,11 +56,11 @@ public void setTimestamp(long timestamp) {
         this.timestamp = timestamp;
     }
 
-    public String getDateTime() {
+    public String getDateVal() {
         return DateUtils.longToDateStr(timestamp, DATE_TIME_FORMAT);
     }
 
-    public void setDateTime(String dateTime) throws ParseException {
+    public void setDateVal(String dateTime) throws ParseException {
         SimpleDateFormat format = new SimpleDateFormat(DATE_TIME_FORMAT);
         Date parsedDate = format.parse(dateTime);
 
diff --git a/web/src/main/resources/batch/applicationContext-batch-schedule.xml b/web/src/main/resources/batch/applicationContext-batch-schedule.xml
index d654595eb0c4..20ff94a9fcc7 100644
--- a/web/src/main/resources/batch/applicationContext-batch-schedule.xml
+++ b/web/src/main/resources/batch/applicationContext-batch-schedule.xml
@@ -13,14 +13,14 @@
 		http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
  	<task:scheduled-tasks scheduler="scheduler">
     	<task:scheduled ref="batchJobLauncher" method="alarmJob" cron="0 0/3 * * * *" />
-		<task:scheduled ref="batchJobLauncher" method="agentCountJob" cron="0 0 2 * * *" />
+        <task:scheduled ref="batchJobLauncher" method="agentCountJob" cron="0 0 2 * * *" />
 	</task:scheduled-tasks>
 	
 	<task:scheduler id="scheduler" pool-size="1"/>
     
     <import resource="classpath:batch/applicationContext-batch.xml" />
     <import resource="classpath:batch/applicationContext-alarmJob.xml" />
-	<import resource="classpath:batch/applicationContext-agentCountJob.xml" />
+    <import resource="classpath:batch/applicationContext-agentCountJob.xml" />
+
 
-    	
 </beans>
\ No newline at end of file
diff --git a/web/src/main/resources/mapper/AgentStaticsMapper.xml b/web/src/main/resources/mapper/AgentStaticsMapper.xml
index 670cb1359de8..09fc5cd593f3 100644
--- a/web/src/main/resources/mapper/AgentStaticsMapper.xml
+++ b/web/src/main/resources/mapper/AgentStaticsMapper.xml
@@ -4,12 +4,12 @@
 <mapper namespace="com.navercorp.pinpoint.web.dao.mysql.MysqlAgentStatisticsDao">
 
     <insert id="insertAgentCount" parameterType="AgentCountStatistics">
-        INSERT INTO agent_statistics (date_time, agent_count)
+        INSERT INTO agent_statistics (date_val, agent_count)
         VALUES
-        (#{dateTime}, #{agentCount})
+        (#{dateVal}, #{agentCount})
         ON DUPLICATE KEY UPDATE
         <trim suffixOverrides=",">
-            <if test="dateTime != null">date_time = #{dateTime},</if>
+            <if test="dateVal != null">date_val = #{dateVal},</if>
             <if test="agentCount != null">agent_count = #{agentCount},</if>
         </trim>
     </insert>
@@ -17,7 +17,7 @@
     <select id="selectAgentCount" parameterType="Range" resultType="AgentCountStatistics">
         SELECT *
         FROM agent_statistics
-        WHERE date_time
+        WHERE date_val
         BETWEEN #{fromDateTime} AND #{toDateTime}
     </select>
 
diff --git a/web/src/main/resources/sql/CreateTableStatement-mysql.sql b/web/src/main/resources/sql/CreateTableStatement-mysql.sql
index 9e6a520e946e..48e75eb2cc2f 100644
--- a/web/src/main/resources/sql/CreateTableStatement-mysql.sql
+++ b/web/src/main/resources/sql/CreateTableStatement-mysql.sql
@@ -55,7 +55,7 @@ CREATE TABLE `alarm_history` (
 ALTER TABLE alarm_history ADD UNIQUE KEY application_id_checker_name_idx (application_id, checker_name);
 
 CREATE TABLE `agent_statistics` (
-	`agent_count` INT(10) UNSIGNED NOT NULL,
-	`date_val`DATETIME NOT NULL,
-	PRIMARY KEY (`date_val`)
+  `agent_count` INT(10) UNSIGNED NOT NULL,
+  `date_val`DATETIME NOT NULL,
+  PRIMARY KEY (`date_val`)
 );


Test patch: