mirror of
https://github.com/lukaszraczylo/traefik-llmgateway.git
synced 2026-12-05 10:56:26 +00:00
This change adds the redesigned admin panel and the smart router decision model assist. It adds opt-in prompt-prefix caching per provider and cached-token pricing and metrics. With Redis, the metrics route reports fleet-wide values. The redis.sharedState switch shares six coordination states across replicas. PR CI grants actions read, which the shared go-pr workflow needs. The pull request description has the full list and the verification.
38 lines
1.1 KiB
Go
38 lines
1.1 KiB
Go
package traefikllmgateway
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func tpmUsage(t *testing.T, limits *LimitsConfig) adminUsageEntryView {
|
|
t.Helper()
|
|
h, gw := exemptGateway(t, nil, limits, nil)
|
|
require.Equal(t, http.StatusOK, memberLimitsChat(t, h, "sk-a").Code)
|
|
return findUsageEntry(t, gw.buildAdminUsage().Users, "a")
|
|
}
|
|
|
|
func TestAdminUsage_TokensPerMinuteLive(t *testing.T) {
|
|
e := tpmUsage(t, &LimitsConfig{TokensPerMinute: 1000})
|
|
assert.GreaterOrEqual(t, e.TokensPerMinute, int64(1), "minute token counter must surface")
|
|
raw, err := json.Marshal(e)
|
|
require.NoError(t, err)
|
|
var m map[string]any
|
|
require.NoError(t, json.Unmarshal(raw, &m))
|
|
assert.Contains(t, m, "tokensPerMinute")
|
|
}
|
|
|
|
func TestAdminUsage_TokensPerMinuteZeroWithoutLimit(t *testing.T) {
|
|
e := tpmUsage(t, &LimitsConfig{RequestsPerDay: 100})
|
|
assert.EqualValues(t, 0, e.TokensPerMinute)
|
|
}
|
|
|
|
func TestAdminUsageChunk_FitsKeyBudget(t *testing.T) {
|
|
assert.LessOrEqual(t, adminUsageChunkScopes*usageKeysPerScope, usageModelsChunkKeys)
|
|
assert.Equal(t, 13, usageKeysPerScope)
|
|
}
|