@@ -13,6 +13,7 @@ import (
13
13
"time"
14
14
15
15
"github.com/coder/coder/v2/coderd/appearance"
16
+ "github.com/coder/coder/v2/coderd/database"
16
17
agplportsharing "github.com/coder/coder/v2/coderd/portsharing"
17
18
"github.com/coder/coder/v2/enterprise/coderd/portsharing"
18
19
@@ -27,6 +28,7 @@ import (
27
28
"github.com/coder/coder/v2/coderd"
28
29
agplaudit "github.com/coder/coder/v2/coderd/audit"
29
30
agpldbauthz "github.com/coder/coder/v2/coderd/database/dbauthz"
31
+ "github.com/coder/coder/v2/coderd/database/dbtime"
30
32
"github.com/coder/coder/v2/coderd/healthcheck"
31
33
"github.com/coder/coder/v2/coderd/httpapi"
32
34
"github.com/coder/coder/v2/coderd/httpmw"
@@ -64,6 +66,11 @@ func New(ctx context.Context, options *Options) (_ *API, err error) {
64
66
if options .Options .Authorizer == nil {
65
67
options .Options .Authorizer = rbac .NewCachingAuthorizer (options .PrometheusRegistry )
66
68
}
69
+ if options .ReplicaErrorGracePeriod == 0 {
70
+ // This will prevent the error from being shown for a minute
71
+ // from when an additional replica was started.
72
+ options .ReplicaErrorGracePeriod = time .Minute
73
+ }
67
74
68
75
ctx , cancelFunc := context .WithCancel (ctx )
69
76
@@ -429,6 +436,7 @@ type Options struct {
429
436
430
437
// Used for high availability.
431
438
ReplicaSyncUpdateInterval time.Duration
439
+ ReplicaErrorGracePeriod time.Duration
432
440
DERPServerRelayAddress string
433
441
DERPServerRegionID int
434
442
@@ -525,9 +533,24 @@ func (api *API) updateEntitlements(ctx context.Context) error {
525
533
api .entitlementsUpdateMu .Lock ()
526
534
defer api .entitlementsUpdateMu .Unlock ()
527
535
536
+ replicas := api .replicaManager .AllPrimary ()
537
+ agedReplicas := make ([]database.Replica , 0 , len (replicas ))
538
+ for _ , replica := range replicas {
539
+ // If a replica is less than the update interval old, we don't
540
+ // want to display a warning. In the open-source version of Coder,
541
+ // Kubernetes Pods will start up before shutting down the other,
542
+ // and we don't want to display a warning in that case.
543
+ //
544
+ // Only display warnings for long-lived replicas!
545
+ if dbtime .Now ().Sub (replica .StartedAt ) < api .ReplicaErrorGracePeriod {
546
+ continue
547
+ }
548
+ agedReplicas = append (agedReplicas , replica )
549
+ }
550
+
528
551
entitlements , err := license .Entitlements (
529
552
ctx , api .Database ,
530
- api .Logger , len (api . replicaManager . AllPrimary () ), len (api .ExternalAuthConfigs ), api .LicenseKeys , map [codersdk.FeatureName ]bool {
553
+ api .Logger , len (agedReplicas ), len (api .ExternalAuthConfigs ), api .LicenseKeys , map [codersdk.FeatureName ]bool {
531
554
codersdk .FeatureAuditLog : api .AuditLogging ,
532
555
codersdk .FeatureBrowserOnly : api .BrowserOnly ,
533
556
codersdk .FeatureSCIM : len (api .SCIMAPIKey ) != 0 ,
0 commit comments