-
Notifications
You must be signed in to change notification settings - Fork 109
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
[CECO-2][DatadogMonitor] Configure force sync period #1404
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,9 @@ package datadogmonitor | |
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
"sort" | ||
"strconv" | ||
"strings" | ||
"time" | ||
|
||
|
@@ -35,10 +37,11 @@ import ( | |
) | ||
|
||
const ( | ||
defaultRequeuePeriod = 60 * time.Second | ||
defaultErrRequeuePeriod = 5 * time.Second | ||
defaultForceSyncPeriod = 60 * time.Minute | ||
maxTriggeredStateGroups = 10 | ||
defaultRequeuePeriod = 60 * time.Second | ||
defaultErrRequeuePeriod = 5 * time.Second | ||
defaultForceSyncPeriod = 60 * time.Minute | ||
maxTriggeredStateGroups = 10 | ||
DDMonitorForceSyncPeriodEnvVar = "DD_MONITOR_FORCE_SYNC_PERIOD" | ||
) | ||
|
||
var supportedMonitorTypes = map[string]bool{ | ||
|
@@ -89,11 +92,20 @@ func (r *Reconciler) internalReconcile(ctx context.Context, req reconcile.Reques | |
logger := r.log.WithValues("datadogmonitor", req.NamespacedName) | ||
logger.Info("Reconciling DatadogMonitor") | ||
now := metav1.NewTime(time.Now()) | ||
forceSyncPeriod := defaultForceSyncPeriod | ||
|
||
forceSyncPeriodInt, err := strconv.Atoi(os.Getenv(DDMonitorForceSyncPeriodEnvVar)) | ||
if err != nil { | ||
logger.Error(err, "Invalid value for monitor force sync period. Defaulting to 60 minutes.") | ||
} else { | ||
logger.V(1).Info("Setting monitor force sync period", "minutes", forceSyncPeriodInt) | ||
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. To avoid spamming the used sync period, this log is set to appear only in |
||
forceSyncPeriod = time.Duration(forceSyncPeriodInt) * time.Minute | ||
} | ||
|
||
// Get instance | ||
instance := &datadoghqv1alpha1.DatadogMonitor{} | ||
var result ctrl.Result | ||
err := r.client.Get(ctx, req.NamespacedName, instance) | ||
err = r.client.Get(ctx, req.NamespacedName, instance) | ||
if err != nil { | ||
if apierrors.IsNotFound(err) { | ||
// Request object not found, could have been deleted after reconcile request. | ||
|
@@ -140,7 +152,7 @@ func (r *Reconciler) internalReconcile(ctx context.Context, req reconcile.Reques | |
// Custom resource manifest has changed, need to update the API | ||
logger.V(1).Info("DatadogMonitor manifest has changed") | ||
shouldUpdate = true | ||
} else if instance.Status.MonitorLastForceSyncTime == nil || (defaultForceSyncPeriod-now.Sub(instance.Status.MonitorLastForceSyncTime.Time)) <= 0 { | ||
} else if instance.Status.MonitorLastForceSyncTime == nil || (forceSyncPeriod-now.Sub(instance.Status.MonitorLastForceSyncTime.Time)) <= 0 { | ||
// Periodically force a sync with the API monitor to ensure parity | ||
// Get monitor to make sure it exists before trying any updates. If it doesn't, set shouldCreate | ||
m, err = r.get(instance, newStatus) | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding this break line so the note stands out properly instead of being on the same line: