bcgov / ckanext-bcgov

BC Data Catalogue source code, main ckan extension
http://catalogue.data.gov.bc.ca
GNU Affero General Public License v3.0
24 stars 23 forks source link

Activity Stream times are not adjusted for GMT #147

Closed Mbrownshoes closed 8 years ago

Mbrownshoes commented 8 years ago

In the activity streams edits that have just been made are showing they were edited '7 hours ago'. I believe was due to the time being set to GMT, and Leo had fixed this with a patch in Cad -- but it looks like his changes have been overwritten by the most recent deploy.

Modify a record and view https://catalogue.data.gov.bc.ca/dataset/activity/[datasetname] to see an example.

gjlawran commented 8 years ago

Not fixed by Leo - wasn't fixed and reverted.

kfishwick commented 8 years ago

Please do some analysis, the calls should all be in UTC, we need more information on time correction for local or profile based time zone that occurs in the templates.

jrods commented 8 years ago

I was able to reproduce this in my local env. The problem stems from changing the /etc/sysconfig/clock to ZONE="America/Vancouver". In my env, it was set to ZONE="UTC"

kfishwick commented 8 years ago

@ll911 any chance we can change that parameter in cad? It seems like it might be actually a better setting anyways.

ll911 commented 8 years ago

@kfishwick Which parm?

kfishwick commented 8 years ago

Change the /etc/sysconfig/clock to ZONE="UTC"

ll911 commented 8 years ago

@kfishwick No, this is root manage system value, should not be changed and should match our current timezone /etc/sysconfig/clock however, I found another parm in ckan ckan.display_timezone default is UTC but it can be changed, after changed to America/Vancouver, it doubled the differences from 7hrs to 14hrs http://docs.ckan.org/en/ckan-2.5.2/maintaining/configuration.html https://cad.data.gov.bc.ca/dataset/activity/creating-geographic-dataset

ll911 commented 8 years ago

@kfishwick @jrods does this have correct time shift https://github.com/bcgov/ckanext-bcgov/blob/master/ckanext/bcgov/controllers/package.py convert timezone with pytz

python

from pytz import timezone fmt = "%Y-%m-%d %H:%M:%S %Z%z" now_utc = datetime.now(timezone('UTC')) print now_utc.strftime(fmt) 2016-08-24 23:20:48 UTC+0000 now_pacific = now_utc.astimezone(timezone('US/Pacific')) print now_pacific.strftime(fmt) 2016-08-24 16:20:48 PDT-0700

kfishwick commented 8 years ago

Is this related to https://github.com/ckan/ckan/issues/2882

ll911 commented 8 years ago

@kfishwick looks like a problem for a while

jrods commented 8 years ago

@ll911 are you also doing something like this on the server?

$ sudo mv /etc/localtime /etc/localtime.bak
$ sudo ln -s /usr/share/zoneinfo/Canada/Pacific /etc/localtime
ll911 commented 8 years ago

Nope, root managed system cannot be changed as they will be overwritten by HPAS patching cycle.

jrods commented 8 years ago

@ll911 ok, so just an overview so i can match my env, on the server, /etc/localtime is UTC, and /etc/sysconfig/clock is ZONE="America/Vancouver", correct?

Are those the only settings I need for time on the server? Is there any other changes I need to make for my env to match the server?

ll911 commented 8 years ago

@jrods you need to set both system clock and localtime with PST

zdump /etc/localtime
/etc/localtime  Thu Aug 25 13:31:40 2016 PDT
jrods commented 8 years ago

@ll911 ok, but how did you specifically changed /etc/localtime?

ll911 commented 8 years ago

@jrods link to

/usr/share/zoneinfo/Canada/Pacific
jrods commented 8 years ago

@ll911 what is the db's set timezone?

ll911 commented 8 years ago

Postgresql calls system time, which should be PST, but it can all set by application during the RUNTIME

https://www.postgresql.org/docs/9.1/static/sql-set.html

jrods commented 8 years ago

From my analysis, this looks to be a ckan core issue with many datetime.datetime.now() calls being use, since the server isn't using UTC, this causes the time difference.

ckan/ckan#2970 is pretty much the exact same problem.

I'll ask around to see if anybody is working on it for core.

kfishwick commented 8 years ago

Recommend deferring to the next release, this could be 2-3 days of work (if it affects more than just activity stream, and to coordinate the strategy for fixing it) and should be integrated into ckan core (and can likely be backported to 1.5 since it is a bug).

jrods commented 8 years ago

I've made PR for activity times above. Note that this does not fix activity times that already have a stored timestamp. I'm not sure on the approach to fixing that. I'm inclined to just leave old timestamps, as they don't seem like they're very crucial (but this isn't my call)

Mbrownshoes commented 8 years ago

Getting a server error on delivery when trying to access activity stream. logs show this related to the time. Error - <type 'exceptions.NameError'>: global name 'datatime_' is not defined [pid: 55356|app: 0|req: 288/288] 142.34.140.32 () {48 vars in 2481 bytes} [Fri Sep 9 11:41:11 2016] GET /dataset/activity/bc-wildfire-active-weather-stations => generated 30065 bytes in 497 msecs (HTTP/1.1 500) 3 headers in 125 bytes (1 switches on core 0) Fri Sep 9 11:41:11 2016 - uwsgi_response_write_body_do(): Broken pipe [core/writer.c line 419] during GET /fanstatic/vendor/:version:2016-09-09T09:47:02.16/select2/select2.css (142.34.140.32) IOError: write error

Mbrownshoes commented 8 years ago

Maybe we should push this back to 1.6 since so far it looks like this is the only hold up. Though it's already been merged (after we deployed to cat). Can we roll this change, which isn't working, back? https://github.com/bcgov/ckan/pull/5

jrods commented 8 years ago

whoops, typo, fixed here: https://github.com/bcgov/ckan/pull/7

Mbrownshoes commented 8 years ago

Don't think this deployed to cad, I think only merges to ckanext-bcgov auto deploy.

kfishwick commented 8 years ago

Getting internal server error when viewing Activity Stream in cad.

jrods commented 8 years ago

@ll911 will you please merge in the above PR and deploy ckan with those changes to delivery?

ll911 commented 8 years ago

done

kfishwick commented 8 years ago

Seems to work in CAD, assigning over to Matt for verification.