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

Modified refresh client to calculate the shortest token expiry #1190

Merged
merged 3 commits into from
Dec 9, 2021

Conversation

sol-0
Copy link
Contributor

@sol-0 sol-0 commented Dec 2, 2021

Signed-off-by: Oleg Solodkov oleg.solodkov@xored.com

Description

Refresh client calculates the shortest token expiry and sets refresh time according to that value

Issue link

Fixes #1189

How Has This Been Tested?

  • Added unit testing to cover
  • Tested manually
  • Tested by integration testing
  • Have not tested

Types of changes

  • Bug fix
  • New functionallity
  • Documentation
  • Refactoring
  • CI

@sol-0 sol-0 force-pushed the bugfix-1189 branch 2 times, most recently from a8be34c to 40a5de6 Compare December 3, 2021 07:42
Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com>
@sol-0 sol-0 marked this pull request as ready for review December 3, 2021 07:51
@sol-0 sol-0 self-assigned this Dec 3, 2021
@Mixaster995 Mixaster995 self-assigned this Dec 3, 2021
if err != nil {
return 0, errors.WithStack(err)
}
var minTimeout = time.Duration(math.MaxInt64)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
var minTimeout = time.Duration(math.MaxInt64)
var minTimeout time.Duration

Copy link
Contributor Author

@sol-0 sol-0 Dec 6, 2021

Choose a reason for hiding this comment

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

If we don't initialize minTimeout, it will always be 0. It's initialized with max possible duration so that it's always greater than any value.

Copy link
Member

Choose a reason for hiding this comment

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

Please fix the case when there no segments.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

timeout := clockTime.Until(expireTime)
log.FromContext(ctx).Infof("expiration after %s at %s", timeout.String(), expireTime.UTC())
timeout := clockTime.Until(expireTime)
log.FromContext(ctx).Infof("expiration after %s at %s", timeout.String(), expireTime.UTC())
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
log.FromContext(ctx).Infof("expiration after %s at %s", timeout.String(), expireTime.UTC())

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done


if timeout < minTimeout {
minTimeout = timeout
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
}
}
log.FromContext(ctx).Infof("expiration after %s at %s", timeout.String(), expireTime.UTC())
if timeout <= 0 {
return 1, nil
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment on lines 122 to 124
if timeout <= 0 {
return 1, nil
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if timeout <= 0 {
return 1, nil
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

return 0, errors.WithStack(err)
}
var minTimeout = time.Duration(math.MaxInt64)
for _, seg := range conn.GetPath().GetPathSegments() {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
for _, seg := range conn.GetPath().GetPathSegments() {
for _, segment := range conn.GetPath().GetPathSegments() {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment on lines 341 to 342
ExpectedRefreshTimeoutMax: 20*time.Minute + time.Second,
ExpectedRefreshTimeoutMin: 20*time.Minute - time.Second,
Copy link
Member

Choose a reason for hiding this comment

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

Please use const time range.

Suggested change
ExpectedRefreshTimeoutMax: 20*time.Minute + time.Second,
ExpectedRefreshTimeoutMin: 20*time.Minute - time.Second,
ExpectedRefreshTimeout: 20*time.Minute

Copy link
Member

@denis-tingaikin denis-tingaikin Dec 5, 2021

Choose a reason for hiding this comment

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

Apply this to other places.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment on lines 361 to 363
timeNow, err := time.Parse("2006-01-02 15:04:05", "2009-11-10 23:00:00")
require.NoError(t, err)

Copy link
Member

Choose a reason for hiding this comment

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

time.Date() is not returning error.

Suggested change
timeNow, err := time.Parse("2006-01-02 15:04:05", "2009-11-10 23:00:00")
require.NoError(t, err)
timeNow := time.Date(/*todo*/)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@denis-tingaikin
Copy link
Member

@edwarnicke We are thinking to solve #1189 with this PR.
Please have a look and share your thoughts.

sol-0 added 2 commits December 6, 2021 16:20
Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com>
Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com>
Copy link
Member

@denis-tingaikin denis-tingaikin left a comment

Choose a reason for hiding this comment

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

LGTM

@edwarnicke Could you have a look?

@edwarnicke edwarnicke merged commit 8e96470 into networkservicemesh:main Dec 9, 2021
nsmbot pushed a commit to networkservicemesh/sdk-kernel that referenced this pull request Dec 9, 2021
…k@main

PR link: networkservicemesh/sdk#1190

Commit: 8e96470
Author: Sol-0
Date: 2021-12-10 00:07:40 +0700
Message:
  - Modified refresh client to calculate the shortest token expiry (#1190)
* Modified refresh client to calculate the shortest token expiry

Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com>

* Addressed review comments

Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com>

* Addressed review comments

Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
nsmbot pushed a commit to networkservicemesh/cmd-nse-vfio that referenced this pull request Dec 9, 2021
…k@main

PR link: networkservicemesh/sdk#1190

Commit: 8e96470
Author: Sol-0
Date: 2021-12-10 00:07:40 +0700
Message:
  - Modified refresh client to calculate the shortest token expiry (#1190)
* Modified refresh client to calculate the shortest token expiry

Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com>

* Addressed review comments

Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com>

* Addressed review comments

Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
nsmbot pushed a commit to networkservicemesh/cmd-registry-memory that referenced this pull request Dec 9, 2021
…k@main

PR link: networkservicemesh/sdk#1190

Commit: 8e96470
Author: Sol-0
Date: 2021-12-10 00:07:40 +0700
Message:
  - Modified refresh client to calculate the shortest token expiry (#1190)
* Modified refresh client to calculate the shortest token expiry

Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com>

* Addressed review comments

Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com>

* Addressed review comments

Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
nsmbot pushed a commit to networkservicemesh/cmd-admission-webhook-k8s that referenced this pull request Dec 9, 2021
…k@main

PR link: networkservicemesh/sdk#1190

Commit: 8e96470
Author: Sol-0
Date: 2021-12-10 00:07:40 +0700
Message:
  - Modified refresh client to calculate the shortest token expiry (#1190)
* Modified refresh client to calculate the shortest token expiry

Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com>

* Addressed review comments

Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com>

* Addressed review comments

Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
nsmbot pushed a commit to networkservicemesh/cmd-registry-proxy-dns that referenced this pull request Dec 9, 2021
…k@main

PR link: networkservicemesh/sdk#1190

Commit: 8e96470
Author: Sol-0
Date: 2021-12-10 00:07:40 +0700
Message:
  - Modified refresh client to calculate the shortest token expiry (#1190)
* Modified refresh client to calculate the shortest token expiry

Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com>

* Addressed review comments

Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com>

* Addressed review comments

Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
nsmbot pushed a commit to networkservicemesh/sdk-k8s that referenced this pull request Dec 9, 2021
…k@main

PR link: networkservicemesh/sdk#1190

Commit: 8e96470
Author: Sol-0
Date: 2021-12-10 00:07:40 +0700
Message:
  - Modified refresh client to calculate the shortest token expiry (#1190)
* Modified refresh client to calculate the shortest token expiry

Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com>

* Addressed review comments

Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com>

* Addressed review comments

Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
nsmbot pushed a commit to networkservicemesh/cmd-nsmgr-proxy that referenced this pull request Dec 9, 2021
…k@main

PR link: networkservicemesh/sdk#1190

Commit: 8e96470
Author: Sol-0
Date: 2021-12-10 00:07:40 +0700
Message:
  - Modified refresh client to calculate the shortest token expiry (#1190)
* Modified refresh client to calculate the shortest token expiry

Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com>

* Addressed review comments

Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com>

* Addressed review comments

Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
nsmbot pushed a commit to networkservicemesh/cmd-nsc-init that referenced this pull request Dec 9, 2021
…k@main

PR link: networkservicemesh/sdk#1190

Commit: 8e96470
Author: Sol-0
Date: 2021-12-10 00:07:40 +0700
Message:
  - Modified refresh client to calculate the shortest token expiry (#1190)
* Modified refresh client to calculate the shortest token expiry

Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com>

* Addressed review comments

Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com>

* Addressed review comments

Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
nsmbot pushed a commit to networkservicemesh/cmd-nsmgr that referenced this pull request Dec 9, 2021
…k@main

PR link: networkservicemesh/sdk#1190

Commit: 8e96470
Author: Sol-0
Date: 2021-12-10 00:07:40 +0700
Message:
  - Modified refresh client to calculate the shortest token expiry (#1190)
* Modified refresh client to calculate the shortest token expiry

Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com>

* Addressed review comments

Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com>

* Addressed review comments

Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
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.

Refresh client should calculate the shortest token expiry time
4 participants