Closed amhuber closed 9 years ago
@amhuber, I determined a fix and will commit a change tomorrow to address.
@amhuber, please try commit https://github.com/cloudfoundry-incubator/admin-ui/commit/f18e2465f1fef38dd110cd684123611951c75582
Well, that did fix the error but it still doesn't seem to be working. Now it just says there are 0 events:
D, [2015-06-18T10:08:51.124115 #7192] DEBUG -- : [ -- ] : [ -- ] : [150 second interval] Starting view model events discovery...
D, [2015-06-18T10:08:51.124174 #7192] DEBUG -- : [ -- ] : [ -- ] : Caching view model events data. Compilation time: 1.5474e-05 seconds
D, [2015-06-18T10:08:51.199199 #7192] DEBUG -- : [ -- ] : [ -- ] : [300 second interval] Starting CC events discovery...
D, [2015-06-18T10:08:51.228147 #7192] DEBUG -- : [ -- ] : [ -- ] : Select for key events, table events: SELECT `actee`, `actee_name`, `actee_type`, `actor`, `actor_name`, `actor_type`, `created_at`, `guid`, `id`, `metadata`, `organization_guid`, `space_guid`, `space_id`, `timestamp`, `type`, `updated_at` FROM `events` WHERE "timestamp" >= CURRENT_TIMESTAMP - INTERVAL '7' DAY
D, [2015-06-18T10:08:51.228221 #7192] DEBUG -- : [ -- ] : [ -- ] : Columns removed for key events, table events: []
D, [2015-06-18T10:08:51.230138 #7192] DEBUG -- : [ -- ] : [ -- ] : Caching CC events data. Count: 0. Retrieval time: 0.030858964 seconds
D, [2015-06-18T10:09:01.148820 #7192] DEBUG -- : [ -- ] : [ -- ] : [150 second interval] Starting view model events discovery...
D, [2015-06-18T10:09:01.148918 #7192] DEBUG -- : [ -- ] : [ -- ] : Caching view model events data. Compilation time: 4.0182e-05 seconds
D, [2015-06-18T10:11:31.199176 #7192] DEBUG -- : [ -- ] : [ -- ] : [150 second interval] Starting view model events discovery...
D, [2015-06-18T10:11:31.199269 #7192] DEBUG -- : [ -- ] : [ -- ] : Caching view model events data. Compilation time: 4.9348e-05 seconds
D, [2015-06-18T10:13:51.540473 #7192] DEBUG -- : [ -- ] : [ -- ] : [300 second interval] Starting CC events discovery...
D, [2015-06-18T10:13:51.559106 #7192] DEBUG -- : [ -- ] : [ -- ] : Caching CC events data. Count: 0. Retrieval time: 0.018569781 seconds
D, [2015-06-18T10:14:01.234742 #7192] DEBUG -- : [ -- ] : [ -- ] : [150 second interval] Starting view model events discovery...
D, [2015-06-18T10:14:01.234840 #7192] DEBUG -- : [ -- ] : [ -- ] : Caching view model events data. Compilation time: 5.3178e-05 seconds
D, [2015-06-18T10:16:31.272851 #7192] DEBUG -- : [ -- ] : [ -- ] : [150 second interval] Starting view model events discovery...
D, [2015-06-18T10:16:31.272993 #7192] DEBUG -- : [ -- ] : [ -- ] : Caching view model events data. Compilation time: 5.3608e-05 seconds
I tested the query manually from the mysql client and I do get records:
mysql> set session sql_mode = 'ANSI';
Query OK, 0 rows affected (0.01 sec)
SELECT `actee`, `actee_name`, `actee_type`, `actor`, `actor_name`, `actor_type`, `created_at`, `guid`, `id`, `metadata`, `organization_guid`, `space_guid`, `space_id`, `timestamp`, `type`, `updated_at` FROM `events` WHERE "timestamp" >= CURRENT_TIMESTAMP - INTERVAL '7' DAY;
<data>
2178 rows in set (0.10 sec)
I'll poke through the code to see if I can find anything.
Aaron
Here is one row of data in case that helps:
mysql> SELECT `actee`, `actee_name`, `actee_type`, `actor`, `actor_name`, `actor_type`, `created_at`, `guid`, `id`, `metadata`, `organization_guid`, `space_guid`, `space_id`, `timestamp`, `type`, `updated_at` FROM `events` WHERE "timestamp" >= CURRENT_TIMESTAMP - INTERVAL '7' DAY LIMIT 1;
+--------------------------------------+-------------+------------+--------------------------------------+------------+------------+---------------------+--------------------------------------+----+-----------------------------------------------------------------------------------------------+--------------------------------------+--------------------------------------+----------+---------------------+--------------------+------------+
| actee | actee_name | actee_type | actor | actor_name | actor_type | created_at | guid | id | metadata | organization_guid | space_guid | space_id | timestamp | type | updated_at |
+--------------------------------------+-------------+------------+--------------------------------------+------------+------------+---------------------+--------------------------------------+----+-----------------------------------------------------------------------------------------------+--------------------------------------+--------------------------------------+----------+---------------------+--------------------+------------+
| 60e26603-661a-4957-8223-ece0d17a9e0c | Development | space | 032ec221-8eb3-4652-a021-7be438c2732e | admin | user | 2015-06-12 11:25:36 | 488c7e58-fda7-4464-9538-8bf683ce9a18 | 2 | {"request":{"name":"Development","organization_guid":"8a84b780-c82f-4968-8a79-62cfa389f85f"}} | 8a84b780-c82f-4968-8a79-62cfa389f85f | 60e26603-661a-4957-8223-ece0d17a9e0c | 2 | 2015-06-12 18:25:36 | audit.space.create | NULL |
+--------------------------------------+-------------+------------+--------------------------------------+------------+------------+---------------------+--------------------------------------+----+-----------------------------------------------------------------------------------------------+--------------------------------------+--------------------------------------+----------+---------------------+--------------------+------------+
1 row in set (0.00 sec)
Aaron
Just did some testing with the Sequel gem, looks like this is just due to the quoting around the field name in the where clause:
require 'sequel'
items = []
Sequel.connect('mysql2://<snip>') do |connection|
#Doesn't work
#connection.fetch("SELECT `actee`, `actee_name`, `actee_type`, `actor`, `actor_name`, `actor_type`, `created_at`, `guid`, `id`, `metadata`, `organization_guid`, `space_guid`, `space_id`, `timestamp`, `type`, `updated_at` FROM `events` WHERE \"timestamp\" >= CURRENT_TIMESTAMP - INTERVAL '1' DAY") do |row|
#Works
connection.fetch("SELECT `actee`, `actee_name`, `actee_type`, `actor`, `actor_name`, `actor_type`, `created_at`, `guid`, `id`, `metadata`, `organization_guid`, `space_guid`, `space_id`, `timestamp`, `type`, `updated_at` FROM `events` WHERE `timestamp` >= CURRENT_TIMESTAMP - INTERVAL '1' DAY") do |row|
items.push(row)
end
end
print items.count
I also tried a single quote and it didn't work either. It worked with either no quotes or with the back-tick character.
Bad:
\"timestamp\"
'timestamp'
Good:
`timestamp`
timestamp
Now hopefully you can find one that works for Postgres as well. :-)
Aaron
Just a final confirmation, everything works as expected when I used backticks in the code:
where: "`timestamp` >= CURRENT_TIMESTAMP - INTERVAL '#{@config.event_days}' DAY"
Log entry:
D, [2015-06-18T11:07:23.809563 #11193] DEBUG -- : [ -- ] : [ -- ] : Caching CC events data. Count: 2178. Retrieval time: 0.150513388 seconds
Page view looks good, etc.
Aaron
@amhuber, back tick does not work with Postgres. But, no quote around timestamp appears to work. I'll run through the rspec tests and do some more freelance testing to make sure.
Taking the back ticks out works fine on MySQL as well, just did a full test:
D, [2015-06-18T11:26:27.540424 #13120] DEBUG -- : [ -- ] : [ -- ] : Caching CC events data. Count: 2178. Retrieval time: 0.261141404 seconds
@amhuber, thanks for the legwork. Here is a commit to remove the quotes from around timestamp in the events predicate: https://github.com/cloudfoundry-incubator/admin-ui/commit/9802863167dadb22d294b37c1722f9467b8cb5fb
Confirmed working, thanks!
I'm getting the following error when moving to a newer version of AdminUI that pulls events:
It looks like the SQL syntax being generated is invalid for MySQL.
Aaron Huber Intel Corporation