This repository has been archived by the owner on Oct 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 63
/
quality_of_service_provider.go
59 lines (50 loc) · 2.25 KB
/
quality_of_service_provider.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package runtime
import (
"fmt"
"github.com/flyteorg/flyteadmin/pkg/runtime/interfaces"
"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core"
"github.com/flyteorg/flytestdlib/config"
"github.com/golang/protobuf/ptypes"
)
const qualityOfServiceKey = "qualityOfService"
var qualityOfServiceConfig = config.MustRegisterSection(qualityOfServiceKey, &interfaces.QualityOfServiceConfig{
TierExecutionValues: make(map[interfaces.TierName]interfaces.QualityOfServiceSpec),
DefaultTiers: make(map[interfaces.DomainName]interfaces.TierName),
})
// Implementation of an interfaces.QualityOfServiceConfiguration
type QualityOfServiceConfigProvider struct {
}
func (p *QualityOfServiceConfigProvider) GetTierExecutionValues() map[core.QualityOfService_Tier]core.QualityOfServiceSpec {
tierExecutionValues := make(map[core.QualityOfService_Tier]core.QualityOfServiceSpec)
configValues := qualityOfServiceConfig.GetConfig().(*interfaces.QualityOfServiceConfig).TierExecutionValues
for tierName, spec := range configValues {
tierExecutionValues[core.QualityOfService_Tier(core.QualityOfService_Tier_value[tierName])] =
core.QualityOfServiceSpec{
QueueingBudget: ptypes.DurationProto(spec.QueueingBudget.Duration),
}
}
return tierExecutionValues
}
func (p *QualityOfServiceConfigProvider) GetDefaultTiers() map[interfaces.DomainName]core.QualityOfService_Tier {
defaultTiers := make(map[interfaces.DomainName]core.QualityOfService_Tier)
tiers := qualityOfServiceConfig.GetConfig().(*interfaces.QualityOfServiceConfig).DefaultTiers
for domainName, tierName := range tiers {
defaultTiers[domainName] = core.QualityOfService_Tier(core.QualityOfService_Tier_value[tierName])
}
return defaultTiers
}
func validateConfigValues() {
if qualityOfServiceConfig != nil {
values := qualityOfServiceConfig.GetConfig().(*interfaces.QualityOfServiceConfig).TierExecutionValues
for tierName, spec := range values {
_, err := ptypes.Duration(ptypes.DurationProto(spec.QueueingBudget.Duration))
if err != nil {
panic(fmt.Sprintf("Invalid duration [%+v] specified for %s", spec.QueueingBudget.Duration, tierName))
}
}
}
}
func NewQualityOfServiceConfigProvider() interfaces.QualityOfServiceConfiguration {
validateConfigValues()
return &QualityOfServiceConfigProvider{}
}