Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support redis pool config from file #325

Merged
12 commits merged into from
Mar 8, 2022
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
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ RUN apk add --no-cache ca-certificates

# Copy the binary to the production image from the builder stage.
COPY --from=builder /src/open-saves/build/server /server
COPY --from=builder /src/open-saves/configs /configs

# Run the web service on container startup.
CMD ["/server"]
57 changes: 7 additions & 50 deletions cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,71 +16,28 @@ package main

import (
"context"
"flag"
"fmt"
"os"
"strconv"

"github.com/googleforgames/open-saves/internal/app/server"
"github.com/googleforgames/open-saves/internal/pkg/cmd"
"github.com/googleforgames/open-saves/internal/pkg/config"
log "github.com/sirupsen/logrus"
"github.com/spf13/viper"
)

func main() {
defaultPort := cmd.GetEnvVarUInt("OPEN_SAVES_PORT", 6000)
defaultCloud := cmd.GetEnvVarString("OPEN_SAVES_CLOUD", "gcp")
defaultBucket := cmd.GetEnvVarString("OPEN_SAVES_BUCKET", "")
defaultProject := cmd.GetEnvVarString("OPEN_SAVES_PROJECT", "")
defaultCache := cmd.GetEnvVarString("OPEN_SAVES_CACHE", "localhost:6379")
defaultLogLevel := cmd.GetEnvVarString("LOG_LEVEL", "info")

var (
port = flag.Uint("port", uint(defaultPort), "The port number to run Open Saves on")
cloud = flag.String("cloud", defaultCloud, "The public cloud provider you wish to run Open Saves on")
bucket = flag.String("bucket", defaultBucket, "The bucket which will hold Open Saves blobs")
project = flag.String("project", defaultProject, "The GCP project ID to use for Datastore")
cache = flag.String("cache", defaultCache, "The address of the cache store instance")
logLevel = flag.String("log", defaultLogLevel, "The level to log messages at")
)

flag.Parse()
if *cloud == "" {
log.Fatal("missing -cloud argument for cloud provider")
}
if *bucket == "" {
log.Fatal("missing -bucket argument for storing blobs")
}
if *project == "" {
log.Fatal("missing -project argument")
}
if *cache == "" {
log.Fatal("missing -cache argument for cache store")
configPath := cmd.GetEnvVarString("OPEN_SAVES_CONFIG", "/configs/")
cfg, err := config.Load(configPath)
if err != nil {
panic(fmt.Errorf("error loading config file: %w", err))
}

ll, err := log.ParseLevel(*logLevel)
ll, err := log.ParseLevel(viper.GetString(config.LogLevel))
if err != nil {
ll = log.InfoLevel
}
log.SetLevel(ll)
log.Infof("Log level is: %s", ll.String())

cfg := &server.Config{
Address: fmt.Sprintf(":%d", *port),
Cloud: *cloud,
Bucket: *bucket,
Project: *project,
Cache: *cache,
}

// Cloud Run environment populates the PORT env var, so check for it here.
if p := os.Getenv("PORT"); p != "" {
p, err := strconv.ParseUint(p, 10, 64)
if err != nil {
log.Fatal("failed to parse PORT env variable, make sure it is of type uint")
}
cfg.Address = fmt.Sprintf(":%d", p)
}

ctx := context.Background()
if err := server.Run(ctx, "tcp", cfg); err != nil {
log.Fatalf("got error starting server: %v", err)
Expand Down
11 changes: 11 additions & 0 deletions configs/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
open_saves_port: 6000
open_saves_cloud: "gcp"
open_saves_bucket: ""
open_saves_project: ""
log_level: "info"

redis_address: "localhost:6379"
redis_pool_maxIdle: 500
redis_pool_maxActive: 10000
redis_pool_idleTimeout: 0
redis_pool_wait: false
43 changes: 29 additions & 14 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,54 @@ go 1.17
require (
cloud.google.com/go/datastore v1.5.0
github.com/golang/mock v1.6.0
github.com/golang/protobuf v1.5.2
github.com/gomodule/redigo v1.8.5
github.com/google/uuid v1.2.0
github.com/sirupsen/logrus v1.8.1
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.10.1
github.com/stretchr/testify v1.7.0
github.com/vmihailenco/msgpack/v5 v5.3.4
gocloud.dev v0.23.0
google.golang.org/api v0.48.0
google.golang.org/grpc v1.38.0
google.golang.org/api v0.63.0
google.golang.org/grpc v1.43.0
google.golang.org/protobuf v1.27.1
)

require (
cloud.google.com/go v0.84.0 // indirect
cloud.google.com/go v0.99.0 // indirect
cloud.google.com/go/storage v1.15.0 // indirect
github.com/census-instrumentation/opencensus-proto v0.3.0 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/cncf/udpa/go v0.0.0-20210930031921-04548b0d99d4 // indirect
github.com/cncf/xds/go v0.0.0-20211130200136-a8f946100490 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/envoyproxy/go-control-plane v0.10.1 // indirect
github.com/envoyproxy/protoc-gen-validate v0.6.2 // indirect
github.com/fsnotify/fsnotify v1.5.1 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/go-cmp v0.5.6 // indirect
github.com/google/wire v0.5.0 // indirect
github.com/googleapis/gax-go/v2 v2.0.5 // indirect
github.com/jstemmer/go-junit-report v0.9.1 // indirect
github.com/googleapis/gax-go/v2 v2.1.1 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/magiconair/properties v1.8.5 // indirect
github.com/mitchellh/mapstructure v1.4.3 // indirect
github.com/pelletier/go-toml v1.9.4 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/spf13/afero v1.6.0 // indirect
github.com/spf13/cast v1.4.1 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/subosito/gotenv v1.2.0 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
go.opencensus.io v0.23.0 // indirect
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 // indirect
golang.org/x/mod v0.4.2 // indirect
golang.org/x/net v0.0.0-20210614182718-04defd469f4e // indirect
golang.org/x/oauth2 v0.0.0-20210615190721-d04028783cf1 // indirect
golang.org/x/sys v0.0.0-20210616094352-59db8d763f22 // indirect
golang.org/x/text v0.3.6 // indirect
golang.org/x/tools v0.1.3 // indirect
golang.org/x/net v0.0.0-20210813160813-60bc85c4be6d // indirect
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 // indirect
golang.org/x/sys v0.0.0-20211210111614-af8b64212486 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20210614182748-5b3b54cad159 // indirect
google.golang.org/genproto v0.0.0-20211208223120-3a66f561d7aa // indirect
gopkg.in/ini.v1 v1.66.2 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
)
Loading