Skip to content

Commit

Permalink
Merge pull request #282 from porters-xyz/develop
Browse files Browse the repository at this point in the history
A few fixes needing to be pushed to prod
  • Loading branch information
wtfsayo authored May 24, 2024
2 parents 6d203f7 + 8aef6d5 commit 1ca0b49
Show file tree
Hide file tree
Showing 39 changed files with 563 additions and 261 deletions.
2 changes: 1 addition & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ services:
- porters-redis:/data

kit:
image: ghcr.io/pokt-network/pocket-gateway-server:0.1.0-BETA
image: ghcr.io/pokt-network/pocket-gateway-server:0.3.0
volumes:
- ./.env:/app/.env
ports:
Expand Down
5 changes: 5 additions & 0 deletions gateway/common/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const (
TENANT = "tenant"
QUEUE = "queue"
STAGE = "stage"
RATE_LIMIT = "rateLimit"
)

var (
Expand All @@ -30,4 +31,8 @@ var (
Help: "Shows how much the proxy process is adding to request",
Buckets: prometheus.ExponentialBucketsRange(float64(10 * time.Millisecond), float64(20 * time.Second), 10),
}, []string{STAGE})
RateLimitGauge = promauto.NewGaugeVec(prometheus.GaugeOpts{
Name: "gateway_rate_limit_hit",
Help: "Shows rate limits hit on a gauge, resets to 0 when resolved",
}, []string{APP, TENANT, RATE_LIMIT})
)
12 changes: 7 additions & 5 deletions gateway/common/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import (
"time"
)

// TODO make it "pluggable" so different types of tasks can operate off queue

type Runnable interface {
error
Run()
Expand Down Expand Up @@ -57,7 +55,6 @@ func GetTaskQueue() *TaskQueue {
return qInst
}

// TODO include workers to clear out error channel
func (q *TaskQueue) SetupWorkers() {
numWorkers := GetConfigInt(NUM_WORKERS)
for i := 0; i < numWorkers; i++ {
Expand Down Expand Up @@ -117,7 +114,6 @@ func worker(q *TaskQueue) {
}
}

// TODO do more than log
func errWorker(q *TaskQueue) {
for err := range q.errors {
log.Error("error encountered", "err", err)
Expand All @@ -129,7 +125,6 @@ func delayWorker(q *TaskQueue) {
for i:=len(q.delayed); i>0; i-- {
task := <- q.delayed
if q.closed {
// TODO log delayed tasks details for cleanup
q.ReportError(errors.New("Shutting down"))
} else if task.Ready() {
q.Add(task)
Expand All @@ -141,6 +136,13 @@ func delayWorker(q *TaskQueue) {
time.Sleep(1 * time.Second)
}

func NewSimpleTask(run func()) *SimpleTask {
return &SimpleTask{
run: run,
runtime: time.Now(),
}
}

// SimpleTask can be extended if needed
func (t *SimpleTask) Run() {
t.run()
Expand Down
2 changes: 1 addition & 1 deletion gateway/common/tasks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestTask(t *testing.T) {
}
}

// TODO use this test to figure out the right blend
// this test can be tweaked to figure out the right blend
// combining is meant to compact multiple updates to redis into one
// rather than incr + incr + incr just do incrBy 3
// This costs a bit of compute and complicates the job queue
Expand Down
Loading

0 comments on commit 1ca0b49

Please sign in to comment.