@@ -37,6 +37,7 @@ import (
3737 "github.com/dash0hq/dash0-operator/internal/selfmonitoringapiaccess"
3838 "github.com/dash0hq/dash0-operator/internal/util"
3939 "github.com/dash0hq/dash0-operator/internal/util/logd"
40+ "github.com/dash0hq/dash0-operator/internal/util/rate"
4041)
4142
4243type PrometheusRuleCrdReconciler struct {
@@ -45,6 +46,7 @@ type PrometheusRuleCrdReconciler struct {
4546 leaderElectionAware util.LeaderElectionAware
4647 mgr ctrl.Manager
4748 httpClient * http.Client
49+ limiter * rate.CappedRateLimiter
4850 skipNameValidation bool
4951 prometheusRuleReconciler * PrometheusRuleReconciler
5052 prometheusRuleCrdExists atomic.Bool
@@ -55,6 +57,7 @@ type PrometheusRuleReconciler struct {
5557 pseudoClusterUid types.UID
5658 queue * workqueue.Typed [ThirdPartyResourceSyncJob ]
5759 httpClient * http.Client
60+ limiter * rate.CappedRateLimiter
5861 defaultApiConfigs selfmonitoringapiaccess.SynchronizedSlice [ApiConfig ]
5962 namespacedApiConfigs selfmonitoringapiaccess.SynchronizedMapSlice [ApiConfig ]
6063 namespacedSyncEnabled sync.Map
@@ -92,12 +95,14 @@ func NewPrometheusRuleCrdReconciler(
9295 queue * workqueue.Typed [ThirdPartyResourceSyncJob ],
9396 leaderElectionAware util.LeaderElectionAware ,
9497 httpClient * http.Client ,
98+ limiter * rate.CappedRateLimiter ,
9599) * PrometheusRuleCrdReconciler {
96100 return & PrometheusRuleCrdReconciler {
97101 Client : k8sClient ,
98102 queue : queue ,
99103 leaderElectionAware : leaderElectionAware ,
100104 httpClient : httpClient ,
105+ limiter : limiter ,
101106 }
102107}
103108
@@ -151,6 +156,7 @@ func (r *PrometheusRuleCrdReconciler) CreateThirdPartyResourceReconciler(pseudoC
151156 queue : r .queue ,
152157 pseudoClusterUid : pseudoClusterUid ,
153158 httpClient : r .httpClient ,
159+ limiter : r .limiter ,
154160 defaultApiConfigs : * selfmonitoringapiaccess .NewSynchronizedSlice [ApiConfig ](),
155161 namespacedApiConfigs : * selfmonitoringapiaccess .NewSynchronizedMapSlice [ApiConfig ](),
156162 }
@@ -559,7 +565,7 @@ func (r *PrometheusRuleReconciler) MapResourceToHttpRequests(
559565 allValidationIssues [checkRuleName ] = validationIssues
560566 // If a rule becomes temporarily invalid due to a bad edit, we do not want to delete it in Dash0
561567 // (assuming it has been valid at some point before and has been synchronized). Instead, we keep the
562- // most recent valid state. To do that, we add its id to the list of ids we have seen (the list will
568+ // most recent valid state. To do that, we add its id to the list of ids we have seen. The list will
563569 // later be used to determine which of the checks in Dash0 need to be removed because they are no longer
564570 // in the K8s resource.
565571 originsInResource = append (originsInResource , checkRuleOriginNotUrlEncoded )
@@ -568,7 +574,7 @@ func (r *PrometheusRuleReconciler) MapResourceToHttpRequests(
568574 if syncError != nil {
569575 // If a rule cannot be synchronized temporarily, we do not want to delete it in Dash0 immediately
570576 // (assuming the rule has been synchronized before at some point). Instead, we keep the
571- // most recent state. To do that, we add its id to the list of ids we have seen (the list will later
577+ // most recent state. To do that, we add its id to the list of ids we have seen. The list will later
572578 // be used to determine which of the checks in Dash0 need to be removed because they are no longer
573579 // in the K8s resource.
574580 allSynchronizationErrors [checkRuleName ] = syncError .Error ()
@@ -1133,9 +1139,6 @@ func (r *PrometheusRuleReconciler) synchronizeNamespacedResources(
11331139 Object : ruleResource ,
11341140 }
11351141 r .Generic (ctx , evt , nil )
1136-
1137- // stagger API requests a bit
1138- time .Sleep (50 * time .Millisecond )
11391142 }
11401143 logger .Info (fmt .Sprintf ("Triggering synchronization of check rules in namespace %s has finished." , namespace ))
11411144 }()
0 commit comments