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

New reva config #4015

Merged
merged 76 commits into from
Jul 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
17fea9e
add new config
gmgigi96 Jun 13, 2023
f3b466e
add helper functions to parse template string
gmgigi96 Jun 13, 2023
bb3d3fe
add helper functions to get values from a key expression
gmgigi96 Jun 13, 2023
817a102
add grpc config
gmgigi96 Jun 13, 2023
6012171
add http config and middlewares
gmgigi96 Jun 14, 2023
ec98660
add serverless config
gmgigi96 Jun 14, 2023
d42cd6b
improvements in tests
gmgigi96 Jun 14, 2023
9d67abf
add rest of config
gmgigi96 Jun 14, 2023
8297b82
do not reference pointers on lookup
gmgigi96 Jun 14, 2023
b2935c6
skip unexported field on lookup
gmgigi96 Jun 14, 2023
abead30
add templates
gmgigi96 Jun 14, 2023
83d2c26
fix typo
gmgigi96 Jun 14, 2023
f518f09
add tests config + bugfixes
gmgigi96 Jun 15, 2023
cfd3ffd
add tests for template
gmgigi96 Jun 15, 2023
9729c8d
fix
gmgigi96 Jun 15, 2023
2f42986
max cpu is int
gmgigi96 Jun 15, 2023
a909cf8
add support for squashed structs
gmgigi96 Jun 15, 2023
0fa1dcb
dump config
gmgigi96 Jun 15, 2023
2f7ce11
add comments
gmgigi96 Jun 15, 2023
2da6f15
expose Lookup method from config
gmgigi96 Jun 16, 2023
98ad8e4
refactor
gmgigi96 Jun 16, 2023
48bbba0
add multi config lookuper
gmgigi96 Jun 16, 2023
43681f2
moved internal to pkg dir
gmgigi96 Jun 16, 2023
525e6b7
add TakeFirst func
gmgigi96 Jun 16, 2023
8a472a6
revert max_cpu config to string
gmgigi96 Jun 16, 2023
cbf32ac
simplified reva http server
gmgigi96 Jun 19, 2023
c3817c5
simplifying grpc server
gmgigi96 Jun 19, 2023
1369efb
grace with multiple services and addresses
gmgigi96 Jun 22, 2023
1b190f6
set servers deps
gmgigi96 Jun 22, 2023
e25b2da
rewritten runtime with new config
gmgigi96 Jun 23, 2023
2b4e28d
use new reva pkg from runtime in main
gmgigi96 Jun 26, 2023
dff18a3
simplified creation of grpc service implementations
gmgigi96 Jun 26, 2023
e0cf040
refactoring
gmgigi96 Jun 26, 2023
2a08e55
cleanup code
gmgigi96 Jun 26, 2023
11589e0
set logger to http and grpc services
gmgigi96 Jun 26, 2023
0abaaf3
set services in grpc and http servers
gmgigi96 Jun 26, 2023
8164c08
initialize grpc interceptors
gmgigi96 Jun 26, 2023
91310b8
set middlewares to http services
gmgigi96 Jun 26, 2023
e374cb4
removed unused code
gmgigi96 Jun 26, 2023
f5fdb62
set label to services
gmgigi96 Jun 26, 2023
1e2b7cc
add header
gmgigi96 Jun 26, 2023
e802a5d
add serverless
gmgigi96 Jun 27, 2023
c74d8e4
Fix linter
gmgigi96 Jun 27, 2023
d3c487e
fix unit tests
gmgigi96 Jun 27, 2023
003feab
add defaults
gmgigi96 Jun 27, 2023
84846c2
log errors
gmgigi96 Jun 27, 2023
28958b1
fix default config for http and grpc
gmgigi96 Jun 27, 2023
f83e10e
bug fixes
gmgigi96 Jun 27, 2023
0791420
cleanup serverless
gmgigi96 Jun 28, 2023
8fc6e08
fixes
gmgigi96 Jun 28, 2023
42bd7c6
init shared config after applying templates
gmgigi96 Jun 28, 2023
aaa17ed
fix port assignement when multiple services listen to the same port
gmgigi96 Jun 28, 2023
db6a029
do not bail out for gotemplates in config
gmgigi96 Jun 28, 2023
6f14042
allow shared config to have templates
gmgigi96 Jun 28, 2023
4234cbd
fix pid file for dev-dir option
gmgigi96 Jun 28, 2023
212e3a5
add useful logs
gmgigi96 Jun 28, 2023
5df025d
fixes with multiple drivers of same service
gmgigi96 Jun 28, 2023
e59b690
clean always pid file on error
gmgigi96 Jun 28, 2023
e438caa
support grpc and http services with same name
gmgigi96 Jun 28, 2023
2c02e04
fix unit tests
gmgigi96 Jun 28, 2023
eafcb2c
replace template as substring
gmgigi96 Jun 28, 2023
fd04c3d
get ports from addresses in the template config
gmgigi96 Jun 29, 2023
3cc82f6
clearer error on lookup
gmgigi96 Jun 29, 2023
beb8f42
fix port addressing from address in driver config
gmgigi96 Jun 29, 2023
494d995
fixes when template is in shared config
gmgigi96 Jun 29, 2023
be4a00d
fix instantiation of middlewares
gmgigi96 Jun 29, 2023
5c7cad1
add comments
gmgigi96 Jun 29, 2023
896d393
fix invalid templates
gmgigi96 Jun 30, 2023
bbb694e
fix linter
gmgigi96 Jun 30, 2023
38fdb58
add changelog
gmgigi96 Jun 30, 2023
1a3869c
fix typo
gmgigi96 Jun 30, 2023
09b0aef
skip no config templates
gmgigi96 Jun 30, 2023
0bf5c7b
improved logging for http services
gmgigi96 Jun 30, 2023
aae8e93
enable tracing from config
gmgigi96 Jun 30, 2023
f13ae92
fix unit tests
gmgigi96 Jun 30, 2023
e4fcad3
fix restart of revad process
gmgigi96 Jun 30, 2023
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
11 changes: 11 additions & 0 deletions changelog/unreleased/new-config.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Enhancement: New configuration

