-
Notifications
You must be signed in to change notification settings - Fork 505
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/unkeyed/unkey
- Loading branch information
Showing
13 changed files
with
943 additions
and
347 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package middleware | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"github.com/unkeyed/unkey/apps/agent/pkg/cache" | ||
"github.com/unkeyed/unkey/apps/agent/pkg/metrics" | ||
) | ||
|
||
type metricsMiddleware[T any] struct { | ||
next cache.Cache[T] | ||
metrics metrics.Metrics | ||
resource string | ||
} | ||
|
||
func WithMetrics[T any](c cache.Cache[T], m metrics.Metrics, resource string) cache.Cache[T] { | ||
return &metricsMiddleware[T]{next: c, metrics: m, resource: resource} | ||
} | ||
|
||
func (mw *metricsMiddleware[T]) Get(ctx context.Context, key string) (T, bool) { | ||
start := time.Now() | ||
value, hit := mw.next.Get(ctx, key) | ||
mw.metrics.ReportCacheHit(metrics.CacheHitReport{ | ||
Key: key, | ||
Hit: hit, | ||
Resource: mw.resource, | ||
Latency: time.Since(start).Milliseconds(), | ||
}) | ||
return value, hit | ||
} | ||
func (mw *metricsMiddleware[T]) Set(ctx context.Context, key string, value T) { | ||
mw.next.Set(ctx, key, value) | ||
|
||
} | ||
func (mw *metricsMiddleware[T]) Remove(ctx context.Context, key string) { | ||
|
||
mw.next.Remove(ctx, key) | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
8904c0b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
unkey – ./
unkey-unkey.vercel.app
unkey-git-main-unkey.vercel.app
www.unkey.dev
unkey.dev
unkey.vercel.app