Skip to content

Commit

Permalink
feat(proto): add Pass field to PushPullEvent message for tracking rat…
Browse files Browse the repository at this point in the history
…elimit decision

chore(proto): update proto file with new fields and messages

feat(proto): add pass field to PushPullEvent message for ratelimit tracking
feat(metrics): add ratelimitAccuracy metric to track ratelimit accuracy
feat(pushpull): update ratelimitAccuracy metric based on ratelimit pass result
  • Loading branch information
chronark committed Aug 6, 2024
1 parent fcca820 commit 4b5a4ad
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 42 deletions.
95 changes: 53 additions & 42 deletions apps/agent/gen/proto/ratelimit/v1/service.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions apps/agent/proto/ratelimit/v1/service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ message PushPullEvent {

// used for metrics
int64 time = 5;

// Whether the serving node has decided to pass the ratelimit or not
// We use this to track the accuracy after syncing with the origin node
bool pass = 6;
}

message PushPullRequest {
Expand Down
12 changes: 12 additions & 0 deletions apps/agent/services/ratelimit/metrics.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package ratelimit

import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
)

var ratelimitAccuracy = promauto.NewCounterVec(prometheus.CounterOpts{
Namespace: "agent",
Subsystem: "ratelimit",
Name: "ratelimit_accuracy",
}, []string{"correct"})
7 changes: 7 additions & 0 deletions apps/agent/services/ratelimit/pushpull.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,17 @@ func (s *service) PushPull(ctx context.Context, req *ratelimitv1.PushPullRequest
RefillInterval: e.Duration,
Cost: e.Cost,
})

res.Updates[i] = &ratelimitv1.PushPullUpdate{
Identifier: e.Identifier,
Current: r.Current,
}

if r.Pass == e.Pass {
ratelimitAccuracy.WithLabelValues("true").Inc()
} else {
ratelimitAccuracy.WithLabelValues("false").Inc()
}
}

return res, nil
Expand Down

0 comments on commit 4b5a4ad

Please sign in to comment.