Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CHE-274 - Improve idling implementation #5512

Merged
merged 15 commits into from
Jul 12, 2017
Merged

CHE-274 - Improve idling implementation #5512

merged 15 commits into from
Jul 12, 2017

Conversation

mkuznyetsov
Copy link
Contributor

@mkuznyetsov mkuznyetsov commented Jul 3, 2017

What does this PR do?

Enable workspace shutdown after a specified inactivity period.

What issues does this PR fix or reference?

This is a copy of PR #5386 with minor fixes

https://issues.jboss.org/browse/CHE-274

Changelog

Added workspace idling tracking, that will shutdown workspaces, which are inactive over a period of time, configured by "che.machine.ws.agent.inactive.stop.timeout.ms" property. Tracking is scheduled to perform in intervals, defined by "stop.workspace.scheduler.period" property.

Release Notes

Per default, a workspace will be stopped after one hour of inactivity.

Docs PR

eclipse-che/che-docs#253

See #5386

@codenvy-ci
Copy link

@mkuznyetsov mkuznyetsov changed the title Che 274a CHE-274 - Improve idling implementation Jul 3, 2017
Copy link
Contributor

@benoitf benoitf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose there is a pending PR on codenvy repository as well ?

@benoitf
Copy link
Contributor

benoitf commented Jul 3, 2017

linked to codenvy/codenvy#2297

@benoitf benoitf added kind/enhancement A feature request - must adhere to the feature request template. status/code-review This issue has a pull request posted for it and is awaiting code review completion by the community. labels Jul 3, 2017
@benoitf
Copy link
Contributor

benoitf commented Jul 3, 2017

@slemeur I think there is some doc required

@benoitf benoitf requested a review from slemeur July 3, 2017 07:55
@mkuznyetsov mkuznyetsov requested a review from benoitf July 3, 2017 08:01
@slemeur
Copy link
Contributor

slemeur commented Jul 3, 2017

added eclipse-che/che-docs#253

# Idle Timeout
# The system will suspend the workspace and snapshot it if the end user is idle for
# this length of time. Idleness is determined by the length of time that a user has
# not interacted with the workspace, meaning that one of our agents has not received

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One of the agents or any?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed this part

@@ -115,6 +115,14 @@ che.workspace.agent.dev.ping_timeout_error_msg=Timeout. The Che server is unable
che.agent.dev.max_start_time_ms=120000
che.agent.dev.ping_delay_ms=2000

# Idle Timeout
# The system will suspend the workspace and snapshot it if the end user is idle for
# this length of time. Idleness is determined by the length of time that a user has

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather use amount of time instead of length of time

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thx, fixed

# not interacted with the workspace, meaning that one of our agents has not received
# instructions. Leaving a browser window open counts as idleness time.
che.machine.ws.agent.inactive.stop.timeout.ms=3600000
stop.workspace.scheduler.period=60

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please prepend property name with che. and add measurement unit as a suffix of the property.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed property name

# this length of time. Idleness is determined by the length of time that a user has
# not interacted with the workspace, meaning that one of our agents has not received
# instructions. Leaving a browser window open counts as idleness time.
che.machine.ws.agent.inactive.stop.timeout.ms=3600000

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Part of a term that means single area are usually divided by underscores, e.g. che.machine.wsagent.inactive_stop_timeout_ms

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed property name

import java.io.IOException;

