Skip to content
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

Add dp to cp airl #1194

Merged
merged 1 commit into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions apim-apk-agent/pkg/managementserver/rest_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,52 @@ func createAPIYaml(apiCPEvent *APICPEvent) (string, string) {
"accessControlExposeHeaders": apiCPEvent.API.CORSPolicy.AccessControlExposeHeaders,
}
}
maxTps := make(map[string]interface{})

// Handle Production fields
if apiCPEvent.API.ProdAIRL != nil {
maxTps["production"] = apiCPEvent.API.ProdAIRL.RequestCount
maxTps["productionTimeUnit"] = apiCPEvent.API.ProdAIRL.TimeUnit

tokenConfig := make(map[string]interface{})
if apiCPEvent.API.ProdAIRL.PromptTokenCount != nil {
tokenConfig["productionMaxPromptTokenCount"] = *apiCPEvent.API.ProdAIRL.PromptTokenCount
}
if apiCPEvent.API.ProdAIRL.CompletionTokenCount != nil {
tokenConfig["productionMaxCompletionTokenCount"] = *apiCPEvent.API.ProdAIRL.CompletionTokenCount
}
if apiCPEvent.API.ProdAIRL.TotalTokenCount != nil {
tokenConfig["productionMaxTotalTokenCount"] = *apiCPEvent.API.ProdAIRL.TotalTokenCount
}
if len(tokenConfig) > 0 {
tokenConfig["isTokenBasedThrottlingEnabled"] = true
maxTps["tokenBasedThrottlingConfiguration"] = tokenConfig
}
}

// Handle Sandbox fields
if apiCPEvent.API.SandAIRL != nil {
maxTps["sandbox"] = apiCPEvent.API.SandAIRL.RequestCount
maxTps["sandboxTimeUnit"] = apiCPEvent.API.SandAIRL.TimeUnit

// Add sandbox token-based throttling config
if maxTps["tokenBasedThrottlingConfiguration"] == nil {
maxTps["tokenBasedThrottlingConfiguration"] = make(map[string]interface{})
}
tokenConfig := maxTps["tokenBasedThrottlingConfiguration"].(map[string]interface{})
if apiCPEvent.API.SandAIRL.PromptTokenCount != nil {
tokenConfig["sandboxMaxPromptTokenCount"] = *apiCPEvent.API.SandAIRL.PromptTokenCount
}
if apiCPEvent.API.SandAIRL.CompletionTokenCount != nil {
tokenConfig["sandboxMaxCompletionTokenCount"] = *apiCPEvent.API.SandAIRL.CompletionTokenCount
}
if apiCPEvent.API.SandAIRL.TotalTokenCount != nil {
tokenConfig["sandboxMaxTotalTokenCount"] = *apiCPEvent.API.SandAIRL.TotalTokenCount
}
}
if len(maxTps) > 0 {
data["data"].(map[string]interface{})["maxTps"] = maxTps
}
logger.LoggerMgtServer.Debugf("Prepared yaml : %+v", data)
definition := apiCPEvent.API.Definition
if strings.EqualFold(apiCPEvent.API.APIType, "rest") {
Expand Down Expand Up @@ -287,6 +333,10 @@ func createAPIYaml(apiCPEvent *APICPEvent) (string, string) {
return string(yamlBytes), definition
}

func getUint32OrNil(i *uint32) {

}

func createDeployementYaml(vhost string) string {
config, err := config.ReadConfigs()
envLabel := []string{"Default"}
Expand Down
11 changes: 11 additions & 0 deletions apim-apk-agent/pkg/managementserver/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,17 @@ type API struct {
AuthHeader string `json:"authHeader"`
APIKeyHeader string `json:"apiKeyHeader"`
Operations []OperationFromDP `json:"operations"`
SandAIRL *AIRL `json:"sandAIRL"`
ProdAIRL *AIRL `json:"prodAIRL"`
}

// AIRL holds AI ratelimit related data
type AIRL struct {
PromptTokenCount *uint32 `json:"promptTokenCount"`
CompletionTokenCount *uint32 `json:"CompletionTokenCount"`
TotalTokenCount *uint32 `json:"totalTokenCount"`
TimeUnit string `json:"timeUnit"`
RequestCount *uint32 `json:"requestCount"`
}

// APKHeaders contains the request and response header modifier information
Expand Down
Loading