Skip to content

Update session history - #523

Merged
interro merged 11 commits into
masterfrom
update-sessions-history
Nov 12, 2018
Merged

Update session history#523
interro merged 11 commits into
masterfrom
update-sessions-history

Conversation

@interro

@interro interro commented Nov 6, 2018

Copy link
Copy Markdown
Contributor

Closes #433

  • This is second PR, which finishes basic scope of having sessions history
  • First part of PR
  • Session history is updated on connection disconnect event
  • Changes in stored session format, now saving TimeStarted and TimeUpdated instead of Duration.
  • /sessions endpoint still returns Duration (TimeUpdated - TimeStarted)
  • Added session status

…ate-sessions-history

# Conflicts:
#	core/connection/session_storage.go
…ate-sessions-history

# Conflicts:
#	core/connection/manager_test.go
#	core/connection/session_storage.go
Comment thread tequilapi/endpoints/sessions.go Outdated
Duration: se.Duration,
BytesSent: uint64(se.DataStats.BytesSent),
BytesReceived: uint64(se.DataStats.BytesReceived),
Duration: getDuration(se.TimeStarted, se.TimeUpdated),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

move the getDuration method to connection.Session struct, that way you can just call se.GetDuration()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

moved

Comment thread core/connection/session_storage.go Outdated
func (repo *SessionStorage) Update(sessionID session.ID, TimeUpdated time.Time, dataStats stats.SessionStats) error {
// update two fields by sessionID
se := Session{SessionID: sessionID, Duration: duration, DataStats: dataStats}
se := Session{SessionID: sessionID, TimeUpdated: TimeUpdated, DataStats: dataStats}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we save session status - NEW, IN Progress, COMPLETED ? How can I tell which session is finished which is ongoing?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Is there a need for session status in history list? This can be added as feature later as we get feedback from using this endpoint

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

imho NEW and COMPLETED should be enough. New session will have TimeStarted set, completed session will have TimeUpdated set?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

added statuses New and Completed

Comment thread e2e/connection_test.go Outdated
@@ -127,6 +127,19 @@ func consumerConnectFlow(t *testing.T, tequilapi *tequilapi_client.Client, consu
assert.NoError(t, err)
seelog.Info("Shifted consumer IP: ", vpnIp)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
seelog.Info("Shifted consumer IP: ", vpnIp)
seelog.Info("Changed consumer IP: ", vpnIp)

}

// GetSessions returns all sessions from history
func (client *Client) GetSessions() (endpoints.SessionsDTO, error) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

sessions := endpoints.SessionsDTO{}
and using only sessions should be simpler.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

refactored

@zolia zolia left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

small issues

Comment thread core/connection/session.go Outdated
Duration int // in seconds
DataStats stats.SessionStats
Status SessionStatus
TimeUpdated time.Time // is updated on disconnect event

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If it updated on disconnect event, maybe we should call it Finished?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Later Session object can be updated during session. So I suggest to leave more generic name

Comment thread core/connection/session.go Outdated
ProviderID identity.Identity
ServiceType string
ProviderCountry string
TimeStarted time.Time

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe we can call it just Started and Finished, it has time time.Time no need Time word at the name of the field.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

removed word Time

Comment thread core/connection/session.go Outdated
// GetDuration returns delta in seconds (TimeUpdated - TimeStarted)
func (se *Session) GetDuration() uint64 {
if se.TimeUpdated.IsZero() {
return 0

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If a session is not finished, GetDuration can return time.Now() - se.TimeStarted instead of 0.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

If a session is not finished, that can mean a case where app crashes. So in that case time.Now() - se.TimeStarted will provide misleading result.
In current logic, in that case it will provide value 0.

Comment thread core/connection/session.go
Comment thread core/connection/session.go Outdated
}

// GetStatus converts status constant to string
func (se *Session) GetStatus() string {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think it should be String() method for the SessionStatus type.

Comment thread core/connection/session_storage.go Outdated
// update two fields by sessionID
se := Session{SessionID: sessionID, Duration: duration, DataStats: dataStats}
func (repo *SessionStorage) Update(sessionID session.ID, TimeUpdated time.Time, dataStats stats.SessionStats,
status SessionStatus) error {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

How does this formatted, why it splitted to 2 lines?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed

@interro
interro merged commit 4f481c4 into master Nov 12, 2018
@interro
interro deleted the update-sessions-history branch November 12, 2018 09:05
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.

5 participants