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

SAK-50846 Sitestats successive sitestats calculated incorrectly #13230

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

st-manu
Copy link
Contributor

@st-manu st-manu commented Jan 23, 2025

https://sakaiproject.atlassian.net/browse/SAK-50846

Conversion: sakaiproject/sakai-reference#263

If a user is connected when the SiteStats Event Aggregator job is run, the user's previously closed session is merged with the active session.

real time presence
x-----x | x-------|----x
calculation
x--------------------------x

@@ -54,6 +58,7 @@ public boolean add(@NonNull Presence presence) {

if (records.contains(additialRecord)) {
// Record is already present in list, leave unchanged
log.debug("Record already present: " + additialRecord);
Copy link
Contributor

Choose a reason for hiding this comment

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

"Concatenation is expensive, so you want it to happen only when needed. By using {}, slf4j performs the concatenation only if the trace is needed. In production, you may configure the log level to INFO, thus ignoring all debug traces."

Copy link
Contributor

Choose a reason for hiding this comment

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

Good point Sam! Most of the time debug is disabled.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I took the opportunity to update the rest of the concatenations in the log.debug statements of the modified files.

Copy link
Contributor

@ottenhoff ottenhoff left a comment

Choose a reason for hiding this comment

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

this passes the tests locally for me.

just need to fix lombok, slf4j log concatenation.

thanks for the patch

public void setOriginallyEnding(boolean originallyEnding) {
this.originallyEnding = originallyEnding;
}

Copy link
Contributor

Choose a reason for hiding this comment

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

the use of lombok @Data means these getters and setters are unnecessary

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, you can remove the getters, setters. I would change to Boolean. Though, you will need to replace the use of isOriginallyEnding with `getOriginallyEnding.

Copy link
Contributor

@stetsche stetsche left a comment

Choose a reason for hiding this comment

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

Great work Manu! I left some comments for minor improvements.


import lombok.NonNull;

public class PresenceConsolidation {


private static final Logger log = LoggerFactory.getLogger(PresenceConsolidation.class);
Copy link
Contributor

Choose a reason for hiding this comment

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

Use @Slf4j instead


log.debug("currentOpenSessions: {}", currentOpenSessions);

if (!allUserSitePresences.isEmpty() && allUserSitePresences.get(0).isBeginning() && savedOpenSessions == 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it safe to look just at the first entry, should we check if there is any beginning presence?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

actually, that check isn't necessary; I removed it. if there were no open sessions (savedOpenSessions == 0), with the current logic, we can disregard the saved login start (savedBegin) since we are no longer dealing with overlapping sessions.

@@ -1669,7 +1735,9 @@ private String parseSiteId(Event e){
if(contextId != null && contextId.startsWith(sitePrefix)) {
contextId = contextId.substring(sitePrefix.length());
}
log.debug("Context read from Event.getContext() for event: " + eventId + " - context: " + contextId);
if (eventId == "pres.end" || eventId == "pres.begin") {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we keep this condition or was it just for your testing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

exactly, I removed the condition, thnks

@@ -54,6 +58,7 @@ public boolean add(@NonNull Presence presence) {

if (records.contains(additialRecord)) {
// Record is already present in list, leave unchanged
log.debug("Record already present: " + additialRecord);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
log.debug("Record already present: " + additialRecord);
log.debug("Record already present: {}", additialRecord);

Copy link
Contributor

Choose a reason for hiding this comment

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

Here an example. Please apply this to the other debug logs as well @st-manu

@@ -54,6 +58,7 @@ public boolean add(@NonNull Presence presence) {

if (records.contains(additialRecord)) {
// Record is already present in list, leave unchanged
log.debug("Record already present: " + additialRecord);
Copy link
Contributor

Choose a reason for hiding this comment

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

Good point Sam! Most of the time debug is disabled.

public void setOriginallyEnding(boolean originallyEnding) {
this.originallyEnding = originallyEnding;
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, you can remove the getters, setters. I would change to Boolean. Though, you will need to replace the use of isOriginallyEnding with `getOriginallyEnding.

@stetsche
Copy link
Contributor

Please also do a rebase on master

@st-manu st-manu force-pushed the SAK-50846-fix branch 2 times, most recently from e762754 to 3c8fb8d Compare January 27, 2025 10:30
@st-manu
Copy link
Contributor Author

st-manu commented Jan 27, 2025

thank you for your comments, @stetsche and @ottenhoff !

Copy link
Contributor

@stetsche stetsche left a comment

Choose a reason for hiding this comment

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

Just found a little error. Else looking good

@@ -1669,9 +1735,9 @@ private String parseSiteId(Event e){
if(contextId != null && contextId.startsWith(sitePrefix)) {
contextId = contextId.substring(sitePrefix.length());
}
log.debug("Context read from Event.getContext() for event: " + eventId + " - context: " + contextId);
log.debug("Context read from Event.getContext() for event: {} - context: ", eventId, contextId);
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing placeholder

Suggested change
log.debug("Context read from Event.getContext() for event: {} - context: ", eventId, contextId);
log.debug("Context read from Event.getContext() for event: {} - context: {}", eventId, contextId);

Comment on lines 1458 to 1460
log.debug("k{} savedBegin: {}", key, savedBegin);
log.debug("k{} firstBeginningPresenceBegin: {}", key, firstBeginningPresenceBegin);
log.debug("k{} lastStart: {}", key, lastStart);
Copy link
Contributor

Choose a reason for hiding this comment

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

these debug statements should probably be consolidated

@ern ern changed the title SAK-50846 Sitestats: Successive sitestats calculated incorrectly SAK-50846 Sitestats successive sitestats calculated incorrectly Jan 28, 2025
@st-manu
Copy link
Contributor Author

st-manu commented Jan 28, 2025

@ern @stetsche changes applied ✅

Copy link
Contributor

@stetsche stetsche left a comment

Choose a reason for hiding this comment

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

Looking good, thanks @st-manu! Could you do a rebase to be current with master please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants