-
Notifications
You must be signed in to change notification settings - Fork 129
Add DD_DASHBOARD_FORCE_SYNC_PERIOD environment variable #2184
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
Changes from 5 commits
760353f
a43835b
d7ce92c
7781b7c
5b38e10
1ab85a8
0fd99dd
99b5401
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2,6 +2,8 @@ package datadogdashboard | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| import ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| "context" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| "os" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| "strconv" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| "strings" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| "time" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -28,10 +30,11 @@ import ( | |||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| const ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| defaultRequeuePeriod = 60 * time.Second | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| defaultErrRequeuePeriod = 5 * time.Second | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| defaultForceSyncPeriod = 60 * time.Minute | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| datadogDashboardKind = "DatadogDashboard" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| defaultRequeuePeriod = 60 * time.Second | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| defaultErrRequeuePeriod = 5 * time.Second | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| defaultForceSyncPeriod = 60 * time.Minute | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| datadogDashboardKind = "DatadogDashboard" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| DDDashboardForceSyncPeriodEnvVar = "DD_DASHBOARD_FORCE_SYNC_PERIOD" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| type Reconciler struct { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -63,6 +66,18 @@ func (r *Reconciler) internalReconcile(ctx context.Context, req reconcile.Reques | |||||||||||||||||||||||||||||||||||||||||||||||||||
| logger.Info("Reconciling Datadog Dashboard") | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| now := metav1.NewTime(time.Now()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| forceSyncPeriod := defaultForceSyncPeriod | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| if userForceSyncPeriod, ok := os.LookupEnv(DDDashboardForceSyncPeriodEnvVar); ok { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| forceSyncPeriodInt, err := strconv.Atoi(userForceSyncPeriod) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| logger.Error(err, "Invalid value for dashboard force sync period. Defaulting to 60 minutes.") | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| logger.V(1).Info("Setting dashboard force sync period", "minutes", forceSyncPeriodInt) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| forceSyncPeriod = time.Duration(forceSyncPeriodInt) * time.Minute | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| instance := &v1alpha1.DatadogDashboard{} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| var result ctrl.Result | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| var err error | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -106,7 +121,7 @@ func (r *Reconciler) internalReconcile(ctx context.Context, req reconcile.Reques | |||||||||||||||||||||||||||||||||||||||||||||||||||
| if instanceSpecHash != statusSpecHash { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| logger.Info("DatadogDashboard manifest has changed") | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| shouldUpdate = true | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } else if instance.Status.LastForceSyncTime == nil || ((defaultForceSyncPeriod - now.Sub(instance.Status.LastForceSyncTime.Time)) <= 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } else if instance.Status.LastForceSyncTime == nil || ((forceSyncPeriod - now.Sub(instance.Status.LastForceSyncTime.Time)) <= 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @puretension Thanks for putting this together! It looks good I think but it seems like this doesn't follow the same pattern as the monitors do exactly. I haven't dived too deeply into the patterns used in other crd controllers here but the Monitor controller seems to check the Monitor specific datadog-operator/internal/controller/datadogmonitor/controller.go Lines 154 to 178 in 900987e
The
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @orkhanM Great catch! You're absolutely right about the consistency issue. Looking at the Monitor controller pattern you referenced, Thanks for pointing this out! |
||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Periodically force a sync with the API to ensure parity | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Get Dashboard to make sure it exists before trying any updates. If it doesn't, set shouldCreate | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| _, err = r.get(instance) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.