Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions docs/datadog_dashboard.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ The `DatadogDashboard` Custom Resource Definition (CRD) allows users to create [
- [Helm][2], to deploy the Datadog Operator
- The [kubectl CLI][3], to install a `DatadogDashboard`


## Adding a DatadogDashboard

To deploy a `DatadogDashboard` with the Datadog Operator, use the [`datadog-operator` Helm chart][4].
Expand Down Expand Up @@ -114,8 +113,8 @@ To deploy a `DatadogDashboard` with the Datadog Operator, use the [`datadog-oper
```

This automatically creates a new dashboard in Datadog. You can find it on the [Dashboards][8] page of your Datadog account.
Datadog Operator occasionally reconciles and keeps dashboards in line with the given configuration. There is also a force
sync every hour, so if a user deletes a dashboard in the Datadog UI, Datadog Operator restores it in under an hour.

By default, the Operator ensures that the API dashboard definition stays in sync with the DatadogDashboard resource every **60** minutes (per dashboard). This interval can be adjusted using the environment variable `DD_DASHBOARD_FORCE_SYNC_PERIOD`, which specifies the number of minutes. For example, setting this variable to `"30"` changes the interval to 30 minutes.


## Cleanup
Expand Down
25 changes: 20 additions & 5 deletions internal/controller/datadogdashboard/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package datadogdashboard

import (
"context"
"os"
"strconv"
"strings"
"time"

Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
// 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)
Expand Down
Loading