@@ -402,3 +402,79 @@ func (c *ClientImpl) UpdateClickPipeSettings(ctx context.Context, serviceId stri
402402
403403 return settingsResponse .Result , nil
404404}
405+
406+ type ClickPipeCdcScaling struct {
407+ ReplicaCpuMillicores int64 `json:"replicaCpuMillicores"`
408+ ReplicaMemoryGb float64 `json:"replicaMemoryGb"`
409+ }
410+
411+ type ClickPipeCdcScalingRequest struct {
412+ ReplicaCpuMillicores int64 `json:"replicaCpuMillicores"`
413+ ReplicaMemoryGb float64 `json:"replicaMemoryGb"`
414+ }
415+
416+ func (c * ClientImpl ) GetClickPipeCdcScaling (ctx context.Context , serviceId string ) (* ClickPipeCdcScaling , error ) {
417+ req , err := http .NewRequest (http .MethodGet , c .getServicePath (serviceId , "/clickpipesCdcScaling" ), nil )
418+ if err != nil {
419+ return nil , err
420+ }
421+ body , err := c .doRequest (ctx , req )
422+ if err != nil {
423+ return nil , err
424+ }
425+
426+ scalingResponse := ResponseWithResult [ClickPipeCdcScaling ]{}
427+ if err := json .Unmarshal (body , & scalingResponse ); err != nil {
428+ return nil , fmt .Errorf ("failed to unmarshal CDC scaling: %w" , err )
429+ }
430+
431+ return & scalingResponse .Result , nil
432+ }
433+
434+ func (c * ClientImpl ) UpdateClickPipeCdcScaling (ctx context.Context , serviceId string , request ClickPipeCdcScalingRequest ) (* ClickPipeCdcScaling , error ) {
435+ var payload bytes.Buffer
436+ if err := json .NewEncoder (& payload ).Encode (request ); err != nil {
437+ return nil , fmt .Errorf ("failed to encode CDC scaling: %w" , err )
438+ }
439+
440+ req , err := http .NewRequest (http .MethodPatch , c .getServicePath (serviceId , "/clickpipesCdcScaling" ), & payload )
441+ if err != nil {
442+ return nil , err
443+ }
444+
445+ body , err := c .doRequest (ctx , req )
446+ if err != nil {
447+ return nil , err
448+ }
449+
450+ scalingResponse := ResponseWithResult [ClickPipeCdcScaling ]{}
451+ if err := json .Unmarshal (body , & scalingResponse ); err != nil {
452+ return nil , fmt .Errorf ("failed to unmarshal CDC scaling: %w" , err )
453+ }
454+
455+ return & scalingResponse .Result , nil
456+ }
457+
458+ func (c * ClientImpl ) WaitForClickPipeCdcScaling (ctx context.Context , serviceId string , expectedCpuMillicores int64 , expectedMemoryGb float64 , maxElapsedTime time.Duration ) (scaling * ClickPipeCdcScaling , err error ) {
459+ checkScaling := func () error {
460+ scaling , err = c .GetClickPipeCdcScaling (ctx , serviceId )
461+ if err != nil {
462+ return err
463+ }
464+
465+ // Check if the scaling values match the expected values
466+ if scaling .ReplicaCpuMillicores == expectedCpuMillicores && scaling .ReplicaMemoryGb == expectedMemoryGb {
467+ return nil
468+ }
469+
470+ return fmt .Errorf ("CDC scaling not yet applied: current cpu=%d (expected %d), memory=%.1f (expected %.1f)" ,
471+ scaling .ReplicaCpuMillicores , expectedCpuMillicores , scaling .ReplicaMemoryGb , expectedMemoryGb )
472+ }
473+
474+ if maxElapsedTime < 5 * time .Second {
475+ maxElapsedTime = 5 * time .Second
476+ }
477+
478+ err = backoff .Retry (checkScaling , backoff .NewExponentialBackOff (backoff .WithMaxElapsedTime (maxElapsedTime ), backoff .WithMaxInterval (maxElapsedTime / 5 )))
479+ return
480+ }
0 commit comments