Skip to content

Commit a5c928e

Browse files
authored
fix: Lint errors (#20)
* Allow set imports of Ginkgo related packages Signed-off-by: Shmuel Kallner <kallner@il.ibm.com> * Updates suggested by golangci-lint Signed-off-by: Shmuel Kallner <kallner@il.ibm.com> * Changed golangci-lint config file format to V2 Signed-off-by: Shmuel Kallner <kallner@il.ibm.com> * Install ginkgo for tests in ci-pr-checks workflow Signed-off-by: Shmuel Kallner <kallner@il.ibm.com> --------- Signed-off-by: Shmuel Kallner <kallner@il.ibm.com>
1 parent 2353712 commit a5c928e

File tree

10 files changed

+82
-71
lines changed

10 files changed

+82
-71
lines changed

.github/workflows/ci-pr-checks.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,10 @@ jobs:
3030
- name: Run go test
3131
shell: bash
3232
run: |
33+
echo "Installing Ginkgo..."
34+
go install github.com/onsi/ginkgo/ginkgo@latest
35+
export PATH=$PATH:$(go env GOPATH)/bin
36+
echo "Ginkgo installed:"
37+
ginkgo version
38+
echo "Running tests with Ginkgo..."
3339
make test

.golangci.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,12 @@ linters:
3131
- prealloc
3232
- unparam
3333
- unused
34+
settings:
35+
revive:
36+
rules:
37+
- name: dot-imports
38+
arguments:
39+
- allowedPackages:
40+
- "github.com/onsi/ginkgo"
41+
- "github.com/onsi/ginkgo/v2"
42+
- "github.com/onsi/gomega"

pkg/llm-d-inference-sim/defs.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
// Definitions of all sturctures used by vLLM simultor
17+
// Definitions of all structures used by vLLM simulator
1818
// Contains the main simulator class and all definitions related to request/response for all supported APIs
1919
package llmdinferencesim
2020

@@ -30,7 +30,7 @@ import (
3030
const (
3131
modeRandom = "random"
3232
modeEcho = "echo"
33-
chatComplIdPrefix = "chatcmpl-"
33+
chatComplIDPrefix = "chatcmpl-"
3434
stopFinishReason = "stop"
3535
roleAssistant = "assistant"
3636
roleUser = "user"
@@ -54,8 +54,8 @@ type VllmSimulator struct {
5454
loraAdaptors sync.Map
5555
// maxLoras defines maximum number of loaded loras
5656
maxLoras int
57-
// maxLoras defines maximum number of loras to store in CPU memory
58-
maxCpuLoras int
57+
// maxCPULoras defines maximum number of loras to store in CPU memory
58+
maxCPULoras int
5959
// runningLoras is a collection of running loras, key of lora's name, value is number of requests using this lora
6060
runningLoras sync.Map
6161
// waitingLoras will represent collection of loras defined in requests in the queue - Not implemented yet
@@ -267,10 +267,10 @@ func (req textCompletionRequest) createResponseText(mode string) (string, error)
267267

268268
// getLastUserMsg returns last message from this request's messages with user role,
269269
// if does not exist - returns an empty string
270-
func (r *chatCompletionRequest) getLastUserMsg() string {
271-
for i := len(r.Messages) - 1; i >= 0; i-- {
272-
if r.Messages[i].Role == roleUser {
273-
return r.Messages[i].Content
270+
func (req *chatCompletionRequest) getLastUserMsg() string {
271+
for i := len(req.Messages) - 1; i >= 0; i-- {
272+
if req.Messages[i].Role == roleUser {
273+
return req.Messages[i].Content
274274
}
275275
}
276276

pkg/llm-d-inference-sim/metrics.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ func (s *VllmSimulator) setInitialPrometheusMetrics() {
115115
func (s *VllmSimulator) reportLoras() {
116116
var loras []string
117117

118-
s.runningLoras.Range(func(key interface{}, value interface{}) bool {
118+
s.runningLoras.Range(func(key interface{}, _ interface{}) bool {
119119
if lora, ok := key.(string); ok {
120120
loras = append(loras, lora)
121121
}

pkg/llm-d-inference-sim/simulator.go

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ package llmdinferencesim
2020
import (
2121
"context"
2222
"encoding/json"
23+
"errors"
2324
"fmt"
2425
"net"
2526
"os"
@@ -86,7 +87,7 @@ func (s *VllmSimulator) parseCommandParams() error {
8687
var lorasStr string
8788
f.StringVar(&lorasStr, "lora", "", "List of LoRA adapters, separated by comma")
8889
f.IntVar(&s.maxLoras, "max-loras", 1, "Maximum number of LoRAs in a single batch")
89-
f.IntVar(&s.maxCpuLoras, "max-cpu-loras", 0, "Maximum number of LoRAs to store in CPU memory")
90+
f.IntVar(&s.maxCPULoras, "max-cpu-loras", 0, "Maximum number of LoRAs to store in CPU memory")
9091
f.Int64Var(&s.maxRunningReqs, "max-running-requests", 5, "Maximum number of inference requests that could be processed at the same time (parameter to simulate requests waiting queue)")
9192

9293
if err := f.Parse(os.Args[1:]); err != nil {
@@ -100,7 +101,7 @@ func (s *VllmSimulator) parseCommandParams() error {
100101

101102
// validate parsed values
102103
if s.model == "" {
103-
return fmt.Errorf("model parameter is empty")
104+
return errors.New("model parameter is empty")
104105
}
105106
if s.mode != modeEcho && s.mode != modeRandom {
106107
return fmt.Errorf("invalid mode '%s', valid values are 'random' and 'echo'", s.mode)
@@ -109,20 +110,20 @@ func (s *VllmSimulator) parseCommandParams() error {
109110
return fmt.Errorf("invalid port '%d'", s.port)
110111
}
111112
if s.interTokenLatency < 0 {
112-
return fmt.Errorf("inter token latency cannot be negative")
113+
return errors.New("inter token latency cannot be negative")
113114
}
114115
if s.timeToFirstToken < 0 {
115-
return fmt.Errorf("time to first token cannot be negative")
116+
return errors.New("time to first token cannot be negative")
116117
}
117118
if s.maxLoras < 1 {
118-
return fmt.Errorf("max loras cannot be less than 1")
119+
return errors.New("max loras cannot be less than 1")
119120
}
120-
if s.maxCpuLoras == 0 {
121+
if s.maxCPULoras == 0 {
121122
// max cpu loras by default is same as max loras
122-
s.maxCpuLoras = s.maxLoras
123+
s.maxCPULoras = s.maxLoras
123124
}
124-
if s.maxCpuLoras < 1 {
125-
return fmt.Errorf("max CPU loras cannot be less than 1")
125+
if s.maxCPULoras < 1 {
126+
return errors.New("max CPU loras cannot be less than 1")
126127
}
127128

128129
// just to suppress not used lint error for now
@@ -309,13 +310,13 @@ func (s *VllmSimulator) reqProcessingWorker(ctx context.Context, id int) {
309310
intValue := 0
310311

311312
if !ok {
312-
s.logger.Info("Create referense counter", "model", model)
313+
s.logger.Info("Create reference counter", "model", model)
313314
intValue = 0
314315
} else {
315316
intValue = value.(int)
316317
}
317318
s.runningLoras.Store(model, intValue+1)
318-
s.logger.Info("Update LoRA referense counter", "model", model, "old value", intValue, "new value", intValue+1)
319+
s.logger.Info("Update LoRA reference counter", "model", model, "old value", intValue, "new value", intValue+1)
319320

320321
// TODO - check if thie request went to the waiting queue - add it to waiting map
321322
s.reportLoras()
@@ -359,13 +360,13 @@ func (s *VllmSimulator) responseSentCallback(model string) {
359360
value, ok := s.runningLoras.Load(model)
360361

361362
if !ok {
362-
s.logger.Info("Error: nil referense counter", "model", model)
363+
s.logger.Info("Error: nil reference counter", "model", model)
363364
s.logger.Error(nil, "Zerro model reference", "model", model)
364365
} else {
365366
intValue := value.(int)
366367
if intValue > 1 {
367368
s.runningLoras.Store(model, intValue-1)
368-
s.logger.Info("Update LoRA referense counter", "model", model, "prev value", intValue, "new value", intValue-1)
369+
s.logger.Info("Update LoRA reference counter", "model", model, "prev value", intValue, "new value", intValue-1)
369370
} else {
370371
// last lora instance stopped it execution - remove from the map
371372
s.runningLoras.Delete(model)
@@ -377,7 +378,7 @@ func (s *VllmSimulator) responseSentCallback(model string) {
377378

378379
}
379380

380-
// sendCompletionError sends an error response for the curent completion request
381+
// sendCompletionError sends an error response for the current completion request
381382
func (s *VllmSimulator) sendCompletionError(ctx *fasthttp.RequestCtx, msg string, errType string, code int) {
382383
compErr := completionError{
383384
Object: "error",
@@ -400,12 +401,7 @@ func (s *VllmSimulator) sendCompletionError(ctx *fasthttp.RequestCtx, msg string
400401

401402
// HandleModels handles /v1/models request according the data stored in the simulator
402403
func (s *VllmSimulator) HandleModels(ctx *fasthttp.RequestCtx) {
403-
modelsResp, err := s.createModelsResponse()
404-
if err != nil {
405-
s.logger.Error(err, "Cannot create /models response")
406-
ctx.Error("Cannot create /models response, "+err.Error(), fasthttp.StatusInternalServerError)
407-
return
408-
}
404+
modelsResp := s.createModelsResponse()
409405

410406
data, err := json.Marshal(modelsResp)
411407
if err != nil {
@@ -419,7 +415,7 @@ func (s *VllmSimulator) HandleModels(ctx *fasthttp.RequestCtx) {
419415
ctx.Response.SetBody(data)
420416
}
421417

422-
func (s *VllmSimulator) HandleError(ctx *fasthttp.RequestCtx, err error) {
418+
func (s *VllmSimulator) HandleError(_ *fasthttp.RequestCtx, err error) {
423419
s.logger.Error(err, "VLLM server error")
424420
}
425421

@@ -429,7 +425,7 @@ func (s *VllmSimulator) HandleError(ctx *fasthttp.RequestCtx, err error) {
429425
// finishReason - a pointer to string that represents finish reason, can be nil or stop or length, ...
430426
func (s *VllmSimulator) createCompletionResponse(isChatCompletion bool, respText string, model string, finishReason *string) completionResponse {
431427
baseResp := baseCompletionResponse{
432-
ID: chatComplIdPrefix + uuid.NewString(),
428+
ID: chatComplIDPrefix + uuid.NewString(),
433429
Created: time.Now().Unix(),
434430
Model: model,
435431
}
@@ -440,11 +436,11 @@ func (s *VllmSimulator) createCompletionResponse(isChatCompletion bool, respText
440436
baseCompletionResponse: baseResp,
441437
Choices: []chatRespChoice{{Message: message{Role: roleAssistant, Content: respText}, baseResponseChoice: baseChoice}},
442438
}
443-
} else {
444-
return &textCompletionResponse{
445-
baseCompletionResponse: baseResp,
446-
Choices: []textRespChoice{{baseResponseChoice: baseChoice, Text: respText}},
447-
}
439+
}
440+
441+
return &textCompletionResponse{
442+
baseCompletionResponse: baseResp,
443+
Choices: []textRespChoice{{baseResponseChoice: baseChoice, Text: respText}},
448444
}
449445
}
450446

@@ -475,7 +471,7 @@ func (s *VllmSimulator) sendResponse(isChatCompletion bool, ctx *fasthttp.Reques
475471
}
476472

477473
// createModelsResponse creates and returns ModelResponse for the current state, returned array of models contains the base model + LoRA adapters if exist
478-
func (s *VllmSimulator) createModelsResponse() (*vllmapi.ModelsResponse, error) {
474+
func (s *VllmSimulator) createModelsResponse() *vllmapi.ModelsResponse {
479475
modelsResp := vllmapi.ModelsResponse{Object: "list", Data: []vllmapi.ModelsResponseModelInfo{}}
480476

481477
// add base model's info
@@ -500,5 +496,5 @@ func (s *VllmSimulator) createModelsResponse() (*vllmapi.ModelsResponse, error)
500496
})
501497
}
502498

503-
return &modelsResp, nil
499+
return &modelsResp
504500
}

pkg/llm-d-inference-sim/simulator_test.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func startServer(ctx context.Context, mode string) (*http.Client, error) {
6969

7070
return &http.Client{
7171
Transport: &http.Transport{
72-
DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
72+
DialContext: func(_ context.Context, _, _ string) (net.Conn, error) {
7373
return listener.Dial()
7474
},
7575
},
@@ -123,7 +123,7 @@ var _ = Describe("Simulator", func() {
123123
Expect(msg).Should(Equal(expectedMsg))
124124
},
125125
func(mode string) string {
126-
return fmt.Sprintf("mode: %s", mode)
126+
return "mode: " + mode
127127
},
128128
Entry(nil, modeRandom),
129129
Entry(nil, modeEcho),
@@ -170,7 +170,7 @@ var _ = Describe("Simulator", func() {
170170
Expect(text).Should(Equal(expectedText))
171171
},
172172
func(mode string) string {
173-
return fmt.Sprintf("mode: %s", mode)
173+
return "mode: " + mode
174174
},
175175
Entry(nil, modeRandom),
176176
Entry(nil, modeEcho),
@@ -192,18 +192,18 @@ var _ = Describe("Simulator", func() {
192192
},
193193
Model: model,
194194
}
195-
num_tokens := 0
195+
numTokens := 0
196196
partialErrMsg := ""
197197
// if maxTokens and maxCompletionTokens are passsed
198198
// maxCompletionTokens is used
199199
if maxTokens != 0 {
200200
params.MaxTokens = param.NewOpt(int64(maxTokens))
201-
num_tokens = maxTokens
201+
numTokens = maxTokens
202202
partialErrMsg = "max_tokens must be at least 1, got -1"
203203
}
204204
if maxCompletionTokens != 0 {
205205
params.MaxCompletionTokens = param.NewOpt(int64(maxCompletionTokens))
206-
num_tokens = maxCompletionTokens
206+
numTokens = maxCompletionTokens
207207
partialErrMsg = "max_completion_tokens must be at least 1, got -1"
208208
}
209209
resp, err := openaiclient.Chat.Completions.New(ctx, params)
@@ -220,14 +220,14 @@ var _ = Describe("Simulator", func() {
220220
}
221221
}
222222
Expect(err).NotTo(HaveOccurred())
223-
Expect(len(resp.Choices)).Should(BeNumerically(">", 0))
223+
Expect(resp.Choices).ShouldNot(BeEmpty())
224224

225225
msg := resp.Choices[0].Message.Content
226226
Expect(msg).ShouldNot(BeEmpty())
227227

228-
if num_tokens > 0 {
228+
if numTokens > 0 {
229229
tokens := strings.Fields(msg)
230-
Expect(int64(len(tokens))).Should(BeNumerically("<=", num_tokens))
230+
Expect(int64(len(tokens))).Should(BeNumerically("<=", numTokens))
231231
} else {
232232
expectedMsg := ""
233233
if mode == modeEcho {
@@ -275,11 +275,11 @@ var _ = Describe("Simulator", func() {
275275
},
276276
Model: openai.CompletionNewParamsModel(model),
277277
}
278-
num_tokens := 0
278+
numTokens := 0
279279
partialErrMsg := "max_tokens must be at least 1, got -1"
280280
if maxTokens != 0 {
281281
params.MaxTokens = param.NewOpt(int64(maxTokens))
282-
num_tokens = maxTokens
282+
numTokens = maxTokens
283283
}
284284
resp, err := openaiclient.Completions.New(ctx, params)
285285
if err != nil {
@@ -295,14 +295,14 @@ var _ = Describe("Simulator", func() {
295295
}
296296
}
297297
Expect(err).NotTo(HaveOccurred())
298-
Expect(len(resp.Choices)).Should(BeNumerically(">", 0))
298+
Expect(resp.Choices).ShouldNot(BeEmpty())
299299

300300
text := resp.Choices[0].Text
301301
Expect(text).ShouldNot(BeEmpty())
302302

303-
if num_tokens != 0 {
303+
if numTokens != 0 {
304304
tokens := strings.Fields(text)
305-
Expect(int64(len(tokens))).Should(BeNumerically("<=", num_tokens))
305+
Expect(int64(len(tokens))).Should(BeNumerically("<=", numTokens))
306306
} else {
307307
expectedText := ""
308308
if mode == modeEcho {

pkg/llm-d-inference-sim/streaming.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func (s *VllmSimulator) sendStreamingResponse(isChatCompletion bool, ctx *fastht
102102
// finishReason - a pointer to string that represents finish reason, can be nil or stop or length, ...
103103
func (s *VllmSimulator) createCompletionChunk(isChatCompletion bool, creationTime int64, token string, model string, role string, finishReason *string) completionRespChunk {
104104
baseChunk := baseCompletionResponse{
105-
ID: chatComplIdPrefix + uuid.NewString(),
105+
ID: chatComplIDPrefix + uuid.NewString(),
106106
Created: creationTime,
107107
Model: model,
108108
}
@@ -122,11 +122,11 @@ func (s *VllmSimulator) createCompletionChunk(isChatCompletion bool, creationTim
122122
}
123123

124124
return &chunk
125-
} else {
126-
return &textCompletionResponse{
127-
baseCompletionResponse: baseChunk,
128-
Choices: []textRespChoice{{baseResponseChoice: baseChoice, Text: token}},
129-
}
125+
}
126+
127+
return &textCompletionResponse{
128+
baseCompletionResponse: baseChunk,
129+
Choices: []textRespChoice{{baseResponseChoice: baseChoice, Text: token}},
130130
}
131131
}
132132

0 commit comments

Comments
 (0)