- 
                Notifications
    You must be signed in to change notification settings 
- Fork 37
Add failure injection mode to simulator #131
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
          
     Merged
      
      
    
  
     Merged
                    Changes from 28 commits
      Commits
    
    
            Show all changes
          
          
            29 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      638d0f7
              
                Add definition of new action input (#123)
              
              
                shmuelk 9ffe957
              
                KV cache and tokenization related configuration (#125)
              
              
                irar2 a5a7d81
              
                Another attempt at adding a latest tag only on release builds (#124)
              
              
                shmuelk 951f4a3
              
                Publish kv-cache events (#126)
              
              
                irar2 6930192
              
                Add failure injection mode to simulator
              
              
                smarunich 5ec92b8
              
                Refactor failure injection and update simulator error handling
              
              
                smarunich 8e0eefa
              
                Make tokenizer version configurable from Dockerfile
              
              
                smarunich 75dcb72
              
                Add failure injection mode to simulator
              
              
                smarunich d7bb175
              
                Refactor failure injection and update simulator error handling
              
              
                smarunich c35dbca
              
                KV cache and tokenization related configuration (#125)
              
              
                irar2 2eca8e6
              
                Publish kv-cache events (#126)
              
              
                irar2 28fb65b
              
                Use same version of tokenizer in both Dockerfile and Makefile (#132)
              
              
                mayabar 3ae7113
              
                Clarify failure injection rate documentation
              
              
                smarunich f5ae85b
              
                Set default failure injection rate to 0
              
              
                smarunich 9dbb689
              
                rebase duplicates
              
              
                smarunich 106e276
              
                re-base the changes
              
              
                irar2 5162226
              
                Update option constructors in simulator tests
              
              
                smarunich 7bd69e8
              
                Merge branch 'main' into failure-mode
              
              
                smarunich 5182187
              
                Document failure injection options in README
              
              
                smarunich b68115f
              
                Set FailureInjectionRate default to 0 in config
              
              
                smarunich bfa02ff
              
                Refactor failure type usage and error response format
              
              
                smarunich 700e36f
              
                Refactor failure type flag handling and code formatting
              
              
                smarunich 14860b3
              
                Merge branch 'main' into failure-mode
              
              
                smarunich 8f6d56c
              
                Fix config validation and simulator test argument handling
              
              
                smarunich e0183b7
              
                remove duplicate
              
              
                smarunich 178a594
              
                Refactor failure handling to use CompletionError struct
              
              
                smarunich 72dde24
              
                Use one type for all errors. Map code to type
              
              
                irar2 13492fc
              
                Merge branch 'main' into failure-mode
              
              
                irar2 7994048
              
                Review comments
              
              
                irar2 File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,88 @@ | ||
| /* | ||
| Copyright 2025 The llm-d-inference-sim Authors. | ||
|  | ||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|  | ||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|  | ||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|  | ||
| package llmdinferencesim | ||
|  | ||
| import ( | ||
| "fmt" | ||
|  | ||
| "github.com/llm-d/llm-d-inference-sim/pkg/common" | ||
| openaiserverapi "github.com/llm-d/llm-d-inference-sim/pkg/openai-server-api" | ||
| ) | ||
|  | ||
| const ( | ||
| // Error message templates | ||
| rateLimitMessageTemplate = "Rate limit reached for %s in organization org-xxx on requests per min (RPM): Limit 3, Used 3, Requested 1." | ||
| modelNotFoundMessageTemplate = "The model '%s-nonexistent' does not exist" | ||
| ) | ||
|         
                  smarunich marked this conversation as resolved.
              Show resolved
            Hide resolved | ||
|  | ||
| var predefinedFailures = map[string]openaiserverapi.CompletionError{ | ||
| common.FailureTypeRateLimit: openaiserverapi.NewCompletionError(rateLimitMessageTemplate, 429, nil), | ||
| common.FailureTypeInvalidAPIKey: openaiserverapi.NewCompletionError("Incorrect API key provided.", 401, nil), | ||
| common.FailureTypeContextLength: openaiserverapi.NewCompletionError( | ||
| "This model's maximum context length is 4096 tokens. However, your messages resulted in 4500 tokens.", | ||
| 400, stringPtr("messages")), | ||
| common.FailureTypeServerError: openaiserverapi.NewCompletionError( | ||
| "The server is overloaded or not ready yet.", 503, nil), | ||
| common.FailureTypeInvalidRequest: openaiserverapi.NewCompletionError( | ||
| "Invalid request: missing required parameter 'model'.", 400, stringPtr("model")), | ||
| common.FailureTypeModelNotFound: openaiserverapi.NewCompletionError(modelNotFoundMessageTemplate, | ||
| 404, stringPtr("model")), | ||
| } | ||
|         
                  smarunich marked this conversation as resolved.
              Show resolved
            Hide resolved | ||
|  | ||
| // shouldInjectFailure determines whether to inject a failure based on configuration | ||
| func shouldInjectFailure(config *common.Configuration) bool { | ||
| if config.FailureInjectionRate == 0 { | ||
| return false | ||
| } | ||
|  | ||
| return common.RandomInt(1, 100) <= config.FailureInjectionRate | ||
| } | ||
|  | ||
| // getRandomFailure returns a random failure from configured types or all types if none specified | ||
| func getRandomFailure(config *common.Configuration) openaiserverapi.CompletionError { | ||
| var availableFailures []string | ||
| if len(config.FailureTypes) == 0 { | ||
| // Use all failure types if none specified | ||
| for failureType := range predefinedFailures { | ||
| availableFailures = append(availableFailures, failureType) | ||
| } | ||
| } else { | ||
| availableFailures = config.FailureTypes | ||
| } | ||
|  | ||
| if len(availableFailures) == 0 { | ||
| // Fallback to server_error if no valid types | ||
| return predefinedFailures[common.FailureTypeServerError] | ||
| } | ||
|  | ||
| randomIndex := common.RandomInt(0, len(availableFailures)-1) | ||
| randomType := availableFailures[randomIndex] | ||
|  | ||
| // Customize message with current model name | ||
| failure := predefinedFailures[randomType] | ||
| if randomType == common.FailureTypeRateLimit && config.Model != "" { | ||
| failure.Message = fmt.Sprintf(rateLimitMessageTemplate, config.Model) | ||
| } else if randomType == common.FailureTypeModelNotFound && config.Model != "" { | ||
| failure.Message = fmt.Sprintf(modelNotFoundMessageTemplate, config.Model) | ||
| } | ||
|  | ||
| return failure | ||
| } | ||
|  | ||
| func stringPtr(s string) *string { | ||
| return &s | ||
| } | ||
  
    
      This file contains hidden or 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,109 @@ | ||
| /* | ||
| Copyright 2025 The llm-d-inference-sim Authors. | ||
|  | ||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|  | ||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|  | ||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|  | ||
| package llmdinferencesim | ||
|  | ||
| import ( | ||
| "strings" | ||
| "time" | ||
|  | ||
| . "github.com/onsi/ginkgo/v2" | ||
| . "github.com/onsi/gomega" | ||
|  | ||
| "github.com/llm-d/llm-d-inference-sim/pkg/common" | ||
| openaiserverapi "github.com/llm-d/llm-d-inference-sim/pkg/openai-server-api" | ||
| ) | ||
|  | ||
| var _ = Describe("Failures", func() { | ||
| Describe("getRandomFailure", Ordered, func() { | ||
| BeforeAll(func() { | ||
| common.InitRandom(time.Now().UnixNano()) | ||
| }) | ||
|  | ||
| It("should return a failure from all types when none specified", func() { | ||
| config := &common.Configuration{ | ||
| Model: "test-model", | ||
| FailureTypes: []string{}, | ||
| } | ||
| failure := getRandomFailure(config) | ||
| Expect(failure.Code).To(BeNumerically(">=", 400)) | ||
| Expect(failure.Message).ToNot(BeEmpty()) | ||
| Expect(failure.Type).ToNot(BeEmpty()) | ||
| }) | ||
|  | ||
| It("should return rate limit failure when specified", func() { | ||
| config := &common.Configuration{ | ||
| Model: "test-model", | ||
| FailureTypes: []string{common.FailureTypeRateLimit}, | ||
| } | ||
| failure := getRandomFailure(config) | ||
| Expect(failure.Code).To(Equal(429)) | ||
| Expect(failure.Type).To(Equal(openaiserverapi.ErrorCodeToType(429))) | ||
| Expect(strings.Contains(failure.Message, "test-model")).To(BeTrue()) | ||
| }) | ||
|  | ||
| It("should return invalid API key failure when specified", func() { | ||
| config := &common.Configuration{ | ||
| FailureTypes: []string{common.FailureTypeInvalidAPIKey}, | ||
| } | ||
| failure := getRandomFailure(config) | ||
| Expect(failure.Code).To(Equal(401)) | ||
| Expect(failure.Type).To(Equal(openaiserverapi.ErrorCodeToType(401))) | ||
| Expect(failure.Message).To(Equal("Incorrect API key provided.")) | ||
| }) | ||
|  | ||
| It("should return context length failure when specified", func() { | ||
| config := &common.Configuration{ | ||
| FailureTypes: []string{common.FailureTypeContextLength}, | ||
| } | ||
| failure := getRandomFailure(config) | ||
| Expect(failure.Code).To(Equal(400)) | ||
| Expect(failure.Type).To(Equal(openaiserverapi.ErrorCodeToType(400))) | ||
| Expect(failure.Param).ToNot(BeNil()) | ||
| Expect(*failure.Param).To(Equal("messages")) | ||
| }) | ||
|  | ||
| It("should return server error when specified", func() { | ||
| config := &common.Configuration{ | ||
| FailureTypes: []string{common.FailureTypeServerError}, | ||
| } | ||
| failure := getRandomFailure(config) | ||
| Expect(failure.Code).To(Equal(503)) | ||
| Expect(failure.Type).To(Equal(openaiserverapi.ErrorCodeToType(503))) | ||
| }) | ||
|  | ||
| It("should return model not found failure when specified", func() { | ||
| config := &common.Configuration{ | ||
| Model: "test-model", | ||
| FailureTypes: []string{common.FailureTypeModelNotFound}, | ||
| } | ||
| failure := getRandomFailure(config) | ||
| Expect(failure.Code).To(Equal(404)) | ||
| Expect(failure.Type).To(Equal(openaiserverapi.ErrorCodeToType(404))) | ||
| Expect(strings.Contains(failure.Message, "test-model-nonexistent")).To(BeTrue()) | ||
| }) | ||
|  | ||
| It("should return server error as fallback for empty types", func() { | ||
| config := &common.Configuration{ | ||
| FailureTypes: []string{}, | ||
| } | ||
| // This test is probabilistic since it randomly selects, but we can test structure | ||
| failure := getRandomFailure(config) | ||
| Expect(failure.Code).To(BeNumerically(">=", 400)) | ||
| Expect(failure.Type).ToNot(BeEmpty()) | ||
| }) | ||
| }) | ||
| }) | 
      
      Oops, something went wrong.
        
    
  
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add json annotation