/**
* Counts every request to the agent as a workspace activity

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it count frames in case of WebSocket connection or only connection itself?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would only react on HTTP requests going through the filter, updated Javadoc

* @author Mihail Kuznyetsov
*/
@Singleton
public class LastAccessTimeFilter implements Filter {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this class is related to wsagent let's move it to wsagent related module

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to a separate module

* @author Mihail Kuznyetsov
*/
@Singleton
public class LastAccessTimeFilter implements Filter {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add tests

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added tests

Copy link

@garagatyi garagatyi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly OK, but, please, add tests and take a look on my comments

import java.util.concurrent.atomic.AtomicBoolean;

/**
* Notifies master about activity in workspace, but not more often than once per minute.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, correct javadocs as actual notification threshold is configurable now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Javadoc updated

* @author Anton Korneta
*/
@Singleton
public class WorkspaceActivityNotifier {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this class is related to wsagent let's move it to wsagent related module

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to separate module

import com.google.inject.Inject;

/**
* Stops the inactive workspaces by given expiration time.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I can see this class not only stops workspaces but provides API for updating workspace activity timestamp. Can you rephrase javadocs in accordance with that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Javadoc updated

workspaceManager.updateWorkspace(workspaceId, workspace);
workspaceManager.stopWorkspace(workspaceId);
} catch (NotFoundException e) {
LOG.info("Workspace already stopped");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please ignore this exception - there is no need to log it

@codenvy-ci
Copy link

import com.google.inject.Inject;

/**
* Stops the inactive workspaces by given expiration time. Upon stopping, workspace attributes will be updated with

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It also provides API for WS activity timestamp updates

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrected

import static org.eclipse.che.api.core.model.workspace.WorkspaceStatus.RUNNING;

/**
* Monitors the activity of the runtime workspace.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't monitor activity itself, but rather provides API for WS activity timestamp updates

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrected

}

@Test
public void shouldLogExceptionUponActivityNotification() throws IOException, ServletException {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test doesn't check logging - it ensures that an exception that can be thrown by activity call doesn't prevent the call of the chain. So, please, rename test and verify the call of the chain.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed name

// when
filter.doFilter(request, response, chain);
// then
verify(workspaceActivityNotifier).onActivity();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, also verify the call of the chain.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@ApiResponses(@ApiResponse(code = 204, message = "Activity counted"))
public void active(@ApiParam(value = "Workspace id")
@PathParam("wsId") String wsId) throws ForbiddenException, NotFoundException, ServerException {
final WorkspaceImpl workspace = workspaceManager.getWorkspace(wsId);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, add tests

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added WorkspaceActivityServiceTest



@Inject
public WorkspaceActivityNotifier(HttpJsonRequestFactory httpJsonRequestFactory,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, add tests

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added WorkspaceActivityNotifierTest

* @author Mihail Kuznyetsov
* @author Anton Korneta
*/
public class WorkspaceWebsocketMessageReceiver implements WSMessageReceiver {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, add tests

* @author Anton Korneta
*/
@Singleton
public class WorkspaceActivityManager {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, add tests

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added WorkspaceActivityManagerTest

@garagatyi garagatyi removed the request for review from skabashnyuk July 11, 2017 13:38
@codenvy-ci
Copy link

Build # 3037 - FAILED

Please check console output at https://ci.codenvycorp.com/job/che-pullrequests-build/3037/ to view the results.

@codenvy-ci
Copy link

Build # 3044 - FAILED

Please check console output at https://ci.codenvycorp.com/job/che-pullrequests-build/3044/ to view the results.

@codenvy-ci
Copy link

@codenvy-ci
Copy link

@mkuznyetsov mkuznyetsov merged commit 0be04a6 into master Jul 12, 2017
@mkuznyetsov mkuznyetsov deleted the che-274a branch July 12, 2017 15:35
@codenvy-ci
Copy link

JPinkney pushed a commit to JPinkney/che that referenced this pull request Aug 17, 2017
* CHE-274 - Improve idling implementation

Signed-off-by: Snjezana Peco <snjezana.peco@redhat.com>

* CHE-274 - Improve idling implementation

* fixup! CHE-274 - Improve idling implementation

* fixup! fixup! CHE-274 - Improve idling implementation

* fixup! fixup! fixup! CHE-274 - Improve idling implementation

* fixup! fixup! fixup! fixup! CHE-274 - Improve idling implementation

* fixup! fixup! fixup! fixup! fixup! CHE-274 - Improve idling implementation

* fixup! fixup! fixup! fixup! fixup! fixup! CHE-274 - Improve idling implementation

* fixup! fixup! fixup! fixup! fixup! fixup! fixup! CHE-274 - Improve idling implementation

* fixup! fixup! fixup! fixup! fixup! fixup! fixup! fixup! CHE-274 - Improve idling implementation

* fixup! fixup! fixup! fixup! fixup! fixup! fixup! fixup! fixup! CHE-274 - Improve idling implementation

* fixup
@benoitf benoitf removed the status/code-review This issue has a pull request posted for it and is awaiting code review completion by the community. label Nov 2, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement A feature request - must adhere to the feature request template.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants