Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion transports/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,15 @@ ARG ENV_PATH
ARG PORT
ARG POOL_SIZE
ARG DROP_EXCESS_REQUESTS
ARG PLUGINS
ARG MAXIM_LOG_REPO_ID

# Set default values if args are not provided
ENV APP_PORT=${PORT:-8080}
ENV APP_POOL_SIZE=${POOL_SIZE:-300}
ENV APP_DROP_EXCESS_REQUESTS=${DROP_EXCESS_REQUESTS:-false}
ENV APP_PLUGINS=${PLUGINS:-""}
ENV APP_MAXIM_LOG_REPO_ID=${MAXIM_LOG_REPO_ID:-""}

# Copy the config and environment files into the image
COPY ${CONFIG_PATH} /app/config/config.json
Expand All @@ -51,7 +55,7 @@ RUN echo '#!/bin/sh' > /app/entrypoint.sh && \
echo 'if [ ! -f /app/config/config.json ]; then echo "Missing config.json"; exit 1; fi' >> /app/entrypoint.sh && \
echo 'if [ ! -f /app/config/.env ]; then echo "Missing .env"; exit 1; fi' >> /app/entrypoint.sh && \
echo 'if [ ! -f /app/main ]; then echo "Missing main binary"; exit 1; fi' >> /app/entrypoint.sh && \
echo 'exec /app/main -config /app/config/config.json -env /app/config/.env -port "$APP_PORT" -pool-size "$APP_POOL_SIZE" -drop-excess-requests "$APP_DROP_EXCESS_REQUESTS"' >> /app/entrypoint.sh && \
echo 'exec /app/main -config /app/config/config.json -env /app/config/.env -port "$APP_PORT" -pool-size "$APP_POOL_SIZE" -drop-excess-requests "$APP_DROP_EXCESS_REQUESTS" -plugins "$APP_PLUGINS" -maxim-log-repo-id "$APP_MAXIM_LOG_REPO_ID"' >> /app/entrypoint.sh && \
chmod +x /app/entrypoint.sh

# Expose the port defined by argument
Expand Down
37 changes: 35 additions & 2 deletions transports/bifrost-http/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ import (
"flag"
"fmt"
"log"
"os"
"strings"

"github.com/fasthttp/router"
bifrost "github.com/maximhq/bifrost/core"
schemas "github.com/maximhq/bifrost/core/schemas"
"github.com/maximhq/bifrost/plugins"
"github.com/maximhq/bifrost/transports/bifrost-http/integrations"
"github.com/maximhq/bifrost/transports/bifrost-http/integrations/genai"
"github.com/maximhq/bifrost/transports/bifrost-http/lib"
Expand All @@ -45,6 +47,8 @@ var (
port string // Port to run the server on
configPath string // Path to the config file
envPath string // Path to the .env file
pluginsToLoad []string // Path to the plugins
maximLogRepoId string // ID of the Maxim log repo
prometheusLabels []string // Labels to add to Prometheus metrics (optional)
)

Expand All @@ -56,16 +60,21 @@ var (
// - env: Path to .env file (required)
// - drop-excess-requests: Whether to drop excess requests
func init() {
pluginString := ""
var prometheusLabelsString string

flag.IntVar(&initialPoolSize, "pool-size", 300, "Initial pool size for Bifrost")
flag.StringVar(&port, "port", "8080", "Port to run the server on")
flag.StringVar(&configPath, "config", "", "Path to the config file")
flag.StringVar(&envPath, "env", "", "Path to the .env file")
flag.BoolVar(&dropExcessRequests, "drop-excess-requests", false, "Drop excess requests")
flag.StringVar(&pluginString, "plugins", "", "Comma separated list of plugins to load")
flag.StringVar(&maximLogRepoId, "maxim-log-repo-id", "", "ID of the Maxim log repo")
flag.StringVar(&prometheusLabelsString, "prometheus-labels", "", "Labels to add to Prometheus metrics")
flag.Parse()

pluginsToLoad = strings.Split(pluginString, ",")

if configPath == "" {
log.Fatalf("config path is required")
}
Expand Down Expand Up @@ -136,14 +145,38 @@ func main() {
log.Printf("warning: failed to read environment variables: %v", err)
}

// Instantiate the Prometheus plugin
loadedPlugins := []schemas.Plugin{}

for _, plugin := range pluginsToLoad {
switch strings.ToLower(plugin) {
case "maxim":
if maximLogRepoId == "" {
log.Println("warning: maxim log repo id is required to initialize maxim plugin")
continue
}
if os.Getenv("MAXIM_API_KEY") == "" {
log.Println("warning: maxim api key is required in environment variable MAXIM_API_KEY to initialize maxim plugin")
continue
}

maximPlugin, err := plugins.NewMaximLoggerPlugin(os.Getenv("MAXIM_API_KEY"), maximLogRepoId)
if err != nil {
log.Printf("warning: failed to initialize maxim plugin: %v", err)
continue
}

loadedPlugins = append(loadedPlugins, maximPlugin)
}
}

promPlugin := tracking.NewPrometheusPlugin()
loadedPlugins = append(loadedPlugins, promPlugin)

client, err := bifrost.Init(schemas.BifrostConfig{
Account: account,
InitialPoolSize: initialPoolSize,
DropExcessRequests: dropExcessRequests,
Plugins: []schemas.Plugin{promPlugin},
Plugins: loadedPlugins,
})
if err != nil {
log.Fatalf("failed to initialize bifrost: %v", err)
Expand Down
2 changes: 2 additions & 0 deletions transports/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
github.com/fasthttp/router v1.5.4
github.com/joho/godotenv v1.5.1
github.com/maximhq/bifrost/core v1.0.5
github.com/maximhq/bifrost/plugins v1.0.1
github.com/prometheus/client_golang v1.22.0
github.com/valyala/fasthttp v1.60.0
google.golang.org/genai v1.4.0
Expand Down Expand Up @@ -41,6 +42,7 @@ require (
github.com/googleapis/gax-go/v2 v2.14.1 // indirect
github.com/gorilla/websocket v1.5.3 // indirect
github.com/klauspost/compress v1.18.0 // indirect
github.com/maximhq/maxim-go v0.1.1 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.62.0 // indirect
Expand Down
4 changes: 4 additions & 0 deletions transports/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
github.com/maximhq/bifrost/core v1.0.5 h1:JopRRuV2zylwisj+cBonIpB/Dw4p8gEQoW3hrKsPyI8=
github.com/maximhq/bifrost/core v1.0.5/go.mod h1:nL2tc1SVJ7EAKxUb1G1yS4nO46ZsCdm1qC3Oc78oYIU=
github.com/maximhq/bifrost/plugins v1.0.1 h1:wu+kEwdEFvnhEiNLsrFHpxVdd/dJ2Uvkk3el3DkFoWc=
github.com/maximhq/bifrost/plugins v1.0.1/go.mod h1:c5L95RCOHGAKGAl9up03/00DHqjdxVG+3MdIUlAnzYM=
github.com/maximhq/maxim-go v0.1.1 h1:69uUQjjDPmUGcKg/M4/3AO0fbD+70Agt66pH/UCsI5M=
github.com/maximhq/maxim-go v0.1.1/go.mod h1:0+UTWM7UZwNNE5VnljLtr/vpRGtYP8r/2q9WDwlLWFw=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
Expand Down