Skip to content
This repository has been archived by the owner on Jul 4, 2024. It is now read-only.

Commit

Permalink
Use the correct unix timestamp format in requests (#1969)
Browse files Browse the repository at this point in the history
* Use the correct unix timestamp format in requests

* Update components version
  • Loading branch information
PetarTodorovv authored Jul 30, 2021
1 parent 7e6f92b commit db2d2d4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion chart/compass/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ global:
version: "PR-1956"
director:
dir:
version: "PR-1961"
version: "PR-1969"
gateway:
dir:
version: "PR-1956"
Expand Down
10 changes: 5 additions & 5 deletions components/director/internal/tenantfetcher/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func (s Service) SyncTenants() error {
if shouldFullResync {
log.C(ctx).Infof("Last full resync was %s ago. Will perform a full resync.", s.fullResyncInterval)
lastConsumedTenantTimestamp = "1"
newLastResyncTimestamp = convertTimeToUnixNanoString(startTime)
newLastResyncTimestamp = convertTimeToUnixMilliSecondString(startTime)
}

tenantsToCreate, err := s.getTenantsToCreate(lastConsumedTenantTimestamp)
Expand Down Expand Up @@ -200,7 +200,7 @@ func (s Service) SyncTenants() error {
if err = tx.Commit(); err != nil {
return err
}
if err = s.kubeClient.UpdateTenantFetcherConfigMapData(ctx, convertTimeToUnixNanoString(startTime), newLastResyncTimestamp); err != nil {
if err = s.kubeClient.UpdateTenantFetcherConfigMapData(ctx, convertTimeToUnixMilliSecondString(startTime), newLastResyncTimestamp); err != nil {
return err
}

Expand Down Expand Up @@ -523,10 +523,10 @@ func (s Service) shouldFullResync(lastFullResyncTimestamp string) (bool, error)
if err != nil {
return false, err
}
ts := time.Unix(0, i)
ts := time.Unix(i/1000, 0)
return time.Now().After(ts.Add(s.fullResyncInterval)), nil
}

func convertTimeToUnixNanoString(timestamp time.Time) string {
return strconv.FormatInt(timestamp.UnixNano(), 10)
func convertTimeToUnixMilliSecondString(timestamp time.Time) string {
return strconv.FormatInt(timestamp.UnixNano()/int64(time.Millisecond), 10)
}
4 changes: 3 additions & 1 deletion components/director/internal/tenantfetcher/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ func TestService_SyncTenants(t *testing.T) {
testErr := errors.New("test error")
txGen := txtest.NewTransactionContextGenerator(testErr)

tNowInMillis := strconv.FormatInt(time.Now().UnixNano()/int64(time.Millisecond), 10)

testCases := []struct {
Name string
TransactionerFn func() (*persistenceautomock.PersistenceTx, *persistenceautomock.Transactioner)
Expand Down Expand Up @@ -568,7 +570,7 @@ func TestService_SyncTenants(t *testing.T) {
},
KubeClientFn: func() *automock.KubeClient {
client := &automock.KubeClient{}
client.On("GetTenantFetcherConfigMapData", mock.Anything).Return("1", strconv.FormatInt(time.Now().UnixNano(), 10), nil).Once()
client.On("GetTenantFetcherConfigMapData", mock.Anything).Return("1", tNowInMillis, nil).Once()
client.On("UpdateTenantFetcherConfigMapData", mock.Anything, mock.Anything, mock.Anything).Return(nil).Once()
return client
},
Expand Down

0 comments on commit db2d2d4

Please sign in to comment.