Files
teleport/integration/time_sync_test.go
T
Vadym Popov af6a6ea734 Add monitoring of the servers time drifting (#44489)
* Add monitoring of the servers time drifting

* Refactor monitor to use inventory stream

* Add command for inventory control stream for time reconciliation

* Reuse ping/pong logic for time reconciliation

* Add integration test to check if global notification is created

* Limits notification length, renaming

* Return system clock instead of time difference
Add parallel requests to ping the nodes
Fix issue with locking inventory store while making ping request

* Refactor to make time reconciliation part of the inventory control stream

* Fix tests

* Rewrite tests
Return inventory store iterator

* Naming adjustments

* Fix test

* Drop timeReconciliation in order to use direct handler functions

* Make time reconciliation with variable duration

* Replace with duration type in proto
Add test cleanup for possible goroutine leak
Add comment about half request duration

* Format notification message

* Add UpstreamInventoryPong.SystemClock check
2024-11-28 21:18:24 +00:00

76 lines
2.4 KiB
Go

/*
* Teleport
* Copyright (C) 2024 Gravitational, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package integration
import (
"context"
"testing"
"time"
"github.com/gravitational/trace"
"github.com/jonboulle/clockwork"
"github.com/stretchr/testify/require"
"github.com/gravitational/teleport/api/utils/retryutils"
"github.com/gravitational/teleport/integration/helpers"
"github.com/gravitational/teleport/lib"
"github.com/gravitational/teleport/lib/service/servicecfg"
)
// TestTimeReconciliation launches two instances with clock differences in system clock,
// to verify that global notification is created about time drifting.
func TestTimeReconciliation(t *testing.T) {
lib.SetInsecureDevMode(true)
defer lib.SetInsecureDevMode(false)
helpers.SetTestTimeouts(2 * time.Second)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
// Start Teleport Auth and Proxy services
authProcess, proxyProcess, provisionToken := helpers.MakeTestServers(t)
authService := authProcess.GetAuthServer()
proxyAddr, err := proxyProcess.ProxyWebAddr()
require.NoError(t, err)
cfg := servicecfg.MakeDefaultConfig()
agentClock := clockwork.NewFakeClockAt(time.Now().Add(24 * time.Hour))
cfg.Clock = agentClock
agent := helpers.MakeAgentServer(t, cfg, *proxyAddr, provisionToken)
require.NotNil(t, agent)
err = retryutils.RetryStaticFor(30*time.Second, time.Second, func() error {
agentClock.Advance(time.Minute)
notifications, _, err := authService.ListGlobalNotifications(ctx, 100, "")
if err != nil {
return trace.Wrap(err)
}
var found bool
for _, notification := range notifications {
found = found || notification.GetMetadata().GetName() == "cluster-monitor-system-clock-warning"
}
if !found {
return trace.BadParameter("expected notification is not found")
}
return nil
})
require.NoError(t, err)
}