Skip to content

Commit

Permalink
Merge pull request #273 from porters-xyz/develop
Browse files Browse the repository at this point in the history
v0.5
  • Loading branch information
wtfsayo authored May 21, 2024
2 parents d56769c + 854be50 commit 6d203f7
Show file tree
Hide file tree
Showing 104 changed files with 2,094 additions and 1,427 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/docs-staging.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Fly Deploy Staging Docs
on:
push:
branches:
- develop
paths:
- "docs/**"
jobs:
deploy:
name: Deploy Staging Frontend
runs-on: ubuntu-latest
concurrency: deploy-group
steps:
- uses: actions/checkout@v4
- uses: superfly/flyctl-actions/setup-flyctl@master
- run: flyctl deploy -c fly.toml --remote-only
env:
FLY_API_TOKEN: ${{ secrets.FLY_STAGING_API_TOKEN }}
4 changes: 1 addition & 3 deletions docs/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
FROM node:21-alpine AS build
FROM node:18 AS build

ENV NEXT_TELEMETRY_DISABLED 1


RUN apk add --no-cache libc6-compat
WORKDIR /app
COPY . .
RUN yarn
Expand Down
5 changes: 1 addition & 4 deletions docs/fly.prod.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@
app = 'porters-docs'
primary_region = 'sea'

[build]
build-target = 'production'

[http_service]
internal_port = 3005
internal_port = 3000
auto_stop_machines = true
auto_start_machines = true
min_machines_running = 0
Expand Down
4 changes: 1 addition & 3 deletions docs/fly.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@
app = 'porters-docs-staging'
primary_region = 'sea'

[build]
build-target = 'production'

[http_service]
internal_port = 3005
internal_port = 3000
auto_stop_machines = true
auto_start_machines = true
min_machines_running = 0
Expand Down
2 changes: 1 addition & 1 deletion docs/theme.config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const config: DocsThemeConfig = {
docsRepositoryBase:
"https://github.com/porters-xyz/gateway-demo/tree/master/docs",
footer: {
text: "Open Gateway Documentation",
text: "Porters RPC Gateway Documentation",
},
};

Expand Down
3 changes: 2 additions & 1 deletion gateway/common/combiner.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package common

import (
log "log/slog"
)

// rather than be too chatty, combine multiple tasks into one
Expand Down Expand Up @@ -55,6 +56,6 @@ func (c *SimpleCombiner) gen() int { return c.genVal }
// Simple version only logs, need to extend to push to redis, etc
func (c *SimpleCombiner) runner() func() {
return func() {
//log.Printf("combined %s to %d", c.keyVal, c.intVal)
log.Debug("combining", "key", c.keyVal, "amt", c.intVal)
}
}
19 changes: 14 additions & 5 deletions gateway/common/config.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package common

import (
"fmt"
"log"
log "log/slog"
"os"
"strconv"
"sync"
Expand All @@ -21,7 +20,7 @@ const (
REDIS_ADDR = "REDIS_ADDR"
REDIS_USER = "REDIS_USER"
REDIS_PASSWORD = "REDIS_PASSWORD"

INSTRUMENT_ENABLED = "ENABLE_INSTRUMENT"
)

// This may evolve to include config outside env, or use .env file for
Expand All @@ -43,6 +42,7 @@ func setupConfig() *Config {
config.defaults[NUM_WORKERS] = "10"
config.defaults[HOST] = "localhost"
config.defaults[PORT] = "9000"
config.defaults[INSTRUMENT_ENABLED] = "false"
})
return config
}
Expand All @@ -57,7 +57,7 @@ func GetConfig(key string) string {
if ok {
return defaultval
} else {
log.Println(fmt.Sprintf("config not set for %s, no default", key))
log.Warn("config not set no default", "key", key)
return ""
}
}
Expand All @@ -67,8 +67,17 @@ func GetConfigInt(key string) int {
configval := GetConfig(key)
intval, err := strconv.Atoi(configval)
if err != nil {
log.Println("Error parsing config", err)
log.Error("Error parsing config", "err", err)
intval = -1
}
return intval
}

func Enabled(key string) bool {
configval := GetConfig(key)
boolval, err := strconv.ParseBool(configval)
if err != nil {
boolval = false
}
return boolval
}
19 changes: 19 additions & 0 deletions gateway/common/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,21 @@ package common

import (
"context"
"time"
)

const (
INSTRUMENT string = "INSTRUMENT_START"
)

type Contextable interface {
ContextKey() string
}

type Instrument struct {
Timestamp time.Time
}

func UpdateContext(ctx context.Context, entity Contextable) context.Context {
return context.WithValue(ctx, entity.ContextKey(), entity)
}
Expand All @@ -20,3 +29,13 @@ func FromContext(ctx context.Context, contextkey string) (any, bool) {
return nil, false
}
}

func StartInstrument() *Instrument {
return &Instrument{
Timestamp: time.Now(),
}
}

func (i *Instrument) ContextKey() string {
return INSTRUMENT
}
7 changes: 7 additions & 0 deletions gateway/common/prometheus.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package common

import (
"time"

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
Expand All @@ -12,6 +13,7 @@ const (
STATUS = "status"
TENANT = "tenant"
QUEUE = "queue"
STAGE = "stage"
)

var (
Expand All @@ -23,4 +25,9 @@ var (
Name: "gateway_job_queue",
Help: "If this grows too big it may effect performance, should scale up",
}, []string{QUEUE})
LatencyHistogram = promauto.NewHistogramVec(prometheus.HistogramOpts{
Name: "gateway_added_latency",
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})
)
8 changes: 4 additions & 4 deletions gateway/common/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package common

import (
"errors"
"log"
log "log/slog"
"sync"
"time"
)
Expand Down Expand Up @@ -82,7 +82,7 @@ func (q *TaskQueue) CloseQueue() {
return
}
case <-time.After(shutdownTime):
log.Println("workers not finished, work may be lost")
log.Warn("workers not finished, work may be lost")
return
}
}
Expand Down Expand Up @@ -111,7 +111,7 @@ func worker(q *TaskQueue) {
case Runnable:
task.Run()
default:
log.Println("unspecified task", task, t)
log.Debug("unspecified task", "task", task, "type", t)
}
JobGauge.WithLabelValues("task").Set(float64(len(q.tasks)))
}
Expand All @@ -120,7 +120,7 @@ func worker(q *TaskQueue) {
// TODO do more than log
func errWorker(q *TaskQueue) {
for err := range q.errors {
log.Println("error encountered", err)
log.Error("error encountered", "err", err)
JobGauge.WithLabelValues("error").Dec()
}
}
Expand Down
Loading

0 comments on commit 6d203f7

Please sign in to comment.