Skip to content

Refactor Redis configuration handling in KV cache scorer #159

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

Closed
wants to merge 1 commit into from
Closed
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
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ require (
github.com/go-logr/logr v1.4.2
github.com/google/go-cmp v0.7.0
github.com/hashicorp/golang-lru/v2 v2.0.7
github.com/llm-d/llm-d-kv-cache-manager v0.1.0
github.com/llm-d/llm-d-kv-cache-manager v0.1.1
github.com/prometheus/client_golang v1.22.0
github.com/redis/go-redis/v9 v9.7.3
github.com/stretchr/testify v1.10.0
go.uber.org/zap v1.27.0
google.golang.org/grpc v1.72.0
Expand Down Expand Up @@ -65,7 +66,6 @@ require (
github.com/prometheus/client_model v0.6.2 // indirect
github.com/prometheus/common v0.64.0 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/redis/go-redis/v9 v9.7.3 // indirect
github.com/spf13/cobra v1.9.1 // indirect
github.com/spf13/pflag v1.0.6 // indirect
github.com/stoewer/go-strcase v1.3.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
github.com/llm-d/llm-d-kv-cache-manager v0.1.0 h1:TabMsVni2AqxsfQtcT3jVjSPvExlbTieJejSVNwlkZ0=
github.com/llm-d/llm-d-kv-cache-manager v0.1.0/go.mod h1:Hu7RvpUg5sP1xnQFfO2dbt96AjGPWKuUvWBWiHj/FUU=
github.com/llm-d/llm-d-kv-cache-manager v0.1.1 h1:k3dpbnXdQ8JBz6tYtaUba58/YVuxiJ6O3Um4bJEjR3I=
github.com/llm-d/llm-d-kv-cache-manager v0.1.1/go.mod h1:Hu7RvpUg5sP1xnQFfO2dbt96AjGPWKuUvWBWiHj/FUU=
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
Expand Down
25 changes: 25 additions & 0 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package config

import (
"github.com/redis/go-redis/v9"

Check failure on line 4 in pkg/config/config_test.go

View workflow job for this annotation

GitHub Actions / lint-and-test

File is not properly formatted (goimports)
"strings"

//"github.com/redis/go-redis/v9"

Check failure on line 7 in pkg/config/config_test.go

View workflow job for this annotation

GitHub Actions / lint-and-test

commentFormatting: put a space between `//` and comment text (gocritic)
"github.com/stretchr/testify/assert"
"testing"
)

func TestURLParse(t *testing.T) {
urlInst := "bd73f810-0eea-46a9-b330-84c9bc36d00d.blrrvkdw0thh68l98t20.private.databases.appdomain.cloud:31394"
if !(strings.HasPrefix(urlInst, "redis://") || strings.HasPrefix(urlInst, "rediss://") || strings.HasPrefix(urlInst, "unix://")) {

Check failure on line 14 in pkg/config/config_test.go

View workflow job for this annotation

GitHub Actions / lint-and-test

QF1001: could apply De Morgan's law (staticcheck)
urlInst = "redis://" + urlInst
}
t.Log(urlInst)
opr, err := redis.ParseURL(urlInst)
assert.NoError(t, err)
t.Log(opr.Addr)
t.Log(opr.Username)
t.Log(opr.Password)
t.Log(opr.DB)
t.Log(opr.TLSConfig)
}
14 changes: 13 additions & 1 deletion pkg/scheduling/plugins/scorer/kvcache-aware.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import (
"context"
"fmt"
"os"
"strings"

"github.com/redis/go-redis/v9"

kvcache "github.com/llm-d/llm-d-kv-cache-manager/pkg/kv-cache"

Expand Down Expand Up @@ -37,7 +40,16 @@ func NewKVCacheAwareScorer(ctx context.Context) (plugins.Scorer, error) {

redisAddr := os.Getenv(kvCacheRedisEnvVar)
if redisAddr != "" {
config.KVBlockIndexerConfig.RedisAddr = redisAddr
// to keep compatibility with deployments only specifying hostname:port: need to add protocol to front to enable parsing
if !strings.HasPrefix(redisAddr, "redis://") && !strings.HasPrefix(redisAddr, "rediss://") && !strings.HasPrefix(redisAddr, "unix://") {
redisAddr = "redis://" + redisAddr
}
redisOpt, err := redis.ParseURL(redisAddr)
if err != nil {
return nil, fmt.Errorf("failed to parse redisURL: %w", err)
}

config.KVBlockIndexerConfig.RedisOpt = redisOpt
} else {
return nil, fmt.Errorf("environment variable %s is not set", kvCacheRedisEnvVar)
}
Expand Down
Loading