Bug 1011459

Summary: [origin_runtime_232] oo-last-access does not process node-web-proxy/websockets.log
Product: OpenShift Online Reporter: chunchen <chunchen>
Component: ContainersAssignee: Jhon Honce <jhonce>
Status: CLOSED CURRENTRELEASE QA Contact: libra bugs <libra-bugs>
Severity: medium Docs Contact:
Priority: medium    
Version: 2.xCC: wsun
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2013-10-17 13:31:02 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:

Description chunchen 2013-09-24 10:43:00 UTC
Description of problem:
The app is auto idled even if having websocket access during auto idle interval time.

Version-Release number of selected component (if applicable):
devenv_3817

How reproducible:
always

Steps to Reproduce:
1. Create a nodejs app
rhc app create cndjs nodejs-0.6
2. Replace server.js to support web sockets as belows:
     
    var host = process.env.OPENSHIFT_NODEJS_IP;
    var port = process.env.OPENSHIFT_NODEJS_PORT || 8080;
     
    var WebSocketServer = require('ws').Server,
        wss = new WebSocketServer({host: host, port: port});
        wss.on('connection', function(ws) {
          ws.on('message', function(message) {
            console.log('received: %s', message);
          });
          ws.send('something');
        });

3. Add dependency to package.json:
    :
    .
      "dependencies": {
        "ws" : ">0.4.30"
      },

4. Push the changes
5. SSH into instance and idle this app
oo-admin-ctl-gears idlegear UUID
6. Access this app via websocket and type words like "hello"
wscat -c wss://cndjs-cdm.dev.rhcloud.com:8443/ -p 8
or 
wscat -c ws://cndjs-cdm.dev.rhcloud.com:8000/ -p 8 (maybe need execute it on instance)
7. Check the state of this app
rhc app show -a cndjs --state
8. Wait some minutes and within 1 hour, then repeat Step 5-6
9. Do auto idle when time is more than 1 hour from Step 6 and less than 1 hour from Step 8
oo-auto-idler idle  --interval 1
10. Show the app status
rhc app show -a cndjs --state

Actual results:
at step 8: Cartridge nodejs-0.6 is started
at step 10: Cartridge nodejs-0.6 is idle

Expected results:
The app should not be auto idled when having websocket access during auto idle interval time

Additional info:

Comment 1 Jhon Honce 2013-09-24 19:01:11 UTC
Note: if wscat is run from the same machine as oo-last-access, the gear will not remain unidled.  The Idler code special cases access from the local machine.

Fixed in https://github.com/openshift/origin-server/pull/3695

Comment 2 openshift-github-bot 2013-09-24 22:31:16 UTC
Commit pushed to master at https://github.com/openshift/origin-server

https://github.com/openshift/origin-server/commit/d057f48981710863635ffb6064dc17643d8d0394
Bug 1011459 - oo-last-access does not process node-web-proxy/websockets.log

* Use access.log format for websockets.log
* Add websockets.log processing to oo-last-access

Comment 3 chunchen 2013-09-25 08:37:00 UTC
It is reproduced, checked this issue on devenv_3824. I found the /var/lib/openshift/.last_access/<UUID> does not be updated the time record after run oo-last-access, but the access records via websocket can be recorded in /var/log/node-web-proxy/websockets.log.

Comment 4 Jhon Honce 2013-09-25 16:12:21 UTC
Verified it works as I expect in devenv_3826.

Please include your steps to reproduce. I remind you wscat cannot be run on the same machine as the node as oo-last-access ignores the localhost.

Comment 5 chunchen 2013-09-26 01:56:12 UTC
It's fixed, verified on devenv_3829, please refer to the following results:

1. Create a nodejs app
rhc app create cndjs nodejs-0.6
2. Replace server.js to support web sockets as belows:
     
    var host = process.env.OPENSHIFT_NODEJS_IP;
    var port = process.env.OPENSHIFT_NODEJS_PORT || 8080;
     
    var WebSocketServer = require('ws').Server,
        wss = new WebSocketServer({host: host, port: port});
        wss.on('connection', function(ws) {
          ws.on('message', function(message) {
            console.log('received: %s', message);
          });
          ws.send('something');
        });

3. Add dependency to package.json:
    :
    .
      "dependencies": {
        "ws" : ">0.4.30"
      },

4. Push the changes
5. SSH into instance and idle this app
oo-admin-ctl-gears idlegear UUID
6. Access this app via websocket and type words like "hello"
wscat -c wss://cndjs-cdm.dev.rhcloud.com:8443/ -p 8 (on my work PC)
7. SSH into this instance and gather the accessing record
oo-last-access
8. Check the state of this app
rhc app show -a cndjs --state
9. Do auto idle when time is  less than 1 hour from Step 6
oo-auto-idler idle  --interval 1
10. Show the app status
rhc app show -a cndjs --state

at step 9:
Gears idle for 1 hours
at step 10:
Cartridge nodejs-0.6 is started