Allow multiple driverts of the same service to be in the
same toml config. Add a `vars` section to contain common
parameters addressable using templates in the configuration
of the different drivers. Support templating to reference
values of other parameters in the configuration.
Assign random ports to services where the address is not
specified.

https://github.com/cs3org/reva/pull/4015
120 changes: 96 additions & 24 deletions cmd/revad/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,22 @@ package main
import (
"flag"
"fmt"
"io"
"io/fs"
"os"
"path"
"regexp"
"sync"
"syscall"

"github.com/cs3org/reva/cmd/revad/internal/config"
"github.com/cs3org/reva/cmd/revad/internal/grace"
"github.com/cs3org/reva/cmd/revad/pkg/config"
"github.com/cs3org/reva/cmd/revad/pkg/grace"
"github.com/cs3org/reva/cmd/revad/runtime"
"github.com/cs3org/reva/pkg/logger"
"github.com/cs3org/reva/pkg/sysinfo"
"github.com/google/uuid"
"github.com/pkg/errors"
"github.com/rs/zerolog"
)

var (
Expand All @@ -41,13 +45,16 @@ var (
signalFlag = flag.String("s", "", "send signal to a master process: stop, quit, reload")
configFlag = flag.String("c", "/etc/revad/revad.toml", "set configuration file")
pidFlag = flag.String("p", "", "pid file. If empty defaults to a random file in the OS temporary directory")
logFlag = flag.String("log", "", "log messages with the given severity or above. One of: [trace, debug, info, warn, error, fatal, panic]")
dirFlag = flag.String("dev-dir", "", "runs any toml file in the specified directory. Intended for development use only")

// Compile time variables initialized with gcc flags.
gitCommit, buildDate, version, goVersion string
)

var (
revaProcs []*runtime.Reva
)

func main() {
flag.Parse()

Expand Down Expand Up @@ -126,15 +133,15 @@ func handleSignalFlag() {

// kill process with signal
if err := process.Signal(signal); err != nil {
fmt.Fprintf(os.Stderr, "error signaling process %d with signal %s\n", process.Pid, signal)
fmt.Fprintf(os.Stderr, "error signaling process %d with signal %s: %v\n", process.Pid, signal, err)
os.Exit(1)
}

os.Exit(0)
}
}

func getConfigs() ([]map[string]interface{}, error) {
func getConfigs() ([]*config.Config, error) {
var confs []string
// give priority to read from dev-dir
if *dirFlag != "" {
Expand Down Expand Up @@ -186,58 +193,123 @@ func getConfigsFromDir(dir string) (confs []string, err error) {
return
}

func readConfigs(files []string) ([]map[string]interface{}, error) {
confs := make([]map[string]interface{}, 0, len(files))
func readConfigs(files []string) ([]*config.Config, error) {
confs := make([]*config.Config, 0, len(files))
for _, conf := range files {
fd, err := os.Open(conf)
if err != nil {
return nil, err
}
defer fd.Close()

v, err := config.Read(fd)
c, err := config.Load(fd)
if err != nil {
return nil, err
}
confs = append(confs, v)
confs = append(confs, c)
}
return confs, nil
}

func runConfigs(confs []map[string]interface{}) {
func runConfigs(confs []*config.Config) {
pidfile := getPidfile()
if len(confs) == 1 {
runSingle(confs[0])
runSingle(confs[0], pidfile)
return
}

runMultiple(confs)
}

func runSingle(conf map[string]interface{}) {
if *pidFlag == "" {
*pidFlag = getPidfile()
}

runtime.Run(conf, *pidFlag, *logFlag)
func registerReva(r *runtime.Reva) {
revaProcs = append(revaProcs, r)
}

func getPidfile() string {
uuid := uuid.New().String()
name := fmt.Sprintf("revad-%s.pid", uuid)
func runSingle(conf *config.Config, pidfile string) {
log := initLogger(conf.Log)
reva, err := runtime.New(conf,
runtime.WithPidFile(pidfile),
runtime.WithLogger(log),
)
if err != nil {
abort(log, "error creating reva runtime: %v", err)
}
registerReva(reva)
if err := reva.Start(); err != nil {
abort(log, "error starting reva: %v", err)
}
}

return path.Join(os.TempDir(), name)
func abort(log *zerolog.Logger, format string, a ...any) {
log.Fatal().Msgf(format, a...)
}

func runMultiple(confs []map[string]interface{}) {
func runMultiple(confs []*config.Config) {
var wg sync.WaitGroup

for _, conf := range confs {
wg.Add(1)
pidfile := getPidfile()
go func(wg *sync.WaitGroup, conf map[string]interface{}) {
go func(wg *sync.WaitGroup, conf *config.Config) {
defer wg.Done()
runtime.Run(conf, pidfile, *logFlag)
runSingle(conf, pidfile)
}(&wg, conf)
}
wg.Wait()
os.Exit(0)
}

func getPidfile() string {
uuid := uuid.New().String()
name := fmt.Sprintf("revad-%s.pid", uuid)

return path.Join(os.TempDir(), name)
}

func initLogger(conf *config.Log) *zerolog.Logger {
log, err := newLogger(conf)
if err != nil {
fmt.Fprintf(os.Stderr, "error creating logger: %v", err)
os.Exit(1)
}
return log
}

func newLogger(conf *config.Log) (*zerolog.Logger, error) {
// TODO(labkode): use debug level rather than info as default until reaching a stable version.
// Helps having smaller development files.
if conf.Level == "" {
conf.Level = zerolog.DebugLevel.String()
}

var opts []logger.Option
opts = append(opts, logger.WithLevel(conf.Level))

w, err := getWriter(conf.Output)
if err != nil {
return nil, err
}

opts = append(opts, logger.WithWriter(w, logger.Mode(conf.Mode)))

l := logger.New(opts...)
sub := l.With().Int("pid", os.Getpid()).Logger()
return &sub, nil
}

func getWriter(out string) (io.Writer, error) {
if out == "stderr" || out == "" {
return os.Stderr, nil
}

if out == "stdout" {
return os.Stdout, nil
}

fd, err := os.OpenFile(out, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
return nil, errors.Wrap(err, "error creating log file: "+out)
}

return fd, nil
}
Loading