-
Notifications
You must be signed in to change notification settings - Fork 104
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
[profiles] DAP slow rollout on DS creation #1365
Changes from all commits
8b0a21f
ce518f9
ae14ff2
a606751
38315fa
e820793
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -177,7 +177,7 @@ func (r *Reconciler) reconcileInstanceV2(ctx context.Context, logger logr.Logger | |
if r.options.DatadogAgentProfileEnabled { | ||
metrics.DAPEnabled.Set(metrics.TrueValue) | ||
var profilesByNode map[string]types.NamespacedName | ||
profiles, profilesByNode, e = r.profilesToApply(ctx, logger, nodeList, now) | ||
profiles, profilesByNode, e = r.profilesToApply(ctx, logger, nodeList, now, instance) | ||
if err != nil { | ||
return r.updateStatusIfNeededV2(logger, instance, newStatus, result, e, now) | ||
} | ||
|
@@ -337,7 +337,7 @@ func (r *Reconciler) updateMetricsForwardersFeatures(dda *datadoghqv2alpha1.Data | |
// is considered to have priority. | ||
// This function also returns a map that maps each node name to the profile that | ||
// should be applied to it. | ||
func (r *Reconciler) profilesToApply(ctx context.Context, logger logr.Logger, nodeList []corev1.Node, now metav1.Time) ([]datadoghqv1alpha1.DatadogAgentProfile, map[string]types.NamespacedName, error) { | ||
func (r *Reconciler) profilesToApply(ctx context.Context, logger logr.Logger, nodeList []corev1.Node, now metav1.Time, dda *datadoghqv2alpha1.DatadogAgent) ([]datadoghqv1alpha1.DatadogAgentProfile, map[string]types.NamespacedName, error) { | ||
profilesList := datadoghqv1alpha1.DatadogAgentProfileList{} | ||
err := r.client.List(ctx, &profilesList) | ||
if err != nil { | ||
|
@@ -349,8 +349,8 @@ func (r *Reconciler) profilesToApply(ctx context.Context, logger logr.Logger, no | |
|
||
sortedProfiles := agentprofile.SortProfiles(profilesList.Items) | ||
for _, profile := range sortedProfiles { | ||
|
||
profileAppliedByNode, err = agentprofile.ProfileToApply(logger, &profile, nodeList, profileAppliedByNode, now) | ||
maxUnavailable := agentprofile.GetMaxUnavailable(logger, dda, &profile, len(nodeList)) | ||
profileAppliedByNode, err = agentprofile.ApplyProfile(logger, &profile, nodeList, profileAppliedByNode, now, maxUnavailable) | ||
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. 🟠 Code VulnerabilityPotential memory range aliasing. Avoid using the memory reference. (...read more)Implicit memory aliasing in for loops refers to a scenario in Go programming when two or more pointers reference the same location in memory, creating unexpected side effects. This often results in a common mistake amongst Go programmers due to the 'range' clause. Consider this example, where a slice of pointers is created in a loop: data := []int{1, 2, 3}
pointers := make([]*int, 3)
for i, v := range data {
pointers[i] = &v
} You might expect the 'pointers' slice to hold addresses of elements in 'data' slice, but that's not the case. In each iteration of the loop, variable 'v' gets a new value but its memory address doesn't change because it's a loop variable. As a result, each element in 'pointers' slice points to the same memory location - the address of the loop variable 'v'. The final value of 'v' is '3', and since all pointers point to 'v', dereferencing the pointers would yield '3' regardless of the pointer's index in the slice. To avoid implicit memory aliasing in for loops in Go, you should address the actual elements in the original data structure, like so: data := []int{1, 2, 3}
pointers := make([]*int, 3)
for i := range data {
pointers[i] = &data[i]
} In this example, each pointer in the 'pointers' slice correctly points to the respective element in the 'data' slice. Learn MoreThere 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. According to the linked stack overflow issue, should be fine with go 1.22 |
||
r.updateDAPStatus(logger, &profile) | ||
if err != nil { | ||
// profile is invalid or conflicts | ||
|
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.
🟠 Code Vulnerability
Potential memory range aliasing. Avoid using the memory reference. (...read more)
Implicit memory aliasing in for loops refers to a scenario in Go programming when two or more pointers reference the same location in memory, creating unexpected side effects. This often results in a common mistake amongst Go programmers due to the 'range' clause.
Consider this example, where a slice of pointers is created in a loop:
You might expect the 'pointers' slice to hold addresses of elements in 'data' slice, but that's not the case. In each iteration of the loop, variable 'v' gets a new value but its memory address doesn't change because it's a loop variable. As a result, each element in 'pointers' slice points to the same memory location - the address of the loop variable 'v'. The final value of 'v' is '3', and since all pointers point to 'v', dereferencing the pointers would yield '3' regardless of the pointer's index in the slice.
To avoid implicit memory aliasing in for loops in Go, you should address the actual elements in the original data structure, like so:
In this example, each pointer in the 'pointers' slice correctly points to the respective element in the 'data' slice.
Learn More
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.
According to the linked stack overflow issue, should be fine with go 1.22