Skip to content

Commit

Permalink
One value for usage
Browse files Browse the repository at this point in the history
  • Loading branch information
klaidliadon committed Dec 13, 2024
1 parent fae05b7 commit 7dfe19c
Show file tree
Hide file tree
Showing 11 changed files with 687 additions and 234 deletions.
21 changes: 12 additions & 9 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,6 @@ func (c *Client) SpendQuota(ctx context.Context, quota *proto.AccessQuota, cost
if err != nil {
// limit exceeded
if errors.Is(err, proto.ErrQuotaExceeded) {
c.usage.AddKeyUsage(accessKey, now, proto.AccessUsage{LimitedCompute: cost})
return false, total, proto.ErrQuotaExceeded
}
// ping the server to prepare usage
Expand All @@ -281,20 +280,24 @@ func (c *Client) SpendQuota(ctx context.Context, quota *proto.AccessQuota, cost

}

usage, event := cfg.GetSpendResult(cost, total)
if quota.AccessKey.AccessKey == "" {
c.usage.AddProjectUsage(quota.AccessKey.ProjectID, now, usage)
} else {
c.usage.AddKeyUsage(accessKey, now, usage)
}
if usage.LimitedCompute != 0 {
return false, total, proto.ErrQuotaExceeded
ok, usage, event := cfg.GetSpendResult(cost, total)
if usage != 0 {
if quota.AccessKey.AccessKey == "" {
c.usage.AddProjectUsage(quota.AccessKey.ProjectID, now, usage)
} else {
c.usage.AddKeyUsage(accessKey, now, usage)
}
}

if event != nil {
if _, err := c.quotaClient.NotifyEvent(ctx, quota.AccessKey.ProjectID, *event); err != nil {
logger.Error("notify event failed", slog.Any("error", err))
}
}

if !ok {
return false, total, proto.ErrQuotaExceeded
}
return true, total, nil
}
logger.Error("operation timed out")
Expand Down
9 changes: 6 additions & 3 deletions go.work.sum
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,8 @@ github.com/supranational/blst v0.3.12/go.mod h1:jZJtfjgudtNl4en1tzwPIV3KjUnQUvG3
github.com/supranational/blst v0.3.13/go.mod h1:jZJtfjgudtNl4en1tzwPIV3KjUnQUvG3/j+w+fVonLw=
github.com/tyler-smith/go-bip39 v1.1.0/go.mod h1:gUYDtqQw1JS3ZJ8UWVcGTGqqr6YIN3CWg+kkNaLt55U=
github.com/webrpc/gen-golang v0.15.0/go.mod h1:qy1qEWMlTvrRzjSuQLy+176RqNaX1ymUULDtlo7Dapo=
github.com/webrpc/gen-golang v0.17.0/go.mod h1:qy1qEWMlTvrRzjSuQLy+176RqNaX1ymUULDtlo7Dapo=
github.com/webrpc/gen-typescript v0.14.1/go.mod h1:xQzYnVaSMfcygDXA5SuW8eYyCLHBHkj15wCF7gcJF5Y=
github.com/webrpc/gen-typescript v0.16.1/go.mod h1:xQzYnVaSMfcygDXA5SuW8eYyCLHBHkj15wCF7gcJF5Y=
github.com/webrpc/webrpc v0.20.3/go.mod h1:nplt2iyIXMsMCGyQx1NgEXwQOifWqKNLXcFnQnG9dBU=
github.com/webrpc/webrpc v0.22.0/go.mod h1:eeABnLz9BC4F9GGw6UKebVPkzkFYLrZRlcOvh6o8n10=
go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo=
go.opentelemetry.io/contrib/detectors/gcp v1.29.0/go.mod h1:GW2aWZNwR2ZxDLdv8OyC2G8zkRoQBuURgV7RPQgcPoU=
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.54.0/go.mod h1:B9yO6b04uB80CzjedvewuqDhxJxi11s7/GtiGa8bAjI=
Expand All @@ -99,25 +96,31 @@ go.opentelemetry.io/otel/sdk/metric v1.29.0/go.mod h1:6zZLdCl2fkauYoZIOn/soQIDSW
go.opentelemetry.io/otel/trace v1.29.0/go.mod h1:eHl3w0sp3paPkYstJOmAimxhiFXPg+MMTlEh3nsQgWQ=
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54=
golang.org/x/crypto v0.27.0/go.mod h1:1Xngt8kV6Dvbssa53Ziq6Eqn0HqbZi5Z6R0ZpwQzt70=
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225/go.mod h1:CxmFvTBINI24O/j8iY7H1xHzx2i4OsyguNBmN/uPtqc=
golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa/go.mod h1:akd2r19cwCdwSwWeIdzYQGa/EZZyqcOdwWiwj5L5eKQ=
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0/go.mod h1:2TbTHSBQa924w8M6Xs1QcRcFwyucIwBGpK1p2f1YFFY=
golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac=
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg=
golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ=
golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.23.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/telemetry v0.0.0-20240228155512-f48c80bd79b2/go.mod h1:TeRTkGYfJXctD9OcfyVLyj2J3IxLnKwHJR8f4D8a3YE=
golang.org/x/telemetry v0.0.0-20240521205824-bda55230c457/go.mod h1:pRgIJT+bRLFKnoM1ldnzKoxTIn14Yxz928LQRYYgIN0=
golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY=
golang.org/x/term v0.21.0/go.mod h1:ooXLefLobQVslOqselCNF4SxFAaoS6KujMbsGzSDmX0=
golang.org/x/term v0.23.0/go.mod h1:DgV24QBUrK6jhZXl+20l6UWznPlwAHm1Q1mGHtydmSk=
golang.org/x/term v0.24.0/go.mod h1:lOBK/LVxemqiMij05LGJ0tzNr8xlmwBRJ81PX6wVLH8=
golang.org/x/term v0.27.0/go.mod h1:iMsnZpn0cago0GOrHO2+Y7u7JPn5AylBrcoWkElMTSM=
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
golang.org/x/time v0.6.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
golang.org/x/tools v0.11.0/go.mod h1:anzJrxPjNtfgiYQYirP2CPGzGLxrH2u2QBhn6Bf3qY8=
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg=
Expand Down
87 changes: 66 additions & 21 deletions handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ type AccessKeyStore interface {
}

type UsageStore interface {
GetAccessKeyUsage(ctx context.Context, projectID uint64, accessKey string, service *proto.Service, min, max time.Time) (proto.AccessUsage, error)
GetAccountUsage(ctx context.Context, projectID uint64, service *proto.Service, min, max time.Time) (proto.AccessUsage, error)
UpdateAccessUsage(ctx context.Context, projectID uint64, accessKey string, service proto.Service, time time.Time, usage proto.AccessUsage) error
GetUsageAccessKey(ctx context.Context, projectID uint64, accessKey string, service *proto.Service, min, max time.Time) (int64, error)
GetUsageProject(ctx context.Context, projectID uint64, service *proto.Service, min, max time.Time) (int64, error)
UpdateUsage(ctx context.Context, projectID uint64, accessKey string, service proto.Service, time time.Time, usage int64) error
}

type CycleStore interface {
Expand Down Expand Up @@ -103,59 +103,86 @@ func (h handler) GetTimeRange(ctx context.Context, projectID uint64, from, to *t
return *from, from.Add(duration), nil
}

func (h handler) GetAccountUsage(ctx context.Context, projectID uint64, service *proto.Service, from, to *time.Time) (*proto.AccessUsage, error) {
func (h handler) GetUsageProject(ctx context.Context, projectID uint64, service *proto.Service, from, to *time.Time) (int64, error) {
min, max, err := h.GetTimeRange(ctx, projectID, from, to)
if err != nil {
return nil, err
return 0, fmt.Errorf("get time range: %w", err)
}

usage, err := h.store.UsageStore.GetUsageProject(ctx, projectID, service, min, max)
if err != nil {
return 0, fmt.Errorf("get project usage: %w", err)
}
return usage, nil
}

usage, err := h.store.UsageStore.GetAccountUsage(ctx, projectID, service, min, max)
// deprecated: use GetUsageProject instead
func (h handler) GetAccountUsage(ctx context.Context, projectID uint64, service *proto.Service, from, to *time.Time) (*proto.AccessUsage, error) {
usage, err := h.GetUsageProject(ctx, projectID, service, from, to)
if err != nil {
return nil, err
}
return &usage, nil
return &proto.AccessUsage{ValidCompute: usage}, nil
}

func (h handler) GetAsyncUsage(ctx context.Context, projectID uint64, service *proto.Service, from, to *time.Time) (*proto.AccessUsage, error) {
func (h handler) GetUsageAsync(ctx context.Context, projectID uint64, service *proto.Service, from, to *time.Time) (int64, error) {
min, max, err := h.GetTimeRange(ctx, projectID, from, to)
if err != nil {
return nil, err
return 0, fmt.Errorf("get time range: %w", err)
}

usage, err := h.store.UsageStore.GetAccessKeyUsage(ctx, projectID, "", service, min, max)
usage, err := h.store.UsageStore.GetUsageAccessKey(ctx, projectID, "", service, min, max)
if err != nil {
return 0, fmt.Errorf("get async usage: %w", err)
}
return usage, nil
}

// deprecated: use GetUsageAsync instead
func (h handler) GetAsyncUsage(ctx context.Context, projectID uint64, service *proto.Service, from, to *time.Time) (*proto.AccessUsage, error) {
usage, err := h.GetUsageAsync(ctx, projectID, service, from, to)
if err != nil {
return nil, err
}
return &usage, nil
return &proto.AccessUsage{ValidCompute: usage}, nil
}

func (h handler) GetAccessKeyUsage(ctx context.Context, accessKey string, service *proto.Service, from, to *time.Time) (*proto.AccessUsage, error) {
func (h handler) GetUsageAccessKey(ctx context.Context, accessKey string, service *proto.Service, from, to *time.Time) (int64, error) {
projectID, err := proto.GetProjectID(accessKey)
if err != nil {
return nil, err
return 0, fmt.Errorf("get project id: %w", err)
}

min, max, err := h.GetTimeRange(ctx, projectID, from, to)
if err != nil {
return nil, err
return 0, fmt.Errorf("get time range: %w", err)
}

usage, err := h.store.UsageStore.GetUsageAccessKey(ctx, projectID, accessKey, service, min, max)
if err != nil {
return 0, fmt.Errorf("get access key usage: %w", err)
}
return usage, nil
}

usage, err := h.store.UsageStore.GetAccessKeyUsage(ctx, projectID, accessKey, service, min, max)
// deprecated: use GetUsageAccessKey instead
func (h handler) GetAccessKeyUsage(ctx context.Context, accessKey string, service *proto.Service, from, to *time.Time) (*proto.AccessUsage, error) {
usage, err := h.GetUsageAccessKey(ctx, accessKey, service, from, to)
if err != nil {
return nil, err
}
return &usage, nil
return &proto.AccessUsage{ValidCompute: usage}, nil
}

func (h handler) PrepareUsage(ctx context.Context, projectID uint64, cycle *proto.Cycle, now time.Time) (bool, error) {
min, max := cycle.GetStart(now), cycle.GetEnd(now)
usage, err := h.GetAccountUsage(ctx, projectID, nil, &min, &max)
usage, err := h.store.GetUsageProject(ctx, projectID, nil, min, max)
if err != nil {
return false, err
}

key := getQuotaKey(projectID, cycle, now)
if err := h.cache.UsageCache.SetUsage(ctx, key, usage.GetTotalUsage()); err != nil {
if err := h.cache.UsageCache.SetUsage(ctx, key, usage); err != nil {
return false, err
}
return true, nil
Expand Down Expand Up @@ -230,11 +257,20 @@ func (h handler) NotifyEvent(ctx context.Context, projectID uint64, eventType pr
return true, nil
}

// deprecated: use StoreUsageProject instead
func (h handler) UpdateProjectUsage(ctx context.Context, service proto.Service, now time.Time, usage map[uint64]*proto.AccessUsage) (map[uint64]bool, error) {
input := make(map[uint64]int64, len(usage))
for projectID, accessUsage := range usage {
input[projectID] = accessUsage.GetTotalUsage()
}
return h.StoreUsageProject(ctx, service, now, input)
}

func (h handler) StoreUsageProject(ctx context.Context, service proto.Service, now time.Time, usage map[uint64]int64) (map[uint64]bool, error) {
var errs []error
m := make(map[uint64]bool, len(usage))
for projectID, accessUsage := range usage {
err := h.store.UsageStore.UpdateAccessUsage(ctx, projectID, "", service, now, *accessUsage)
for projectID, u := range usage {
err := h.store.UsageStore.UpdateUsage(ctx, projectID, "", service, now, u)
if err != nil {
errs = append(errs, fmt.Errorf("%d: %w", projectID, err))
}
Expand All @@ -246,7 +282,16 @@ func (h handler) UpdateProjectUsage(ctx context.Context, service proto.Service,
return m, nil
}

// deprecated: use UpdateKeyUsage instead
func (h handler) UpdateKeyUsage(ctx context.Context, service proto.Service, now time.Time, usage map[string]*proto.AccessUsage) (map[string]bool, error) {
input := make(map[string]int64, len(usage))
for key, accessUsage := range usage {
input[key] = accessUsage.GetTotalUsage()
}
return h.StoreUsageAccessKey(ctx, service, now, input)
}

func (h handler) StoreUsageAccessKey(ctx context.Context, service proto.Service, now time.Time, usage map[string]int64) (map[string]bool, error) {
var errs []error
m := make(map[string]bool, len(usage))
for key, u := range usage {
Expand All @@ -255,7 +300,7 @@ func (h handler) UpdateKeyUsage(ctx context.Context, service proto.Service, now
errs = append(errs, fmt.Errorf("%s: %w", key, err))
continue
}
if err = h.store.UsageStore.UpdateAccessUsage(ctx, projectID, key, service, now, *u); err != nil {
if err = h.store.UsageStore.UpdateUsage(ctx, projectID, key, service, now, u); err != nil {
errs = append(errs, fmt.Errorf("%s: %w", key, err))
}
m[key] = err == nil
Expand Down
38 changes: 18 additions & 20 deletions handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func TestMiddlewareUseAccessKey(t *testing.T) {

r.Handle("/*", &counter)

expectedUsage := proto.AccessUsage{}
expectedUsage := int64(0)

t.Run("WithAccessKey", func(t *testing.T) {
go client.Run(context.Background())
Expand All @@ -106,7 +106,7 @@ func TestMiddlewareUseAccessKey(t *testing.T) {
assert.Equal(t, strconv.FormatInt(limit.FreeMax-i, 10), headers.Get(middleware.HeaderQuotaRemaining))
assert.Equal(t, "", headers.Get(middleware.HeaderQuotaOverage))
assert.Empty(t, server.GetEvents(ProjectID), i)
expectedUsage.Add(proto.AccessUsage{ValidCompute: _credits})
expectedUsage += _credits
}

// Go over free CU
Expand All @@ -117,7 +117,7 @@ func TestMiddlewareUseAccessKey(t *testing.T) {
assert.Equal(t, "0", headers.Get(middleware.HeaderQuotaRemaining))
assert.Equal(t, "", headers.Get(middleware.HeaderQuotaOverage))
assert.Contains(t, server.GetEvents(ProjectID), proto.EventType_FreeMax)
expectedUsage.Add(proto.AccessUsage{ValidCompute: _credits})
expectedUsage += _credits

// Get close to soft quota
for i := limit.FreeWarn + _credits; i < limit.OverWarn; i += _credits {
Expand All @@ -128,7 +128,7 @@ func TestMiddlewareUseAccessKey(t *testing.T) {
assert.Equal(t, "0", headers.Get(middleware.HeaderQuotaRemaining))
assert.Equal(t, strconv.FormatInt(i-limit.FreeWarn, 10), headers.Get(middleware.HeaderQuotaOverage))
assert.Len(t, server.GetEvents(ProjectID), 1)
expectedUsage.Add(proto.AccessUsage{OverCompute: _credits})
expectedUsage += _credits
}

// Go over soft quota
Expand All @@ -139,7 +139,7 @@ func TestMiddlewareUseAccessKey(t *testing.T) {
assert.Equal(t, "0", headers.Get(middleware.HeaderQuotaRemaining))
assert.Equal(t, strconv.FormatInt(limit.OverWarn-limit.FreeWarn, 10), headers.Get(middleware.HeaderQuotaOverage))
assert.Contains(t, server.GetEvents(ProjectID), proto.EventType_OverWarn)
expectedUsage.Add(proto.AccessUsage{OverCompute: _credits})
expectedUsage += _credits

// Get close to hard quota
for i := limit.OverWarn + _credits; i < limit.OverMax; i += _credits {
Expand All @@ -150,7 +150,7 @@ func TestMiddlewareUseAccessKey(t *testing.T) {
assert.Equal(t, "0", headers.Get(middleware.HeaderQuotaRemaining))
assert.Equal(t, strconv.FormatInt(i-limit.FreeWarn, 10), headers.Get(middleware.HeaderQuotaOverage))
assert.Len(t, server.GetEvents(ProjectID), 2)
expectedUsage.Add(proto.AccessUsage{OverCompute: _credits})
expectedUsage += _credits
}

// Go over hard quota
Expand All @@ -161,7 +161,7 @@ func TestMiddlewareUseAccessKey(t *testing.T) {
assert.Equal(t, "0", headers.Get(middleware.HeaderQuotaRemaining))
assert.Equal(t, strconv.FormatInt(limit.OverMax-limit.FreeWarn, 10), headers.Get(middleware.HeaderQuotaOverage))
assert.Contains(t, server.GetEvents(ProjectID), proto.EventType_OverMax)
expectedUsage.Add(proto.AccessUsage{OverCompute: _credits})
expectedUsage += _credits

// Denied
for i := 0; i < 10; i++ {
Expand All @@ -171,15 +171,13 @@ func TestMiddlewareUseAccessKey(t *testing.T) {
assert.Equal(t, strconv.FormatInt(limit.FreeMax, 10), headers.Get(middleware.HeaderQuotaLimit))
assert.Equal(t, "0", headers.Get(middleware.HeaderQuotaRemaining))
assert.Equal(t, strconv.FormatInt(limit.OverMax-limit.FreeWarn, 10), headers.Get(middleware.HeaderQuotaOverage))
expectedUsage.Add(proto.AccessUsage{LimitedCompute: _credits})
}

// check the usage
client.Stop(context.Background())
usage, err := server.Store.GetAccountUsage(ctx, ProjectID, &Service, now.Add(-time.Hour), now.Add(time.Hour))
usage, err := server.Store.GetUsageProject(ctx, ProjectID, &Service, now.Add(-time.Hour), now.Add(time.Hour))
assert.NoError(t, err)
assert.Equal(t, int64(expectedUsage.GetTotalUsage()), _credits*counter.GetValue())
assert.Equal(t, &expectedUsage, &usage)
assert.Equal(t, expectedUsage, usage)
})

t.Run("ChangeLimits", func(t *testing.T) {
Expand All @@ -204,10 +202,10 @@ func TestMiddlewareUseAccessKey(t *testing.T) {
assert.Equal(t, "0", headers.Get(middleware.HeaderQuotaLimit))

client.Stop(context.Background())
usage, err := server.Store.GetAccountUsage(ctx, ProjectID, &Service, now.Add(-time.Hour), now.Add(time.Hour))
usage, err := server.Store.GetUsageProject(ctx, ProjectID, &Service, now.Add(-time.Hour), now.Add(time.Hour))
assert.NoError(t, err)
expectedUsage.Add(proto.AccessUsage{ValidCompute: 0, OverCompute: _credits, LimitedCompute: 0})
assert.Equal(t, int64(expectedUsage.GetTotalUsage()), _credits*counter.GetValue())
expectedUsage += _credits
assert.Equal(t, expectedUsage, _credits*counter.GetValue())
assert.Equal(t, &expectedUsage, &usage)
})

Expand All @@ -230,9 +228,9 @@ func TestMiddlewareUseAccessKey(t *testing.T) {
}

client.Stop(context.Background())
usage, err := server.Store.GetAccountUsage(ctx, ProjectID, &Service, now.Add(-time.Hour), now.Add(time.Hour))
usage, err := server.Store.GetUsageProject(ctx, ProjectID, &Service, now.Add(-time.Hour), now.Add(time.Hour))
assert.NoError(t, err)
assert.Equal(t, int64(expectedUsage.GetTotalUsage()), _credits*counter.GetValue())
assert.Equal(t, expectedUsage, _credits*counter.GetValue())
assert.Equal(t, &expectedUsage, &usage)
})

Expand Down Expand Up @@ -270,9 +268,9 @@ func TestMiddlewareUseAccessKey(t *testing.T) {
server.ErrPrepareUsage = nil

client.Stop(context.Background())
usage, err := server.Store.GetAccountUsage(ctx, ProjectID, &Service, now.Add(-time.Hour), now.Add(time.Hour))
usage, err := server.Store.GetUsageProject(ctx, ProjectID, &Service, now.Add(-time.Hour), now.Add(time.Hour))
assert.NoError(t, err)
assert.Equal(t, int64(expectedUsage.GetTotalUsage()), _credits*counter.GetValue())
assert.Equal(t, expectedUsage, _credits*counter.GetValue())
assert.Equal(t, &expectedUsage, &usage)
})

Expand All @@ -290,9 +288,9 @@ func TestMiddlewareUseAccessKey(t *testing.T) {
assert.NoError(t, err)

client.Stop(context.Background())
usage, err := server.Store.GetAccountUsage(ctx, ProjectID, &Service, now.Add(-time.Hour), now.Add(time.Hour))
usage, err := server.Store.GetUsageProject(ctx, ProjectID, &Service, now.Add(-time.Hour), now.Add(time.Hour))
assert.NoError(t, err)
assert.Equal(t, int64(expectedUsage.GetTotalUsage()), _credits*counter.GetValue())
assert.Equal(t, expectedUsage, _credits*counter.GetValue())
assert.Equal(t, &expectedUsage, &usage)
})
}
Expand Down
Loading

0 comments on commit 7dfe19c

Please sign in to comment.