Skip to content

Use only valkey go - #202

Draft
majst01 wants to merge 12 commits into
mainfrom
use-only-valkey-go
Draft

Use only valkey go#202
majst01 wants to merge 12 commits into
mainfrom
use-only-valkey-go

Conversation

@majst01

@majst01 majst01 commented May 11, 2026

Copy link
Copy Markdown
Contributor

Description

This migrates all our valkey client code to valkey-go except the one for asynq (interface does not allow it).

During the refactoring i think i found some BUGs with the expiration of tokens, even if expiration was set to time.Now() the tokens where still present during the tests. I had to explicitly set the expiration to an hour in the future to make most of the tests work again ?

Benchmarks also show some nice improvements:

Valkey-go:
goos: linux
goarch: amd64
pkg: github.com/metal-stack/metal-apiserver/pkg/token
cpu: 12th Gen Intel(R) Core(TM) i7-1260P
BenchmarkTokenSetAndGet-16    	   12592	     97796 ns/op	    8474 B/op	     128 allocs/op
PASS
ok  	github.com/metal-stack/metal-apiserver/pkg/token	1.240s

Redis-go:
goos: linux
goarch: amd64
pkg: github.com/metal-stack/metal-apiserver/pkg/token
cpu: 12th Gen Intel(R) Core(TM) i7-1260P
BenchmarkTokenSetAndGet-16    	   10000	    114080 ns/op	    9453 B/op	     146 allocs/op
PASS
ok  	github.com/metal-stack/metal-apiserver/pkg/token	1.149s

Hibeken Asynq does not support valkey-go, did not try to convert to use valkeycompat either.

Used AI-Tools ✨

  • none used for generation

@metal-robot metal-robot Bot added the area: control-plane Affects the metal-stack control-plane area. label May 11, 2026
@codecov

codecov Bot commented May 14, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 72.11538% with 29 lines in your changes missing coverage. Please review.
✅ Project coverage is 72.46%. Comparing base (865e73c) to head (00e149c).

Files with missing lines Patch % Lines
pkg/token/token-store.go 69.23% 6 Missing and 2 partials ⚠️
pkg/invite/invite-store.go 78.78% 4 Missing and 3 partials ⚠️
pkg/certs/certs-store.go 68.75% 2 Missing and 3 partials ⚠️
cmd/server/serve-cmd.go 0.00% 3 Missing ⚠️
cmd/server/token-cmd.go 0.00% 3 Missing ⚠️
pkg/rate-limiter/rate-limiter.go 70.00% 1 Missing and 2 partials ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #202   +/-   ##
=======================================
  Coverage   72.45%   72.46%           
=======================================
  Files         194      194           
  Lines       15243    15249    +6     
=======================================
+ Hits        11045    11050    +5     
  Misses       3102     3102           
- Partials     1096     1097    +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

expectCertStore(t, ctx, certStore, 1)
expectTokenWorks(t, ctx, auth, token1)
},
// synctest.Test(t, func(t *testing.T) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

valkey-go has its own background worker which breaks synctest.Test


return err
cmds := make(valkey.Commands, 0, 2)
cmds = append(cmds, c.B().Set().Key(keyFn()).Value(string(encoded)).Exat(i.GetExpiresAt().AsTime()).Build())

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clarify the usage of .Ex() vs .Exat()

Comment thread pkg/repository/machine.go
@majst01
majst01 marked this pull request as ready for review June 8, 2026 08:59
@majst01
majst01 requested a review from a team as a code owner June 8, 2026 08:59
Comment thread pkg/certs/certs-store.go
cmds = append(cmds, r.client.B().Set().Key(keyPublic()).Value(string(rawBytes)).Ex(expires).Build())
for i, resp := range r.client.DoMulti(ctx, cmds...) {
if resp.Error() != nil {
return nil, fmt.Errorf("unable to store certificate with command:%s %w", cmds[i].Commands()[1], resp.Error())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unchecked index ref

Comment thread pkg/certs/certs-store.go
Comment on lines +134 to +136
cmds := make(valkey.Commands, 0, 2)
cmds = append(cmds, r.client.B().Set().Key(keyPrivateLatest()).Value(string(encoded)).Ex(expires).Build())
cmds = append(cmds, r.client.B().Set().Key(keyPublic()).Value(string(rawBytes)).Ex(expires).Build())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be combined

err = json.Unmarshal(encoded, &e)
if err != nil {
return zero, err
return zero, fmt.Errorf("unable to unmarshal secret from bytes:%w", err)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return zero, fmt.Errorf("unable to unmarshal secret from bytes:%w", err)
return zero, fmt.Errorf("unable to unmarshal invite from bytes: %w", err)

cmds = append(cmds, c.B().Set().Key(keyFn()).Value(string(encoded)).Exat(i.GetExpiresAt().AsTime()).Build())
cmds = append(cmds, c.B().Set().Key(secretkey(i.GetSecret())).Value(string(encoded)).Exat(i.GetExpiresAt().AsTime()).Build())
for _, cmd := range cmds {
fmt.Printf("cmd:%s\n", cmd.Commands())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No fmt.Println

@majst01
majst01 marked this pull request as draft June 8, 2026 11:12
Comment on lines -21 to +20
t.Parallel()
// t.Parallel()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either remove or comment in

@majst01

majst01 commented Jun 8, 2026

Copy link
Copy Markdown
Contributor Author

Not to be merged immediately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: control-plane Affects the metal-stack control-plane area.

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

3 participants