-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add External Priority Multipliers (#4174)
* Create auction.proto * wip * wip * wip * wip * test * test * lint * log msg * default disable priority multipliers * add missing file
- Loading branch information
Showing
25 changed files
with
1,325 additions
and
17 deletions.
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
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
2 changes: 1 addition & 1 deletion
2
internal/scheduler/mocks/grpc.go → internal/scheduler/mocks/executor_api.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package prioritymultiplier | ||
|
||
import ( | ||
"fmt" | ||
"sync/atomic" | ||
"time" | ||
|
||
"google.golang.org/grpc" | ||
"google.golang.org/grpc/credentials" | ||
"google.golang.org/grpc/credentials/insecure" | ||
|
||
"github.com/armadaproject/armada/internal/common/armadacontext" | ||
schedulerconfig "github.com/armadaproject/armada/internal/scheduler/configuration" | ||
"github.com/armadaproject/armada/pkg/priorityoverride" | ||
) | ||
|
||
func NewServiceClient(config schedulerconfig.PriorityMultiplierConfig) (priorityoverride.PriorityMultiplierServiceClient, error) { | ||
creds := credentials.NewClientTLSFromCert(nil, "") | ||
if config.ForceNoTls { | ||
creds = insecure.NewCredentials() | ||
} | ||
client, err := grpc.NewClient(config.ServiceUrl, grpc.WithTransportCredentials(creds)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return priorityoverride.NewPriorityMultiplierServiceClient(client), nil | ||
} | ||
|
||
// ServiceProvider is an implementation of Provider that fetches priority multipliers from the Priority Multiplier Service. | ||
// We cache the multipliers in memory so that we can continue scheduling even if the API is unavailable | ||
type ServiceProvider struct { | ||
updateFrequency time.Duration | ||
apiClient priorityoverride.PriorityMultiplierServiceClient | ||
multipliers atomic.Pointer[map[multiplierKey]float64] | ||
} | ||
|
||
func NewServiceProvider(apiClient priorityoverride.PriorityMultiplierServiceClient, updateFrequency time.Duration) *ServiceProvider { | ||
return &ServiceProvider{ | ||
updateFrequency: updateFrequency, | ||
apiClient: apiClient, | ||
multipliers: atomic.Pointer[map[multiplierKey]float64]{}, | ||
} | ||
} | ||
|
||
func (p *ServiceProvider) Run(ctx *armadacontext.Context) error { | ||
if err := p.fetchMultipliers(ctx); err != nil { | ||
ctx.Warnf("Error fetching multipliers: %v", err) | ||
} | ||
ticker := time.NewTicker(p.updateFrequency) | ||
for { | ||
select { | ||
case <-ctx.Done(): | ||
return nil | ||
case <-ticker.C: | ||
if err := p.fetchMultipliers(ctx); err != nil { | ||
ctx.Warnf("Error fetching multipliers: %v", err) | ||
} | ||
} | ||
} | ||
} | ||
|
||
func (p *ServiceProvider) Ready() bool { | ||
return p.multipliers.Load() != nil | ||
} | ||
|
||
func (p *ServiceProvider) Multiplier(pool, queue string) (float64, error) { | ||
multipliers := p.multipliers.Load() | ||
if multipliers == nil { | ||
return 0, fmt.Errorf("no multipliers available") | ||
} | ||
multiplier, ok := (*multipliers)[multiplierKey{pool: pool, queue: queue}] | ||
if !ok { | ||
return 1.0, nil | ||
} | ||
return multiplier, nil | ||
} | ||
|
||
func (p *ServiceProvider) fetchMultipliers(ctx *armadacontext.Context) error { | ||
resp, err := p.apiClient.GetPriorityMultipliers(ctx, &priorityoverride.PriorityMultiplierRequest{}) | ||
if err != nil { | ||
return err | ||
} | ||
multipliers := make(map[multiplierKey]float64) | ||
for _, poolMultipliers := range resp.PoolPriorityMultipliers { | ||
for queue, multiplier := range poolMultipliers.Multipliers { | ||
key := multiplierKey{pool: poolMultipliers.Pool, queue: queue} | ||
multipliers[key] = multiplier | ||
} | ||
} | ||
p.multipliers.Store(&multipliers) | ||
return nil | ||
} |
Oops, something went wrong.